add clang
This commit is contained in:
parent
4715742aa8
commit
9a4b261179
890 changed files with 229323 additions and 20 deletions
18
05/tcc-final/tests/tests2/00_assignment.c
Normal file
18
05/tcc-final/tests/tests2/00_assignment.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
a = 42;
|
||||
printf("%d\n", a);
|
||||
|
||||
int b = 64;
|
||||
printf("%d\n", b);
|
||||
|
||||
int c = 12, d = 34;
|
||||
printf("%d, %d\n", c, d);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
3
05/tcc-final/tests/tests2/00_assignment.expect
Normal file
3
05/tcc-final/tests/tests2/00_assignment.expect
Normal file
|
@ -0,0 +1,3 @@
|
|||
42
|
||||
64
|
||||
12, 34
|
14
05/tcc-final/tests/tests2/01_comment.c
Normal file
14
05/tcc-final/tests/tests2/01_comment.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("Hello\n");
|
||||
printf("Hello\n"); /* this is a comment */ printf("Hello\n");
|
||||
printf("Hello\n");
|
||||
// this is also a comment sayhello();
|
||||
printf("Hello\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
5
05/tcc-final/tests/tests2/01_comment.expect
Normal file
5
05/tcc-final/tests/tests2/01_comment.expect
Normal file
|
@ -0,0 +1,5 @@
|
|||
Hello
|
||||
Hello
|
||||
Hello
|
||||
Hello
|
||||
Hello
|
18
05/tcc-final/tests/tests2/02_printf.c
Normal file
18
05/tcc-final/tests/tests2/02_printf.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("Hello world\n");
|
||||
|
||||
int Count;
|
||||
for (Count = -5; Count <= 5; Count++)
|
||||
printf("Count = %d\n", Count);
|
||||
|
||||
printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there");
|
||||
printf("Character 'A' is '%c'\n", 65);
|
||||
printf("Character 'a' is '%c'\n", 'a');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
15
05/tcc-final/tests/tests2/02_printf.expect
Normal file
15
05/tcc-final/tests/tests2/02_printf.expect
Normal file
|
@ -0,0 +1,15 @@
|
|||
Hello world
|
||||
Count = -5
|
||||
Count = -4
|
||||
Count = -3
|
||||
Count = -2
|
||||
Count = -1
|
||||
Count = 0
|
||||
Count = 1
|
||||
Count = 2
|
||||
Count = 3
|
||||
Count = 4
|
||||
Count = 5
|
||||
String 'hello', 'there' is 'hello', 'there'
|
||||
Character 'A' is 'A'
|
||||
Character 'a' is 'a'
|
38
05/tcc-final/tests/tests2/03_struct.c
Normal file
38
05/tcc-final/tests/tests2/03_struct.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
extern int printf(const char*, ...);
|
||||
|
||||
struct fred;
|
||||
|
||||
void fred$(struct fred* this)
|
||||
{
|
||||
printf("~fred()\n");
|
||||
}
|
||||
|
||||
struct __attribute__((__cleanup__(fred$))) fred
|
||||
{
|
||||
int boris;
|
||||
int natasha;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
struct fred __attribute__((__cleanup__(fred$))) bloggs;
|
||||
|
||||
bloggs.boris = 12;
|
||||
bloggs.natasha = 34;
|
||||
|
||||
printf("%d\n", bloggs.boris);
|
||||
printf("%d\n", bloggs.natasha);
|
||||
|
||||
struct fred jones[2];
|
||||
jones[0].boris = 12;
|
||||
jones[0].natasha = 34;
|
||||
jones[1].boris = 56;
|
||||
jones[1].natasha = 78;
|
||||
|
||||
printf("%d\n", jones[0].boris);
|
||||
printf("%d\n", jones[0].natasha);
|
||||
printf("%d\n", jones[1].boris);
|
||||
printf("%d\n", jones[1].natasha);
|
||||
|
||||
return 0;
|
||||
}
|
8
05/tcc-final/tests/tests2/03_struct.expect
Normal file
8
05/tcc-final/tests/tests2/03_struct.expect
Normal file
|
@ -0,0 +1,8 @@
|
|||
03_struct.c:14: warning: attribute '__cleanup__' ignored on type
|
||||
12
|
||||
34
|
||||
12
|
||||
34
|
||||
56
|
||||
78
|
||||
~fred()
|
15
05/tcc-final/tests/tests2/04_for.c
Normal file
15
05/tcc-final/tests/tests2/04_for.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Count;
|
||||
|
||||
for (Count = 1; Count <= 10; Count++)
|
||||
{
|
||||
printf("%d\n", Count);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
10
05/tcc-final/tests/tests2/04_for.expect
Normal file
10
05/tcc-final/tests/tests2/04_for.expect
Normal file
|
@ -0,0 +1,10 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
21
05/tcc-final/tests/tests2/05_array.c
Normal file
21
05/tcc-final/tests/tests2/05_array.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Count;
|
||||
int Array[10];
|
||||
|
||||
for (Count = 1; Count <= 10; Count++)
|
||||
{
|
||||
Array[Count-1] = Count * Count;
|
||||
}
|
||||
|
||||
for (Count = 0; Count < 10; Count++)
|
||||
{
|
||||
printf("%d\n", Array[Count]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
10
05/tcc-final/tests/tests2/05_array.expect
Normal file
10
05/tcc-final/tests/tests2/05_array.expect
Normal file
|
@ -0,0 +1,10 @@
|
|||
1
|
||||
4
|
||||
9
|
||||
16
|
||||
25
|
||||
36
|
||||
49
|
||||
64
|
||||
81
|
||||
100
|
29
05/tcc-final/tests/tests2/06_case.c
Normal file
29
05/tcc-final/tests/tests2/06_case.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Count;
|
||||
|
||||
for (Count = 0; Count < 4; Count++)
|
||||
{
|
||||
printf("%d\n", Count);
|
||||
switch (Count)
|
||||
{
|
||||
case 1:
|
||||
printf("%d\n", 1);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
printf("%d\n", 2);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("%d\n", 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
8
05/tcc-final/tests/tests2/06_case.expect
Normal file
8
05/tcc-final/tests/tests2/06_case.expect
Normal file
|
@ -0,0 +1,8 @@
|
|||
0
|
||||
0
|
||||
1
|
||||
1
|
||||
2
|
||||
2
|
||||
3
|
||||
0
|
35
05/tcc-final/tests/tests2/07_function.c
Normal file
35
05/tcc-final/tests/tests2/07_function.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int myfunc(int x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
void vfunc(int a)
|
||||
{
|
||||
printf("a=%d\n", a);
|
||||
}
|
||||
|
||||
void qfunc()
|
||||
{
|
||||
printf("qfunc()\n");
|
||||
}
|
||||
|
||||
void zfunc()
|
||||
{
|
||||
((void (*)(void))0) ();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("%d\n", myfunc(3));
|
||||
printf("%d\n", myfunc(4));
|
||||
|
||||
vfunc(1234);
|
||||
|
||||
qfunc();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
4
05/tcc-final/tests/tests2/07_function.expect
Normal file
4
05/tcc-final/tests/tests2/07_function.expect
Normal file
|
@ -0,0 +1,4 @@
|
|||
9
|
||||
16
|
||||
a=1234
|
||||
qfunc()
|
24
05/tcc-final/tests/tests2/08_while.c
Normal file
24
05/tcc-final/tests/tests2/08_while.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
int p;
|
||||
int t;
|
||||
|
||||
a = 1;
|
||||
p = 0;
|
||||
t = 0;
|
||||
|
||||
while (a < 100)
|
||||
{
|
||||
printf("%d\n", a);
|
||||
t = a;
|
||||
a = t + p;
|
||||
p = t;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
11
05/tcc-final/tests/tests2/08_while.expect
Normal file
11
05/tcc-final/tests/tests2/08_while.expect
Normal file
|
@ -0,0 +1,11 @@
|
|||
1
|
||||
1
|
||||
2
|
||||
3
|
||||
5
|
||||
8
|
||||
13
|
||||
21
|
||||
34
|
||||
55
|
||||
89
|
24
05/tcc-final/tests/tests2/09_do_while.c
Normal file
24
05/tcc-final/tests/tests2/09_do_while.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
int p;
|
||||
int t;
|
||||
|
||||
a = 1;
|
||||
p = 0;
|
||||
t = 0;
|
||||
|
||||
do
|
||||
{
|
||||
printf("%d\n", a);
|
||||
t = a;
|
||||
a = t + p;
|
||||
p = t;
|
||||
} while (a < 100);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
11
05/tcc-final/tests/tests2/09_do_while.expect
Normal file
11
05/tcc-final/tests/tests2/09_do_while.expect
Normal file
|
@ -0,0 +1,11 @@
|
|||
1
|
||||
1
|
||||
2
|
||||
3
|
||||
5
|
||||
8
|
||||
13
|
||||
21
|
||||
34
|
||||
55
|
||||
89
|
34
05/tcc-final/tests/tests2/100_c99array-decls.c
Normal file
34
05/tcc-final/tests/tests2/100_c99array-decls.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
void foo(int [5]);
|
||||
void fooc(int x[const 5]);
|
||||
void foos(int x[static 5]);
|
||||
void foov(int x[volatile 5]);
|
||||
void foor(int x[restrict 5]);
|
||||
void fooc(int [const 5]);
|
||||
void foos(int [static 5]);
|
||||
void foov(int [volatile 5]);
|
||||
void foor(int [restrict 5]);
|
||||
void fooc(int (* const x));
|
||||
void foos(int *x);
|
||||
void foov(int * volatile x);
|
||||
void foor(int * restrict x);
|
||||
void fooc(int x[volatile 5])
|
||||
{
|
||||
x[3] = 42;
|
||||
#ifdef INVALID
|
||||
x = 0;
|
||||
#endif
|
||||
}
|
||||
void foovm(int x[const *]);
|
||||
void foovm(int * const x);
|
||||
#ifdef INVALID
|
||||
void wrongc(int x[3][const 4]);
|
||||
void wrongvm(int x[static *]);
|
||||
void foovm(int x[const *])
|
||||
{
|
||||
x[2] = 1;
|
||||
}
|
||||
#endif
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
0
05/tcc-final/tests/tests2/100_c99array-decls.expect
Normal file
0
05/tcc-final/tests/tests2/100_c99array-decls.expect
Normal file
227
05/tcc-final/tests/tests2/101_cleanup.c
Normal file
227
05/tcc-final/tests/tests2/101_cleanup.c
Normal file
|
@ -0,0 +1,227 @@
|
|||
extern int printf(const char*, ...);
|
||||
static int glob_i = 0;
|
||||
|
||||
void incr_glob_i(int *i)
|
||||
{
|
||||
glob_i += *i;
|
||||
}
|
||||
|
||||
#define INCR_GI { \
|
||||
int i __attribute__ ((__cleanup__(incr_glob_i))) = 1; \
|
||||
}
|
||||
|
||||
#define INCR_GI0 INCR_GI INCR_GI INCR_GI INCR_GI
|
||||
#define INCR_GI1 INCR_GI0 INCR_GI0 INCR_GI0 INCR_GI0
|
||||
#define INCR_GI2 INCR_GI1 INCR_GI1 INCR_GI1 INCR_GI1
|
||||
#define INCR_GI3 INCR_GI2 INCR_GI2 INCR_GI2 INCR_GI2
|
||||
#define INCR_GI4 INCR_GI3 INCR_GI3 INCR_GI3 INCR_GI3
|
||||
#define INCR_GI5 INCR_GI4 INCR_GI4 INCR_GI4 INCR_GI4
|
||||
#define INCR_GI6 INCR_GI5 INCR_GI5 INCR_GI5 INCR_GI5
|
||||
#define INCR_GI7 INCR_GI6 INCR_GI6 INCR_GI6 INCR_GI6
|
||||
|
||||
|
||||
void check2(char **hum);
|
||||
|
||||
void check(int *j)
|
||||
{
|
||||
char * __attribute__ ((cleanup(check2))) stop_that = "wololo";
|
||||
int chk = 0;
|
||||
|
||||
{
|
||||
char * __attribute__ ((cleanup(check2))) stop_that = "plop";
|
||||
|
||||
{
|
||||
non_plopage:
|
||||
printf("---- %d\n", chk);
|
||||
}
|
||||
if (!chk) {
|
||||
chk = 1;
|
||||
goto non_plopage;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
char * __attribute__ ((cleanup(check2))) stop_that = "tata !";
|
||||
|
||||
goto out;
|
||||
stop_that = "titi";
|
||||
}
|
||||
again:
|
||||
chk = 2;
|
||||
{
|
||||
char * __attribute__ ((cleanup(check2))) cascade1 = "1";
|
||||
{
|
||||
char * __attribute__ ((cleanup(check2))) cascade2 = "2";
|
||||
{
|
||||
char * __attribute__ ((cleanup(check2))) cascade3 = "3";
|
||||
|
||||
goto out;
|
||||
cascade3 = "nope";
|
||||
}
|
||||
}
|
||||
}
|
||||
out:
|
||||
if (chk != 2)
|
||||
goto again;
|
||||
{
|
||||
{
|
||||
char * __attribute__ ((cleanup(check2))) out = "last goto out";
|
||||
++chk;
|
||||
if (chk != 3)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void check_oh_i(char *oh_i)
|
||||
{
|
||||
printf("c: %c\n", *oh_i);
|
||||
}
|
||||
|
||||
void goto_hell(double *f)
|
||||
{
|
||||
printf("oo: %f\n", *f);
|
||||
}
|
||||
|
||||
char *test()
|
||||
{
|
||||
char *__attribute__ ((cleanup(check2))) str = "I don't think this should be print(but gcc got it wrong too)";
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void test_ret_subcall(char *that)
|
||||
{
|
||||
printf("should be print before\n");
|
||||
}
|
||||
|
||||
void test_ret()
|
||||
{
|
||||
char *__attribute__ ((cleanup(check2))) that = "that";
|
||||
return test_ret_subcall(that);
|
||||
}
|
||||
|
||||
void test_ret2()
|
||||
{
|
||||
char *__attribute__ ((cleanup(check2))) that = "-that";
|
||||
{
|
||||
char *__attribute__ ((cleanup(check2))) that = "this should appear only once";
|
||||
}
|
||||
{
|
||||
char *__attribute__ ((cleanup(check2))) that = "-that2";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void test2(void) {
|
||||
int chk = 0;
|
||||
again:
|
||||
if (!chk) {
|
||||
char * __attribute__ ((cleanup(check2))) stop_that = "test2";
|
||||
chk++;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
|
||||
int test3(void) {
|
||||
char * __attribute__ ((cleanup(check2))) stop_that = "three";
|
||||
int chk = 0;
|
||||
|
||||
if (chk) {
|
||||
{
|
||||
outside:
|
||||
{
|
||||
char * __attribute__ ((cleanup(check2))) stop_that = "two";
|
||||
printf("---- %d\n", chk);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!chk)
|
||||
{
|
||||
char * __attribute__ ((cleanup(check2))) stop_that = "one";
|
||||
|
||||
if (!chk) {
|
||||
chk = 1;
|
||||
goto outside;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cl(int *ip)
|
||||
{
|
||||
printf("%d\n", *ip);
|
||||
}
|
||||
|
||||
void loop_cleanups(void)
|
||||
{
|
||||
__attribute__((cleanup(cl))) int l = 1000;
|
||||
|
||||
printf("-- loop 0 --\n");
|
||||
for ( __attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
|
||||
__attribute__((cleanup(cl))) int j = 100;
|
||||
}
|
||||
|
||||
printf("-- loop 1 --\n");
|
||||
for (__attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
|
||||
__attribute__((cleanup(cl))) int j = 200;
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("-- loop 2 --\n");
|
||||
for (__attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
|
||||
__attribute__((cleanup(cl))) int j = 300;
|
||||
break;
|
||||
}
|
||||
|
||||
printf("-- loop 3 --\n");
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
__attribute__((cleanup(cl))) int j = 400;
|
||||
switch (i) {
|
||||
case 0:
|
||||
continue;
|
||||
default:
|
||||
{
|
||||
__attribute__((cleanup(cl))) int jj = 500;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("after break\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i __attribute__ ((__cleanup__(check))) = 0, not_i;
|
||||
int chk = 0;
|
||||
(void)not_i;
|
||||
|
||||
{
|
||||
__attribute__ ((__cleanup__(check_oh_i))) char oh_i = 'o', o = 'a';
|
||||
}
|
||||
|
||||
INCR_GI7;
|
||||
printf("glob_i: %d\n", glob_i);
|
||||
naaaaaaaa:
|
||||
if (!chk) {
|
||||
__attribute__ ((__cleanup__(check_oh_i))) char oh_i = 'f';
|
||||
double __attribute__ ((__cleanup__(goto_hell))) f = 2.6;
|
||||
|
||||
chk = 1;
|
||||
goto naaaaaaaa;
|
||||
}
|
||||
i = 105;
|
||||
printf("because what if free was call inside cleanup function %s\n", test());
|
||||
test_ret();
|
||||
test_ret2();
|
||||
test2();
|
||||
test3();
|
||||
loop_cleanups();
|
||||
return i;
|
||||
}
|
||||
|
||||
void check2(char **hum)
|
||||
{
|
||||
printf("str: %s\n", *hum);
|
||||
}
|
59
05/tcc-final/tests/tests2/101_cleanup.expect
Normal file
59
05/tcc-final/tests/tests2/101_cleanup.expect
Normal file
|
@ -0,0 +1,59 @@
|
|||
c: a
|
||||
c: o
|
||||
glob_i: 65536
|
||||
oo: 2.600000
|
||||
c: f
|
||||
str: I don't think this should be print(but gcc got it wrong too)
|
||||
because what if free was call inside cleanup function I don't think this should be print(but gcc got it wrong too)
|
||||
should be print before
|
||||
str: that
|
||||
str: this should appear only once
|
||||
str: -that2
|
||||
str: -that
|
||||
str: test2
|
||||
str: one
|
||||
---- 1
|
||||
str: two
|
||||
str: three
|
||||
-- loop 0 --
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
10
|
||||
-- loop 1 --
|
||||
200
|
||||
200
|
||||
200
|
||||
200
|
||||
200
|
||||
200
|
||||
200
|
||||
200
|
||||
200
|
||||
200
|
||||
10
|
||||
-- loop 2 --
|
||||
300
|
||||
0
|
||||
-- loop 3 --
|
||||
400
|
||||
500
|
||||
400
|
||||
after break
|
||||
1000
|
||||
---- 0
|
||||
---- 1
|
||||
str: plop
|
||||
str: tata !
|
||||
str: 3
|
||||
str: 2
|
||||
str: 1
|
||||
str: last goto out
|
||||
str: wololo
|
29
05/tcc-final/tests/tests2/102_alignas.c
Normal file
29
05/tcc-final/tests/tests2/102_alignas.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
_Alignas(16) int i1;
|
||||
int _Alignas(16) i2;
|
||||
void _Alignas(16) *p2;
|
||||
_Alignas(16) i3;
|
||||
int _Alignas(double) i4;
|
||||
int _Alignas(int) i5;
|
||||
#if 0
|
||||
/* The following are currently wrongly accepted by TCC but really shouldn't. */
|
||||
int _Alignas(int _Alignas(16)) i6; //wrong, 'int _Alignas(16)' is no type-name
|
||||
typedef int _Alignas(16) int16aligned_t; //wrong, _Alignas invalid on typedef
|
||||
int16aligned_t i7;
|
||||
#endif
|
||||
/* i8 should get an alignment of 16, because unlike _Alignas the
|
||||
corresponding attribute _does_ apply to type-name, though not in
|
||||
some clang versions. */
|
||||
int _Alignas(int __attribute__((aligned(16)))) i8;
|
||||
extern int printf(const char*, ...);
|
||||
#ifdef _MSC_VER
|
||||
#define alignof(x) (int)__alignof(x)
|
||||
#else
|
||||
#define alignof(x) (int)__alignof__(x)
|
||||
#endif
|
||||
int main()
|
||||
{
|
||||
printf("%d %d %d %d\n",
|
||||
alignof(i1) == 16, alignof(i4) == alignof(double),
|
||||
alignof(i5) == alignof(int) , alignof(i8) == 16);
|
||||
return 0;
|
||||
}
|
2
05/tcc-final/tests/tests2/102_alignas.expect
Normal file
2
05/tcc-final/tests/tests2/102_alignas.expect
Normal file
|
@ -0,0 +1,2 @@
|
|||
102_alignas.c:4: warning: type defaults to int
|
||||
1 1 1 1
|
20
05/tcc-final/tests/tests2/103_implicit_memmove.c
Normal file
20
05/tcc-final/tests/tests2/103_implicit_memmove.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* Test that the memmove TCC is emitting for the struct copy
|
||||
and hence implicitely declares can be declared properly also
|
||||
later. */
|
||||
struct S { int a,b,c,d, e[1024];};
|
||||
int foo (struct S *a, struct S *b)
|
||||
{
|
||||
*a = *b;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *memmove(void*,const void*,__SIZE_TYPE__);
|
||||
void foo2 (struct S *a, struct S *b)
|
||||
{
|
||||
memmove(a, b, sizeof *a);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
0
05/tcc-final/tests/tests2/103_implicit_memmove.expect
Normal file
0
05/tcc-final/tests/tests2/103_implicit_memmove.expect
Normal file
54
05/tcc-final/tests/tests2/104+_inline.c
Normal file
54
05/tcc-final/tests/tests2/104+_inline.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
|
||||
#define GOT(f) \
|
||||
__attribute__((weak)) void f(void); \
|
||||
printf("%d %s\n", !!f, #f);
|
||||
|
||||
int printf(const char*, ...);
|
||||
|
||||
void check_exports()
|
||||
{
|
||||
// 0
|
||||
GOT(inline_inline_2decl_only)
|
||||
GOT(inline_inline_undeclared)
|
||||
GOT(inline_inline_predeclared)
|
||||
GOT(inline_inline_postdeclared)
|
||||
GOT(inline_inline_prepostdeclared)
|
||||
GOT(inline_inline_undeclared2)
|
||||
GOT(inline_inline_predeclared2)
|
||||
GOT(inline_inline_postdeclared2)
|
||||
GOT(inline_inline_prepostdeclared2)
|
||||
|
||||
// 1
|
||||
GOT(extern_extern_postdeclared)
|
||||
GOT(extern_extern_postdeclared2)
|
||||
GOT(extern_extern_predeclared)
|
||||
GOT(extern_extern_predeclared2)
|
||||
GOT(extern_extern_prepostdeclared)
|
||||
GOT(extern_extern_prepostdeclared2)
|
||||
GOT(extern_extern_undeclared)
|
||||
GOT(extern_extern_undeclared2)
|
||||
GOT(extern_postdeclared)
|
||||
GOT(extern_postdeclared2)
|
||||
GOT(extern_predeclared)
|
||||
GOT(extern_predeclared2)
|
||||
GOT(extern_prepostdeclared)
|
||||
GOT(extern_undeclared)
|
||||
GOT(extern_undeclared2)
|
||||
GOT(inst2_extern_inline_postdeclared)
|
||||
GOT(inst2_extern_inline_predeclared)
|
||||
GOT(inst3_extern_inline_predeclared)
|
||||
GOT(inst_extern_inline_postdeclared)
|
||||
GOT(inst_extern_inline_predeclared)
|
||||
GOT(main)
|
||||
GOT(noinst_extern_inline_func)
|
||||
GOT(noinst_extern_inline_postdeclared)
|
||||
GOT(noinst_extern_inline_postdeclared2)
|
||||
GOT(noinst_extern_inline_undeclared)
|
||||
|
||||
// 0
|
||||
GOT(noinst_static_inline_postdeclared)
|
||||
GOT(noinst2_static_inline_postdeclared)
|
||||
GOT(noinst_static_inline_predeclared)
|
||||
GOT(noinst2_static_inline_predeclared)
|
||||
GOT(static_func)
|
||||
}
|
132
05/tcc-final/tests/tests2/104_inline.c
Normal file
132
05/tcc-final/tests/tests2/104_inline.c
Normal file
|
@ -0,0 +1,132 @@
|
|||
inline void inline_inline_2decl_only(void);
|
||||
inline void inline_inline_2decl_only(void);
|
||||
|
||||
inline void inline_inline_undeclared(void){}
|
||||
|
||||
inline void inline_inline_predeclared(void);
|
||||
inline void inline_inline_predeclared(void){}
|
||||
|
||||
inline void inline_inline_postdeclared(void){}
|
||||
inline void inline_inline_postdeclared(void);
|
||||
|
||||
inline void inline_inline_prepostdeclared(void);
|
||||
inline void inline_inline_prepostdeclared(void){}
|
||||
inline void inline_inline_prepostdeclared(void);
|
||||
|
||||
inline void inline_inline_undeclared2(void){}
|
||||
|
||||
inline void inline_inline_predeclared2(void);
|
||||
inline void inline_inline_predeclared2(void);
|
||||
inline void inline_inline_predeclared2(void){}
|
||||
|
||||
inline void inline_inline_postdeclared2(void){}
|
||||
inline void inline_inline_postdeclared2(void);
|
||||
inline void inline_inline_postdeclared2(void);
|
||||
|
||||
inline void inline_inline_prepostdeclared2(void);
|
||||
inline void inline_inline_prepostdeclared2(void);
|
||||
inline void inline_inline_prepostdeclared2(void){}
|
||||
inline void inline_inline_prepostdeclared2(void);
|
||||
inline void inline_inline_prepostdeclared2(void);
|
||||
|
||||
extern void extern_extern_undeclared(void){}
|
||||
|
||||
extern void extern_extern_predeclared(void);
|
||||
extern void extern_extern_predeclared(void){}
|
||||
|
||||
extern void extern_extern_postdeclared(void){}
|
||||
extern void extern_extern_postdeclared(void);
|
||||
|
||||
extern void extern_extern_prepostdeclared(void);
|
||||
extern void extern_extern_prepostdeclared(void){}
|
||||
extern void extern_extern_prepostdeclared(void);
|
||||
|
||||
extern void extern_extern_undeclared2(void){}
|
||||
|
||||
extern void extern_extern_predeclared2(void);
|
||||
extern void extern_extern_predeclared2(void);
|
||||
extern void extern_extern_predeclared2(void){}
|
||||
|
||||
extern void extern_extern_postdeclared2(void){}
|
||||
extern void extern_extern_postdeclared2(void);
|
||||
extern void extern_extern_postdeclared2(void);
|
||||
|
||||
extern void extern_extern_prepostdeclared2(void);
|
||||
extern void extern_extern_prepostdeclared2(void);
|
||||
extern void extern_extern_prepostdeclared2(void){}
|
||||
extern void extern_extern_prepostdeclared2(void);
|
||||
extern void extern_extern_prepostdeclared2(void);
|
||||
|
||||
void extern_undeclared(void){}
|
||||
|
||||
void extern_predeclared(void);
|
||||
void extern_predeclared(void){}
|
||||
|
||||
void extern_postdeclared(void){}
|
||||
void extern_postdeclared(void);
|
||||
|
||||
void extern_prepostdeclared(void);
|
||||
void extern_prepostdeclared(void){}
|
||||
void extern_prepostdeclared(void);
|
||||
|
||||
void extern_undeclared2(void){}
|
||||
|
||||
void extern_predeclared2(void);
|
||||
void extern_predeclared2(void);
|
||||
void extern_predeclared2(void){}
|
||||
|
||||
void extern_postdeclared2(void){}
|
||||
void extern_postdeclared2(void);
|
||||
void extern_postdeclared2(void);
|
||||
|
||||
|
||||
extern inline void noinst_extern_inline_undeclared(void){}
|
||||
|
||||
extern inline void noinst_extern_inline_postdeclared(void){}
|
||||
inline void noinst_extern_inline_postdeclared(void);
|
||||
|
||||
extern inline void noinst_extern_inline_postdeclared2(void){}
|
||||
inline void noinst_extern_inline_postdeclared2(void);
|
||||
inline void noinst_extern_inline_postdeclared2(void);
|
||||
|
||||
extern inline void inst_extern_inline_postdeclared(void){}
|
||||
extern inline void inst_extern_inline_postdeclared(void);
|
||||
inline void inst2_extern_inline_postdeclared(void){}
|
||||
void inst2_extern_inline_postdeclared(void);
|
||||
|
||||
void inst_extern_inline_predeclared(void);
|
||||
extern inline void inst_extern_inline_predeclared(void){}
|
||||
void inst2_extern_inline_predeclared(void);
|
||||
inline void inst2_extern_inline_predeclared(void){}
|
||||
extern inline void inst3_extern_inline_predeclared(void);
|
||||
inline void inst3_extern_inline_predeclared(void){}
|
||||
|
||||
static inline void noinst_static_inline_postdeclared(void){}
|
||||
static inline void noinst_static_inline_postdeclared(void);
|
||||
static inline void noinst2_static_inline_postdeclared(void){}
|
||||
static void noinst2_static_inline_postdeclared(void);
|
||||
|
||||
static void noinst_static_inline_predeclared(void);
|
||||
static inline void noinst_static_inline_predeclared(void){}
|
||||
static void noinst2_static_inline_predeclared(void);
|
||||
static inline void noinst2_static_inline_predeclared(void){}
|
||||
|
||||
static void static_func(void);
|
||||
void static_func(void) { }
|
||||
|
||||
inline void noinst_extern_inline_func(void);
|
||||
void noinst_extern_inline_func(void) { }
|
||||
|
||||
int main()
|
||||
{
|
||||
inline_inline_undeclared(); inline_inline_predeclared(); inline_inline_postdeclared();
|
||||
inline_inline_undeclared2(); inline_inline_predeclared2(); inline_inline_postdeclared2();
|
||||
noinst_static_inline_predeclared();
|
||||
noinst2_static_inline_predeclared();
|
||||
noinst_static_inline_predeclared();
|
||||
noinst2_static_inline_predeclared();
|
||||
|
||||
void check_exports();
|
||||
check_exports();
|
||||
return 0;
|
||||
}
|
39
05/tcc-final/tests/tests2/104_inline.expect
Normal file
39
05/tcc-final/tests/tests2/104_inline.expect
Normal file
|
@ -0,0 +1,39 @@
|
|||
0 inline_inline_2decl_only
|
||||
0 inline_inline_undeclared
|
||||
0 inline_inline_predeclared
|
||||
0 inline_inline_postdeclared
|
||||
0 inline_inline_prepostdeclared
|
||||
0 inline_inline_undeclared2
|
||||
0 inline_inline_predeclared2
|
||||
0 inline_inline_postdeclared2
|
||||
0 inline_inline_prepostdeclared2
|
||||
1 extern_extern_postdeclared
|
||||
1 extern_extern_postdeclared2
|
||||
1 extern_extern_predeclared
|
||||
1 extern_extern_predeclared2
|
||||
1 extern_extern_prepostdeclared
|
||||
1 extern_extern_prepostdeclared2
|
||||
1 extern_extern_undeclared
|
||||
1 extern_extern_undeclared2
|
||||
1 extern_postdeclared
|
||||
1 extern_postdeclared2
|
||||
1 extern_predeclared
|
||||
1 extern_predeclared2
|
||||
1 extern_prepostdeclared
|
||||
1 extern_undeclared
|
||||
1 extern_undeclared2
|
||||
1 inst2_extern_inline_postdeclared
|
||||
1 inst2_extern_inline_predeclared
|
||||
1 inst3_extern_inline_predeclared
|
||||
1 inst_extern_inline_postdeclared
|
||||
1 inst_extern_inline_predeclared
|
||||
1 main
|
||||
1 noinst_extern_inline_func
|
||||
1 noinst_extern_inline_postdeclared
|
||||
1 noinst_extern_inline_postdeclared2
|
||||
1 noinst_extern_inline_undeclared
|
||||
0 noinst_static_inline_postdeclared
|
||||
0 noinst2_static_inline_postdeclared
|
||||
0 noinst_static_inline_predeclared
|
||||
0 noinst2_static_inline_predeclared
|
||||
0 static_func
|
12
05/tcc-final/tests/tests2/105_local_extern.c
Normal file
12
05/tcc-final/tests/tests2/105_local_extern.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
extern int printf(const char *, ...);
|
||||
void f(void);
|
||||
void bar(void) { void f(void); f(); }
|
||||
void foo(void) { extern void f(void); f(); }
|
||||
void f(void) { printf("f\n"); }
|
||||
|
||||
int main()
|
||||
{
|
||||
bar();
|
||||
foo();
|
||||
return 0;
|
||||
}
|
2
05/tcc-final/tests/tests2/105_local_extern.expect
Normal file
2
05/tcc-final/tests/tests2/105_local_extern.expect
Normal file
|
@ -0,0 +1,2 @@
|
|||
f
|
||||
f
|
18
05/tcc-final/tests/tests2/106_versym.c
Normal file
18
05/tcc-final/tests/tests2/106_versym.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_condattr_t attr;
|
||||
pthread_cond_t condition;
|
||||
|
||||
/* This test fails if symbol versioning does not work */
|
||||
pthread_condattr_init (&attr);
|
||||
pthread_condattr_setpshared (&attr, PTHREAD_PROCESS_SHARED);
|
||||
printf ("%s\n", pthread_cond_init (&condition, &attr) ? "fail":"ok");
|
||||
pthread_condattr_destroy (&attr);
|
||||
return 0;
|
||||
}
|
1
05/tcc-final/tests/tests2/106_versym.expect
Normal file
1
05/tcc-final/tests/tests2/106_versym.expect
Normal file
|
@ -0,0 +1 @@
|
|||
ok
|
13
05/tcc-final/tests/tests2/107_stack_safe.c
Normal file
13
05/tcc-final/tests/tests2/107_stack_safe.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
extern int printf(const char *, ...);
|
||||
|
||||
static void func_ull_ull(unsigned long long l1,unsigned long long l2){
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int a,b,c,d;
|
||||
a=1;b=2;c=3;d=4;
|
||||
func_ull_ull((unsigned long long)a/1.0,(unsigned long long)b/1.0);
|
||||
printf("%d %d %d %d",a,b,c,d);
|
||||
return 0;
|
||||
}
|
1
05/tcc-final/tests/tests2/107_stack_safe.expect
Normal file
1
05/tcc-final/tests/tests2/107_stack_safe.expect
Normal file
|
@ -0,0 +1 @@
|
|||
1 2 3 4
|
20
05/tcc-final/tests/tests2/108_constructor.c
Normal file
20
05/tcc-final/tests/tests2/108_constructor.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
extern int write (int fd, void *buf, int len);
|
||||
|
||||
static void __attribute__ ((constructor))
|
||||
testc (void)
|
||||
{
|
||||
write (1, "constructor\n", 12);
|
||||
}
|
||||
|
||||
static void __attribute__ ((destructor))
|
||||
testd (void)
|
||||
{
|
||||
write (1, "destructor\n", 11);
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
write (1, "main\n", 5);
|
||||
return 0;
|
||||
}
|
3
05/tcc-final/tests/tests2/108_constructor.expect
Normal file
3
05/tcc-final/tests/tests2/108_constructor.expect
Normal file
|
@ -0,0 +1,3 @@
|
|||
constructor
|
||||
main
|
||||
destructor
|
24
05/tcc-final/tests/tests2/109_float_struct_calling.c
Normal file
24
05/tcc-final/tests/tests2/109_float_struct_calling.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
|
||||
/* This test used to fail on x86_64 on linux with sse registers */
|
||||
|
||||
struct Point {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
struct Rect {
|
||||
struct Point top_left;
|
||||
struct Point size;
|
||||
};
|
||||
|
||||
float foo(struct Point p, struct Rect r) {
|
||||
return r.size.x;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct Point p = {1, 2};
|
||||
struct Rect r = {{3, 4}, {5, 6}};
|
||||
printf("%f\n", foo(p, r));
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
5.000000
|
40
05/tcc-final/tests/tests2/10_pointer.c
Normal file
40
05/tcc-final/tests/tests2/10_pointer.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include <stdio.h>
|
||||
|
||||
struct ziggy
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
} bolshevic;
|
||||
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
int *b;
|
||||
int c;
|
||||
|
||||
a = 42;
|
||||
b = &a;
|
||||
printf("a = %d\n", *b);
|
||||
|
||||
bolshevic.a = 12;
|
||||
bolshevic.b = 34;
|
||||
bolshevic.c = 56;
|
||||
|
||||
printf("bolshevic.a = %d\n", bolshevic.a);
|
||||
printf("bolshevic.b = %d\n", bolshevic.b);
|
||||
printf("bolshevic.c = %d\n", bolshevic.c);
|
||||
|
||||
struct ziggy *tsar = &bolshevic;
|
||||
|
||||
printf("tsar->a = %d\n", tsar->a);
|
||||
printf("tsar->b = %d\n", tsar->b);
|
||||
printf("tsar->c = %d\n", tsar->c);
|
||||
|
||||
b = &(bolshevic.b);
|
||||
printf("bolshevic.b = %d\n", *b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
8
05/tcc-final/tests/tests2/10_pointer.expect
Normal file
8
05/tcc-final/tests/tests2/10_pointer.expect
Normal file
|
@ -0,0 +1,8 @@
|
|||
a = 42
|
||||
bolshevic.a = 12
|
||||
bolshevic.b = 34
|
||||
bolshevic.c = 56
|
||||
tsar->a = 12
|
||||
tsar->b = 34
|
||||
tsar->c = 56
|
||||
bolshevic.b = 34
|
27
05/tcc-final/tests/tests2/110_average.c
Normal file
27
05/tcc-final/tests/tests2/110_average.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <stdio.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double average;
|
||||
int count;
|
||||
}
|
||||
stats_type;
|
||||
|
||||
static void
|
||||
testc (stats_type *s, long long data)
|
||||
{
|
||||
s->average = (s->average * s->count + data) / (s->count + 1);
|
||||
s->count++;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
stats_type s;
|
||||
|
||||
s.average = 0;
|
||||
s.count = 0;
|
||||
testc (&s, 10);
|
||||
testc (&s, 20);
|
||||
printf ("%g %d\n", s.average, s.count);
|
||||
return 0;
|
||||
}
|
1
05/tcc-final/tests/tests2/110_average.expect
Normal file
1
05/tcc-final/tests/tests2/110_average.expect
Normal file
|
@ -0,0 +1 @@
|
|||
15 2
|
22
05/tcc-final/tests/tests2/111_conversion.c
Normal file
22
05/tcc-final/tests/tests2/111_conversion.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
|
||||
union u {
|
||||
unsigned long ul;
|
||||
long double ld;
|
||||
};
|
||||
|
||||
void
|
||||
conv (union u *p)
|
||||
{
|
||||
p->ul = (unsigned int) p->ld;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
union u v;
|
||||
|
||||
v.ld = 42;
|
||||
conv (&v);
|
||||
printf ("%lu\n", v.ul);
|
||||
return 0;
|
||||
}
|
1
05/tcc-final/tests/tests2/111_conversion.expect
Normal file
1
05/tcc-final/tests/tests2/111_conversion.expect
Normal file
|
@ -0,0 +1 @@
|
|||
42
|
165
05/tcc-final/tests/tests2/112_backtrace.c
Normal file
165
05/tcc-final/tests/tests2/112_backtrace.c
Normal file
|
@ -0,0 +1,165 @@
|
|||
#include <stdio.h>
|
||||
|
||||
/* ------------------------------------------------------- */
|
||||
#if defined test_backtrace_1
|
||||
|
||||
void f3()
|
||||
{
|
||||
printf("* f3()\n"), fflush(stdout);
|
||||
*(void**)0 = 0;
|
||||
}
|
||||
void f2()
|
||||
{
|
||||
printf("* f2()\n"), fflush(stdout);
|
||||
f3();
|
||||
}
|
||||
void f1()
|
||||
{
|
||||
printf("* f1()\n"), fflush(stdout);
|
||||
f2();
|
||||
}
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("* main\n"), fflush(stdout);
|
||||
f1();
|
||||
printf("* exit main\n"), fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------- */
|
||||
#elif defined test_bcheck_1
|
||||
|
||||
struct s { int a,b,c,d,e; };
|
||||
struct s s[3];
|
||||
struct s *ps = s;
|
||||
void f1()
|
||||
{
|
||||
printf("* f1()\n"), fflush(stdout);
|
||||
ps[3] = ps[2];
|
||||
}
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("* main\n"), fflush(stdout);
|
||||
f1();
|
||||
printf("* exit main\n"), fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------- */
|
||||
#elif defined test_tcc_backtrace_2
|
||||
|
||||
/* test custom backtrace and 'exit()' redirection */
|
||||
int tcc_backtrace(const char *fmt, ...);
|
||||
void exit(int);
|
||||
|
||||
void f2()
|
||||
{
|
||||
printf("* f2()\n");
|
||||
printf("* exit f2\n"), fflush(stdout);
|
||||
exit(34);
|
||||
}
|
||||
void f1()
|
||||
{
|
||||
printf("* f1()\n"), fflush(stdout);
|
||||
tcc_backtrace("Hello from %s!", "f1");
|
||||
f2();
|
||||
}
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("* main\n"), fflush(stdout);
|
||||
f1();
|
||||
printf("* exit main\n"), fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------- */
|
||||
#elif defined test_tcc_backtrace_3
|
||||
|
||||
/* this test should be run despite of the exit(34) above */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("* main\n"), fflush(stdout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------- */
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
char *strdup();
|
||||
int main()
|
||||
{
|
||||
char pad1[10];
|
||||
char a[10];
|
||||
char pad2[10];
|
||||
char b[10];
|
||||
char pad3[10];
|
||||
memset (pad1, 0, sizeof(pad1));
|
||||
memset (pad2, 0, sizeof(pad2));
|
||||
memset (pad3, 0, sizeof(pad3));
|
||||
|
||||
memset (a, 'a', 10);
|
||||
a[3] = 0;
|
||||
a[9] = 0;
|
||||
memset (b, 'b', 10);
|
||||
|
||||
#if defined test_bcheck_100
|
||||
memcpy(&a[1],&b[0],10);
|
||||
#elif defined test_bcheck_101
|
||||
memcpy(&a[0],&b[1],10);
|
||||
#elif defined test_bcheck_102
|
||||
memcpy(&a[0],&a[3],4);
|
||||
#elif defined test_bcheck_103
|
||||
memcpy(&a[3],&a[0],4);
|
||||
#elif defined test_bcheck_104
|
||||
memcmp(&b[1],&b[0],10);
|
||||
#elif defined test_bcheck_105
|
||||
memcmp(&b[0],&b[1],10);
|
||||
#elif defined test_bcheck_106
|
||||
memmove(&b[1],&b[0],10);
|
||||
#elif defined test_bcheck_107
|
||||
memmove(&b[0],&b[1],10);
|
||||
#elif defined test_bcheck_108
|
||||
memset(&b[1],'b',10);
|
||||
#elif defined test_bcheck_109
|
||||
strlen(&b[0]);
|
||||
#elif defined test_bcheck_110
|
||||
strcpy(&a[7], &a[0]);
|
||||
#elif defined test_bcheck_111
|
||||
strcpy(&a[0], &b[7]);
|
||||
#elif defined test_bcheck_112
|
||||
strcpy(&a[0], &a[1]);
|
||||
#elif defined test_bcheck_113
|
||||
strcpy(&a[2], &a[0]);
|
||||
#elif defined test_bcheck_114
|
||||
strncpy(&a[7], &a[0], 10);
|
||||
#elif defined test_bcheck_115
|
||||
strncpy(&a[0], &b[7], 10);
|
||||
#elif defined test_bcheck_116
|
||||
strncpy(&a[0], &a[1], 10);
|
||||
#elif defined test_bcheck_117
|
||||
strncpy(&a[2], &a[0], 10);
|
||||
#elif defined test_bcheck_118
|
||||
strcmp(&b[2], &b[0]);
|
||||
#elif defined test_bcheck_119
|
||||
strcmp(&b[0], &b[2]);
|
||||
#elif defined test_bcheck_120
|
||||
strncmp(&b[5], &b[0], 10);
|
||||
#elif defined test_bcheck_121
|
||||
strncmp(&b[0], &b[5], 10);
|
||||
#elif defined test_bcheck_122
|
||||
strcat(&a[7], &a[0]);
|
||||
#elif defined test_bcheck_123
|
||||
strcat(&a[0], &b[3]);
|
||||
#elif defined test_bcheck_124
|
||||
strcat(&a[0], &a[4]);
|
||||
#elif defined test_bcheck_125
|
||||
strcat(&a[3], &a[0]);
|
||||
#elif defined test_bcheck_126
|
||||
strchr(&b[0], 'a');
|
||||
#elif defined test_bcheck_127
|
||||
free(strdup(&b[0]));
|
||||
#endif
|
||||
}
|
||||
/* ------------------------------------------------------- */
|
||||
#endif
|
142
05/tcc-final/tests/tests2/112_backtrace.expect
Normal file
142
05/tcc-final/tests/tests2/112_backtrace.expect
Normal file
|
@ -0,0 +1,142 @@
|
|||
[test_backtrace_1]
|
||||
* main
|
||||
* f1()
|
||||
* f2()
|
||||
* f3()
|
||||
112_backtrace.c:9: at f3: RUNTIME ERROR: invalid memory access
|
||||
112_backtrace.c:14: by f2
|
||||
112_backtrace.c:19: by f1
|
||||
112_backtrace.c:24: by main
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_1]
|
||||
* main
|
||||
* f1()
|
||||
112_backtrace.c:38: at f1: BCHECK: invalid pointer ........, size 0x? in memmove dest
|
||||
112_backtrace.c:43: by main
|
||||
[returns 255]
|
||||
|
||||
[test_tcc_backtrace_2]
|
||||
* main
|
||||
* f1()
|
||||
112_backtrace.c:64: at f1: Hello from f1!
|
||||
112_backtrace.c:70: by main
|
||||
* f2()
|
||||
* exit f2
|
||||
[returns 34]
|
||||
|
||||
[test_tcc_backtrace_3]
|
||||
* main
|
||||
[returns 1]
|
||||
|
||||
[test_bcheck_100]
|
||||
112_backtrace.c:107: at main: BCHECK: invalid pointer ........, size 0x? in memcpy dest
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_101]
|
||||
112_backtrace.c:109: at main: BCHECK: invalid pointer ........, size 0x? in memcpy src
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_102]
|
||||
112_backtrace.c:111: at main: BCHECK: overlapping regions ........(0x?), ........(0x?) in memcpy
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_103]
|
||||
112_backtrace.c:113: at main: BCHECK: overlapping regions ........(0x?), ........(0x?) in memcpy
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_104]
|
||||
112_backtrace.c:115: at main: BCHECK: invalid pointer ........, size 0x? in memcmp s1
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_105]
|
||||
112_backtrace.c:117: at main: BCHECK: invalid pointer ........, size 0x? in memcmp s2
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_106]
|
||||
112_backtrace.c:119: at main: BCHECK: invalid pointer ........, size 0x? in memmove dest
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_107]
|
||||
112_backtrace.c:121: at main: BCHECK: invalid pointer ........, size 0x? in memmove src
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_108]
|
||||
112_backtrace.c:123: at main: BCHECK: invalid pointer ........, size 0x? in memset
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_109]
|
||||
112_backtrace.c:125: at main: BCHECK: invalid pointer ........, size 0x? in strlen
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_110]
|
||||
112_backtrace.c:127: at main: BCHECK: invalid pointer ........, size 0x? in strcpy dest
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_111]
|
||||
112_backtrace.c:129: at main: BCHECK: invalid pointer ........, size 0x? in strcpy src
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_112]
|
||||
112_backtrace.c:131: at main: BCHECK: overlapping regions ........(0x?), ........(0x?) in strcpy
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_113]
|
||||
112_backtrace.c:133: at main: BCHECK: overlapping regions ........(0x?), ........(0x?) in strcpy
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_114]
|
||||
112_backtrace.c:135: at main: BCHECK: invalid pointer ........, size 0x? in strncpy dest
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_115]
|
||||
112_backtrace.c:137: at main: BCHECK: invalid pointer ........, size 0x? in strncpy src
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_116]
|
||||
112_backtrace.c:139: at main: BCHECK: overlapping regions ........(0x?), ........(0x?) in strncpy
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_117]
|
||||
112_backtrace.c:141: at main: BCHECK: overlapping regions ........(0x?), ........(0x?) in strncpy
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_118]
|
||||
112_backtrace.c:143: at main: BCHECK: invalid pointer ........, size 0x? in strcmp s1
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_119]
|
||||
112_backtrace.c:145: at main: BCHECK: invalid pointer ........, size 0x? in strcmp s2
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_120]
|
||||
112_backtrace.c:147: at main: BCHECK: invalid pointer ........, size 0x? in strncmp s1
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_121]
|
||||
112_backtrace.c:149: at main: BCHECK: invalid pointer ........, size 0x? in strncmp s2
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_122]
|
||||
112_backtrace.c:151: at main: BCHECK: invalid pointer ........, size 0x? in strcat dest
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_123]
|
||||
112_backtrace.c:153: at main: BCHECK: invalid pointer ........, size 0x? in strcat dest
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_124]
|
||||
112_backtrace.c:155: at main: BCHECK: overlapping regions ........(0x?), ........(0x?) in strcat
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_125]
|
||||
112_backtrace.c:157: at main: BCHECK: overlapping regions ........(0x?), ........(0x?) in strcat
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_126]
|
||||
112_backtrace.c:159: at main: BCHECK: invalid pointer ........, size 0x? in strchr
|
||||
[returns 255]
|
||||
|
||||
[test_bcheck_127]
|
||||
112_backtrace.c:161: at main: BCHECK: invalid pointer ........, size 0x? in strdup
|
||||
[returns 255]
|
43
05/tcc-final/tests/tests2/113_btdll.c
Normal file
43
05/tcc-final/tests/tests2/113_btdll.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
int tcc_backtrace(const char*, ...);
|
||||
#define hello() \
|
||||
tcc_backtrace("hello from %s() / %s:%d",__FUNCTION__,__FILE__,__LINE__)
|
||||
|
||||
#ifndef _WIN32
|
||||
# define __declspec(n)
|
||||
#endif
|
||||
|
||||
#if DLL==1
|
||||
__declspec(dllexport) int f_1()
|
||||
{
|
||||
hello();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#elif DLL==2
|
||||
__declspec(dllexport) int f_2()
|
||||
{
|
||||
hello();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
int f_1();
|
||||
int f_2();
|
||||
int f_main()
|
||||
{
|
||||
hello();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
f_1();
|
||||
f_2();
|
||||
f_main();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
6
05/tcc-final/tests/tests2/113_btdll.expect
Normal file
6
05/tcc-final/tests/tests2/113_btdll.expect
Normal file
|
@ -0,0 +1,6 @@
|
|||
113_btdll.c:12: at f_1: hello from f_1() / 113_btdll.c:12
|
||||
113_btdll.c:37: by main
|
||||
113_btdll.c:20: at f_2: hello from f_2() / 113_btdll.c:20
|
||||
113_btdll.c:38: by main
|
||||
113_btdll.c:31: at f_main: hello from f_main() / 113_btdll.c:31
|
||||
113_btdll.c:39: by main
|
143
05/tcc-final/tests/tests2/114_bound_signal.c
Normal file
143
05/tcc-final/tests/tests2/114_bound_signal.c
Normal file
|
@ -0,0 +1,143 @@
|
|||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
static volatile int run = 1;
|
||||
static sem_t sem;
|
||||
static sem_t sem_child;
|
||||
|
||||
static void
|
||||
add (int n)
|
||||
{
|
||||
int i;
|
||||
int arr[n];
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
arr[i]++;
|
||||
}
|
||||
memset (&arr[0], 0, n * sizeof(int));
|
||||
}
|
||||
|
||||
static void *
|
||||
high_load (void *unused)
|
||||
{
|
||||
while (run) {
|
||||
add(10);
|
||||
add(20);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *
|
||||
do_signal (void *unused)
|
||||
{
|
||||
while (run) {
|
||||
kill (getpid(), SIGUSR1);
|
||||
while (sem_wait(&sem) < 0 && errno == EINTR);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *
|
||||
do_fork (void *unused)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
while (run) {
|
||||
switch ((pid = fork())) {
|
||||
case 0:
|
||||
add(1000);
|
||||
add(2000);
|
||||
exit(0);
|
||||
break;
|
||||
case -1:
|
||||
return NULL;
|
||||
default:
|
||||
while (sem_wait(&sem_child) < 0 && errno == EINTR);
|
||||
wait(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void signal_handler(int sig)
|
||||
{
|
||||
add(10);
|
||||
add(20);
|
||||
sem_post (&sem);
|
||||
}
|
||||
|
||||
static void child_handler(int sig)
|
||||
{
|
||||
add(10);
|
||||
add(20);
|
||||
sem_post (&sem_child);
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int i;
|
||||
pthread_t id1, id2, id3;
|
||||
struct sigaction act;
|
||||
sigjmp_buf sj;
|
||||
sigset_t m;
|
||||
time_t end;
|
||||
|
||||
memset (&act, 0, sizeof (act));
|
||||
act.sa_handler = signal_handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset (&act.sa_mask);
|
||||
sigaction (SIGUSR1, &act, NULL);
|
||||
act.sa_handler = child_handler;
|
||||
sigaction (SIGCHLD, &act, NULL);
|
||||
|
||||
printf ("start\n"); fflush(stdout);
|
||||
|
||||
sem_init (&sem, 0, 0);
|
||||
sem_init (&sem_child, 0, 0);
|
||||
pthread_create(&id1, NULL, high_load, NULL);
|
||||
pthread_create(&id2, NULL, do_signal, NULL);
|
||||
#if !defined(__APPLE__)
|
||||
pthread_create(&id3, NULL, do_fork, NULL);
|
||||
#endif
|
||||
|
||||
/* sleep does not work !!! */
|
||||
end = time(NULL) + 2;
|
||||
while (time(NULL) < end) ;
|
||||
run = 0;
|
||||
|
||||
pthread_join(id1, NULL);
|
||||
pthread_join(id2, NULL);
|
||||
#if !defined(__APPLE__)
|
||||
pthread_join(id3, NULL);
|
||||
#endif
|
||||
sem_destroy (&sem);
|
||||
sem_destroy (&sem_child);
|
||||
|
||||
printf ("end\n"); fflush(stdout);
|
||||
|
||||
sigemptyset (&m);
|
||||
sigprocmask (SIG_SETMASK, &m, NULL);
|
||||
if (sigsetjmp (sj, 0) == 0)
|
||||
{
|
||||
sigaddset (&m, SIGUSR1);
|
||||
sigprocmask (SIG_SETMASK, &m, NULL);
|
||||
siglongjmp (sj, 1);
|
||||
printf ("failed");
|
||||
return 1;
|
||||
}
|
||||
sigprocmask (SIG_SETMASK, NULL, &m);
|
||||
if (!sigismember (&m, SIGUSR1))
|
||||
printf ("failed");
|
||||
return 0;
|
||||
}
|
2
05/tcc-final/tests/tests2/114_bound_signal.expect
Normal file
2
05/tcc-final/tests/tests2/114_bound_signal.expect
Normal file
|
@ -0,0 +1,2 @@
|
|||
start
|
||||
end
|
172
05/tcc-final/tests/tests2/115_bound_setjmp.c
Normal file
172
05/tcc-final/tests/tests2/115_bound_setjmp.c
Normal file
|
@ -0,0 +1,172 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#define TST int i, a[2], b[2]; \
|
||||
for (i = 0; i < 2; i++) a[i] = 0; \
|
||||
for (i = 0; i < 2; i++) b[i] = 0
|
||||
|
||||
static jmp_buf jmp;
|
||||
|
||||
static void tst1 (void)
|
||||
{
|
||||
TST;
|
||||
longjmp(jmp, 1);
|
||||
}
|
||||
|
||||
static void tst2(void)
|
||||
{
|
||||
jmp_buf jmp;
|
||||
|
||||
setjmp (jmp);
|
||||
TST;
|
||||
tst1();
|
||||
}
|
||||
|
||||
static void tst3 (jmp_buf loc)
|
||||
{
|
||||
TST;
|
||||
longjmp(loc, 1);
|
||||
}
|
||||
|
||||
static void tst4(jmp_buf loc)
|
||||
{
|
||||
jmp_buf jmp;
|
||||
|
||||
setjmp (jmp);
|
||||
TST;
|
||||
tst3(loc);
|
||||
}
|
||||
|
||||
static void tst (void)
|
||||
{
|
||||
jmp_buf loc;
|
||||
static int cnt;
|
||||
|
||||
cnt = 0;
|
||||
if (setjmp (jmp) == 0) {
|
||||
TST;
|
||||
tst2();
|
||||
}
|
||||
else {
|
||||
cnt++;
|
||||
}
|
||||
if (setjmp (loc) == 0) {
|
||||
TST;
|
||||
tst4(loc);
|
||||
}
|
||||
else {
|
||||
cnt++;
|
||||
}
|
||||
if (cnt != 2)
|
||||
printf ("incorrect cnt %d\n", cnt);
|
||||
}
|
||||
|
||||
static jmp_buf buf1;
|
||||
static jmp_buf buf2;
|
||||
static int *p;
|
||||
static int n_x = 6;
|
||||
static int g_counter;
|
||||
|
||||
static void stack (void)
|
||||
{
|
||||
static int counter;
|
||||
static int way_point1;
|
||||
static int way_point2;
|
||||
|
||||
counter = 0;
|
||||
way_point1 = 3;
|
||||
way_point2 = 2;
|
||||
g_counter = 0;
|
||||
if (setjmp (buf1) != 101) {
|
||||
int a[n_x];
|
||||
g_counter++;
|
||||
p = &a[0];
|
||||
if (g_counter < 5)
|
||||
longjmp (buf1, 2);
|
||||
else if (g_counter == 5)
|
||||
longjmp (buf1, 101);
|
||||
else {
|
||||
setjmp (buf2);
|
||||
longjmp (buf1, 101);
|
||||
}
|
||||
}
|
||||
|
||||
way_point1--;
|
||||
|
||||
if (counter == 0) {
|
||||
counter++;
|
||||
{
|
||||
int a[n_x];
|
||||
g_counter++;
|
||||
p = &a[0];
|
||||
if (g_counter < 5)
|
||||
longjmp (buf1, 2);
|
||||
else if (g_counter == 5)
|
||||
longjmp (buf1, 101);
|
||||
else {
|
||||
setjmp (buf2);
|
||||
longjmp (buf1, 101);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
way_point2--;
|
||||
|
||||
if (counter == 1) {
|
||||
counter++;
|
||||
longjmp (buf2, 2);
|
||||
}
|
||||
|
||||
if (!(way_point1 == 0 && way_point2 == 0 &&
|
||||
g_counter == 6 && counter == 2))
|
||||
printf ("Failed %d %d %d %d\n",
|
||||
way_point1, way_point2, g_counter, counter);
|
||||
}
|
||||
|
||||
static jmp_buf env;
|
||||
static int last_value;
|
||||
|
||||
static void jump (int val)
|
||||
{
|
||||
longjmp (env, val);
|
||||
}
|
||||
|
||||
static void check (void)
|
||||
{
|
||||
int value;
|
||||
|
||||
last_value = -1;
|
||||
value = setjmp (env);
|
||||
if (value != last_value + 1) {
|
||||
printf ("incorrect value %d %d\n",
|
||||
value, last_value + 1);
|
||||
return;
|
||||
}
|
||||
last_value = value;
|
||||
switch (value) {
|
||||
#if !(defined(__FreeBSD__) || defined(__NetBSD__))
|
||||
/* longjmp(jmp_buf, 0) not supported */
|
||||
case 0:
|
||||
jump (0);
|
||||
#endif
|
||||
default:
|
||||
if (value < 10)
|
||||
jump (value + 1);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
tst();
|
||||
stack();
|
||||
check();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
0
05/tcc-final/tests/tests2/115_bound_setjmp.expect
Normal file
0
05/tcc-final/tests/tests2/115_bound_setjmp.expect
Normal file
84
05/tcc-final/tests/tests2/116_bound_setjmp2.c
Normal file
84
05/tcc-final/tests/tests2/116_bound_setjmp2.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
#if !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define SIZE 10
|
||||
#define COUNT 10
|
||||
|
||||
#define TST int i, a[2], b[2]; \
|
||||
for (i = 0; i < 2; i++) a[i] = 0; \
|
||||
for (i = 0; i < 2; i++) b[i] = 0
|
||||
|
||||
static int count[SIZE];
|
||||
|
||||
static void tst1 (jmp_buf loc)
|
||||
{
|
||||
TST;
|
||||
longjmp(loc, 1);
|
||||
}
|
||||
|
||||
static void tst2(jmp_buf loc)
|
||||
{
|
||||
jmp_buf jmp;
|
||||
|
||||
setjmp (jmp);
|
||||
TST;
|
||||
tst1(loc);
|
||||
}
|
||||
|
||||
static void *tst (void * index)
|
||||
{
|
||||
jmp_buf loc;
|
||||
int i = *(int *) index;
|
||||
static int v[SIZE];
|
||||
|
||||
for (v[i] = 0; v[i] < COUNT; v[i]++) {
|
||||
if (setjmp (loc) == 0) {
|
||||
TST;
|
||||
tst2(loc);
|
||||
}
|
||||
else {
|
||||
count[i]++;
|
||||
}
|
||||
i = *(int *) index;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int i;
|
||||
#if !defined(_WIN32)
|
||||
pthread_t id[SIZE];
|
||||
#else
|
||||
HANDLE id[SIZE];
|
||||
#endif
|
||||
int index[SIZE];
|
||||
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
index[i] = i;
|
||||
#if !defined(_WIN32)
|
||||
pthread_create (&id[i], NULL, tst, (void *) &index[i]);
|
||||
#else
|
||||
id[i] = CreateThread(NULL, 8192, (LPTHREAD_START_ROUTINE) tst, (void *) &index[i], 0, NULL);
|
||||
#endif
|
||||
}
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
#if !defined(_WIN32)
|
||||
pthread_join (id[i], NULL);
|
||||
#else
|
||||
WaitForSingleObject(id[i], INFINITE);
|
||||
#endif
|
||||
}
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
if (count[i] != COUNT)
|
||||
printf ("error: %d %d\n", i, count[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
0
05/tcc-final/tests/tests2/116_bound_setjmp2.expect
Normal file
0
05/tcc-final/tests/tests2/116_bound_setjmp2.expect
Normal file
86
05/tcc-final/tests/tests2/117_builtins.c
Normal file
86
05/tcc-final/tests/tests2/117_builtins.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include <stdio.h>
|
||||
|
||||
struct big_struct { char a[262144]; };
|
||||
|
||||
static const char str[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
char *p;
|
||||
char tmp[100];
|
||||
int r = 0;
|
||||
|
||||
#if defined __BOUNDS_CHECKING_ON || defined BC_ON
|
||||
printf("BOUNDS ON:\n");
|
||||
#else
|
||||
printf("BOUNDS OFF:\n");
|
||||
#endif
|
||||
|
||||
if (r != 0)
|
||||
__builtin_abort();
|
||||
|
||||
r = (__builtin_offsetof(struct big_struct, a) != 0);
|
||||
printf(" 1:%d", !r);
|
||||
|
||||
p = __builtin_memcpy (tmp, str, sizeof(str));
|
||||
r = (p != tmp);
|
||||
printf(" 2:%d", !r);
|
||||
|
||||
r = __builtin_memcmp (p, str, sizeof(str));
|
||||
printf(" 3:%d", !r);
|
||||
|
||||
p = __builtin_memmove(tmp, str, sizeof(str));
|
||||
r = (__builtin_memcmp (p, str, sizeof(str)));
|
||||
printf(" 4:%d", !r);
|
||||
|
||||
p = __builtin_memset(tmp, 0, sizeof (tmp));
|
||||
r = (p != tmp || tmp[0] != 0 || tmp[99] != 0);
|
||||
printf(" 5:%d", !r);
|
||||
|
||||
r = (__builtin_strlen(str) != sizeof(str) - 1);
|
||||
printf(" 6:%d", !r);
|
||||
|
||||
p = __builtin_strcpy(tmp, str);
|
||||
r = (__builtin_memcmp (p, str, sizeof(str)));
|
||||
printf(" 7:%d", !r);
|
||||
|
||||
p = __builtin_strncpy(tmp, str, sizeof(str));
|
||||
r = (__builtin_memcmp (p, str, sizeof(str)));
|
||||
printf(" 8:%d", !r);
|
||||
|
||||
r = (__builtin_strcmp (p, str));
|
||||
printf(" 9:%d", !r);
|
||||
|
||||
r = (__builtin_strncmp (p, str, sizeof(str)));
|
||||
printf(" 10:%d", !r);
|
||||
|
||||
tmp[0] = '\0';
|
||||
p = __builtin_strcat(tmp, str);
|
||||
r = (__builtin_memcmp (p, str, sizeof(str)));
|
||||
printf(" 11:%d", !r);
|
||||
|
||||
r = (__builtin_strchr(p, 'z') != &p[25]);
|
||||
printf(" 12:%d", !r);
|
||||
|
||||
p = __builtin_strdup (str);
|
||||
r = (__builtin_memcmp (p, str, sizeof(str)));
|
||||
printf(" 13:%d", !r);
|
||||
__builtin_free(p);
|
||||
|
||||
p = __builtin_malloc (100);
|
||||
__builtin_memset(p, 0, 100);
|
||||
p = __builtin_realloc (p, 1000);
|
||||
__builtin_memset(p, 0, 1000);
|
||||
__builtin_free(p);
|
||||
|
||||
p = __builtin_calloc(10, 10);
|
||||
__builtin_memset(p, 0, 100);
|
||||
__builtin_free(p);
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
p = __builtin_alloca(100);
|
||||
__builtin_memset(p, 0, 100);
|
||||
#endif
|
||||
printf("\n");
|
||||
}
|
4
05/tcc-final/tests/tests2/117_builtins.expect
Normal file
4
05/tcc-final/tests/tests2/117_builtins.expect
Normal file
|
@ -0,0 +1,4 @@
|
|||
BOUNDS OFF:
|
||||
1:1 2:1 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 11:1 12:1 13:1
|
||||
BOUNDS ON:
|
||||
1:1 2:1 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 11:1 12:1 13:1
|
75
05/tcc-final/tests/tests2/118_switch.c
Normal file
75
05/tcc-final/tests/tests2/118_switch.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ibdg(long long n)
|
||||
{
|
||||
switch (n) {
|
||||
case 1LL ... 9LL: return 1;
|
||||
case 10LL ... 99LL: return 2;
|
||||
case 100LL ... 999LL: return 3;
|
||||
case 1000LL ... 9999LL: return 4;
|
||||
case 10000LL ... 99999LL: return 5;
|
||||
case 100000LL ... 999999LL: return 6;
|
||||
case 1000000LL ... 9999999LL: return 7;
|
||||
case 10000000LL ... 99999999LL: return 8;
|
||||
case 100000000LL ... 999999999LL: return 9;
|
||||
case 1000000000LL ... 9999999999LL: return 10;
|
||||
case 10000000000LL ... 99999999999LL: return 11;
|
||||
case 100000000000LL ... 999999999999LL: return 12;
|
||||
case 1000000000000LL ... 9999999999999LL: return 13;
|
||||
case 10000000000000LL ... 99999999999999LL: return 14;
|
||||
case 100000000000000LL ... 999999999999999LL: return 15;
|
||||
case 1000000000000000LL ... 9999999999999999LL: return 16;
|
||||
case 10000000000000000LL ... 99999999999999999LL: return 17;
|
||||
case 100000000000000000LL ... 999999999999999999LL: return 18;
|
||||
case 1000000000000000000LL ... 9223372036854775807LL: return 19;
|
||||
case -9223372036854775807LL-1LL ... -1LL: return 20;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ubdg(unsigned long long n)
|
||||
{
|
||||
switch (n) {
|
||||
case 1ULL ... 9ULL: return 1;
|
||||
case 10ULL ... 99ULL: return 2;
|
||||
case 100ULL ... 999ULL: return 3;
|
||||
case 1000ULL ... 9999ULL: return 4;
|
||||
case 10000ULL ... 99999ULL: return 5;
|
||||
case 100000ULL ... 999999ULL: return 6;
|
||||
case 1000000ULL ... 9999999ULL: return 7;
|
||||
case 10000000ULL ... 99999999ULL: return 8;
|
||||
case 100000000ULL ... 999999999ULL: return 9;
|
||||
case 1000000000ULL ... 9999999999ULL: return 10;
|
||||
case 10000000000ULL ... 99999999999ULL: return 11;
|
||||
case 100000000000ULL ... 999999999999ULL: return 12;
|
||||
case 1000000000000ULL ... 9999999999999ULL: return 13;
|
||||
case 10000000000000ULL ... 99999999999999ULL: return 14;
|
||||
case 100000000000000ULL ... 999999999999999ULL: return 15;
|
||||
case 1000000000000000ULL ... 9999999999999999ULL: return 16;
|
||||
case 10000000000000000ULL ... 99999999999999999ULL: return 17;
|
||||
case 100000000000000000ULL ... 999999999999999999ULL: return 18;
|
||||
case 1000000000000000000ULL ... 9999999999999999999ULL: return 19;
|
||||
case 10000000000000000000ULL ... 18446744073709551615ULL: return 20;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned long long v = 1;
|
||||
|
||||
v = 1;
|
||||
for (i = 1; i <= 20; i++) {
|
||||
printf("%lld : %d\n", (long long) v, ibdg((long long)v));
|
||||
v *= 10;
|
||||
}
|
||||
v = 1;
|
||||
for (i = 1; i <= 20; i++) {
|
||||
printf("%llu : %d\n", v, ubdg(v));
|
||||
v *= 10;
|
||||
}
|
||||
return 0;
|
||||
}
|
40
05/tcc-final/tests/tests2/118_switch.expect
Normal file
40
05/tcc-final/tests/tests2/118_switch.expect
Normal file
|
@ -0,0 +1,40 @@
|
|||
1 : 1
|
||||
10 : 2
|
||||
100 : 3
|
||||
1000 : 4
|
||||
10000 : 5
|
||||
100000 : 6
|
||||
1000000 : 7
|
||||
10000000 : 8
|
||||
100000000 : 9
|
||||
1000000000 : 10
|
||||
10000000000 : 11
|
||||
100000000000 : 12
|
||||
1000000000000 : 13
|
||||
10000000000000 : 14
|
||||
100000000000000 : 15
|
||||
1000000000000000 : 16
|
||||
10000000000000000 : 17
|
||||
100000000000000000 : 18
|
||||
1000000000000000000 : 19
|
||||
-8446744073709551616 : 20
|
||||
1 : 1
|
||||
10 : 2
|
||||
100 : 3
|
||||
1000 : 4
|
||||
10000 : 5
|
||||
100000 : 6
|
||||
1000000 : 7
|
||||
10000000 : 8
|
||||
100000000 : 9
|
||||
1000000000 : 10
|
||||
10000000000 : 11
|
||||
100000000000 : 12
|
||||
1000000000000 : 13
|
||||
10000000000000 : 14
|
||||
100000000000000 : 15
|
||||
1000000000000000 : 16
|
||||
10000000000000000 : 17
|
||||
100000000000000000 : 18
|
||||
1000000000000000000 : 19
|
||||
10000000000000000000 : 20
|
108
05/tcc-final/tests/tests2/119_random_stuff.c
Normal file
108
05/tcc-final/tests/tests2/119_random_stuff.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
#include <stdio.h>
|
||||
|
||||
struct big_struct { char a[262144]; };
|
||||
|
||||
static const char str[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
void tst_branch(void)
|
||||
{
|
||||
printf("tst_branch --");
|
||||
goto *&&a;
|
||||
printf (" dummy");
|
||||
a: ;
|
||||
printf(" --\n");
|
||||
}
|
||||
|
||||
void tst_void_ptr(void *pv, int i)
|
||||
{
|
||||
i ? *pv : *pv; // dr106
|
||||
}
|
||||
|
||||
void tst_shift(void)
|
||||
{
|
||||
int i = 1;
|
||||
long long l = 1;
|
||||
i = i << 32; // illegal. just test
|
||||
l = l << 64; // illegal. just test
|
||||
}
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <sys/mman.h>
|
||||
|
||||
void tst_const_addr(void)
|
||||
{
|
||||
void *addr = mmap ((void *)0x20000000, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS, -1, 0);
|
||||
if (addr != (void *) -1) {
|
||||
*(int *)0x20000000 += 42;
|
||||
munmap (addr, 4096);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
struct zero_struct {};
|
||||
|
||||
struct zero_struct tst_zero_struct(void)
|
||||
{
|
||||
struct zero_struct ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct big_struct tst_big(struct big_struct tst)
|
||||
{
|
||||
return tst;
|
||||
}
|
||||
|
||||
void tst_adr (int (*fp)(char *, const char *, ...))
|
||||
{
|
||||
char buf[10];
|
||||
(*fp)(buf, "%.0f", 5.0);
|
||||
printf("tst_adr %s\n", buf);
|
||||
}
|
||||
|
||||
int tst(void)
|
||||
{
|
||||
long long value = 3;
|
||||
return -value;
|
||||
}
|
||||
|
||||
void tst_compare(void)
|
||||
{
|
||||
/* This failed on risc64 */
|
||||
printf ("tst_compare: %s\n", tst() > 0 ? "error" : "ok");
|
||||
}
|
||||
|
||||
#pragma pack(1)
|
||||
struct S { int d:24; int f:14; } i, j;
|
||||
#pragma pack()
|
||||
|
||||
void tst_pack (void)
|
||||
{
|
||||
i.f = 5; j.f = 5;
|
||||
printf("tst_pack: j.f = %d, i.f = %d\n", j.f, i.f);
|
||||
}
|
||||
|
||||
void tst_cast(void)
|
||||
{
|
||||
signed char c = (signed char) 0xaaaaaaaa;
|
||||
int r = (unsigned short) c ^ (signed char) 0x99999999;
|
||||
printf ("schar to ushort cast: %x\n", r);
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
struct big_struct big;
|
||||
|
||||
tst_branch();
|
||||
tst_shift();
|
||||
tst_void_ptr(&big.a[0], 0);
|
||||
#if !defined(_WIN32)
|
||||
tst_const_addr();
|
||||
#endif
|
||||
tst_zero_struct();
|
||||
tst_big(big);
|
||||
tst_adr(&sprintf);
|
||||
tst_compare();
|
||||
tst_pack();
|
||||
tst_cast();
|
||||
}
|
5
05/tcc-final/tests/tests2/119_random_stuff.expect
Normal file
5
05/tcc-final/tests/tests2/119_random_stuff.expect
Normal file
|
@ -0,0 +1,5 @@
|
|||
tst_branch -- --
|
||||
tst_adr 5
|
||||
tst_compare: ok
|
||||
tst_pack: j.f = 5, i.f = 5
|
||||
schar to ushort cast: ffff0033
|
41
05/tcc-final/tests/tests2/11_precedence.c
Normal file
41
05/tcc-final/tests/tests2/11_precedence.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
//#include <stdio.h>
|
||||
extern int printf(const char *, ...);
|
||||
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
int e;
|
||||
int f;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
a = 12;
|
||||
b = 34;
|
||||
c = 56;
|
||||
d = 78;
|
||||
e = 0;
|
||||
f = 1;
|
||||
|
||||
printf("%d\n", c + d);
|
||||
printf("%d\n", (y = c + d));
|
||||
printf("%d\n", e || e && f);
|
||||
printf("%d\n", e || f && f);
|
||||
printf("%d\n", e && e || f);
|
||||
printf("%d\n", e && f || f);
|
||||
printf("%d\n", a && f | f);
|
||||
printf("%d\n", a | b ^ c & d);
|
||||
printf("%d, %d\n", a == a, a == b);
|
||||
printf("%d, %d\n", a != a, a != b);
|
||||
printf("%d\n", a != b && c != d);
|
||||
printf("%d\n", a + b * c / f);
|
||||
printf("%d\n", a + b * c / f);
|
||||
printf("%d\n", (4 << 4));
|
||||
printf("%d\n", (64 >> 4));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
15
05/tcc-final/tests/tests2/11_precedence.expect
Normal file
15
05/tcc-final/tests/tests2/11_precedence.expect
Normal file
|
@ -0,0 +1,15 @@
|
|||
134
|
||||
134
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
46
|
||||
1, 0
|
||||
0, 1
|
||||
1
|
||||
1916
|
||||
1916
|
||||
64
|
||||
4
|
15
05/tcc-final/tests/tests2/120+_alias.c
Normal file
15
05/tcc-final/tests/tests2/120+_alias.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
extern int printf (const char *, ...);
|
||||
extern void target(void);
|
||||
extern void alias_for_target(void);
|
||||
extern void asm_for_target(void);
|
||||
|
||||
void inunit2(void);
|
||||
|
||||
void inunit2(void)
|
||||
{
|
||||
target();
|
||||
alias_for_target();
|
||||
/* This symbol is not supposed to be available in this unit:
|
||||
asm_for_target();
|
||||
*/
|
||||
}
|
29
05/tcc-final/tests/tests2/120_alias.c
Normal file
29
05/tcc-final/tests/tests2/120_alias.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* Check semantics of various constructs to generate renamed symbols. */
|
||||
extern int printf (const char *, ...);
|
||||
void target(void);
|
||||
void target(void) {
|
||||
printf("in target function\n");
|
||||
}
|
||||
|
||||
void alias_for_target(void) __attribute__((alias("target")));
|
||||
#ifdef __leading_underscore
|
||||
void asm_for_target(void) __asm__("_target");
|
||||
#else
|
||||
void asm_for_target(void) __asm__("target");
|
||||
#endif
|
||||
|
||||
/* This is not supposed to compile, alias targets must be defined in the
|
||||
same unit. In TCC they even must be defined before the reference
|
||||
void alias_for_undef(void) __attribute__((alias("undefined")));
|
||||
*/
|
||||
|
||||
extern void inunit2(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
target();
|
||||
alias_for_target();
|
||||
asm_for_target();
|
||||
inunit2();
|
||||
return 0;
|
||||
}
|
5
05/tcc-final/tests/tests2/120_alias.expect
Normal file
5
05/tcc-final/tests/tests2/120_alias.expect
Normal file
|
@ -0,0 +1,5 @@
|
|||
in target function
|
||||
in target function
|
||||
in target function
|
||||
in target function
|
||||
in target function
|
35
05/tcc-final/tests/tests2/121_struct_return.c
Normal file
35
05/tcc-final/tests/tests2/121_struct_return.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <stdio.h>
|
||||
|
||||
typedef struct {
|
||||
int data[4];
|
||||
double d1;
|
||||
double d2;
|
||||
} Node;
|
||||
|
||||
Node init(Node self) {
|
||||
self.data[0] = 0;
|
||||
self.data[1] = 1;
|
||||
self.data[2] = 2;
|
||||
self.data[3] = 3;
|
||||
self.d1 = 1234;
|
||||
self.d2 = 2345;
|
||||
return self;
|
||||
}
|
||||
|
||||
void dummy(Node self) {
|
||||
}
|
||||
|
||||
void print_data(Node data) {
|
||||
printf ("%d %d %d %d %g %g\n",
|
||||
data.data[0], data.data[1], data.data[2], data.data[3],
|
||||
data.d1, data.d2);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/* This code resulted in a bounds checking error */
|
||||
Node data;
|
||||
dummy (data);
|
||||
char val;
|
||||
data = init (data);
|
||||
print_data(data);
|
||||
}
|
1
05/tcc-final/tests/tests2/121_struct_return.expect
Normal file
1
05/tcc-final/tests/tests2/121_struct_return.expect
Normal file
|
@ -0,0 +1 @@
|
|||
0 1 2 3 1234 2345
|
31
05/tcc-final/tests/tests2/122_vla_reuse.c
Normal file
31
05/tcc-final/tests/tests2/122_vla_reuse.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int n = 0;
|
||||
int first=1;
|
||||
int *p[101];
|
||||
if (0) {
|
||||
lab:;
|
||||
}
|
||||
int x[n % 100 + 1];
|
||||
if (first == 0) {
|
||||
if (&x[0] != p[n % 100 + 1]) {
|
||||
printf ("ERROR: %d %p $p\n", &x[0], p[n % 100 + 1]);
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
p[n % 100 + 1] = &x[0];
|
||||
first = n < 100;
|
||||
}
|
||||
x[0] = 1;
|
||||
x[n % 100] = 2;
|
||||
n++;
|
||||
if (n < 100000)
|
||||
goto lab;
|
||||
printf ("OK\n");
|
||||
return 0;
|
||||
}
|
||||
|
1
05/tcc-final/tests/tests2/122_vla_reuse.expect
Normal file
1
05/tcc-final/tests/tests2/122_vla_reuse.expect
Normal file
|
@ -0,0 +1 @@
|
|||
OK
|
40
05/tcc-final/tests/tests2/123_vla_bug.c
Normal file
40
05/tcc-final/tests/tests2/123_vla_bug.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
typedef __SIZE_TYPE__ size_t;
|
||||
extern int printf(const char*, ...);
|
||||
extern size_t strlen(const char*);
|
||||
char str[] = "blabla";
|
||||
int g;
|
||||
int main()
|
||||
{
|
||||
//char helpme[strlen(str) + 1];
|
||||
int i = 0;
|
||||
#if 0
|
||||
if (g) {
|
||||
char buf[strlen(str) + 10];
|
||||
buf[0] = 0;
|
||||
}
|
||||
alabel:
|
||||
printf("default: i = %d\n", i);
|
||||
#else
|
||||
for (i = 0; i < 5; i++) {
|
||||
switch (i) {
|
||||
case 10:
|
||||
if (g) {
|
||||
char buf[strlen(str) + 10];
|
||||
buf[0] = 0;
|
||||
goto do_cmd;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
printf("reached 3\n");
|
||||
do_cmd:
|
||||
printf("after do_cmd");
|
||||
break;
|
||||
default:
|
||||
g++;
|
||||
printf("default: i = %d\n", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
5
05/tcc-final/tests/tests2/123_vla_bug.expect
Normal file
5
05/tcc-final/tests/tests2/123_vla_bug.expect
Normal file
|
@ -0,0 +1,5 @@
|
|||
default: i = 0
|
||||
reached 3
|
||||
after do_cmddefault: i = 2
|
||||
default: i = 3
|
||||
default: i = 4
|
75
05/tcc-final/tests/tests2/124_atomic_counter.c
Normal file
75
05/tcc-final/tests/tests2/124_atomic_counter.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
|
||||
#define NR_THREADS 16
|
||||
#define NR_STEPS ((uint32_t)UINT16_MAX * 4)
|
||||
|
||||
#define BUG_ON(COND) \
|
||||
do { \
|
||||
if (!!(COND)) \
|
||||
abort(); \
|
||||
} while (0)
|
||||
|
||||
static
|
||||
void *adder_simple(void *arg)
|
||||
{
|
||||
size_t step;
|
||||
atomic_size_t *counter = arg;
|
||||
|
||||
for (step = 0; step < NR_STEPS; ++step)
|
||||
atomic_fetch_add_explicit(counter, 1, memory_order_relaxed);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
void *adder_cmpxchg(void *arg)
|
||||
{
|
||||
size_t step;
|
||||
atomic_size_t *counter = arg;
|
||||
|
||||
for (step = 0; step < NR_STEPS; ++step) {
|
||||
size_t xchg;
|
||||
size_t cmp = atomic_load_explicit(counter, memory_order_relaxed);
|
||||
|
||||
do {
|
||||
xchg = (cmp + 1);
|
||||
} while (!atomic_compare_exchange_strong_explicit(counter,
|
||||
&cmp, xchg, memory_order_relaxed, memory_order_relaxed));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
void atomic_counter_test(void *(*adder)(void *arg))
|
||||
{
|
||||
size_t index;
|
||||
atomic_size_t counter;
|
||||
pthread_t thread[NR_THREADS];
|
||||
|
||||
atomic_init(&counter, 0);
|
||||
|
||||
for (index = 0; index < NR_THREADS; ++index)
|
||||
BUG_ON(pthread_create(&thread[index], NULL, adder, (void *)&counter));
|
||||
|
||||
for (index = 0; index < NR_THREADS; ++index)
|
||||
BUG_ON(pthread_join(thread[index], NULL));
|
||||
|
||||
if (atomic_load(&counter) == (NR_THREADS * NR_STEPS))
|
||||
printf("SUCCESS\n");
|
||||
else
|
||||
printf("FAILURE\n");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
atomic_counter_test(adder_simple);
|
||||
atomic_counter_test(adder_cmpxchg);
|
||||
|
||||
return 0;
|
||||
}
|
2
05/tcc-final/tests/tests2/124_atomic_counter.expect
Normal file
2
05/tcc-final/tests/tests2/124_atomic_counter.expect
Normal file
|
@ -0,0 +1,2 @@
|
|||
SUCCESS
|
||||
SUCCESS
|
108
05/tcc-final/tests/tests2/125_atomic_misc.c
Normal file
108
05/tcc-final/tests/tests2/125_atomic_misc.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
#include <stdatomic.h>
|
||||
int printf(const char*,...);
|
||||
|
||||
#if defined test_atomic_compare_exchange
|
||||
int main()
|
||||
{
|
||||
_Atomic int a = 12;
|
||||
int b = 77;
|
||||
int r;
|
||||
|
||||
atomic_store(&a, b + 0);
|
||||
r = atomic_compare_exchange_strong(&a, &b, 99);
|
||||
printf("%d %d %d\n", r, a, b);
|
||||
|
||||
atomic_store(&a, b + 3);
|
||||
r = atomic_compare_exchange_strong(&a, &b, 99);
|
||||
printf("%d %d %d\n", r, a, b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif defined test_atomic_store
|
||||
int main()
|
||||
{
|
||||
int _Atomic i;
|
||||
int r;
|
||||
atomic_store(&i, 12);
|
||||
r = atomic_fetch_add(&i, i);
|
||||
printf("r = %d, i = %d\n", r, i);
|
||||
}
|
||||
|
||||
#elif defined test_atomic_store_pointer
|
||||
typedef struct { char c[4]; } c4;
|
||||
int main()
|
||||
{
|
||||
int i = 1;
|
||||
int _Atomic *p = &i;
|
||||
int k = 2;
|
||||
atomic_store(&p, &k);
|
||||
printf("*p = %d\n", *p);
|
||||
}
|
||||
|
||||
#elif defined test_atomic_store_struct
|
||||
typedef struct { char c[4]; } c4;
|
||||
int main()
|
||||
{
|
||||
c4 _Atomic p;
|
||||
c4 v = { 1,2,3,4 };
|
||||
atomic_store(&p, v);
|
||||
printf("%d %d %d %d\n", p.c[0], p.c[1], p.c[2], p.c[3]);
|
||||
}
|
||||
|
||||
#elif defined test_atomic_error_1
|
||||
int main()
|
||||
{
|
||||
int _Atomic i;
|
||||
atomic_load(i);
|
||||
}
|
||||
|
||||
#elif defined test_atomic_error_2
|
||||
int main()
|
||||
{
|
||||
struct { char c[3]; } _Atomic c3;
|
||||
atomic_load(&c3);
|
||||
}
|
||||
|
||||
#elif defined test_atomic_error_3
|
||||
int main()
|
||||
{
|
||||
_Atomic int *p = 0;
|
||||
atomic_fetch_add(&p, 1);
|
||||
}
|
||||
|
||||
#elif defined test_atomic_error_4
|
||||
int main()
|
||||
{
|
||||
int _Atomic i = 1;
|
||||
char c = 2;
|
||||
atomic_compare_exchange_strong(&i, &c, 0);
|
||||
}
|
||||
|
||||
#elif defined test_atomic_warn_1
|
||||
int main()
|
||||
{
|
||||
size_t _Atomic i = 1;
|
||||
/* assignment to integer from pointer */
|
||||
atomic_store(&i, &i);
|
||||
}
|
||||
|
||||
#elif defined test_atomic_warn_2
|
||||
int main()
|
||||
{
|
||||
int i = 1;
|
||||
char c = 2;
|
||||
int _Atomic *p = &i;
|
||||
/* assignment from incompatible pointer */
|
||||
atomic_store(&p, &c);
|
||||
}
|
||||
|
||||
#elif defined test_atomic_warn_3
|
||||
int main()
|
||||
{
|
||||
int const i = 1;
|
||||
/* assignment to read-only -location */
|
||||
atomic_fetch_add(&i, 2);
|
||||
}
|
||||
|
||||
#endif
|
33
05/tcc-final/tests/tests2/125_atomic_misc.expect
Normal file
33
05/tcc-final/tests/tests2/125_atomic_misc.expect
Normal file
|
@ -0,0 +1,33 @@
|
|||
[test_atomic_compare_exchange]
|
||||
1 99 77
|
||||
0 80 80
|
||||
|
||||
[test_atomic_store]
|
||||
r = 12, i = 24
|
||||
|
||||
[test_atomic_store_pointer]
|
||||
*p = 2
|
||||
|
||||
[test_atomic_store_struct]
|
||||
1 2 3 4
|
||||
|
||||
[test_atomic_error_1]
|
||||
125_atomic_misc.c:57: error: pointer expected
|
||||
|
||||
[test_atomic_error_2]
|
||||
125_atomic_misc.c:64: error: integral or integer-sized pointer target type expected
|
||||
|
||||
[test_atomic_error_3]
|
||||
125_atomic_misc.c:71: error: integral or integer-sized pointer target type expected
|
||||
|
||||
[test_atomic_error_4]
|
||||
125_atomic_misc.c:79: error: pointer target type mismatch in argument 2
|
||||
|
||||
[test_atomic_warn_1]
|
||||
125_atomic_misc.c:87: warning: assignment makes integer from pointer without a cast
|
||||
|
||||
[test_atomic_warn_2]
|
||||
125_atomic_misc.c:97: warning: assignment from incompatible pointer type
|
||||
|
||||
[test_atomic_warn_3]
|
||||
125_atomic_misc.c:105: warning: assignment of read-only location
|
13
05/tcc-final/tests/tests2/126_bound_global.c
Normal file
13
05/tcc-final/tests/tests2/126_bound_global.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
/* test bound checking code without -run */
|
||||
|
||||
int arr[10];
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i <= sizeof(arr)/sizeof(arr[0]); i++)
|
||||
arr[i] = 0;
|
||||
return 0;
|
||||
}
|
2
05/tcc-final/tests/tests2/126_bound_global.expect
Normal file
2
05/tcc-final/tests/tests2/126_bound_global.expect
Normal file
|
@ -0,0 +1,2 @@
|
|||
126_bound_global.c:11: at main: BCHECK: ........ is outside of the region
|
||||
126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access
|
14
05/tcc-final/tests/tests2/12_hashdefine.c
Normal file
14
05/tcc-final/tests/tests2/12_hashdefine.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define FRED 12
|
||||
#define BLOGGS(x) (12*(x))
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("%d\n", FRED);
|
||||
printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
2
05/tcc-final/tests/tests2/12_hashdefine.expect
Normal file
2
05/tcc-final/tests/tests2/12_hashdefine.expect
Normal file
|
@ -0,0 +1,2 @@
|
|||
12
|
||||
12, 24, 36
|
20
05/tcc-final/tests/tests2/13_integer_literals.c
Normal file
20
05/tcc-final/tests/tests2/13_integer_literals.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a = 24680;
|
||||
int b = 01234567;
|
||||
int c = 0x2468ac;
|
||||
int d = 0x2468AC;
|
||||
int e = 0b010101010101;
|
||||
|
||||
printf("%d\n", a);
|
||||
printf("%d\n", b);
|
||||
printf("%d\n", c);
|
||||
printf("%d\n", d);
|
||||
printf("%d\n", e);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
5
05/tcc-final/tests/tests2/13_integer_literals.expect
Normal file
5
05/tcc-final/tests/tests2/13_integer_literals.expect
Normal file
|
@ -0,0 +1,5 @@
|
|||
24680
|
||||
342391
|
||||
2386092
|
||||
2386092
|
||||
1365
|
21
05/tcc-final/tests/tests2/14_if.c
Normal file
21
05/tcc-final/tests/tests2/14_if.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a = 1;
|
||||
|
||||
if (a)
|
||||
printf("a is true\n");
|
||||
else
|
||||
printf("a is false\n");
|
||||
|
||||
int b = 0;
|
||||
if (b)
|
||||
printf("b is true\n");
|
||||
else
|
||||
printf("b is false\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
|
2
05/tcc-final/tests/tests2/14_if.expect
Normal file
2
05/tcc-final/tests/tests2/14_if.expect
Normal file
|
@ -0,0 +1,2 @@
|
|||
a is true
|
||||
b is false
|
21
05/tcc-final/tests/tests2/15_recursion.c
Normal file
21
05/tcc-final/tests/tests2/15_recursion.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int factorial(int i)
|
||||
{
|
||||
if (i < 2)
|
||||
return i;
|
||||
else
|
||||
return i * factorial(i - 1);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Count;
|
||||
|
||||
for (Count = 1; Count <= 10; Count++)
|
||||
printf("%d\n", factorial(Count));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|
10
05/tcc-final/tests/tests2/15_recursion.expect
Normal file
10
05/tcc-final/tests/tests2/15_recursion.expect
Normal file
|
@ -0,0 +1,10 @@
|
|||
1
|
||||
2
|
||||
6
|
||||
24
|
||||
120
|
||||
720
|
||||
5040
|
||||
40320
|
||||
362880
|
||||
3628800
|
21
05/tcc-final/tests/tests2/16_nesting.c
Normal file
21
05/tcc-final/tests/tests2/16_nesting.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x, y, z;
|
||||
|
||||
for (x = 0; x < 2; x++)
|
||||
{
|
||||
for (y = 0; y < 3; y++)
|
||||
{
|
||||
for (z = 0; z < 3; z++)
|
||||
{
|
||||
printf("%d %d %d\n", x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|
18
05/tcc-final/tests/tests2/16_nesting.expect
Normal file
18
05/tcc-final/tests/tests2/16_nesting.expect
Normal file
|
@ -0,0 +1,18 @@
|
|||
0 0 0
|
||||
0 0 1
|
||||
0 0 2
|
||||
0 1 0
|
||||
0 1 1
|
||||
0 1 2
|
||||
0 2 0
|
||||
0 2 1
|
||||
0 2 2
|
||||
1 0 0
|
||||
1 0 1
|
||||
1 0 2
|
||||
1 1 0
|
||||
1 1 1
|
||||
1 1 2
|
||||
1 2 0
|
||||
1 2 1
|
||||
1 2 2
|
72
05/tcc-final/tests/tests2/17_enum.c
Normal file
72
05/tcc-final/tests/tests2/17_enum.c
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include <stdio.h>
|
||||
|
||||
enum fred
|
||||
{
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d,
|
||||
e = 54,
|
||||
f = 73,
|
||||
g,
|
||||
h
|
||||
};
|
||||
|
||||
/* All following uses of enum efoo should compile
|
||||
without warning. While forward enums aren't ISO C,
|
||||
it's accepted by GCC also in strict mode, and only warned
|
||||
about with -pedantic. This happens in the real world. */
|
||||
/* Strict ISO C doesn't allow this kind of forward declaration of
|
||||
enums, but GCC accepts it (and gives only pedantic warning), and
|
||||
it occurs in the wild. */
|
||||
enum efoo;
|
||||
struct Sforward_use {
|
||||
int (*fmember) (enum efoo x);
|
||||
};
|
||||
|
||||
extern enum efoo it_real_fn(void);
|
||||
enum efoo {
|
||||
ONE,
|
||||
TWO,
|
||||
};
|
||||
struct S2 {
|
||||
enum efoo (*f2) (void);
|
||||
};
|
||||
void should_compile(struct S2 *s)
|
||||
{
|
||||
s->f2 = it_real_fn;
|
||||
}
|
||||
|
||||
enum efoo it_real_fn(void)
|
||||
{
|
||||
return TWO;
|
||||
}
|
||||
|
||||
static unsigned int deref_uintptr(unsigned int *p)
|
||||
{
|
||||
return *p;
|
||||
}
|
||||
|
||||
enum Epositive {
|
||||
epos_one, epos_two
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
enum fred frod;
|
||||
enum Epositive epos = epos_two;
|
||||
|
||||
printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h);
|
||||
/* printf("%d\n", frod); */
|
||||
frod = 12;
|
||||
printf("%d\n", frod);
|
||||
frod = e;
|
||||
printf("%d\n", frod);
|
||||
|
||||
/* Following should compile without warning. */
|
||||
printf ("enum to int: %u\n", deref_uintptr(&epos));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|
4
05/tcc-final/tests/tests2/17_enum.expect
Normal file
4
05/tcc-final/tests/tests2/17_enum.expect
Normal file
|
@ -0,0 +1,4 @@
|
|||
0 1 2 3 54 73 74 75
|
||||
12
|
||||
54
|
||||
enum to int: 1
|
12
05/tcc-final/tests/tests2/18_include.c
Normal file
12
05/tcc-final/tests/tests2/18_include.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("including\n");
|
||||
#include "18_include.h"
|
||||
printf("done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|
3
05/tcc-final/tests/tests2/18_include.expect
Normal file
3
05/tcc-final/tests/tests2/18_include.expect
Normal file
|
@ -0,0 +1,3 @@
|
|||
including
|
||||
included
|
||||
done
|
1
05/tcc-final/tests/tests2/18_include.h
Normal file
1
05/tcc-final/tests/tests2/18_include.h
Normal file
|
@ -0,0 +1 @@
|
|||
printf("included\n");
|
28
05/tcc-final/tests/tests2/19_pointer_arithmetic.c
Normal file
28
05/tcc-final/tests/tests2/19_pointer_arithmetic.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
int *b;
|
||||
int *c;
|
||||
|
||||
a = 42;
|
||||
b = &a;
|
||||
c = NULL;
|
||||
|
||||
printf("%d\n", *b);
|
||||
|
||||
if (b == NULL)
|
||||
printf("b is NULL\n");
|
||||
else
|
||||
printf("b is not NULL\n");
|
||||
|
||||
if (c == NULL)
|
||||
printf("c is NULL\n");
|
||||
else
|
||||
printf("c is not NULL\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|
3
05/tcc-final/tests/tests2/19_pointer_arithmetic.expect
Normal file
3
05/tcc-final/tests/tests2/19_pointer_arithmetic.expect
Normal file
|
@ -0,0 +1,3 @@
|
|||
42
|
||||
b is not NULL
|
||||
c is NULL
|
24
05/tcc-final/tests/tests2/20_pointer_comparison.c
Normal file
24
05/tcc-final/tests/tests2/20_pointer_comparison.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
int *d;
|
||||
int *e;
|
||||
d = &a;
|
||||
e = &b;
|
||||
a = 12;
|
||||
b = 34;
|
||||
printf("%d\n", *d);
|
||||
printf("%d\n", *e);
|
||||
printf("%d\n", d == e);
|
||||
printf("%d\n", d != e);
|
||||
d = e;
|
||||
printf("%d\n", d == e);
|
||||
printf("%d\n", d != e);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|
6
05/tcc-final/tests/tests2/20_pointer_comparison.expect
Normal file
6
05/tcc-final/tests/tests2/20_pointer_comparison.expect
Normal file
|
@ -0,0 +1,6 @@
|
|||
12
|
||||
34
|
||||
0
|
||||
1
|
||||
1
|
||||
0
|
33
05/tcc-final/tests/tests2/21_char_array.c
Normal file
33
05/tcc-final/tests/tests2/21_char_array.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 'a';
|
||||
char y = x;
|
||||
|
||||
char *a = "hello";
|
||||
|
||||
printf("%s\n", a);
|
||||
|
||||
int c;
|
||||
c = *a;
|
||||
|
||||
char *b;
|
||||
for (b = a; *b != 0; b++)
|
||||
printf("%c: %d\n", *b, *b);
|
||||
|
||||
char destarray[10];
|
||||
char *dest = &destarray[0];
|
||||
char *src = a;
|
||||
|
||||
while (*src != 0)
|
||||
*dest++ = *src++;
|
||||
|
||||
*dest = 0;
|
||||
|
||||
printf("copied string is %s\n", destarray);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue