Alien-TinyCCx
view release on metacpan or search on metacpan
src/tests/tcctest.c view on Meta::CPAN
#include TCCLIB_INC1.TCCLIB_INC2
#include TCCLIB_INC1.h>
/* gcc 3.2 does not accept that (bug ?) */
//#include TCCLIB_INC3 ".h"
#include <tcclib.h>
#include "tcclib.h"
void intdiv_test();
void string_test();
void expr_test();
void macro_test();
void recursive_macro_test();
void scope_test();
void forward_test();
void funcptr_test();
void loop_test();
void switch_test();
void goto_test();
void enum_test();
void typedef_test();
void struct_test();
void array_test();
void expr_ptr_test();
void bool_test();
void expr2_test();
void constant_expr_test();
void expr_cmp_test();
void char_short_test();
void init_test(void);
void compound_literal_test(void);
int kr_test();
void struct_assign_test(void);
void cast_test(void);
void bitfield_test(void);
void c99_bool_test(void);
void float_test(void);
void longlong_test(void);
void manyarg_test(void);
void stdarg_test(void);
void whitespace_test(void);
void relocation_test(void);
void old_style_function(void);
void alloca_test(void);
void c99_vla_test(int size1, int size2);
void sizeof_test(void);
void typeof_test(void);
void local_label_test(void);
void statement_expr_test(void);
void asm_test(void);
void builtin_test(void);
void weak_test(void);
void global_data_test(void);
void cmp_comparison_test(void);
void math_cmp_test(void);
void callsave_test(void);
void builtin_frame_address_test(void);
int fib(int n);
void num(int n);
void forward_ref(void);
int isid(int c);
/* Line joining happens before tokenization, so the following
must be parsed as ellipsis. */
void funny_line_continuation (int, ..\
. );
char via_volatile (char);
#define A 2
#define N 1234 + A
#define pf printf
#define M1(a, b) (a) + (b)
#define str\
(s) # s
#define glue(a, b) a ## b
#define xglue(a, b) glue(a, b)
#define HIGHLOW "hello"
#define LOW LOW ", world"
static int onetwothree = 123;
#define onetwothree4 onetwothree
#define onetwothree xglue(onetwothree,4)
#define min(a, b) ((a) < (b) ? (a) : (b))
#ifdef C99_MACROS
#define dprintf(level,...) printf(__VA_ARGS__)
#endif
/* gcc vararg macros */
#define dprintf1(level, fmt, args...) printf(fmt, ## args)
#define MACRO_NOARGS()
#define AAA 3
#undef AAA
#define AAA 4
#if 1
#define B3 1
#elif 1
#define B3 2
#elif 0
#define B3 3
#else
#define B3 4
#endif
#define __INT64_C(c) c ## LL
#define INT64_MIN (-__INT64_C(9223372036854775807)-1)
int qq(int x)
{
return x + 40;
src/tests/tcctest.c view on Meta::CPAN
};
union union2 {
int w1;
int w2;
};
struct struct1 st1, st2;
int main(int argc, char **argv)
{
string_test();
expr_test();
macro_test();
recursive_macro_test();
scope_test();
forward_test();
funcptr_test();
loop_test();
switch_test();
goto_test();
enum_test();
typedef_test();
struct_test();
array_test();
expr_ptr_test();
bool_test();
expr2_test();
constant_expr_test();
expr_cmp_test();
char_short_test();
init_test();
compound_literal_test();
kr_test();
struct_assign_test();
cast_test();
bitfield_test();
c99_bool_test();
float_test();
longlong_test();
manyarg_test();
stdarg_test();
whitespace_test();
relocation_test();
old_style_function();
alloca_test();
c99_vla_test(5, 2);
sizeof_test();
typeof_test();
statement_expr_test();
local_label_test();
asm_test();
builtin_test();
#ifndef _WIN32
weak_test();
#endif
global_data_test();
cmp_comparison_test();
math_cmp_test();
callsave_test();
builtin_frame_address_test();
intdiv_test();
if (via_volatile (42) != 42)
printf ("via_volatile broken\n");
return 0;
}
int tab[3];
int tab2[3][2];
int g;
void f1(g)
{
printf("g1=%d\n", g);
}
void scope_test()
{
printf("scope:\n");
g = 2;
f1(1);
printf("g2=%d\n", g);
{
int g;
g = 3;
printf("g3=%d\n", g);
{
int g;
g = 4;
printf("g4=%d\n", g);
}
}
printf("g5=%d\n", g);
}
void array_test()
{
int i, j, a[4];
printf("array:\n");
printf("sizeof(a) = %d\n", sizeof(a));
printf("sizeof(\"a\") = %d\n", sizeof("a"));
#ifdef C99_MACROS
printf("sizeof(__func__) = %d\n", sizeof(__func__));
#endif
printf("sizeof tab %d\n", sizeof(tab));
printf("sizeof tab2 %d\n", sizeof tab2);
tab[0] = 1;
tab[1] = 2;
tab[2] = 3;
printf("%d %d %d\n", tab[0], tab[1], tab[2]);
for(i=0;i<3;i++)
for(j=0;j<2;j++)
tab2[i][j] = 10 * i + j;
for(i=0;i<3*2;i++) {
printf(" %3d", ((int *)tab2)[i]);
}
printf("\n");
printf("sizeof(size_t)=%d\n", sizeof(size_t));
printf("sizeof(ptrdiff_t)=%d\n", sizeof(ptrdiff_t));
src/tests/tcctest.c view on Meta::CPAN
bug (a,b,op,iop,1); \
if (a op b) \
bug (a,b,op,iop,2); \
if (a iop b) \
; \
else \
bug (a,b,op,iop,3); \
if ((a op b) || comp) \
bug (a,b,op,iop,4); \
if ((a iop b) || comp) \
; \
else \
bug (a,b,op,iop,5);
/* Equality tests. */
FCMP(nan, nan, ==, !=, 0);
FCMP(one, two, ==, !=, 0);
FCMP(one, one, !=, ==, 1);
/* Non-equality is a bit special. */
if (!fcompare (nan, nan, 1))
bug (nan, nan, !=, ==, 6);
/* Relational tests on numbers. */
FCMP(two, one, <, >=, 2);
FCMP(one, two, >=, <, 3);
FCMP(one, two, >, <=, 4);
FCMP(two, one, <=, >, 5);
/* Relational tests on NaNs. Note that the inverse op here is
always !=, there's no operator in C that is equivalent to !(a < b),
when NaNs are involved, same for the other relational ops. */
FCMP(nan, nan, <, !=, 2);
FCMP(nan, nan, >=, !=, 3);
FCMP(nan, nan, >, !=, 4);
FCMP(nan, nan, <=, !=, 5);
}
double get100 () { return 100.0; }
void callsave_test(void)
{
#if defined __i386__ || defined __x86_64__ || defined __arm__
int i, s; double *d; double t;
s = sizeof (double);
printf ("callsavetest: %d\n", s);
d = alloca (sizeof(double));
d[0] = 10.0;
/* x86-64 had a bug were the next call to get100 would evict
the lvalue &d[0] as VT_LLOCAL, and the reload would be done
in int type, not pointer type. When alloca returns a pointer
with the high 32 bit set (which is likely on x86-64) the access
generates a segfault. */
i = d[0] > get100 ();
printf ("%d\n", i);
#endif
}
void bfa3(ptrdiff_t str_offset)
{
printf("bfa3: %s\n", (char *)__builtin_frame_address(3) + str_offset);
}
void bfa2(ptrdiff_t str_offset)
{
printf("bfa2: %s\n", (char *)__builtin_frame_address(2) + str_offset);
bfa3(str_offset);
}
void bfa1(ptrdiff_t str_offset)
{
printf("bfa1: %s\n", (char *)__builtin_frame_address(1) + str_offset);
bfa2(str_offset);
}
void builtin_frame_address_test(void)
{
/* builtin_frame_address fails on ARM with gcc which make test3 fail */
#ifndef __arm__
char str[] = "__builtin_frame_address";
char *fp0 = __builtin_frame_address(0);
printf("str: %s\n", str);
bfa1(str-fp0);
#endif
}
char via_volatile (char i)
{
char volatile vi;
vi = i;
return vi;
}
( run in 0.560 second using v1.01-cache-2.11-cpan-df04353d9ac )