tests2: rework 117..119 to follow our conventions

Please respect some conventions:

- tests2 filenames don't end with '..._test'

- tests2 tests are meant to produce some output

- the output should be somehow informative, not just
  "error" or "dummy". Because other people would want to
  know where it fails if it does.

- tests2 tests should work with both GCC and TCC, except
  if there are specifc reasons (like testing tcc-only
  feature such as bounds checking)

- tests2 tests should never crash or abort.  Because that
  would cause gui dialogs to pop up on windows, and because
  other people would not know where it fails if it does.

- tests2 tests should be somehow specific, in general.
  (rather than just collections of random stuff)

- in general, do not use 'long' if you mean 'larger than int'
  Because it isn't on many platforms.

- use four (4) spaces for block indention.  Do not insert
  tab characters in files if possible.

Also:
- tccgen.c:gen_cast() simplify last fix.
This commit is contained in:
grischka 2020-07-08 04:37:04 +02:00
parent f9870f7860
commit d746e32349
10 changed files with 212 additions and 179 deletions

View File

@ -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 */
}
}

View 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");
}

View 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

View File

@ -1,166 +0,0 @@
#include <stdio.h>
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 <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) {
#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();
}

View File

@ -0,0 +1,110 @@
#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) {
#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();
}

View 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

View File

@ -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'