Kirstóf Umann | a2b6ece | 2020-03-20 16:45:53 +0100 | [diff] [blame] | 1 | // RUN: %clang_analyze_cc1 -verify %s -fblocks \ |
| 2 | // RUN: -analyzer-checker=core \ |
| 3 | // RUN: -analyzer-output=text |
| 4 | |
| 5 | int* stack_addr_escape_base() { |
| 6 | int x = 0; |
| 7 | // FIXME: This shouldn't be tied to a modeling checker. |
Kirstóf Umann | 3a6ee4f | 2020-04-11 00:21:48 +0200 | [diff] [blame] | 8 | return &x; // expected-warning{{Address of stack memory associated with local variable 'x' returned to caller [core.StackAddressEscape]}} |
Kirstóf Umann | a2b6ece | 2020-03-20 16:45:53 +0100 | [diff] [blame] | 9 | // expected-note-re@-1{{{{^Address of stack memory associated with local variable 'x' returned to caller$}}}} |
| 10 | // Just a regular compiler warning. |
| 11 | // expected-warning@-3{{address of stack memory associated with local variable 'x' returned}} |
| 12 | } |
| 13 | |
Kirstóf Umann | 3a6ee4f | 2020-04-11 00:21:48 +0200 | [diff] [blame] | 14 | char const *p; |
| 15 | |
| 16 | void f0() { |
| 17 | char const str[] = "This will change"; |
| 18 | p = str; |
| 19 | } // expected-warning{{Address of stack memory associated with local variable 'str' is still referred to by the global variable 'p' upon returning to the caller. This will be a dangling reference [core.StackAddressEscape]}} |
| 20 | // expected-note@-1{{Address of stack memory associated with local variable 'str' is still referred to by the global variable 'p' upon returning to the caller. This will be a dangling reference}} |