2009-07-03 02:02:15 +04:00
// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -verify %s &&
2009-07-10 04:41:58 +04:00
// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic-old-cast -verify %s &&
2009-07-03 02:02:15 +04:00
// RUN: clang-cc -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>
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 )
2009-05-16 15:45:48 +04:00
return & ( unsigned short ) { ( ( unsigned short ) 0x22EF ) } ; // expected-warning{{Address of stack memory}}
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 ( ) {
2009-02-18 04:02:14 +03:00
void * p = __builtin_alloca ( 10 ) ;
2008-11-02 03:37:31 +03:00
return p ; // expected-warning{{Address of stack memory}}
}
2009-07-02 03:24:11 +04:00
int array_test ( int x [ 2 ] ) {
return x [ 0 ] ; // no-warning
}
2009-07-03 02:02:15 +04:00
struct baz {
int x ;
int y [ 2 ] ;
} ;
int struct_test ( struct baz byVal , int flag ) {
if ( flag )
return byVal . x ; // no-warning
else {
return byVal . y [ 0 ] ; // no-warning
}
2009-07-02 03:24:11 +04:00
}