blob: 9bf89541107344cdf61f3ce2dd9e8c3fd39d7da3 [file] [log] [blame]
Ted Kremenekd71ed262008-04-10 22:16:52 +00001// RUN: clang -checker-simple -verify %s
Ted Kremenek02737ed2008-03-31 15:02:58 +00002
3int* f1() {
4 int x = 0;
Ted Kremenek22bda882008-07-31 20:31:27 +00005 return &x; // expected-warning{{Address of stack memory associated with local variable 'x' returned.}} expected-warning{{address of stack memory associated with local variable 'x' returned}}
Ted Kremenek02737ed2008-03-31 15:02:58 +00006}
7
8int* f2(int y) {
Ted Kremenek22bda882008-07-31 20:31:27 +00009 return &y; // expected-warning{{Address of stack memory associated with local variable 'y' returned.}} expected-warning{{address of stack memory associated with local variable 'y' returned}}
Ted Kremenek02737ed2008-03-31 15:02:58 +000010}
11
12int* f3(int x, int *y) {
13 int w = 0;
14
15 if (x)
16 y = &w;
17
Ted Kremenek22bda882008-07-31 20:31:27 +000018 return y; // expected-warning{{Address of stack memory associated with local variable 'w' returned.}}
Ted Kremenek02737ed2008-03-31 15:02:58 +000019}
20
Ted Kremenekd4a07982008-10-30 18:46:50 +000021void* compound_literal(int x) {
22 if (x)
23 return &(unsigned short){((unsigned short)0x22EF)}; // expected-warning{{Address of stack memory}} expected-warning{{braces around scalar initializer}}
24
25 struct s { int z; double y; int w; };
26 return &((struct s){ 2, 0.4, 5 * 8 });
Ted Kremenek194aade2008-10-27 21:57:17 +000027}
Ted Kremenek02737ed2008-03-31 15:02:58 +000028