aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-1.c
blob: fa52e0ca85dad7a45146ffa6198f86a711463604 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* This tests that when faced with two references to the same memory
   location in the same basic block, the second reference should not
   be instrumented by the Address Sanitizer.  */

/* { dg-options "-fdump-tree-asan0" } */
/* { dg-do compile } */
/* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */

extern char tab[4];

static int
test0 ()
{
  /* __builtin___asan_report_store1 called 2 times for the two stores
     below.  */
  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 t1 = tab[1];

  return t0 + t1;
}

__attribute__((noinline, noclone)) static int
test1 (int i)
{
  char foo[4] = {};
  
  /*__builtin___asan_report_store1 called 1 time here to instrument
    the initialization.  */
  foo[i] = 1;

  /*__builtin___asan_report_store1 called 2 times here to instrument
    the store to the memory region of tab.  */
  __builtin_memset (tab, 3, sizeof (tab));

  /* There is no instrumentation for the two memset calls below.  */
  __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
     (subset of) the memory region of tab.  */
  __builtin_memcpy (&tab[1], foo + i, 3);

  /* This should not generate a __builtin___asan_report_load1 because
     the reference to tab[1] has been already instrumented above.  */
  return tab[1];

  /* So for these function, there should be 7 calls to
     __builtin___asan_report_store1.  */
}

int
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" } } */