stack-addr-ps.c revision 31483b48c75e2bd544964102f67809b46603c683
1// RUN: clang -checker-simple -verify %s 2 3#include <stdlib.h> 4#include <alloca.h> 5 6int* f1() { 7 int x = 0; 8 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}} 9} 10 11int* f2(int y) { 12 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}} 13} 14 15int* f3(int x, int *y) { 16 int w = 0; 17 18 if (x) 19 y = &w; 20 21 return y; // expected-warning{{Address of stack memory associated with local variable 'w' returned.}} 22} 23 24void* compound_literal(int x, int y) { 25 if (x) 26 return &(unsigned short){((unsigned short)0x22EF)}; // expected-warning{{Address of stack memory}} expected-warning{{braces around scalar initializer}} 27 28 int* array[] = {}; 29 struct s { int z; double y; int w; }; 30 31 if (y) 32 return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of stack memory}} 33 34 35 void* p = &((struct s){ 42, 0.4, x ? 42 : 0 }); 36 return p; // expected-warning{{Address of stack memory}} 37} 38 39void* alloca_test() { 40 void* p = alloca(10); 41 return p; // expected-warning{{Address of stack memory}} 42} 43 44