From 62b273f73cd7a4db22b1161f450ae7267d185890 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Thu, 8 Nov 2018 23:09:38 +0000
Subject: [PATCH 4/7] [TESTSUITE] Fix tests when int is 16-bit by default
2018-11-14 Jozef Lawrynowicz <jozef.l@mittosystems.com>
gcc/testsuite/ChangeLog:
* c-c++-common/Warray-bounds-3.c (test_strcpy_bounds): Use long instead
of int if __SIZEOF_INT__ == 2.
* c-c++-common/Wrestrict.c: Test memcpy range with smaller length when
__SIZEOF_SIZE_T < 4.
* c-c++-common/rotate-8.c: Define smaller "large" constant when
__SIZEOF_INT__ == 2.
* gcc.dg/pr53037-1.c: Add dg-require-effective-target int32.
* gcc.dg/pr53037-2.c: Likewise.
* gcc.dg/pr53037-3.c: Likewise.
* gcc.dg/pr85512.c: Likewise.
* gcc.dg/pr59963-2.c: Add dg-warning for int16.
* gcc.dg/sancov/cmp0.c: Explicitly use __INT32_TYPE__ instead of int.
* gcc.dg/tree-ssa/addadd.c: Fix dg-final directives for int16.
* gcc.dg/tree-ssa/pr79327-2.c: Likewise.
* gcc.dg/tree-ssa/builtin-sprintf-2.c: Filter out invalid tests for
int16.
* gcc.dg/tree-ssa/builtin-sprintf-warn-10.c: Update sizes in dg-warning
directives for int16.
---
gcc/testsuite/c-c++-common/Warray-bounds-3.c | 4 +
gcc/testsuite/c-c++-common/Wrestrict.c | 5 ++
gcc/testsuite/c-c++-common/rotate-8.c | 14 +++-
gcc/testsuite/gcc.dg/pr53037-1.c | 2 +-
gcc/testsuite/gcc.dg/pr53037-2.c | 2 +-
gcc/testsuite/gcc.dg/pr53037-3.c | 2 +-
gcc/testsuite/gcc.dg/pr59963-2.c | 1 +
gcc/testsuite/gcc.dg/pr85512.c | 1 +
gcc/testsuite/gcc.dg/sancov/cmp0.c | 14 +++-
gcc/testsuite/gcc.dg/tree-ssa/addadd.c | 4 +-
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-2.c | 9 ++-
.../gcc.dg/tree-ssa/builtin-sprintf-warn-10.c | 94 +++++++++++-----------
gcc/testsuite/gcc.dg/tree-ssa/pr79327-2.c | 5 +-
13 files changed, 96 insertions(+), 61 deletions(-)
@@ -326,7 +326,11 @@ void test_strcpy_bounds (char *d, const char *s)
struct MA
{
+#if __SIZEOF_INT__ == 2
+ long i;
+#else
int i;
+#endif
char a5[5];
char a11[11];
};
@@ -262,8 +262,13 @@ void test_memcpy_range (char *d, size_t sz)
{
/* Create an offset in the range [0, -1]. */
size_t o = sz << 1;
+#if __SIZEOF_SIZE_T__ < 4
+ T (d, d + o, 1234);
+ T (d + o, d, 2345);
+#else
T (d, d + o, 12345);
T (d + o, d, 23456);
+#endif
}
/* Exercise memcpy with both destination and source pointer offsets
@@ -5,6 +5,12 @@
/* { dg-final { scan-tree-dump-times "r\[<>]\[<>]" 23 "optimized" } } */
/* { dg-final { scan-tree-dump-not "PHI <" "optimized" } } */
+#if __SIZEOF_INT__ == 2
+#define LARGE_UNSIGNED 0x1234U
+#else
+#define LARGE_UNSIGNED 0x12345678U
+#endif
+
unsigned int
f1 (unsigned int x, unsigned char y)
{
@@ -60,25 +66,25 @@ f8 (unsigned int x, unsigned char y)
unsigned int
f9 (unsigned int x, int y)
{
- return (0x12345678U << (y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1))) | (0x12345678U >> (-y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1)));
+ return (LARGE_UNSIGNED << (y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1))) | (LARGE_UNSIGNED >> (-y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1)));
}
unsigned int
f10 (unsigned int x, int y)
{
- return (0x12345678U >> (-y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1))) | (0x12345678U << (y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1)));
+ return (LARGE_UNSIGNED >> (-y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1))) | (LARGE_UNSIGNED << (y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1)));
}
unsigned int
f11 (unsigned int x, int y)
{
- return (0x12345678U >> (y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1))) | (0x12345678U << (-y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1)));
+ return (LARGE_UNSIGNED >> (y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1))) | (LARGE_UNSIGNED << (-y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1)));
}
unsigned int
f12 (unsigned int x, int y)
{
- return (0x12345678U << (-y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1))) | (0x12345678U >> (y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1)));
+ return (LARGE_UNSIGNED << (-y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1))) | (LARGE_UNSIGNED >> (y & (__CHAR_BIT__ * __SIZEOF_INT__ - 1)));
}
unsigned
@@ -1,7 +1,7 @@
/* PR c/53037. */
/* { dg-do compile } */
/* { dg-options "-O0" } */
-/* { dg-skip-if "" { avr-*-* } } */
+/* { dg-require-effective-target int32 } */
typedef unsigned long long __u64
__attribute__((aligned(4),warn_if_not_aligned(8)));
@@ -1,7 +1,7 @@
/* PR c/53037. */
/* { dg-do compile } */
/* { dg-options "-O0 -Wpacked-not-aligned" } */
-/* { dg-skip-if "" { avr-*-* } } */
+/* { dg-require-effective-target int32 } */
struct __attribute__ ((aligned (8))) S8 { char a[8]; };
struct __attribute__ ((packed)) S1 {
@@ -1,7 +1,7 @@
/* PR c/53037. */
/* { dg-do compile } */
/* { dg-options "-O0 -Wall" } */
-/* { dg-skip-if "" { avr-*-* } } */
+/* { dg-require-effective-target int32 } */
struct __attribute__ ((aligned (8))) S8 { char a[8]; };
struct __attribute__ ((packed)) S1 {
@@ -33,4 +33,5 @@ foo (int i)
-8); /* { dg-warning "16:-Wsign-conversion" } */
bazu (i, i); /* { dg-warning "9:conversion" } */
bazi (0x8, 0x80000000); /* { dg-warning "14:-Wsign-conversion" "" { xfail int16 } } */
+ /* { dg-warning "overflow in conversion from" "" { target int16 } .-1 } */
}
@@ -1,5 +1,6 @@
/* { dg-do assemble } */
/* { dg-options "-O -fno-if-conversion" } */
+/* { dg-require-effective-target int32 } */
typedef unsigned char u8;
typedef unsigned short u16;
@@ -3,8 +3,14 @@
/* { dg-options "-fsanitize-coverage=trace-cmp -fdump-tree-optimized" } */
/* { dg-skip-if "different type layout" { avr-*-* } } */
+#if __SIZEOF_INT__ < 4
+typedef __INT32_TYPE__ int32;
+#else
+typedef int int32;
+#endif
+
void
-foo (char *a, short *b, int *c, long long *d, float *e, double *f)
+foo (char *a, short *b, int32 *c, long long *d, float *e, double *f)
{
if (*a)
*a += 1;
@@ -63,7 +69,7 @@ foo (char *a, short *b, int *c, long long *d, float *e, double *f)
}
void
-bar (int *c)
+bar (int32 *c)
{
if (*c == 27)
*c += 2;
@@ -71,8 +77,8 @@ bar (int *c)
*c += 2;
}
-int
-baz (int *c, long long d, long long e)
+int32
+baz (int32 *c, long long d, long long e)
{
*c = (*c == 48) ? 12 : 24;
return d == e;
@@ -25,5 +25,7 @@ int i(int x){
}
/* { dg-final { scan-tree-dump-times " \\+ 24;" 2 "optimized" } } */
-/* { dg-final { scan-tree-dump-times "\\(unsigned int\\)" 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "\\(unsigned int\\)" 2 "optimized" { target { ! int16 } } } } */
+/* { dg-final { scan-tree-dump-times "\\(unsigned int\\)" 1 "optimized" { target int16 } } } */
+/* { dg-final { scan-tree-dump-times "\\(unsigned short\\)" 1 "optimized" { target int16 } } } */
/* { dg-final { scan-tree-dump-not "2147483647" "optimized" } } */
@@ -78,7 +78,10 @@ EQL (0, 0, "%-s", "");
EQL (1, 1, "%c", 'x');
EQL (1, 1, "%-s", "x");
+/* Size of character constant must be larger than 2 for this to overflow. */
+#if __SIZEOF_INT__ > 2
EQL (1, 2, "%c", 'x');
+#endif
EQL (4, 4, "%4c", 'x');
@@ -168,7 +171,11 @@ RNG (0, 4, 6, "%i", i)
RNG (0, 5, 6, "%i", i)
RNG (0, 6, 6, "%i", i)
+/* If int is 16bit then it will always fit in 7 char characters with this
+ formatting. */
+#if __SIZEOF_INT__ > 2
RNG (0, 0, 7, "%i", i)
+#endif
RNG (0, 1, 7, "%i", i)
RNG (0, 2, 7, "%i", i)
RNG (0, 3, 7, "%i", i)
@@ -291,6 +298,6 @@ RNG (0, 6, 8, "%s%ls", "1", L"2");
/* Only conditional calls to must_not_eliminate must be made (with
any probability):
{ dg-final { scan-tree-dump-times "> \\\[local count: \[0-9INV\]*\\\]:\n *must_not_eliminate" 127 "optimized" { target { ilp32 || lp64 } } } }
- { dg-final { scan-tree-dump-times "> \\\[local count: \[0-9INV\]*\\\]:\n *must_not_eliminate" 96 "optimized" { target { { ! ilp32 } && { ! lp64 } } } } }
+ { dg-final { scan-tree-dump-times "> \\\[local count: \[0-9INV\]*\\\]:\n *must_not_eliminate" 94 "optimized" { target { ! { ilp32 || lp64 } } } } }
No unconditional calls to abort should be made:
{ dg-final { scan-tree-dump-not ";\n *must_not_eliminate" "optimized" } } */
@@ -39,17 +39,17 @@ void test_a (int w, int p, double x)
T1 ("%*.a", 6); /* { dg-warning "between 6 and 10 bytes" } */
T1 ("%*.a", 7); /* { dg-warning "between 7 and 10 bytes" } */
- T1 ("%*.a", w); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
- T1 ("%*.0a", w); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
- T1 ("%*.1a", w); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
- T1 ("%*.2a", w); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
+ T1 ("%*.a", w); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
+ T1 ("%*.0a", w); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
+ T1 ("%*.1a", w); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
+ T1 ("%*.2a", w); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
- T1 ("%.*a", p); /* { dg-warning "writing between 3 and 2147483658 bytes" } */
- T1 ("%1.*a", p); /* { dg-warning "writing between 3 and 2147483658 bytes" } */
- T1 ("%2.*a", p); /* { dg-warning "writing between 3 and 2147483658 bytes" } */
- T1 ("%3.*a", p); /* { dg-warning "writing between 3 and 2147483658 bytes" } */
+ T1 ("%.*a", p); /* { dg-warning "writing between 3 and (2147483658|32778) bytes" } */
+ T1 ("%1.*a", p); /* { dg-warning "writing between 3 and (2147483658|32778) bytes" } */
+ T1 ("%2.*a", p); /* { dg-warning "writing between 3 and (2147483658|32778) bytes" } */
+ T1 ("%3.*a", p); /* { dg-warning "writing between 3 and (2147483658|32778) bytes" } */
- T2 ("%*.*a", w, p); /* { dg-warning "writing between 3 and 2147483658 bytes" } */
+ T2 ("%*.*a", w, p); /* { dg-warning "writing between 3 and (2147483658|32778) bytes" } */
}
/* Exercise %e. */
@@ -69,17 +69,17 @@ void test_e (int w, int p, double x)
T1 ("%*.e", 6); /* { dg-warning "between 6 and 7 bytes" } */
T1 ("%*.e", 7); /* { dg-warning "writing 7 bytes" } */
- T1 ("%*.e", w); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
- T1 ("%*.0e", w); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
- T1 ("%*.1e", w); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
- T1 ("%*.2e", w); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
+ T1 ("%*.e", w); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
+ T1 ("%*.0e", w); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
+ T1 ("%*.1e", w); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
+ T1 ("%*.2e", w); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
- T1 ("%.*e", p); /* { dg-warning "writing between 3 and 2147483655 bytes" } */
- T1 ("%1.*e", p); /* { dg-warning "writing between 3 and 2147483655 bytes" } */
- T1 ("%2.*e", p); /* { dg-warning "writing between 3 and 2147483655 bytes" } */
- T1 ("%3.*e", p); /* { dg-warning "writing between 3 and 2147483655 bytes" } */
+ T1 ("%.*e", p); /* { dg-warning "writing between 3 and (2147483655|32775) bytes" } */
+ T1 ("%1.*e", p); /* { dg-warning "writing between 3 and (2147483655|32775) bytes" } */
+ T1 ("%2.*e", p); /* { dg-warning "writing between 3 and (2147483655|32775) bytes" } */
+ T1 ("%3.*e", p); /* { dg-warning "writing between 3 and (2147483655|32775) bytes" } */
- T2 ("%*.*e", w, p); /* { dg-warning "writing between 3 and 2147483655 bytes" } */
+ T2 ("%*.*e", w, p); /* { dg-warning "writing between 3 and (2147483655|32775) bytes" } */
}
/* Exercise %f. */
@@ -101,17 +101,17 @@ void test_f (int w, int p, double x)
T2 ("%*.*f", 312, 312); /* { dg-warning "between 312 and 623 bytes" } */
T2 ("%*.*f", 312, 313); /* { dg-warning "between 312 and 624 bytes" } */
- T1 ("%*.f", w); /* { dg-warning "writing between 1 and 2147483648 bytes" } */
- T1 ("%*.0f", w); /* { dg-warning "writing between 1 and 2147483648 bytes" } */
- T1 ("%*.1f", w); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
- T1 ("%*.2f", w); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
+ T1 ("%*.f", w); /* { dg-warning "writing between 1 and (2147483648|32768) bytes" } */
+ T1 ("%*.0f", w); /* { dg-warning "writing between 1 and (2147483648|32768) bytes" } */
+ T1 ("%*.1f", w); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
+ T1 ("%*.2f", w); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
- T1 ("%.*f", p); /* { dg-warning "writing between 1 and 2147483958 bytes" } */
- T1 ("%1.*f", p); /* { dg-warning "writing between 1 and 2147483958 bytes" } */
- T1 ("%2.*f", p); /* { dg-warning "writing between 2 and 2147483958 bytes" } */
- T1 ("%3.*f", p); /* { dg-warning "writing between 3 and 2147483958 bytes" } */
+ T1 ("%.*f", p); /* { dg-warning "writing between 1 and (2147483958|33078) bytes" } */
+ T1 ("%1.*f", p); /* { dg-warning "writing between 1 and (2147483958|33078) bytes" } */
+ T1 ("%2.*f", p); /* { dg-warning "writing between 2 and (2147483958|33078) bytes" } */
+ T1 ("%3.*f", p); /* { dg-warning "writing between 3 and (2147483958|33078) bytes" } */
- T2 ("%*.*f", w, p); /* { dg-warning "writing between 1 and 2147483958 bytes" } */
+ T2 ("%*.*f", w, p); /* { dg-warning "writing between 1 and (2147483958|33078) bytes" } */
}
/* Exercise %g. The expected output is the lesser of %e and %f. */
@@ -152,18 +152,18 @@ void test_a_va (va_list va)
T ("%6.a"); /* { dg-warning "between 6 and 10 bytes" } */
T ("%7.a"); /* { dg-warning "between 7 and 10 bytes" } */
- T ("%*.a"); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
- T ("%*.0a"); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
- T ("%*.1a"); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
- T ("%*.2a"); /* { dg-warning "writing between 3 and 2147483648 bytes" } */
+ T ("%*.a"); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
+ T ("%*.0a"); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
+ T ("%*.1a"); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
+ T ("%*.2a"); /* { dg-warning "writing between 3 and (2147483648|32768) bytes" } */
- T ("%.*a"); /* { dg-warning "writing between 3 and 2147483658 bytes" } */
- T ("%1.*a"); /* { dg-warning "writing between 3 and 2147483658 bytes" } */
- T ("%2.*a"); /* { dg-warning "writing between 3 and 2147483658 bytes" } */
- T ("%6.*a"); /* { dg-warning "writing between 6 and 2147483658 bytes" } */
- T ("%9.*a"); /* { dg-warning "writing between 9 and 2147483658 bytes" } */
+ T ("%.*a"); /* { dg-warning "writing between 3 and (2147483658|32778) bytes" } */
+ T ("%1.*a"); /* { dg-warning "writing between 3 and (2147483658|32778) bytes" } */
+ T ("%2.*a"); /* { dg-warning "writing between 3 and (2147483658|32778) bytes" } */
+ T ("%6.*a"); /* { dg-warning "writing between 6 and (2147483658|32778) bytes" } */
+ T ("%9.*a"); /* { dg-warning "writing between 9 and (2147483658|32778) bytes" } */
- T ("%*.*a"); /* { dg-warning "writing between 3 and 2147483658 bytes" } */
+ T ("%*.*a"); /* { dg-warning "writing between 3 and (2147483658|32778) bytes" } */
}
/* Exercise %e. */
@@ -191,12 +191,12 @@ void test_e_va (va_list va)
T ("%6.e"); /* { dg-warning "between 6 and 7 bytes" } */
T ("%7.e"); /* { dg-warning "writing 7 bytes" } */
- T ("%.*e"); /* { dg-warning "writing between 3 and 2147483655 bytes" } */
- T ("%1.*e"); /* { dg-warning "writing between 3 and 2147483655 bytes" } */
- T ("%6.*e"); /* { dg-warning "writing between 6 and 2147483655 bytes" } */
- T ("%9.*e"); /* { dg-warning "writing between 9 and 2147483655 bytes" } */
+ T ("%.*e"); /* { dg-warning "writing between 3 and (2147483655|32775) bytes" } */
+ T ("%1.*e"); /* { dg-warning "writing between 3 and (2147483655|32775) bytes" } */
+ T ("%6.*e"); /* { dg-warning "writing between 6 and (2147483655|32775) bytes" } */
+ T ("%9.*e"); /* { dg-warning "writing between 9 and (2147483655|32775) bytes" } */
- T ("%*.*e"); /* { dg-warning "writing between 3 and 2147483655 bytes" } */
+ T ("%*.*e"); /* { dg-warning "writing between 3 and (2147483655|32775) bytes" } */
}
/* Exercise %f. */
@@ -228,11 +228,11 @@ void test_f_va (va_list va)
T ("%312.312f"); /* { dg-warning "between 312 and 623 bytes" } */
T ("%312.313f"); /* { dg-warning "between 312 and 624 bytes" } */
- T ("%.*f"); /* { dg-warning "writing between 1 and 2147483958 bytes" } */
- T ("%1.*f"); /* { dg-warning "writing between 1 and 2147483958 bytes" } */
- T ("%3.*f"); /* { dg-warning "writing between 3 and 2147483958 bytes" } */
+ T ("%.*f"); /* { dg-warning "writing between 1 and (2147483958|33078) bytes" } */
+ T ("%1.*f"); /* { dg-warning "writing between 1 and (2147483958|33078) bytes" } */
+ T ("%3.*f"); /* { dg-warning "writing between 3 and (2147483958|33078) bytes" } */
- T ("%*.*f"); /* { dg-warning "writing between 1 and 2147483958 bytes" } */
+ T ("%*.*f"); /* { dg-warning "writing between 1 and (2147483958|33078) bytes" } */
}
/* Exercise %g. The expected output is the lesser of %e and %f. */
@@ -270,5 +270,5 @@ void test_g_va (va_list va)
T ("%1.*g"); /* { dg-warning "writing between 1 and 310 bytes" } */
T ("%4.*g"); /* { dg-warning "writing between 4 and 310 bytes" } */
- T ("%*.*g"); /* { dg-warning "writing between 1 and 2147483648 bytes" } */
+ T ("%*.*g"); /* { dg-warning "writing between 1 and (2147483648|32768) bytes" } */
}
@@ -76,6 +76,7 @@ int test_o_var (int i)
ASSERT_MAYBE (5 == n);
ASSERT_MAYBE (6 == n);
ASSERT_MAYBE (7 == n);
+ /* Below will be optimized out for 16-bit int. */
ASSERT_MAYBE (8 == n);
ASSERT_MAYBE (9 == n);
ASSERT_MAYBE (10 == n);
@@ -147,6 +148,7 @@ int test_x_var (int i)
ASSERT_MAYBE (4 == n);
ASSERT_MAYBE (5 == n);
ASSERT_MAYBE (6 == n);
+ /* Below will be optimized out for 16-bit int. */
ASSERT_MAYBE (7 == n);
ASSERT_MAYBE (8 == n);
ASSERT_MAYBE (9 == n);
@@ -156,4 +158,5 @@ int test_x_var (int i)
}
/* { dg-final { scan-tree-dump-not "failure_on_line" "optimized"} }
- { dg-final { scan-tree-dump-times "keep_call_on_line" 43 "optimized"} } */
+ { dg-final { scan-tree-dump-times "keep_call_on_line" 43 "optimized" { target { ! int16 } } } }
+ { dg-final { scan-tree-dump-times "keep_call_on_line" 34 "optimized" { target int16 } } } */
--
2.7.4