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
|
typedef int int_array [10] ;
void instr(){
//@ ghost int x ;
//@ ghost int \ghost* p ;
//@ ghost int arr[10] ;
//@ ghost x = 1 ;
//@ ghost *p = 1 ;
//@ ghost arr[0] = 1 ;
}
void named(void){
//@ ghost int_array a ;
//@ ghost a[0] = 42 ;
}
struct Type {
int field ;
} ;
void field_access(){
struct Type ng_var ;
//@ ghost struct Type g_var ;
ng_var.field = 42 ;
//@ ghost g_var.field = 42 ;
}
void nested(void){
/*@ ghost
int * * ptrp ;
int * \ghost * ptrpg ;
int \ghost * \ghost * ptrpgg ;
int arra[10][10] ;
int * arrp[10] ;
int \ghost * arrpg[10] ;
int (* ptra)[10] ;
int \ghost (* ptrag) [10] ;
*/
// ALLOWED
/*@ ghost
ptrp = 0 ;
ptrpg = 0 ;
*ptrpg = 0 ;
ptrpgg = 0 ;
*ptrpgg = 0 ;
**ptrpgg = 1 ;
arra[0][0] = 1 ;
arrp[0] = 0 ;
arrpg[0] = 0 ;
*arrpg[0] = 1 ;
ptra = 0 ;
ptrag = 0 ;
(*ptrag)[0] = 1 ;
*/
}
void assigns_clause(void){
//@ ghost int *p ;
/*@ loop assigns p, i ; */
for(int i = 0; i < 10; i++);
/*@ ghost
/@ loop assigns p, i ; @/
for(int i = 0; i < 10; i++);
*/
}
/*@ ghost
/@ assigns *p ; @/
void g_decl_star(int \ghost *p);
/@ assigns *p ; @/
void g_def_star(int \ghost *p){
}
*/
// Note: this should be accepted as the pointer might point to a
// memory location which is indeed assigned by the actual code.
/*@ assigns *p ; */
void ng_decl_star(void) /*@ ghost (int \ghost *p) */ ;
/*@ assigns *p ; */
void ng_def_star(void) /*@ ghost (int \ghost *p) */ {
}
/*@ assigns *p ; */
void ng_decl_star_ng(void) /*@ ghost (int *p) */ ;
/*@ assigns *p ; */
void ng_def_star_ng(void) /*@ ghost (int *p) */ {
}
void assigns_loop_star(){
//@ ghost int \ghost *p ;
/*@ loop assigns *p, i ; */
for(int i = 0; i < 10; i++);
/*@ ghost
/@ loop assigns *p, i ; @/
for(int i = 0; i < 10; i++);
*/
}
/*@ ghost
/@ assigns p[ 0 .. max ] ; @/
void g_decl_set(int \ghost *p, int max);
/@ assigns p[ 0 .. max ] ; @/
void g_def_set(int \ghost *p, int max){
}
*/
/*@ assigns p[ 0 .. max ] ; */
void ng_decl_set(int max) /*@ ghost (int \ghost *p) */ ;
/*@ assigns p[ 0 .. max ] ; */
void ng_def_set(int max) /*@ghost (int \ghost *p) */ {
}
/*@ assigns p[ 0 .. max ] ; */
void ng_decl_set_ng(int max) /*@ ghost (int \ghost *p) */ ;
/*@ assigns p[ 0 .. max ] ; */
void ng_def_set_ng(int max) /*@ghost (int \ghost *p) */ {
}
void assigns_loop_set(){
//@ ghost int \ghost *p ;
int max = 42 ;
/*@ loop assigns p[ 0 .. max ], i ; */
for(int i = 0; i < 10; i++);
/*@ ghost
/@ loop assigns p[ 0 .. max ], i ; @/
for(int i = 0; i < 10; i++);
*/
}
/*@ ghost
/@ assigns \nothing ; @/
void ghost_decl_nothing(int * a) ;
/@ assigns *a ; @/
void ghost_decl_valid_a(int \ghost * a) ;
void ghost_def_nothing(int * a){
int x = *a ;
}
void ghost_def_valid_a(int \ghost * a){
*a = 42 ;
}
*/
void assigns_nothing_or_correct(void){
int ng ;
//@ ghost ghost_decl_nothing(&ng);
//@ ghost ghost_def_nothing(&ng);
//@ ghost int g ;
//@ ghost ghost_decl_valid_a(&g);
//@ ghost ghost_def_valid_a(&g);
}
|