File: ghost_cv_incompat.i

package info (click to toggle)
frama-c 20220511-manganese-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 66,492 kB
  • sloc: ml: 278,834; ansic: 47,093; sh: 4,823; makefile: 3,613; javascript: 2,436; python: 1,919; perl: 897; lisp: 293; xml: 62
file content (195 lines) | stat: -rw-r--r-- 6,202 bytes parent folder | download | duplicates (2)
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
/* run.config*
 EXIT: 1
   STDOPT:
*/

typedef int int_array [10] ;
struct Type { int field ; } ;

void decl_ghost(void) /*@ ghost (int \ghost * p) */ ;
void def_ghost(void) /*@ ghost (int \ghost * p) */ {}

void decl_not_ghost(void) /*@ ghost (int * p) */ ;
void def_not_ghost(void) /*@ ghost (int * p) */ {}

/*@
  ghost
  /@ assigns \nothing ; @/
  int * function(void) ;
*/

//
// Non-ghost -> Ghost
//

int ng ;
//@ ghost int * gl_gp ;
//@ ghost int \ghost * gl_gpg_1 = &ng ;   // error: address of non-ghost integer into pointer to ghost
//@ ghost int \ghost * gl_gpg_2 = gl_gp ; // error: pointer to a non-ghost location into pointer to ghost


int *gl_p00, *gl_p01 ;
// error: we transform pointer to non-ghost into pointer to ghosts
//@ ghost int \ghost * gl_array[3] = { gl_p00, gl_p00, gl_p01 };

void assign_ng_to_g(){
  int i ;
  int *p ;
  int a[10];

  /*@ ghost
    int \ghost * gpg ;
    {
      gpg = &i ; // error: address of non-ghost integer into pointer to ghost
      gpg = p ;  // error: pointer to a non-ghost location into pointer to ghost
      gpg = a ;  // error: array of non-ghost values into pointer to ghost
    }
  */

  int (* nga) [10] ;
  //@ ghost int \ghost (*gpgagi)[10] ;
  //@ ghost gpgagi = nga ; // error: pointer to a non-ghost array into pointer to ghost array


  //@ ghost int \ghost * \ghost * p1 ;
  //@ ghost int        * \ghost * p2 ;
  //@ ghost int * array[10] ;

  //@ ghost p1 = p2 ;         // error: pointer to a pointer to non-ghost into pointer to pointer to ghost
  //@ ghost p1 = array ;      // error: array of pointers to non-ghost into pointer to pointer to ghost

  //@ ghost *p1 = *p2 ;       // error: pointer to non-ghost into pointer to ghost
  //@ ghost *p1 = array[0] ;  // error: pointer to non-ghost into pointer to ghost

  //@ ghost int \ghost * \ghost * \ghost * p3 ;
  //@ ghost int * \ghost (\ghost (*p4))[10] ;
  //@ ghost p3 = p4 ;         // error: pointer to ghost array of ghost pointers to non-ghost
                              //   into pointer to ghost pointers to ghost pointers to ghost

  struct Type ng_var ;
  //@ ghost int \ghost* r_ptr_2 ;
  //@ ghost r_ptr_2 = &(ng_var.field) ;     // error: address of a non-ghost field into pointer to ghost
}

void init_ng_to_g(void){
  int i ;
  int *p ;
  int a[10];

  //@ ghost int \ghost * gpg1 = &i ;  // error: address of non-ghost integer into pointer to ghost
  //@ ghost int \ghost * gpg2 = p ;   // error: pointer to a non-ghost location into pointer to ghost
  //@ ghost int \ghost * gpg3 = a ;   // error: array of non-ghost values into pointer to ghost

  //@ ghost int \ghost * gpg = function() ; // error: pointer to a non-ghost location into pointer to ghost

  int *p00, *p01 ;
  //@ ghost int \ghost * array[3] = { p00, p00, p01 };

  //@ ghost int_array ga ;
  //@ ghost int \ghost* ptr = ga ;
}

void call_ng_to_g(void){
  int i ;
  decl_ghost() /*@ ghost(&i) */ ; // error: address of non-ghost integer into pointer to ghost
  def_ghost() /*@ ghost(&i) */ ;  // error: address of non-ghost integer into pointer to ghost
}

//
// Ghost -> Non-ghost
//

//@ ghost int g ;
//@ ghost int \ghost * gl_gpg ;
//@ ghost int * gl_gp_1 = &g ;     // error: address of ghost integer into pointer to non-ghost
//@ ghost int * gl_gp_2 = gl_gpg ; // error: pointer to a ghost location into pointer to non-ghost


//@ ghost int \ghost *gl_pg00, *gl_pg01 ;
// error: we transform pointer to ghost into pointer to non-ghosts
//@ ghost int * gl_array_ng[3] = { gl_p00, gl_p00, gl_p01 };

void assign_g_to_ng(){
  //@ ghost int i ;
  //@ ghost int \ghost *p ;
  //@ ghost int a[10];

  /*@ ghost
    int * gp ;
    {
      gp = &i ; // error: address of ghost integer into pointer to non-ghost
      gp = p ;  // error: pointer to a ghost location into pointer to non-ghost
      gp = a ;  // error: array of ghost values into pointer to non-ghost
    }
  */

  //@ ghost int \ghost (*gpgagi) [10] ;
  //@ ghost int (*gpai)[10] ;
  //@ ghost gpgagi = gpai ; // error: pointer to a ghost array into pointer to non-ghost array


  //@ ghost int        * \ghost * p1 ;
  //@ ghost int \ghost * \ghost * p2 ;
  //@ ghost int \ghost * array[10] ;

  //@ ghost p1 = p2 ;         // error: pointer to a pointer to ghost into pointer to pointer to non-ghost
  //@ ghost p1 = array ;      // error: array of pointers to ghost into pointer to pointer to non-ghost

  //@ ghost *p1 = *p2 ;       // error: pointer to ghost into pointer to non-ghost
  //@ ghost *p1 = array[0] ;  // error: pointer to ghost into pointer to non-ghost

  //@ ghost int * \ghost * \ghost * p3 ;
  //@ ghost int \ghost * \ghost (\ghost (*p4))[10] ;
  //@ ghost p3 = p4 ;         // error: pointer to ghost array of ghost pointers to ghost
                              //   into pointer to ghost pointers to ghost pointers to non-ghost

  //@ ghost struct Type g_var ;

  //@ ghost int* r_ptr_3 ;
  //@ ghost r_ptr_3 = &(g_var.field) ; // error: address of a ghost field into pointer to non-ghost
}

/*@
  ghost
  /@ assigns \nothing ; @/
  int \ghost * function_g(void) ;
*/

void init_g_to_ng(void){
  //@ ghost int i ;
  //@ ghost int \ghost *p ;
  //@ ghost int a[10];

  //@ ghost int * gp1 = &i ;  // error: address of ghost integer into pointer to non-ghost
  //@ ghost int * gp2 = p ;   // error: pointer to a ghost location into pointer to non-ghost
  //@ ghost int * gp3 = a ;   // error: array of ghost values into pointer to non-ghost

  //@ ghost int * gpg = function_g() ; // error: pointer to a ghost location into pointer to non-ghost

  //@ ghost int \ghost *p00, *p01 ;
  //@ ghost int * array[3] = { p00, p00, p01 };

  //@ ghost int_array ga ;
  //@ ghost int * ptr = ga ;
}

void call_g_to_ng(void){
  //@ ghost int b = 42 ;
  decl_not_ghost() /*@ ghost(&b) */ ; // error: address of ghost integer into pointer to non-ghost
  def_not_ghost() /*@ ghost(&b) */ ;  // error: address of ghost integer into pointer to non-ghost
}

/*@ ghost
  /@ assigns \nothing ; @/
  void ghost_decl_nothing(int * a) ;

  void ghost_def_nothing(int * a){
    int x = *a ;
  }
*/

void ghost_calls(void){
  //@ ghost int g;
  //@ ghost ghost_decl_nothing(&g);
  //@ ghost ghost_def_nothing(&g);
}