1 /* Test to verify that a PHI with a COND_EXPR argument in a return
2 statement is handled correctly.
3 { dg-do compile }
4 { dg-options "-O2 -Wall" } */
5
6 extern struct S s;
7
8 void* f (int n)
9 {
10 void *p;
11 int x = 0;
12
13 for (int i = n; i >= 0; i--)
14 {
15 p = &s;
16 if (p == (void*)-1)
17 x = 1;
18 else if (p)
19 return p;
20 }
21
22 /* The return statement below ends up with the following IL:
23 <bb 6> [local count: 59055800]:
24 # x_10 = PHI <1(5), 0(2)>
25 _5 = x_10 != 0 ? -1B : 0B;
26
27 <bb 7> [local count: 114863532]:
28 # _3 = PHI <&s(4), _5(6), &s(3)>
29 return _3; */
30 return x ? (void*)-1 : 0;
31 }
32
33 void* g (int n)
34 {
35 void *p;
36 int x = 0; /* { dg-message "declared here" } */
37
38 for (int i = n; i >= 0; i--)
39 {
40 p = &s;
41 if (p == (void*)-1)
42 x = 1;
43 else if (p)
44 return p;
45 }
46
47 /* The return statement below does not reference a COND_EXPR argument. */
48 return x ? &x : 0; /* { dg-warning "may return address of local variable" "missing location" { xfail *-*-* } } */
49 /* { dg-warning "may return address of local variable" "pr90735" { target *-*-* } 0 } */
50 }