comparison gcc/testsuite/gcc.dg/Wreturn-local-addr-9.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* PR c/71924 - missing -Wreturn-local-addr returning alloca result
2 Test derived from gcc.c-torture/execute/20071108-1.c. It shows
3 a false positive at -Os caused by the jump threading/vrp1 pass.
4 { dg-do compile }
5 { dg-options "-Os -fdump-tree-optimized" } */
6
7 struct S
8 {
9 int i;
10 };
11
12 void* f (void);
13
14 __attribute__ ((noinline))
15 struct S* g (int i)
16 {
17 struct S *p = f (), q;
18
19 if (p == 0)
20 p = &q;
21
22 p->i = i;
23
24 if (p == &q)
25 p = 0;
26
27 /* With -Os the warning pass sees:
28
29 ...
30 <bb 4>
31 # p_1 = PHI <&q(2), p_5(3)>
32 p_1->i = i_6(D);
33 if (&q == p_1)
34 goto <bb 6>; [14.90%]
35 else
36 goto <bb 5>; [85.10%]
37
38 <bb 5>
39
40 <bb 6>
41 # p_2 = PHI <0B(4), p_1(5)>
42 q ={v} {CLOBBER};
43 return p_2;
44 }
45
46 which leads to: */
47 return p; /* { dg-bogus "may return address of local variable" "" { xfail *-*-* } } */
48
49 /* Whereas as -O2 the pass sees:
50
51 <bb 2>
52 p_5 = f ();
53 if (p_5 == 0B)
54 goto <bb 4>; [30.00%]
55 else
56 goto <bb 3>; [70.00%]
57
58 <bb 3>
59 # p_2 = PHI <0B(5), p_5(4)>
60 q ={v} {CLOBBER};
61 return p_2;
62
63 <bb 4>
64 p_5->i = i_6(D);
65 goto <bb 3>; [100.00%]
66
67 <bb 5>
68 q.i = i_6(D);
69 goto <bb 3>; [100.00%]
70 }
71
72 and no warning. */
73 }