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/asan | |
parent | f378ebf14df0952eae870c9865bab8326aa8f137 (diff) | |
download | toolchain_gcc-1d9fec7937f45dde5e04cac966a2d9a12f2fc15a.zip toolchain_gcc-1d9fec7937f45dde5e04cac966a2d9a12f2fc15a.tar.gz toolchain_gcc-1d9fec7937f45dde5e04cac966a2d9a12f2fc15a.tar.bz2 |
Synchronize with google/gcc-4_9 to r224707 (from r214835)
Change-Id: I3d6f06fc613c8f8b6a82143dc44b7338483aac5d
Diffstat (limited to 'gcc-4.9/gcc/testsuite/c-c++-common/asan')
25 files changed, 432 insertions, 43 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 0000000..8cd80ca --- /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 0000000..b3f300c --- /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 0000000..8ab0f80 --- /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 0000000..c590778 --- /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 0000000..94de9a4 --- /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 b9c6734..36cc3d8 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 0000000..32e32a6 --- /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 0000000..1b361e6 --- /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 0000000..0c5b6e0 --- /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 0000000..7fbe299 --- /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 fa52e0c..028f8d7 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 28525e0..a58411c 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 420a263..5193ae0 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 b2e7284..c3632aa 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 ead3f58..077ea34 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 e4691bc..6d87104 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 bf40a03..5baa10d 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 38ea7a2..2a4c081 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 0000000..9449de5 --- /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 0000000..e306a71 --- /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 0000000..9b92e9b --- /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 0000000..f0b026d --- /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 0000000..0bb2563 --- /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 0000000..a8bafc5 --- /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 0000000..4833dc7 --- /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)" } */ |