diff options
author | Yiran Wang <yiran@google.com> | 2015-06-23 15:33:17 -0700 |
---|---|---|
committer | Yiran Wang <yiran@google.com> | 2015-06-29 10:56:28 -0700 |
commit | 1d9fec7937f45dde5e04cac966a2d9a12f2fc15a (patch) | |
tree | 3fbcd18a379a05fd6d43491a107e1f36bc61b185 /gcc-4.9/gcc/testsuite/c-c++-common | |
parent | f378ebf14df0952eae870c9865bab8326aa8f137 (diff) | |
download | toolchain_gcc-1d9fec7937f45dde5e04cac966a2d9a12f2fc15a.tar.gz toolchain_gcc-1d9fec7937f45dde5e04cac966a2d9a12f2fc15a.tar.bz2 toolchain_gcc-1d9fec7937f45dde5e04cac966a2d9a12f2fc15a.zip |
Synchronize with google/gcc-4_9 to r224707 (from r214835)
Change-Id: I3d6f06fc613c8f8b6a82143dc44b7338483aac5d
Diffstat (limited to 'gcc-4.9/gcc/testsuite/c-c++-common')
46 files changed, 657 insertions, 82 deletions
diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/asan-interface-1.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/asan-interface-1.c new file mode 100644 index 000000000..8cd80caaa --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/asan-interface-1.c @@ -0,0 +1,14 @@ +/* Check that interface headers work. */ + +/* { dg-do run { target { *-*-linux* } } } */ + +#include <stdbool.h> +#include <sanitizer/asan_interface.h> + +int main() { + char tmp; + if (__asan_address_is_poisoned((volatile char *)&tmp + 1)) + return 0; + return 1; +} + diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-1.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-1.c new file mode 100644 index 000000000..b3f300c64 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-1.c @@ -0,0 +1,25 @@ +/* Check that Asan correctly instruments bitfields with non-round size. */ + +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +struct A +{ + char base; + int : 4; + long x : 7; +}; + +int __attribute__ ((noinline, noclone)) +f (void *p) { + return ((struct A *)p)->x; +} + +int +main () +{ + char a = 0; + return f (&a); +} + +/* { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-2.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-2.c new file mode 100644 index 000000000..8ab0f8069 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-2.c @@ -0,0 +1,25 @@ +/* Check that Asan correctly instruments bitfields with non-round offset. */ + +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +struct A +{ + char base; + int : 7; + int x : 8; +}; + +int __attribute__ ((noinline, noclone)) +f (void *p) { + return ((struct A *)p)->x; +} + +int +main () +{ + char a = 0; + return f (&a); +} + +/* { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-3.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-3.c new file mode 100644 index 000000000..c5907786f --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-3.c @@ -0,0 +1,25 @@ +/* Check that Asan correctly instruments bitfields with round offset. */ + +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +struct A +{ + char base; + int : 8; + int x : 8; +}; + +int __attribute__ ((noinline, noclone)) +f (void *p) { + return ((struct A *)p)->x; +} + +int +main () +{ + char a = 0; + return f (&a); +} + +/* { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-4.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-4.c new file mode 100644 index 000000000..94de9a437 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/bitfield-4.c @@ -0,0 +1,25 @@ +/* Check that Asan correctly instruments bitfields with round offset. */ + +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +struct A +{ + char base; + int : 0; + int x : 8; +}; + +int __attribute__ ((noinline, noclone)) +f (void *p) { + return ((struct A *)p)->x; +} + +int +main () +{ + char a = 0; + return f (&a); +} + +/* { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/inc.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/inc.c index b9c6734ea..36cc3d8d8 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/asan/inc.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/inc.c @@ -16,6 +16,6 @@ main () return 0; } -/* { dg-final { scan-tree-dump-times "__builtin___asan_report" 1 "asan0" } } */ -/* { dg-final { scan-tree-dump "__builtin___asan_report_load4" "asan0" } } */ +/* { dg-final { scan-tree-dump-times "ASAN_" 1 "asan0" } } */ +/* { dg-final { scan-tree-dump "ASAN_CHECK \\(.*, 4\\);" "asan0" } } */ /* { dg-final { cleanup-tree-dump "asan0" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/instrument-with-calls-1.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/instrument-with-calls-1.c new file mode 100644 index 000000000..32e32a600 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/instrument-with-calls-1.c @@ -0,0 +1,10 @@ +/* { dg-do assemble } */ +/* { dg-options "-fno-sanitize=address -fsanitize=kernel-address --param asan-instrumentation-with-call-threshold=0 -save-temps" } */ + +void f(char *a, int *b) { + *b = *a; +} + +/* { dg-final { scan-assembler "__asan_load1" } } */ +/* { dg-final { scan-assembler "__asan_store4" } } */ +/* { dg-final { cleanup-saved-temps } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/instrument-with-calls-2.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/instrument-with-calls-2.c new file mode 100644 index 000000000..1b361e627 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/instrument-with-calls-2.c @@ -0,0 +1,16 @@ +/* { dg-do assemble } */ +/* { dg-options "-fno-sanitize=address -fsanitize=kernel-address --param asan-instrumentation-with-call-threshold=1 -save-temps" } */ + +int x; + +void f(int *a, int *b) { + *a = 0; + asm volatile ("" ::: "memory"); + x = *b; +} + +/* { dg-final { scan-assembler "__asan_store4" } } */ +/* { dg-final { scan-assembler-not "__asan_report_store4" } } */ +/* { dg-final { scan-assembler "__asan_load4" } } */ +/* { dg-final { scan-assembler-not "__asan_report_load4" } } */ +/* { dg-final { cleanup-saved-temps } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/misalign-1.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/misalign-1.c new file mode 100644 index 000000000..0c5b6e0c7 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/misalign-1.c @@ -0,0 +1,42 @@ +/* { dg-do run { target { ilp32 || lp64 } } } */ +/* { dg-options "-O2" } */ +/* { dg-shouldfail "asan" } */ + +struct S { int i; } __attribute__ ((packed)); + +__attribute__((noinline, noclone)) int +foo (struct S *s) +{ + return s->i; +} + +__attribute__((noinline, noclone)) int +bar (int *s) +{ + return *s; +} + +__attribute__((noinline, noclone)) struct S +baz (struct S *s) +{ + return *s; +} + +int +main () +{ + struct T { char a[3]; struct S b[3]; char c; } t; + int v = 5; + struct S *p = t.b; + asm volatile ("" : "+rm" (p)); + p += 3; + if (bar (&v) != 5) __builtin_abort (); + volatile int w = foo (p); + return 0; +} + +/* { dg-output "ERROR: AddressSanitizer:\[^\n\r]*on address\[^\n\r]*" } */ +/* { dg-output "0x\[0-9a-f\]+ at pc 0x\[0-9a-f\]+ bp 0x\[0-9a-f\]+ sp 0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*READ of size 4 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #0 0x\[0-9a-f\]+ (in _*foo(\[^\n\r]*misalign-1.c:10|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #1 0x\[0-9a-f\]+ (in _*main (\[^\n\r]*misalign-1.c:34|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/misalign-2.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/misalign-2.c new file mode 100644 index 000000000..7fbe299cc --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/misalign-2.c @@ -0,0 +1,42 @@ +/* { dg-do run { target { ilp32 || lp64 } } } */ +/* { dg-options "-O2" } */ +/* { dg-shouldfail "asan" } */ + +struct S { int i; } __attribute__ ((packed)); + +__attribute__((noinline, noclone)) int +foo (struct S *s) +{ + return s->i; +} + +__attribute__((noinline, noclone)) int +bar (int *s) +{ + return *s; +} + +__attribute__((noinline, noclone)) struct S +baz (struct S *s) +{ + return *s; +} + +int +main () +{ + struct T { char a[3]; struct S b[3]; char c; } t; + int v = 5; + struct S *p = t.b; + asm volatile ("" : "+rm" (p)); + p += 3; + if (bar (&v) != 5) __builtin_abort (); + volatile struct S w = baz (p); + return 0; +} + +/* { dg-output "ERROR: AddressSanitizer:\[^\n\r]*on address\[^\n\r]*" } */ +/* { dg-output "0x\[0-9a-f\]+ at pc 0x\[0-9a-f\]+ bp 0x\[0-9a-f\]+ sp 0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*READ of size 4 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #0 0x\[0-9a-f\]+ (in _*baz(\[^\n\r]*misalign-2.c:22|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #1 0x\[0-9a-f\]+ (in _*main (\[^\n\r]*misalign-2.c:34|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-1.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-1.c index fa52e0ca8..028f8d715 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-1.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-1.c @@ -2,7 +2,7 @@ location in the same basic block, the second reference should not be instrumented by the Address Sanitizer. */ -/* { dg-options "-fdump-tree-asan0" } */ +/* { dg-options "-fdump-tree-sanopt" } */ /* { dg-do compile } */ /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ @@ -16,12 +16,11 @@ test0 () tab[0] = 1; tab[1] = 2; - /* __builtin___asan_report_load1 called 1 time for the store - below. */ - char t0 = tab[1]; - /* This load should not be instrumented because it is to the same memory location as above. */ + char t0 = tab[1]; + + /* Likewise. */ char t1 = tab[1]; return t0 + t1; @@ -36,7 +35,7 @@ test1 (int i) the initialization. */ foo[i] = 1; - /*__builtin___asan_report_store1 called 2 times here to instrument + /*__builtin___asan_report_store_n called once here to instrument the store to the memory region of tab. */ __builtin_memset (tab, 3, sizeof (tab)); @@ -44,8 +43,8 @@ test1 (int i) __builtin_memset (tab, 4, sizeof (tab)); __builtin_memset (tab, 5, sizeof (tab)); - /* There are 2 calls to __builtin___asan_report_store1 and 2 calls - to __builtin___asan_report_load1 to instrument the store to + /* There is a call to __builtin___asan_report_store_n and a call + to __builtin___asan_report_load_n to instrument the store to (subset of) the memory region of tab. */ __builtin_memcpy (&tab[1], foo + i, 3); @@ -53,7 +52,7 @@ test1 (int i) the reference to tab[1] has been already instrumented above. */ return tab[1]; - /* So for these function, there should be 7 calls to + /* So for these functions, there should be 3 calls to __builtin___asan_report_store1. */ } @@ -63,6 +62,7 @@ main () return test0 () && test1 (0); } -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 7 "asan0" } } */ -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load" 2 "asan0" } } */ -/* { dg-final { cleanup-tree-dump "asan0" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 3 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store_n" 2 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load" 1 "sanopt" } } */ +/* { dg-final { cleanup-tree-dump "sanopt" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-2.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-2.c index 28525e0ff..a58411c3a 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-2.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-2.c @@ -3,7 +3,7 @@ be instrumented by the Address Sanitizer. But in case of access to overlapping regions we must be precise. */ -/* { dg-options "-fdump-tree-asan0" } */ +/* { dg-options "-fdump-tree-sanopt" } */ /* { dg-do compile } */ /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ @@ -20,6 +20,7 @@ main () __builtin_memset (tab, 1, 3); } -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 3 "asan0" } } */ -/* { dg-final { scan-tree-dump-times "__builtin___asan_report" 3 "asan0" } } */ -/* { dg-final { cleanup-tree-dump "asan0" } } */ +/* { dg-final { scan-tree-dump-times "& 7" 3 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store_n" 2 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report" 2 "sanopt" } } */ +/* { dg-final { cleanup-tree-dump "sanopt" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-3.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-3.c index 420a26309..5193ae06f 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-3.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-3.c @@ -1,4 +1,4 @@ -/* { dg-options "-fdump-tree-asan0" } */ +/* { dg-options "-fdump-tree-sanopt" } */ /* { dg-do compile } */ /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ @@ -12,7 +12,7 @@ foo (__INT32_TYPE__ *p) return ret; } -/* { dg-final { scan-tree-dump-times "__builtin___asan_report" 2 "asan0" } } */ -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load1" 1 "asan0" } } */ -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store" 1 "asan0" } } */ -/* { dg-final { cleanup-tree-dump "asan0" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report" 2 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load1" 1 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store" 1 "sanopt" } } */ +/* { dg-final { cleanup-tree-dump "sanopt" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-4.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-4.c index b2e72841b..c3632aa3d 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-4.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-4.c @@ -1,13 +1,17 @@ -/* { dg-options "-fdump-tree-asan0" } */ +/* { dg-options "-fdump-tree-sanopt" } */ /* { dg-do compile } */ /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ void foo (int *a, char *b, char *c) { + /* One check for c[0], one check for a[], one check for c, two checks for b. */ __builtin_memmove (c, b, a[c[0]]); + /* For a total of 5 checks. */ } -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load1" 3 "asan0" } } */ -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 1 "asan0" } } */ -/* { dg-final { cleanup-tree-dump "asan0" } } */ +/* { dg-final { scan-tree-dump-times "& 7" 5 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load1" 1 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load_n" 1 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store_n" 1 "sanopt" } } */ +/* { dg-final { cleanup-tree-dump "sanopt" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-5.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-5.c index ead3f5823..077ea34d0 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-5.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-5.c @@ -1,13 +1,18 @@ -/* { dg-options "-fdump-tree-asan0" } */ +/* { dg-options "-fdump-tree-sanopt" } */ /* { dg-do compile } */ /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ void foo (int *a, char *b, char *c) { + /* One check for b[0], one check for a[], 2 checks for c and one checks for b. */ __builtin_memmove (c, b, a[b[0]]); + /* For a total of 5 checks. */ } -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load1" 2 "asan0" } } */ -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 2 "asan0" } } */ -/* { dg-final { cleanup-tree-dump "asan0" } } */ +/* { dg-final { scan-tree-dump-times "& 7" 5 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load1" 1 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load4" 1 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load_n" 1 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store_n" 1 "sanopt" } } */ +/* { dg-final { cleanup-tree-dump "sanopt" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-6.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-6.c index e4691bc47..6d87104aa 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-6.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-6.c @@ -1,14 +1,20 @@ -/* { dg-options "-fdump-tree-asan0" } */ +/* { dg-options "-fdump-tree-sanopt" } */ /* { dg-do compile } */ /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ void foo (int *a, char *b, char *c) { + /* One check for c[0], one check for a[], one check for c and 2 checks for b. */ __builtin_memmove (c, b, a[c[0]]); + /* One check for a[], one check for c and one check for b. */ __builtin_memmove (c, b, a[b[0]]); + /* For a total of 8 checks. */ } -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load1" 5 "asan0" } } */ -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 2 "asan0" } } */ -/* { dg-final { cleanup-tree-dump "asan0" } } */ +/* { dg-final { scan-tree-dump-times "& 7" 8 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load1" 1 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load4" 2 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load_n" 2 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store_n" 2 "sanopt" } } */ +/* { dg-final { cleanup-tree-dump "sanopt" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-7.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-7.c index bf40a0376..5baa10dcd 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-7.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-7.c @@ -1,4 +1,4 @@ -/* { dg-options "-fdump-tree-asan0" } */ +/* { dg-options "-fdump-tree-sanopt" } */ /* { dg-do compile } */ /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ @@ -13,11 +13,15 @@ struct S int foo (int *a, char *b, char *c) { + /* 2 checks for s.a, 2 checks for e. */ int d = __builtin_memcmp (s.a, e, 100); + /* One check for s.a and one check for e. */ d += __builtin_memcmp (s.a, e, 200); + /* For a total of 6 checks. */ return d; } -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load" 6 "asan0" } } */ -/* { dg-final { scan-tree-dump-not "__builtin___asan_report_store" "asan0" } } */ -/* { dg-final { cleanup-tree-dump "asan0" } } */ +/* { dg-final { scan-tree-dump-times "& 7" 6 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load_n" 4 "sanopt" } } */ +/* { dg-final { scan-tree-dump-not "__builtin___asan_report_store" "sanopt" } } */ +/* { dg-final { cleanup-tree-dump "sanopt" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-8.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-8.c index 38ea7a21d..2a4c0812f 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-8.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-8.c @@ -1,14 +1,20 @@ -/* { dg-options "-fdump-tree-asan0" } */ +/* { dg-options "-fdump-tree-sanopt" } */ /* { dg-do compile } */ /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ char foo (int *a, char *b, char *c) { + /* One check for b[0], one check for a[], two checks for c and one check for b. */ __builtin_memmove (c, b, a[b[0]]); + /* No checks here. */ return c[0] + b[0]; + /* For a total of 5 checks. */ } -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load1" 3 "asan0" } } */ -/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 2 "asan0" } } */ -/* { dg-final { cleanup-tree-dump "asan0" } } */ +/* { dg-final { scan-tree-dump-times "& 7" 5 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load1" 1 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load4" 1 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_load_n" 1 "sanopt" } } */ +/* { dg-final { scan-tree-dump-times "__builtin___asan_report_store_n" 1 "sanopt" } } */ +/* { dg-final { cleanup-tree-dump "sanopt" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-9.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-9.c new file mode 100644 index 000000000..9449de578 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-9.c @@ -0,0 +1,13 @@ +/* { dg-options "-fdump-tree-sanopt" } */ +/* { dg-do compile } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ + +__SIZE_TYPE__ +f (char *a) +{ + a[0] = '1'; + return __builtin_strlen (a); +} + +/* { dg-final { scan-tree-dump-times "__asan_report_load1" 1 "sanopt" } } */ +/* { dg-final { cleanup-tree-dump "sanopt" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr61530.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr61530.c new file mode 100644 index 000000000..e306a71be --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr61530.c @@ -0,0 +1,17 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +__attribute__((noinline,noclone)) void +foo (char *a, char *b) { + a[0] = b[0] = 0; + __builtin_memcpy(a, b, 4); +} + +int +main () { + char a, b; + foo (&a, &b); + return 0; +} + +/* { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr62089.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr62089.c new file mode 100644 index 000000000..9b92e9bbf --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr62089.c @@ -0,0 +1,38 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include <stdbool.h> +#include <sanitizer/asan_interface.h> + +struct vfsmount {}; +struct dentry {}; + +struct path { + struct vfsmount *mnt; + struct dentry *dentry; +}; + +struct fs_struct { + int users; + int lock; + int seq; + int umask; + int in_exec; + struct path root, pwd; +}; + +void __attribute__((noinline, noclone)) +copy_fs_struct(struct fs_struct *a, struct fs_struct *b) { + a->root = b->root; +} + +struct fs_struct a, b; + +int +main () { + __asan_poison_memory_region (&a.root, sizeof (a.root)); + copy_fs_struct (&a, &b); + return 0; +} + +/* { dg-output "ERROR: AddressSanitizer:\[^\n\r]*on address\[^\n\r]*" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr62140-1.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr62140-1.c new file mode 100644 index 000000000..f0b026de2 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr62140-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-w -fpermissive" } */ + +int memcmp (const void *p, const void *q, int len); + +int f (int *p, int *q, int len) +{ + return memcmp (p, q, len); +} + diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr62140-2.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr62140-2.c new file mode 100644 index 000000000..0bb2563ab --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr62140-2.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-w -fpermissive" } */ + +int strlen (const char *p); + +int f (char *p) +{ + int x = strlen (p); + return x; +} + diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr63638.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr63638.c new file mode 100644 index 000000000..a8bafc5aa --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/pr63638.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ + +extern +#ifdef __cplusplus +"C" +#endif +void *memcpy (void *, const void *, __SIZE_TYPE__); + +struct S{ + long d0, d1, d2, d3, d4, d5, d6; +}; + +struct S s[6]; + +int f(struct S *p) +{ + memcpy(p, &s[2], sizeof(*p)); + memcpy(p, &s[1], sizeof(*p)); +} + diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/asan/strlen-overflow-1.c b/gcc-4.9/gcc/testsuite/c-c++-common/asan/strlen-overflow-1.c new file mode 100644 index 000000000..4833dc778 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/asan/strlen-overflow-1.c @@ -0,0 +1,30 @@ +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ +/* { dg-shouldfail "asan" } */ + +#include <stdbool.h> +#include <sanitizer/asan_interface.h> + +char a[2] = "0"; + +#ifdef __cplusplus +extern "C" +#endif + +__attribute__((no_sanitize_address, noinline)) __SIZE_TYPE__ +strlen (const char *p) { + + __SIZE_TYPE__ n = 0; + for (; *p; ++n, ++p); + return n; +} + +int main () { + char *p = &a[0]; + asm ("" : "+r"(p)); + __asan_poison_memory_region ((char *)&a[1], 1); + return __builtin_strlen (a); +} + +/* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */ +/* { dg-output " #0 0x\[0-9a-f\]+ (in _*main (\[^\n\r]*strlen-overflow-1.c:26|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr60823-4.c b/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr60823-4.c new file mode 100644 index 000000000..a9bc0fa25 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr60823-4.c @@ -0,0 +1,7 @@ +/* PR tree-optimization/63915 */ +/* { dg-do run } */ +/* { dg-require-effective-target vect_simd_clones } */ +/* { dg-options "-O2 -fopenmp-simd" } */ +/* { dg-additional-options "-fpic" { target fpic } } */ + +#include "pr60823-2.c" diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr61200.c b/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr61200.c new file mode 100644 index 000000000..d0d699dfa --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr61200.c @@ -0,0 +1,13 @@ +/* PR libgomp/61200 */ + +int +main () +{ + int var = 1; + #pragma omp parallel + if (var != 1) + __builtin_abort (); + #pragma omp task shared(var) + var = 2; + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr63249.c b/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr63249.c new file mode 100644 index 000000000..878788ad7 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr63249.c @@ -0,0 +1,16 @@ +/* PR c++/63249 */ +/* { dg-do compile } */ +/* { dg-options "-Wall -W -fopenmp" } */ + +int +foo (int *v, int A, int B) /* { dg-bogus "set but not used" } */ +{ + int r = 0; + int a = 2; /* { dg-bogus "set but not used" } */ + int b = 4; /* { dg-bogus "set but not used" } */ +#pragma omp target map(to: v[a:b]) + r |= v[3]; +#pragma omp target map(to: v[A:B]) + r |= v[3]; + return r; +} diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr63328.c b/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr63328.c new file mode 100644 index 000000000..3958abe16 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/gomp/pr63328.c @@ -0,0 +1,5 @@ +/* PR debug/63328 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fopenmp-simd -fno-strict-aliasing -fcompare-debug" } */ + +#include "pr60823-3.c" diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/pr56493.c b/gcc-4.9/gcc/testsuite/c-c++-common/pr56493.c new file mode 100644 index 000000000..418126043 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/pr56493.c @@ -0,0 +1,16 @@ +/* PR c++/56493 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-gimple" } */ + +unsigned long long bar (void); +int x; + +void +foo (void) +{ + x += bar (); +} + +/* Verify we narrow the addition from unsigned long long to unsigned int type. */ +/* { dg-final { scan-tree-dump " (\[a-zA-Z._0-9]*) = \\(unsigned int\\) \[^;\n\r]*;.* (\[a-zA-Z._0-9]*) = \\(unsigned int\\) \[^;\n\r]*;.* = \\1 \\+ \\2;" "gimple" { target { ilp32 || lp64 } } } } */ +/* { dg-final { cleanup-tree-dump "gimple" } } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/pr61553.c b/gcc-4.9/gcc/testsuite/c-c++-common/pr61553.c new file mode 100644 index 000000000..8a3b699ee --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/pr61553.c @@ -0,0 +1,8 @@ +/* PR c/61553 */ +/* { dg-do compile } */ + +void +foo (char *s) +{ + __atomic_store (s, (void *) 0, __ATOMIC_SEQ_CST); /* { dg-error "size mismatch" } */ +} diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/atomic_stack.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/atomic_stack.c index 6a3795120..746afa7b4 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/atomic_stack.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/atomic_stack.c @@ -1,22 +1,26 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <unistd.h> +#include "tsan_barrier.h" +static pthread_barrier_t barrier; int Global; void *Thread1(void *x) { - sleep(1); + barrier_wait(&barrier); __atomic_fetch_add(&Global, 1, __ATOMIC_RELAXED); return NULL; } void *Thread2(void *x) { Global++; + barrier_wait(&barrier); return NULL; } int main() { + barrier_init(&barrier, 2); pthread_t t[2]; pthread_create(&t[0], NULL, Thread1, NULL); pthread_create(&t[1], NULL, Thread2, NULL); diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/fd_pipe_race.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/fd_pipe_race.c index 28cd630d2..e2176da4b 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/fd_pipe_race.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/fd_pipe_race.c @@ -1,30 +1,35 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <stdio.h> #include <unistd.h> +#include "tsan_barrier.h" +static pthread_barrier_t barrier; int fds[2]; void *Thread1(void *x) { write(fds[1], "a", 1); + barrier_wait(&barrier); return NULL; } void *Thread2(void *x) { - sleep(1); + barrier_wait(&barrier); close(fds[0]); close(fds[1]); return NULL; } int main() { + barrier_init(&barrier, 2); pipe(fds); pthread_t t[2]; pthread_create(&t[0], NULL, Thread1, NULL); pthread_create(&t[1], NULL, Thread2, NULL); pthread_join(t[0], NULL); pthread_join(t[1], NULL); + return 0; } /* { dg-output "WARNING: ThreadSanitizer: data race.*\n" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/mutexset1.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/mutexset1.c index 7c32a8524..084f5141d 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/mutexset1.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/mutexset1.c @@ -1,14 +1,15 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <stdio.h> -#include <unistd.h> +#include "tsan_barrier.h" +static pthread_barrier_t barrier; int Global; pthread_mutex_t mtx; void *Thread1(void *x) { - sleep(1); + barrier_wait(&barrier); pthread_mutex_lock(&mtx); Global++; pthread_mutex_unlock(&mtx); @@ -17,11 +18,13 @@ void *Thread1(void *x) { void *Thread2(void *x) { Global--; + barrier_wait(&barrier); return NULL;/* { dg-output ".*" } */ } int main() { + barrier_init(&barrier, 2); pthread_mutex_init(&mtx, 0); pthread_t t[2]; pthread_create(&t[0], NULL, Thread1, NULL); diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_barrier.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_barrier.c index 0a0e5faba..3de3ff225 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_barrier.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_barrier.c @@ -1,26 +1,28 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <stdio.h> -#include <stddef.h> -#include <unistd.h> +#include "tsan_barrier.h" +static pthread_barrier_t barrier; pthread_barrier_t B; int Global; void *Thread1(void *x) { pthread_barrier_init(&B, 0, 2); + barrier_wait(&barrier); pthread_barrier_wait(&B); return NULL; } void *Thread2(void *x) { - sleep(1); + barrier_wait(&barrier); pthread_barrier_wait(&B); return NULL; } int main() { + barrier_init(&barrier, 2); pthread_t t; pthread_create(&t, NULL, Thread1, NULL); Thread2(0); diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_mutex.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_mutex.c index 5dad345d8..ae30d053c 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_mutex.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_mutex.c @@ -1,10 +1,10 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <stdio.h> -#include <stddef.h> -#include <unistd.h> +#include "tsan_barrier.h" +static pthread_barrier_t barrier; pthread_mutex_t Mtx; int Global; @@ -13,11 +13,12 @@ void *Thread1(void *x) { pthread_mutex_lock(&Mtx); Global = 42; pthread_mutex_unlock(&Mtx); + barrier_wait(&barrier); return NULL; } void *Thread2(void *x) { - sleep(1); + barrier_wait(&barrier); pthread_mutex_lock(&Mtx); Global = 43; pthread_mutex_unlock(&Mtx); @@ -25,6 +26,7 @@ void *Thread2(void *x) { } int main() { + barrier_init(&barrier, 2); pthread_t t[2]; pthread_create(&t[0], NULL, Thread1, NULL); pthread_create(&t[1], NULL, Thread2, NULL); @@ -37,7 +39,7 @@ int main() { /* { dg-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */ /* { dg-output " Atomic read of size 1 at .* by thread T2:(\n|\r\n|\r)" } */ /* { dg-output " #0 pthread_mutex_lock.*" } */ -/* { dg-output " #1 Thread2.* .*(race_on_mutex.c:21|\\?{2}:0) (.*)" } */ +/* { dg-output " #1 Thread2.* .*(race_on_mutex.c:22|\\?{2}:0) (.*)" } */ /* { dg-output " Previous write of size 1 at .* by thread T1:(\n|\r\n|\r)" } */ /* { dg-output " #0 pthread_mutex_init .* (.)*" } */ /* { dg-output " #1 Thread1.* .*(race_on_mutex.c:12|\\?{2}:0) .*" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_mutex2.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_mutex2.c index 80a6fb6c0..57d7e21e7 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_mutex2.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/race_on_mutex2.c @@ -1,22 +1,25 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <stdio.h> -#include <stddef.h> -#include <unistd.h> +#include "tsan_barrier.h" + +static pthread_barrier_t barrier; void *Thread(void *x) { pthread_mutex_lock((pthread_mutex_t*)x); pthread_mutex_unlock((pthread_mutex_t*)x); + barrier_wait(&barrier); return 0; } int main() { + barrier_init(&barrier, 2); pthread_mutex_t Mtx; pthread_mutex_init(&Mtx, 0); pthread_t t; pthread_create(&t, 0, Thread, &Mtx); - sleep(1); + barrier_wait(&barrier); pthread_mutex_destroy(&Mtx); pthread_join(t, 0); return 0; diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/simple_race.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/simple_race.c index a40accd40..c1a369b45 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/simple_race.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/simple_race.c @@ -1,13 +1,15 @@ /* { dg-set-target-env-var TSAN_OPTIONS "halt_on_error=1" } */ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <stdio.h> #include <unistd.h> +#include "tsan_barrier.h" -#define MAX_ITERATIONS_NUMBER 100 -#define SLEEP_STEP 128000 +#define MAX_ITERATIONS_NUMBER 1 +#define SLEEP_STEP 128000 +static pthread_barrier_t barrier; unsigned int delay_time = 1000; static inline void delay () { @@ -17,6 +19,7 @@ static inline void delay () { extern int main_1(); int main() { + barrier_init(&barrier, 2); int i; for (i = 0; i < MAX_ITERATIONS_NUMBER; i++) { main_1(); @@ -28,6 +31,7 @@ int main() { int Global; void *Thread1(void *x) { + barrier_wait(&barrier); delay(); Global = 42; return NULL; @@ -35,6 +39,7 @@ void *Thread1(void *x) { void *Thread2(void *x) { Global = 43; + barrier_wait(&barrier); return NULL; } diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/simple_stack.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/simple_stack.c index b66a67085..a4d0aba69 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/simple_stack.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/simple_stack.c @@ -1,9 +1,10 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <stdio.h> -#include <unistd.h> +#include "tsan_barrier.h" +static pthread_barrier_t barrier; int Global; void __attribute__((noinline)) foo1() { @@ -25,13 +26,14 @@ void __attribute__((noinline)) bar2() { } void *Thread1(void *x) { - sleep(1); + barrier_wait(&barrier); bar1(); return NULL; } void *Thread2(void *x) { bar2(); + barrier_wait(&barrier); return NULL; } @@ -40,6 +42,7 @@ void StartThread(pthread_t *t, void *(*f)(void*)) { } int main() { + barrier_init(&barrier, 2); pthread_t t[2]; StartThread(&t[0], Thread1); StartThread(&t[1], Thread2); @@ -50,16 +53,16 @@ int main() { /* { dg-output "WARNING: ThreadSanitizer: data race.*" } */ /* { dg-output " Write of size 4 at .* by thread T1:(\n|\r\n|\r)" } */ -/* { dg-output " #0 foo1.* .*(simple_stack.c:10|\\?{2}:0) (.*)" } */ -/* { dg-output " #1 bar1.* .*(simple_stack.c:15|\\?{2}:0) (.*)" } */ -/* { dg-output " #2 Thread1.* .*(simple_stack.c:29|\\?{2}:0) (.*)" } */ +/* { dg-output " #0 foo1.* .*(simple_stack.c:11|\\?{2}:0) (.*)" } */ +/* { dg-output " #1 bar1.* .*(simple_stack.c:16|\\?{2}:0) (.*)" } */ +/* { dg-output " #2 Thread1.* .*(simple_stack.c:30|\\?{2}:0) (.*)" } */ /* { dg-output " Previous read of size 4 at .* by thread T2:(\n|\r\n|\r)" } */ -/* { dg-output " #0 foo2.* .*(simple_stack.c:19|\\?{2}:0) (.*)" } */ -/* { dg-output " #1 bar2.* .*(simple_stack.c:24|\\?{2}:0) (.*)" } */ -/* { dg-output " #2 Thread2.* .*(simple_stack.c:34|\\?{2}:0) (.*)" } */ +/* { dg-output " #0 foo2.* .*(simple_stack.c:20|\\?{2}:0) (.*)" } */ +/* { dg-output " #1 bar2.* .*(simple_stack.c:25|\\?{2}:0) (.*)" } */ +/* { dg-output " #2 Thread2.* .*(simple_stack.c:35|\\?{2}:0) (.*)" } */ /* { dg-output " Thread T1 \\(tid=.*, running\\) created by main thread at:(\n|\r\n|\r)" } */ /* { dg-output " #0 pthread_create .* (.*)" } */ -/* { dg-output " #1 StartThread.* .*(simple_stack.c:39|\\?{2}:0) (.*)" } */ +/* { dg-output " #1 StartThread.* .*(simple_stack.c:41|\\?{2}:0) (.*)" } */ /* { dg-output " Thread T2 (.*) created by main thread at:(\n|\r\n|\r)" } */ /* { dg-output " #0 pthread_create .* (.*)" } */ -/* { dg-output " #1 StartThread.* .*(simple_stack.c:39|\\?{2}:0) (.*)" } */ +/* { dg-output " #1 StartThread.* .*(simple_stack.c:41|\\?{2}:0) (.*)" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/sleep_sync.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/sleep_sync.c index 44d44554c..c681dcef1 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/sleep_sync.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/sleep_sync.c @@ -1,8 +1,11 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> #include <unistd.h> +#include "tsan_barrier.h" +static pthread_barrier_t barrier; int X = 0; void MySleep() { @@ -10,15 +13,18 @@ void MySleep() { } void *Thread(void *p) { + barrier_wait(&barrier); MySleep(); // Assume the main thread has done the write. X = 42; return 0; } int main() { + barrier_init(&barrier, 2); pthread_t t; pthread_create(&t, 0, Thread, 0); X = 43; + barrier_wait(&barrier); pthread_join(t, 0); return 0; } diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tiny_race.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tiny_race.c index 962497b28..10a3feb9b 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tiny_race.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tiny_race.c @@ -1,20 +1,24 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <unistd.h> +#include "tsan_barrier.h" +static pthread_barrier_t barrier; int Global; void *Thread1(void *x) { - sleep(1); + barrier_wait(&barrier); Global = 42; return x; } int main() { + barrier_init(&barrier, 2); pthread_t t; pthread_create(&t, 0, Thread1, 0); Global = 43; + barrier_wait(&barrier); pthread_join(t, 0); return Global; } diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tls_race.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tls_race.c index 423867e38..4dd650604 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tls_race.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tls_race.c @@ -1,18 +1,24 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <stddef.h> +#include "tsan_barrier.h" + +static pthread_barrier_t barrier; void *Thread(void *a) { + barrier_wait(&barrier); *(int*)a = 43; return 0; } int main() { + barrier_init(&barrier, 2); static __thread int Var = 42; pthread_t t; pthread_create(&t, 0, Thread, &Var); Var = 43; + barrier_wait(&barrier); pthread_join(t, 0); } diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tsan_barrier.h b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tsan_barrier.h new file mode 100644 index 000000000..5d37a6475 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/tsan_barrier.h @@ -0,0 +1,14 @@ +/* TSAN-invisible barriers. Link with -ldl. */ +#include <pthread.h> +#include <dlfcn.h> + +static __typeof(pthread_barrier_wait) *barrier_wait; + +static +void barrier_init (pthread_barrier_t *barrier, unsigned count) +{ + void *h = dlopen ("libpthread.so.0", RTLD_LAZY); + barrier_wait = (__typeof (pthread_barrier_wait) *) + dlsym (h, "pthread_barrier_wait"); + pthread_barrier_init (barrier, NULL, count); +} diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/write_in_reader_lock.c b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/write_in_reader_lock.c index 898d23d50..df32632bf 100644 --- a/gcc-4.9/gcc/testsuite/c-c++-common/tsan/write_in_reader_lock.c +++ b/gcc-4.9/gcc/testsuite/c-c++-common/tsan/write_in_reader_lock.c @@ -1,8 +1,10 @@ /* { dg-shouldfail "tsan" } */ +/* { dg-additional-options "-ldl" } */ #include <pthread.h> -#include <unistd.h> +#include "tsan_barrier.h" +static pthread_barrier_t barrier; pthread_rwlock_t rwlock; int GLOB; @@ -10,13 +12,14 @@ void *Thread1(void *p) { (void)p; pthread_rwlock_rdlock(&rwlock); // Write under reader lock. - sleep(1); + barrier_wait(&barrier); GLOB++; pthread_rwlock_unlock(&rwlock); return 0; } int main(int argc, char *argv[]) { + barrier_init(&barrier, 2); pthread_rwlock_init(&rwlock, NULL); pthread_rwlock_rdlock(&rwlock); pthread_t t; @@ -24,6 +27,7 @@ int main(int argc, char *argv[]) { volatile int x = GLOB; (void)x; pthread_rwlock_unlock(&rwlock); + barrier_wait(&barrier); pthread_join(t, 0); pthread_rwlock_destroy(&rwlock); return 0; diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/overflow-sub-3.c b/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/overflow-sub-3.c new file mode 100644 index 000000000..deec5c411 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/overflow-sub-3.c @@ -0,0 +1,34 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=signed-integer-overflow" } */ + +__attribute__((noinline, noclone)) int +foo1 (int x, int y) +{ + return x - y; +} + +__attribute__((noinline, noclone)) int +foo2 (int x, int y) +{ + unsigned int xa = (unsigned int) x - (__INT_MAX__ - 3); + xa &= 3; + x = __INT_MAX__ - 3 + xa; + unsigned int ya = y + 1U; + ya &= 1; + y = ya - 1; + return x - y; +} + +int +main () +{ + int xm1, y; + for (xm1 = __INT_MAX__ - 4; xm1 < __INT_MAX__; xm1++) + for (y = -1; y <= 0; y++) + if (foo1 (xm1 + 1, y) != (int) (xm1 + 1U - y) + || foo2 (xm1 + 1, y) != (int) (xm1 + 1U - y)) + __builtin_abort (); + return 0; +} +/* { dg-output ":7:\[0-9]\[^\n\r]*signed integer overflow: 2147483647 - -1 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*:19:\[0-9]\[^\n\r]*signed integer overflow: 2147483647 - -1 cannot be represented in type 'int'" } */ diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/undefined-2.c b/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/undefined-2.c new file mode 100644 index 000000000..fd5b4d3e9 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/undefined-2.c @@ -0,0 +1,26 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=undefined" } */ +/* { dg-additional-options "-std=gnu11" { target c } } */ +/* { dg-additional-options "-std=c++11" { target c++ } } */ + +#include <stdio.h> + +volatile int w, z; + +__attribute__ ((noinline, noclone)) int +foo (int x, int y) +{ + z++; + return x << y; +} + +int +main () +{ + fputs ("1st\n", stderr); + w = foo (0, -__INT_MAX__); + return 0; +} + +/* { dg-output "1st(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent -\[^\n\r]* is negative\[^\n\r]*(\n|\r\n|\r)" } */ |