]>
Commit | Line | Data |
---|---|---|
aac9480d MS |
1 | /* PR c/71924 - missing -Wreturn-local-addr returning alloca result |
2 | { dg-do compile } | |
3 | { dg-options "-O2 -Wall" } */ | |
4 | ||
5 | void sink (void*); | |
6 | ||
7 | void* loop_idx (int x) | |
8 | { | |
9 | char a[32]; /* { dg-message "declared here" } */ | |
10 | char *p = a; | |
11 | ||
12 | sink (a); | |
13 | ||
14 | int i; | |
15 | for (i = 0; i != 32; ++i) | |
16 | if (p[i] == x) | |
17 | break; | |
18 | ||
19 | p = i < 32 ? &p[i] : 0; | |
20 | return p; /* { dg-warning "may return address of local variable" } */ | |
21 | } | |
22 | ||
23 | ||
24 | void* loop_ptr (int i, int x) | |
25 | { | |
26 | char a[32]; /* { dg-message "declared here" } */ | |
27 | char *p; | |
28 | ||
29 | sink (a); | |
30 | ||
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 } */ | |
38 | ||
39 | return 0; | |
40 | } |