Ted Kremenek | d71ed26 | 2008-04-10 22:16:52 +0000 | [diff] [blame] | 1 | // RUN: clang -checker-simple -verify %s |
Ted Kremenek | 02737ed | 2008-03-31 15:02:58 +0000 | [diff] [blame] | 2 | |
| 3 | int* f1() { |
| 4 | int x = 0; |
Ted Kremenek | 22bda88 | 2008-07-31 20:31:27 +0000 | [diff] [blame] | 5 | 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 Kremenek | 02737ed | 2008-03-31 15:02:58 +0000 | [diff] [blame] | 6 | } |
| 7 | |
| 8 | int* f2(int y) { |
Ted Kremenek | 22bda88 | 2008-07-31 20:31:27 +0000 | [diff] [blame] | 9 | 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 Kremenek | 02737ed | 2008-03-31 15:02:58 +0000 | [diff] [blame] | 10 | } |
| 11 | |
| 12 | int* f3(int x, int *y) { |
| 13 | int w = 0; |
| 14 | |
| 15 | if (x) |
| 16 | y = &w; |
| 17 | |
Ted Kremenek | 22bda88 | 2008-07-31 20:31:27 +0000 | [diff] [blame] | 18 | return y; // expected-warning{{Address of stack memory associated with local variable 'w' returned.}} |
Ted Kremenek | 02737ed | 2008-03-31 15:02:58 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Ted Kremenek | 194aade | 2008-10-27 21:57:17 +0000 | [diff] [blame^] | 21 | unsigned short* compound_literal() { |
| 22 | return &(unsigned short){((unsigned short)0x22EF)}; // expected-warning{{Address of stack memory}} |
| 23 | } |
Ted Kremenek | 02737ed | 2008-03-31 15:02:58 +0000 | [diff] [blame] | 24 | |