diff --git a/tccgen.c b/tccgen.c index 03c46ee..06d8f02 100644 --- a/tccgen.c +++ b/tccgen.c @@ -3569,13 +3569,8 @@ again: if (ds <= ss) goto done; /* ss <= 4 here */ - if (ds <= 4) { + if (ds <= 4 && dbt != (VT_SHORT | VT_UNSIGNED) && sbt != VT_BYTE) { gv(RC_INT); - if (ds == 2 && (dbt & VT_UNSIGNED) && - ss == 1 && (sbt & VT_UNSIGNED) == 0) { - vpushi(0xffff); - gen_op('&'); - } goto done; /* no 64bit envolved */ } } diff --git a/tests/tests2/117_builtins.c b/tests/tests2/117_builtins.c new file mode 100644 index 0000000..4da28ff --- /dev/null +++ b/tests/tests2/117_builtins.c @@ -0,0 +1,86 @@ +#include + +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"); +} diff --git a/tests/tests2/117_builtins.expect b/tests/tests2/117_builtins.expect new file mode 100644 index 0000000..776e432 --- /dev/null +++ b/tests/tests2/117_builtins.expect @@ -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 diff --git a/tests/tests2/117_gcc_test.c b/tests/tests2/117_gcc_test.c deleted file mode 100644 index 8b0467f..0000000 --- a/tests/tests2/117_gcc_test.c +++ /dev/null @@ -1,166 +0,0 @@ -#include - -void tst_branch(void) -{ - goto *&&a; - printf ("dummy"); -a: ; -} - -void tst_void_ptr(void *pv, int i) -{ - i ? *pv : *pv; // dr106 -} - -void tst_shift(void) -{ - int i = 1; - long l = 1; - - i = i << 32; // illegal. just test - l = l << 64; // illegal. just test -} - -#if !defined(_WIN32) -#include - -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) { -#if !defined(__riscv) - *(int *)0x20000000 += 42; -#endif - munmap (addr, 4096); - } -} -#endif - -struct zero_struct {}; - -struct zero_struct tst_zero_struct(void) -{ - struct zero_struct ret; - - return ret; -} - -struct big_struct { char a[262144]; }; - -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); -} - -static const char str[] = "abcdefghijklmnopqrstuvwxyz"; - -void tst_builtin(void) -{ - char *p; - char tmp[100]; - - if (__builtin_offsetof(struct big_struct, a) != 0) __builtin_abort(); - - p = __builtin_memcpy (tmp, str, sizeof(str)); - if (p != tmp) __builtin_abort(); - - if (__builtin_memcmp (p, str, sizeof(str))) __builtin_abort(); - - p = __builtin_memmove(tmp, str, sizeof(str)); - if (__builtin_memcmp (p, str, sizeof(str))) __builtin_abort(); - - p = __builtin_memset(tmp, 0, sizeof (tmp)); - if (p != tmp || tmp[0] != 0 || tmp[99] != 0) __builtin_abort(); - - if (__builtin_strlen(str) != sizeof(str) - 1) __builtin_abort(); - - p = __builtin_strcpy(tmp, str); - if (__builtin_memcmp (p, str, sizeof(str))) __builtin_abort(); - - p = __builtin_strncpy(tmp, str, sizeof(str)); - if (__builtin_memcmp (p, str, sizeof(str))) __builtin_abort(); - - if (__builtin_strcmp (p, str)) __builtin_abort(); - - if (__builtin_strncmp (p, str, sizeof(str))) __builtin_abort(); - - tmp[0] = '\0'; - p = __builtin_strcat(tmp, str); - if (__builtin_memcmp (p, str, sizeof(str))) __builtin_abort(); - - if (__builtin_strchr(p, 'z') != &p[25]) __builtin_abort(); - - p = __builtin_strdup (str); - if (__builtin_memcmp (p, str, sizeof(str))) __builtin_abort(); - __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 -} - -int tst(void) -{ - long value = 3; - return -value; -} - -void tst_compare(void) -{ - /* This failed on risc64 */ - if (tst() > 0) printf ("error\n"); -} - -#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; - if (j.f != i.f) printf("error\n"); -} - -void tst_cast(void) -{ - signed char c = (signed char) 0xaaaaaaaa; - int r = (unsigned short) c ^ (signed char) 0x99999999; - if (r != 0xffff0033) printf ("%x\n", r); -} - -int -main (void) -{ - struct big_struct big; - - 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_builtin(); - tst_compare(); - tst_pack(); - tst_cast(); -} diff --git a/tests/tests2/117_gcc_test.expect b/tests/tests2/117_gcc_test.expect deleted file mode 100644 index e69de29..0000000 diff --git a/tests/tests2/118_switch_test.c b/tests/tests2/118_switch.c similarity index 100% rename from tests/tests2/118_switch_test.c rename to tests/tests2/118_switch.c diff --git a/tests/tests2/118_switch_test.expect b/tests/tests2/118_switch.expect similarity index 100% rename from tests/tests2/118_switch_test.expect rename to tests/tests2/118_switch.expect diff --git a/tests/tests2/119_random_stuff.c b/tests/tests2/119_random_stuff.c new file mode 100644 index 0000000..6c425de --- /dev/null +++ b/tests/tests2/119_random_stuff.c @@ -0,0 +1,110 @@ +#include + +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 + +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) { +#if !defined(__riscv) + *(int *)0x20000000 += 42; +#endif + 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(); +} diff --git a/tests/tests2/119_random_stuff.expect b/tests/tests2/119_random_stuff.expect new file mode 100644 index 0000000..0ad779e --- /dev/null +++ b/tests/tests2/119_random_stuff.expect @@ -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 diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index 8b169b4..93e4062 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -87,17 +87,16 @@ GEN-ALWAYS = -e 's;0x[0-9A-Fa-f]\{1,\};0x?;g' # this test creates two DLLs and an EXE -113_btdll.test: NORUN = true -113_btdll.test: FLAGS += \ - -bt $1 -shared -D DLL=1 -o a1$(DLLSUF) && $(TCC) \ - -bt $1 -shared -D DLL=2 -o a2$(DLLSUF) && $(TCC) \ - -bt a1$(DLLSUF) a2$(DLLSUF) -Wl,-rpath=. +113_btdll.test: T1 = \ + $(TCC) -bt $1 -shared -D DLL=1 -o a1$(DLLSUF) && \ + $(TCC) -bt $1 -shared -D DLL=2 -o a2$(DLLSUF) && \ + $(TCC) -bt $1 a1$(DLLSUF) a2$(DLLSUF) -Wl,-rpath=. -o a.exe && \ + ./a.exe 114_bound_signal.test: FLAGS += -b 115_bound_setjmp.test: FLAGS += -b 116_bound_setjmp2.test: FLAGS += -b - -117_gcc_test.test: FLAGS += $(T2) && $(TCC) -b +117_builtins.test: T1 = ( $(TCC) -run $1 && $(TCC) -b -run $1 ) # Filter source directory in warnings/errors (out-of-tree builds) FILTER = 2>&1 | sed -e 's,$(SRC)/,,g'