1 /* { dg-do run } */
2 /* { dg-options "-O -fdump-tree-alias-details -fdelete-null-pointer-checks" } */
3 
4 int *i;
5 void __attribute__((noinline))
foo(void)6 foo (void)
7 {
8   *i = 1;
9 }
10 int **__attribute__((noinline,const))
foobar(void)11 foobar (void)
12 {
13   return &i;
14 }
15 int __attribute__((noinline))
bar(int local_p)16 bar(int local_p)
17 {
18   int x = 0;
19   int *j;
20   int **p;
21   if (local_p)
22     p = &j;
23   else
24     p = foobar();
25   *p = &x;  /* This makes x escape.  */
26   foo ();
27   return x;
28 }
29 extern void abort (void);
main()30 int main()
31 {
32   int k = 2;
33   i = &k;
34   if (bar (1) != 0 || k != 1)
35     abort ();
36   if (bar (0) != 1)
37     abort ();
38   return 0;
39 }
40 
41 /* { dg-final { scan-tree-dump "ESCAPED = { NULL ESCAPED NONLOCAL x }" "alias" { target { ! keeps_null_pointer_checks } } } } */
42 /* { dg-final { scan-tree-dump "ESCAPED = { ESCAPED NONLOCAL x }" "alias" { target { keeps_null_pointer_checks } } } } */
43