annotate gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-1.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* This tests that when faced with two references to the same memory
kono
parents:
diff changeset
2 location in the same basic block, the second reference should not
kono
parents:
diff changeset
3 be instrumented by the Address Sanitizer. */
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 /* { dg-options "-fdump-tree-sanopt" } */
kono
parents:
diff changeset
6 /* { dg-do compile } */
kono
parents:
diff changeset
7 /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 extern char tab[6];
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 static int
kono
parents:
diff changeset
12 test0 ()
kono
parents:
diff changeset
13 {
kono
parents:
diff changeset
14 /* __builtin___asan_report_store1 called 2 times for the two stores
kono
parents:
diff changeset
15 below. */
kono
parents:
diff changeset
16 tab[0] = 1;
kono
parents:
diff changeset
17 tab[1] = 2;
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 /* This load should not be instrumented because it is to the same
kono
parents:
diff changeset
20 memory location as above. */
kono
parents:
diff changeset
21 char t0 = tab[1];
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 /* Likewise. */
kono
parents:
diff changeset
24 char t1 = tab[1];
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 return t0 + t1;
kono
parents:
diff changeset
27 }
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 __attribute__((noinline, noclone)) static int
kono
parents:
diff changeset
30 test1 (int i)
kono
parents:
diff changeset
31 {
kono
parents:
diff changeset
32 char foo[4] = {};
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 /*__builtin___asan_report_store1 called 1 time here to instrument
kono
parents:
diff changeset
35 the initialization. */
kono
parents:
diff changeset
36 foo[i] = 1;
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 /* Instrument tab memory region. */
kono
parents:
diff changeset
39 __builtin_memset (tab, 3, sizeof (tab));
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 /* Instrument tab[1] with access size 3. */
kono
parents:
diff changeset
42 __builtin_memcpy (&tab[1], foo + i, 3);
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 /* This should not generate a __builtin___asan_report_load1 because
kono
parents:
diff changeset
45 the reference to tab[1] has been already instrumented above. */
kono
parents:
diff changeset
46 return tab[1];
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 /* So for these functions, there should be 3 calls to
kono
parents:
diff changeset
49 __builtin___asan_report_store1. */
kono
parents:
diff changeset
50 }
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 int
kono
parents:
diff changeset
53 main ()
kono
parents:
diff changeset
54 {
kono
parents:
diff changeset
55 return test0 () && test1 (0);
kono
parents:
diff changeset
56 }
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 /* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 3 "sanopt" } } */
kono
parents:
diff changeset
59 /* { dg-final { scan-tree-dump-not "__builtin___asan_report_load1" "sanopt" } } */