summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/tree-ssa/vrp03.c
blob: 9b7c08256da3683f50cacb7176019a810ddf64bd (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
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-vrp1" } */

struct A
{
  int a;
  int b;
};

foo (struct A *p, struct A *q)
{
  int *r = 0;

  if (p)
    {
      if (p == q)
	{
	  /* This should be folded to 'if (1)' because q is [p, p]
	     and p is ~[0, 0].  */
	  if (q)
	    r = &q->a;

	  /* This should be folded to 'if (1)' because q should be
	     ~[0, 0] and thus &q->a should be ~[0, 0].  */
	  if (r)
	    return 5;
	}
    }

  return q->a;
}

/* { dg-final { scan-tree-dump-times "Folding predicate q_.*to 1" 1 "vrp1" } } */
/* { dg-final { scan-tree-dump-times "Folding predicate r_.*to 1" 1 "vrp1" } } */
/* { dg-final { cleanup-tree-dump "vrp1" } } */