aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.dg/asan/nosanitize-and-inline.c
blob: 585380162165dc539ea6ce51d47551e219d2aff1 (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
/* { dg-do run } */

/* This is a simplified version of what Emacs does internally,
   when marking its stack.  */

static unsigned long sum;
static void *stack_base;

/* A simple substitute for what Emacs actually does.  */
static void
mark_maybe_pointer (void *p)
{
  sum ^= (unsigned long) p;
}

static inline void __attribute__ ((no_sanitize_address))
mark_memory (void **start, void **end)
{
  void **pp;

  if (end < start)
    {
      void **tem = start;
      start = end;
      end = tem;
    }

  for (pp = start; pp < end; pp++)
    {
      /* This is the dereference that we don't want sanitized.  */
      void *p = *pp;

      mark_maybe_pointer (p);
    }
}

static void
mark_stack (void)
{
  void *end;
  mark_memory (stack_base, &end);
}

void
garbage_collect (void)
{
  mark_stack ();
}

int
main (void)
{
  void *dummy;
  stack_base = &dummy;
  garbage_collect ();
  return 0;
}