2009-02-18 01:47:27 +03:00
// RUN: clang -analyze -checker-simple -verify %s &&
// RUN: clang -analyze -checker-cfref -analyzer-store=basic -verify %s &&
// RUN: clang -analyze -checker-cfref -analyzer-store=region -verify %s
2008-03-31 19:02:58 +04:00
2008-11-02 03:37:31 +03:00
# include <stdlib.h>
2009-02-18 01:47:27 +03:00
# include "../../../../include/llvm/Config/config.h"
2009-02-17 20:33:31 +03:00
# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# endif
2008-11-02 03:37:31 +03:00
2008-03-31 19:02:58 +04:00
int * f1 ( ) {
int x = 0 ;
2008-08-01 00:31:27 +04:00
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}}
2008-03-31 19:02:58 +04:00
}
int * f2 ( int y ) {
2008-08-01 00:31:27 +04:00
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}}
2008-03-31 19:02:58 +04:00
}
int * f3 ( int x , int * y ) {
int w = 0 ;
if ( x )
y = & w ;
2008-08-01 00:31:27 +04:00
return y ; // expected-warning{{Address of stack memory associated with local variable 'w' returned.}}
2008-03-31 19:02:58 +04:00
}
2008-10-31 03:19:42 +03:00
void * compound_literal ( int x , int y ) {
2008-10-30 21:46:50 +03:00
if ( x )
return & ( unsigned short ) { ( ( unsigned short ) 0x22EF ) } ; // expected-warning{{Address of stack memory}} expected-warning{{braces around scalar initializer}}
2008-10-31 02:17:05 +03:00
int * array [ ] = { } ;
2008-10-30 21:46:50 +03:00
struct s { int z ; double y ; int w ; } ;
2008-10-31 03:19:42 +03:00
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 } ) ;
2008-10-31 03:20:13 +03:00
return p ; // expected-warning{{Address of stack memory}}
2008-10-28 00:57:17 +03:00
}
2008-03-31 19:02:58 +04:00
2008-11-02 03:37:31 +03:00
void * alloca_test ( ) {
void * p = alloca ( 10 ) ;
return p ; // expected-warning{{Address of stack memory}}
}