1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
/* run.config
EXIT: 1
OPT:-cpp-extra-args="-DFAIL_DECL_TYPE"
EXIT: 0
MODULE: @PTEST_NAME@
OPT:
*/
/* When there is no comment, the code should be allowed */
void f_ints(){
int ng ;
//@ ghost int g0 ;
//@ ghost int \ghost g1 ; // should warn (g1 is already ghost)
}
void f_ptrs(){
int* ng ;
/*@ ghost
int * g ;
int \ghost* g0 ;
int * \ghost g1 ; // should warn (g1 is already ghost)
int \ghost * \ghost g2 ; // should warn (g2 is already ghost)
*/
}
void f_arrays(){
int ng[10] ;
/*@ ghost
int g[10] ;
int \ghost g0[10] ; // should warn (g0 elements are already ghost)
*/
}
struct S {
int field ;
};
void f_structs(void){
struct S ng ;
/*@ ghost
struct S g ;
struct S \ghost g0 ; // should warn (g0 is already ghost)
*/
}
typedef int int_array [10] ;
typedef int* int_ptr ;
void named(void){
//@ ghost int_array a ;
//@ ghost int_ptr ptr ;
}
struct S_with_pointer {
int * field ;
};
struct S_with_array {
int field[10] ;
};
struct S_with_ptr_of_array {
int (*field) [10] ;
};
struct S_with_array_of_ptr {
int* field [10] ;
};
void nesting_non_ghost (void){
int a ;
int * ptr ;
int array[10] ;
int * * pptr ;
int (* parray)[10] ;
int * aptr[10] ;
int aarray[10][10] ;
struct S_with_pointer sp ;
struct S_with_array sa ;
struct S_with_ptr_of_array spa ;
struct S_with_array_of_ptr sap ;
struct S_with_pointer * psp ;
struct S_with_array * psa ;
struct S_with_ptr_of_array * pspa ;
struct S_with_array_of_ptr * psap ;
struct S_with_pointer asp[10] ;
struct S_with_array asa[10] ;
struct S_with_ptr_of_array aspa[10] ;
struct S_with_array_of_ptr asap[10] ;
a = 1 ;
}
void nesting_ghost(void){
/*@ ghost {
int a ;
int * ptr ;
int \ghost * ptrg ;
int array[10] ;
int * * pptr ;
int * \ghost * pptrg ;
int \ghost * \ghost * pptrgg ;
int (* parray)[10] ;
int \ghost (* parrayg)[10] ;
int * aptr[10] ;
int \ghost * aptrg[10] ;
int aarray[10][10] ;
struct S_with_pointer sp ;
struct S_with_array sa ;
struct S_with_ptr_of_array spa ;
struct S_with_array_of_ptr sap ;
struct S_with_pointer * psp ;
struct S_with_pointer \ghost * pspg ;
struct S_with_array * psa ;
struct S_with_array \ghost * psag ;
struct S_with_ptr_of_array * pspa ;
struct S_with_ptr_of_array \ghost * pspag ;
struct S_with_array_of_ptr * psap ;
struct S_with_array_of_ptr \ghost * psapg ;
struct S_with_pointer asp[10] ;
struct S_with_array asa[10] ;
struct S_with_ptr_of_array aspa[10] ;
struct S_with_array_of_ptr asap[10] ;
a = 1 ;
}
*/
}
#ifdef FAIL_DECL_TYPE /* In this section types are ill-formed (ghost -> non-ghost -> ghost) */
/*@ ghost
int \ghost * * decl_bad_return_type(void) ;
void decl_bad_parameter_type(int \ghost * * param) ;
int \ghost * * def_bad_return_type(void) {
return 0 ;
}
void def_bad_parameter_type(int \ghost * * param) {
}
void reference_bad_types_functions (void) {
decl_bad_return_type() ;
decl_bad_parameter_type(0) ;
}
*/
void ghost_incorrect(void){
/*@ ghost {
int \ghost * * pptrg ;
pptrg = 0 ;
}
*/
}
#endif
void foo_1(int a){
}
void foo_2(int a) /*@ ghost (int \ghost b) */ { // should warn (b is already ghost)
}
void foo_3(int a) /*@ ghost (int b, int c) */ {
}
void bar_1(int a) ;
void bar_2(int a) /*@ ghost (int \ghost b) */ ; // should warn (b is already ghost)
void bar_3(int a) /*@ ghost (int b, int c) */ ;
void pfoo_1(int* a){
}
void pfoo_2(int a) /*@ ghost (int * \ghost b) */ { // should warn (b is already ghost)
}
void pfoo_3(int a) /*@ ghost (int \ghost* b, int * c) */ {
}
void pbar_1(int* a) ;
void pbar_2(int a) /*@ ghost (int * \ghost b) */ ; // should warn (b is already ghost)
void pbar_3(int a) /*@ ghost (int \ghost* b, int * c) */ ;
void afoo_1(int a[10]){
}
void afoo_2(int a) /*@ ghost (int \ghost b[10]) */ { // should warn (b elements are already ghost)
}
void afoo_3(int a) /*@ ghost (int b[10]) */ {
}
void abar_1(int a[10]) ;
void abar_2(int a) /*@ ghost (int \ghost b[10]) */ ; // should warn (b elements are already ghost)
void abar_3(int a) /*@ ghost (int b[10]) */ ;
void reference_functions(){
bar_1(1);
bar_2(1) /*@ ghost (1) */;
bar_3(1) /*@ ghost (1, 1) */;
int v ;
//@ ghost int \ghost* gp ;
pbar_1(&v);
pbar_2(1) /*@ ghost (&v) */;
pbar_3(1) /*@ ghost (gp, &v) */;
int ng[10] ;
//@ ghost int ga[10] ;
abar_1(ng);
abar_2(1) /*@ ghost (ga) */;
abar_3(1) /*@ ghost (ga) */;
}
//@ ghost int x ;
int i ;
int * p ;
//@ ghost int * gp1 = &i ;
//@ ghost int * gp2 = p ;
//@ ghost int x = 42 ;
int main(){
//@ ghost int value = x + *gp1 + *gp2 ;
}
|