diff options
| author | Ed Schouten <ed@FreeBSD.org> | 2009-06-02 17:58:47 +0000 |
|---|---|---|
| committer | Ed Schouten <ed@FreeBSD.org> | 2009-06-02 17:58:47 +0000 |
| commit | ec2b103c267a06a66e926f62cd96767b280f5cf5 (patch) | |
| tree | ce7d964cbb5e39695b71481698f10cb099c23d4a /test/Analysis/stack-addr-ps.c | |
Notes
Diffstat (limited to 'test/Analysis/stack-addr-ps.c')
| -rw-r--r-- | test/Analysis/stack-addr-ps.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/Analysis/stack-addr-ps.c b/test/Analysis/stack-addr-ps.c new file mode 100644 index 000000000000..4bc9a7def2c8 --- /dev/null +++ b/test/Analysis/stack-addr-ps.c @@ -0,0 +1,44 @@ +// RUN: clang-cc -analyze -checker-simple -verify %s && +// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -verify %s && +// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -verify %s + +#include <stdlib.h> + +int* f1() { + int x = 0; + 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}} +} + +int* f2(int y) { + 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}} +} + +int* f3(int x, int *y) { + int w = 0; + + if (x) + y = &w; + + return y; // expected-warning{{Address of stack memory associated with local variable 'w' returned.}} +} + +void* compound_literal(int x, int y) { + if (x) + return &(unsigned short){((unsigned short)0x22EF)}; // expected-warning{{Address of stack memory}} + + int* array[] = {}; + struct s { int z; double y; int w; }; + + if (y) + return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of stack memory}} + + + void* p = &((struct s){ 42, 0.4, x ? 42 : 0 }); + return p; // expected-warning{{Address of stack memory}} +} + +void* alloca_test() { + void* p = __builtin_alloca(10); + return p; // expected-warning{{Address of stack memory}} +} + |
