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