libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / Wreturn-local-addr-5.c
blobbdf1cd40c1b61a447444455096b2fbb7964ac3b7
1 /* PR c/71924 - missing -Wreturn-local-addr returning alloca result
2 { dg-do compile }
3 { dg-options "-O2 -Wall" } */
5 void sink (void*);
7 void* loop_idx (int x)
9 char a[32]; /* { dg-message "declared here" } */
10 char *p = a;
12 sink (a);
14 int i;
15 for (i = 0; i != 32; ++i)
16 if (p[i] == x)
17 break;
19 p = i < 32 ? &p[i] : 0;
20 return p; /* { dg-warning "may return address of local variable" } */
24 void* loop_ptr (int i, int x)
26 char a[32]; /* { dg-message "declared here" } */
27 char *p;
29 sink (a);
31 /* The warning for the statement below would ideally be a "returns"
32 because it definitely returns the address of a, but when both
33 returns get merged into one we end up with a "may return". */
34 for (p = a; *p; ++p)
35 if (*p == x)
36 return p; /* { dg-warning "(returns|may return) address of local variable" "missing location" { xfail *-*-* } } */
37 /* { dg-warning "(returns|may return) address of local variable" "pr90735" { target *-*-* } 0 } */
39 return 0;