Mercurial > hg > CbC > CbC_gcc
comparison 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 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 /* This tests that when faced with two references to the same memory | |
2 location in the same basic block, the second reference should not | |
3 be instrumented by the Address Sanitizer. */ | |
4 | |
5 /* { dg-options "-fdump-tree-sanopt" } */ | |
6 /* { dg-do compile } */ | |
7 /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ | |
8 | |
9 extern char tab[6]; | |
10 | |
11 static int | |
12 test0 () | |
13 { | |
14 /* __builtin___asan_report_store1 called 2 times for the two stores | |
15 below. */ | |
16 tab[0] = 1; | |
17 tab[1] = 2; | |
18 | |
19 /* This load should not be instrumented because it is to the same | |
20 memory location as above. */ | |
21 char t0 = tab[1]; | |
22 | |
23 /* Likewise. */ | |
24 char t1 = tab[1]; | |
25 | |
26 return t0 + t1; | |
27 } | |
28 | |
29 __attribute__((noinline, noclone)) static int | |
30 test1 (int i) | |
31 { | |
32 char foo[4] = {}; | |
33 | |
34 /*__builtin___asan_report_store1 called 1 time here to instrument | |
35 the initialization. */ | |
36 foo[i] = 1; | |
37 | |
38 /* Instrument tab memory region. */ | |
39 __builtin_memset (tab, 3, sizeof (tab)); | |
40 | |
41 /* Instrument tab[1] with access size 3. */ | |
42 __builtin_memcpy (&tab[1], foo + i, 3); | |
43 | |
44 /* This should not generate a __builtin___asan_report_load1 because | |
45 the reference to tab[1] has been already instrumented above. */ | |
46 return tab[1]; | |
47 | |
48 /* So for these functions, there should be 3 calls to | |
49 __builtin___asan_report_store1. */ | |
50 } | |
51 | |
52 int | |
53 main () | |
54 { | |
55 return test0 () && test1 (0); | |
56 } | |
57 | |
58 /* { dg-final { scan-tree-dump-times "__builtin___asan_report_store1" 3 "sanopt" } } */ | |
59 /* { dg-final { scan-tree-dump-not "__builtin___asan_report_load1" "sanopt" } } */ |