]>
Commit | Line | Data |
---|---|---|
65f973be | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
c59f5181 | 3 | ** Copyright (C) 1994-2003 University of Virginia, |
65f973be | 4 | ** Massachusetts Institute of Technology |
5 | ** | |
6 | ** This program is free software; you can redistribute it and/or modify it | |
7 | ** under the terms of the GNU General Public License as published by the | |
8 | ** Free Software Foundation; either version 2 of the License, or (at your | |
9 | ** option) any later version. | |
10 | ** | |
11 | ** This program is distributed in the hope that it will be useful, but | |
12 | ** WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | ** General Public License for more details. | |
15 | ** | |
16 | ** The GNU General Public License is available from http://www.gnu.org/ or | |
17 | ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
18 | ** MA 02111-1307, USA. | |
19 | ** | |
155af98d | 20 | ** For information on splint: info@splint.org |
21 | ** To report a bug: splint-bug@splint.org | |
11db3170 | 22 | ** For more information: http://www.splint.org |
65f973be | 23 | */ |
616915dd | 24 | |
25 | /* | |
26 | ** constraintGeneration.c | |
27 | */ | |
28 | ||
b7b694d6 | 29 | /* #define DEBUGPRINT 1 */ |
616915dd | 30 | |
31 | # include <ctype.h> /* for isdigit */ | |
1b8ae690 | 32 | # include "splintMacros.nf" |
616915dd | 33 | # include "basic.h" |
920a3797 | 34 | |
616915dd | 35 | # include "cgrammar_tokens.h" |
36 | ||
37 | # include "exprChecks.h" | |
616915dd | 38 | # include "exprNodeSList.h" |
39 | ||
965143f0 | 40 | /*drl We need to access the internal representation of exprNode |
41 | because these functions walk down the parse tree and need a richer | |
42 | information than is accessible through the exprNode interface.*/ | |
43 | ||
44 | /*@access exprNode@*/ | |
470b7798 | 45 | |
965143f0 | 46 | static /*@nullwhentrue@*/ bool exprNode_handleError (/*@temp@*/ exprNode p_e); |
616915dd | 47 | |
abd7f895 | 48 | static void exprNode_stmt (/*@temp@*/ /*@temp@*/ exprNode p_e); |
49 | static void exprNode_multiStatement (/*@temp@*/ exprNode p_e); | |
24633cea | 50 | |
abd7f895 | 51 | static constraintList exprNode_traversTrueEnsuresConstraints (/*@temp@*/ exprNode p_e); |
52 | static constraintList exprNode_traversFalseEnsuresConstraints (/*@temp@*/ exprNode p_e); | |
616915dd | 53 | |
28bf4b0b | 54 | static void checkArgumentList (/*@out@*/ exprNode p_temp, exprNodeList p_arglist, fileloc p_sequencePoint) /*@modifies p_temp @*/; |
55 | ||
abd7f895 | 56 | static constraintList checkCall (/*@temp@*/ exprNode p_fcn, exprNodeList p_arglist); |
4ab867d6 | 57 | |
abd7f895 | 58 | static bool exprNode_isUnhandled (/*@temp@*/ /*@observer@*/ exprNode e) |
616915dd | 59 | { |
abd7f895 | 60 | llassert(exprNode_isDefined(e)); |
616915dd | 61 | switch (e->kind) |
62 | { | |
63 | case XPR_INITBLOCK: | |
64 | case XPR_EMPTY: | |
65 | case XPR_LABEL: | |
66 | case XPR_CONST: | |
67 | case XPR_VAR: | |
68 | case XPR_BODY: | |
69 | case XPR_OFFSETOF: | |
70 | case XPR_ALIGNOFT: | |
71 | case XPR_ALIGNOF: | |
72 | case XPR_VAARG: | |
73 | case XPR_ITERCALL: | |
74 | case XPR_ITER: | |
616915dd | 75 | case XPR_GOTO: |
76 | case XPR_CONTINUE: | |
77 | case XPR_BREAK: | |
78 | case XPR_COMMA: | |
79 | case XPR_COND: | |
80 | case XPR_TOK: | |
81 | case XPR_FTDEFAULT: | |
82 | case XPR_DEFAULT: | |
616915dd | 83 | case XPR_FTCASE: |
84 | case XPR_CASE: | |
616915dd | 85 | case XPR_NODE: |
abd7f895 | 86 | DPRINTF((message ("Warning current constraint generation does not handle expression %s", exprNode_unparse(e)))); |
616915dd | 87 | return TRUE; |
88 | /*@notreached@*/ | |
89 | break; | |
90 | default: | |
91 | return FALSE; | |
92 | ||
93 | } | |
94 | /*not reached*/ | |
95 | return FALSE; | |
96 | } | |
97 | ||
965143f0 | 98 | /*@nullwhentrue@*/ bool exprNode_handleError (exprNode e) |
616915dd | 99 | { |
abd7f895 | 100 | if (exprNode_isError (e) || exprNode_isUnhandled (e)) |
616915dd | 101 | { |
abd7f895 | 102 | return TRUE; |
616915dd | 103 | } |
abd7f895 | 104 | |
616915dd | 105 | return FALSE; |
106 | } | |
107 | ||
abd7f895 | 108 | /* evans 2002-03-2 - parameter was dependent */ |
109 | bool /*@alt void@*/ exprNode_generateConstraints (/*@temp@*/ exprNode e) | |
616915dd | 110 | { |
abd7f895 | 111 | if (exprNode_isError (e)) |
616915dd | 112 | return FALSE; |
9280addf | 113 | |
abd7f895 | 114 | if (exprNode_isUnhandled (e)) |
616915dd | 115 | { |
abd7f895 | 116 | DPRINTF((message("Warning ignoring %s", exprNode_unparse (e)))); |
24633cea | 117 | return FALSE; |
616915dd | 118 | } |
119 | ||
abd7f895 | 120 | DPRINTF((message ("exprNode_generateConstraints Analysising %s at %s", exprNode_unparse(e), |
121 | fileloc_unparse(exprNode_getfileloc(e))))); | |
616915dd | 122 | |
abd7f895 | 123 | if (exprNode_isMultiStatement (e)) |
616915dd | 124 | { |
125 | exprNode_multiStatement(e); | |
126 | } | |
127 | else | |
128 | { | |
24633cea | 129 | /* fileloc loc; */ |
9280addf | 130 | |
24633cea | 131 | /* loc = exprNode_getNextSequencePoint(e); */ |
132 | /* exprNode_exprTraverse(e, FALSE, FALSE, loc); */ | |
9280addf | 133 | |
24633cea | 134 | /* fileloc_free(loc); */ |
135 | ||
136 | exprNode_stmt(e); | |
616915dd | 137 | return FALSE; |
24633cea | 138 | |
616915dd | 139 | } |
140 | ||
141 | { | |
142 | constraintList c; | |
143 | ||
144 | c = constraintList_makeFixedArrayConstraints (e->uses); | |
28bf4b0b | 145 | e->requiresConstraints = constraintList_reflectChangesFreePre (e->requiresConstraints, c); |
bb25bea6 | 146 | constraintList_free(c); |
616915dd | 147 | } |
148 | ||
abd7f895 | 149 | DPRINTF ((message ("e->requiresConstraints %s", constraintList_printDetailed (e->requiresConstraints)))); |
616915dd | 150 | return FALSE; |
616915dd | 151 | } |
152 | ||
abd7f895 | 153 | static void exprNode_stmt (/*@temp@*/ exprNode e) |
616915dd | 154 | { |
155 | exprNode snode; | |
156 | fileloc loc; | |
d46ce6a4 | 157 | cstring s; |
9280addf | 158 | |
abd7f895 | 159 | if (exprNode_isError(e)) |
616915dd | 160 | { |
b7b694d6 | 161 | return; |
616915dd | 162 | } |
b7b694d6 | 163 | |
bb25bea6 | 164 | /*e->requiresConstraints = constraintList_makeNew(); |
165 | e->ensuresConstraints = constraintList_makeNew(); */ | |
616915dd | 166 | |
abd7f895 | 167 | DPRINTF(("expNode_stmt: STMT:")); |
9280addf | 168 | s = exprNode_unparse(e); |
abd7f895 | 169 | DPRINTF ((message("exprNode_stmt: STMT: %s ", s))); |
9280addf | 170 | |
616915dd | 171 | if (e->kind == XPR_INIT) |
172 | { | |
bb25bea6 | 173 | constraintList tempList; |
abd7f895 | 174 | DPRINTF (("Init")); |
175 | DPRINTF ((message ("%s ", exprNode_unparse (e)))); | |
616915dd | 176 | loc = exprNode_getNextSequencePoint(e); /* reduces to an expression */ |
84c9ffbf | 177 | exprNode_exprTraverse (e, FALSE, FALSE, loc); |
bb25bea6 | 178 | fileloc_free(loc); |
179 | ||
180 | tempList = e->requiresConstraints; | |
616915dd | 181 | e->requiresConstraints = exprNode_traversRequiresConstraints(e); |
bb25bea6 | 182 | constraintList_free(tempList); |
183 | ||
184 | tempList = e->ensuresConstraints; | |
616915dd | 185 | e->ensuresConstraints = exprNode_traversEnsuresConstraints(e); |
bb25bea6 | 186 | constraintList_free(tempList); |
b7b694d6 | 187 | return; |
616915dd | 188 | } |
24633cea | 189 | |
190 | /*drl 2/13/002 patched bug so return statement will be checked*/ | |
191 | /*return is a stmt not not expression ...*/ | |
192 | if (e->kind == XPR_RETURN) | |
193 | { | |
194 | constraintList tempList; | |
195 | ||
196 | loc = exprNode_getNextSequencePoint(e); /* reduces to an expression */ | |
197 | ||
198 | exprNode_exprTraverse (exprData_getSingle (e->edata), FALSE, TRUE, loc); | |
199 | fileloc_free(loc); | |
200 | ||
201 | tempList = e->requiresConstraints; | |
202 | e->requiresConstraints = exprNode_traversRequiresConstraints(e); | |
203 | constraintList_free(tempList); | |
204 | } | |
616915dd | 205 | |
206 | if (e->kind != XPR_STMT) | |
207 | { | |
208 | ||
abd7f895 | 209 | DPRINTF (("Not Stmt")); |
210 | DPRINTF ((message ("%s ", exprNode_unparse (e)))); | |
b7e84605 | 211 | |
212 | if (exprNode_isMultiStatement (e)) | |
616915dd | 213 | { |
b7e84605 | 214 | exprNode_multiStatement (e); /* evans 2001-08-21: spurious return removed */ |
616915dd | 215 | } |
24633cea | 216 | else |
217 | { | |
218 | loc = exprNode_getNextSequencePoint(e); /* reduces to an expression */ | |
219 | ||
220 | exprNode_exprTraverse (e, FALSE, TRUE, loc); | |
221 | fileloc_free(loc); | |
222 | ||
223 | } | |
224 | return; | |
616915dd | 225 | } |
226 | ||
abd7f895 | 227 | DPRINTF (("Stmt")); |
228 | DPRINTF ((message ("%s ", exprNode_unparse (e)))); | |
616915dd | 229 | |
230 | snode = exprData_getUopNode (e->edata); | |
231 | ||
232 | /* could be stmt involving multiple statements: | |
233 | i.e. if, while for ect. | |
234 | */ | |
235 | ||
236 | if (exprNode_isMultiStatement (snode)) | |
237 | { | |
b7e84605 | 238 | exprNode_multiStatement (snode); |
84c9ffbf | 239 | (void) exprNode_copyConstraints (e, snode); |
240 | return; | |
616915dd | 241 | } |
242 | ||
243 | loc = exprNode_getNextSequencePoint(e); /* reduces to an expression */ | |
84c9ffbf | 244 | exprNode_exprTraverse (snode, FALSE, FALSE, loc); |
bb25bea6 | 245 | |
246 | fileloc_free(loc); | |
247 | ||
248 | constraintList_free (e->requiresConstraints); | |
616915dd | 249 | e->requiresConstraints = exprNode_traversRequiresConstraints(snode); |
bb25bea6 | 250 | |
251 | constraintList_free (e->ensuresConstraints); | |
616915dd | 252 | e->ensuresConstraints = exprNode_traversEnsuresConstraints(snode); |
bb25bea6 | 253 | |
bb7c2085 | 254 | DPRINTF ((message ("smtlist constraints are: pre: %s \n and \t post %s\n", |
bb25bea6 | 255 | constraintList_print(e->requiresConstraints), |
abd7f895 | 256 | constraintList_print(e->ensuresConstraints)))); |
bb25bea6 | 257 | |
b7b694d6 | 258 | return; |
616915dd | 259 | } |
260 | ||
28bf4b0b | 261 | static void exprNode_stmtList (/*@dependent@*/ exprNode e) |
616915dd | 262 | { |
263 | exprNode stmt1, stmt2; | |
abd7f895 | 264 | if (exprNode_isError (e)) |
616915dd | 265 | { |
b7b694d6 | 266 | return; |
616915dd | 267 | } |
268 | ||
bb25bea6 | 269 | /* |
b7b694d6 | 270 | Handle case of stmtList with only one statement: |
271 | The parse tree stores this as stmt instead of stmtList | |
bb25bea6 | 272 | */ |
b7b694d6 | 273 | |
616915dd | 274 | if (e->kind != XPR_STMTLIST) |
275 | { | |
84c9ffbf | 276 | exprNode_stmt(e); |
277 | return; | |
616915dd | 278 | } |
279 | llassert (e->kind == XPR_STMTLIST); | |
abd7f895 | 280 | DPRINTF(("exprNode_stmtList STMTLIST:")); |
281 | DPRINTF ((cstring_toCharsSafe (exprNode_unparse(e)))); | |
616915dd | 282 | stmt1 = exprData_getPairA (e->edata); |
283 | stmt2 = exprData_getPairB (e->edata); | |
284 | ||
285 | ||
abd7f895 | 286 | DPRINTF(("exprNode_stmtlist ")); |
287 | DPRINTF ((message("XW%s | %s", exprNode_unparse(stmt1), exprNode_unparse(stmt2)))); | |
616915dd | 288 | |
289 | exprNode_stmt (stmt1); | |
abd7f895 | 290 | DPRINTF(("\nstmt after stmtList call ")); |
616915dd | 291 | |
292 | exprNode_stmt (stmt2); | |
abd7f895 | 293 | exprNode_mergeResolve (e, stmt1, stmt2); |
616915dd | 294 | |
bb7c2085 | 295 | DPRINTF ((message ("smtlist constraints are: pre: %s \n and \t post %s\n", |
616915dd | 296 | constraintList_print(e->requiresConstraints), |
abd7f895 | 297 | constraintList_print(e->ensuresConstraints)))); |
b7b694d6 | 298 | return; |
a8e557d3 | 299 | } |
300 | ||
28bf4b0b | 301 | static exprNode doIf (/*@returned@*/ exprNode e, /*@dependent@*/ exprNode test, /*@dependent@*/ exprNode body) |
616915dd | 302 | { |
bb25bea6 | 303 | constraintList temp; |
304 | ||
abd7f895 | 305 | DPRINTF ((message ("doIf: %s ", exprNode_unparse(e)))); |
470b7798 | 306 | |
abd7f895 | 307 | llassert(exprNode_isDefined(test)); |
308 | llassert (exprNode_isDefined (e)); | |
309 | llassert (exprNode_isDefined (body)); | |
bb25bea6 | 310 | |
616915dd | 311 | |
abd7f895 | 312 | DPRINTF((message ("ensures constraints for %s are %s", exprNode_unparse(e), constraintList_printDetailed(e->ensuresConstraints)))); |
bb25bea6 | 313 | |
abd7f895 | 314 | DPRINTF((message ("Requires constraints for %s are %s", exprNode_unparse(e), constraintList_printDetailed(e->ensuresConstraints)))); |
bb25bea6 | 315 | |
abd7f895 | 316 | DPRINTF((message ("trueEnsures constraints for %s are %s", exprNode_unparse(e), constraintList_printDetailed(e->trueEnsuresConstraints)))); |
bb25bea6 | 317 | |
abd7f895 | 318 | DPRINTF((message ("falseEnsures constraints for %s are %s", exprNode_unparse(e), constraintList_printDetailed(e->falseEnsuresConstraints)))); |
bb25bea6 | 319 | |
320 | ||
321 | ||
abd7f895 | 322 | DPRINTF((message ("ensures constraints for %s are %s", exprNode_unparse(test), constraintList_printDetailed(test->ensuresConstraints)))); |
bb25bea6 | 323 | |
abd7f895 | 324 | DPRINTF((message ("Requires constraints for %s are %s", exprNode_unparse(test), constraintList_printDetailed(test->ensuresConstraints)))); |
bb25bea6 | 325 | |
abd7f895 | 326 | DPRINTF((message ("trueEnsures constraints for %s are %s", exprNode_unparse(test), constraintList_printDetailed(test->trueEnsuresConstraints)))); |
bb25bea6 | 327 | |
abd7f895 | 328 | DPRINTF((message ("falseEnsures constraints for %s are %s", exprNode_unparse(test), constraintList_printDetailed(test->falseEnsuresConstraints)))); |
bb25bea6 | 329 | |
330 | ||
331 | ||
332 | temp = test->trueEnsuresConstraints; | |
333 | test->trueEnsuresConstraints = exprNode_traversTrueEnsuresConstraints(test); | |
334 | constraintList_free(temp); | |
335 | ||
336 | temp = test->ensuresConstraints; | |
616915dd | 337 | test->ensuresConstraints = exprNode_traversEnsuresConstraints (test); |
bb25bea6 | 338 | constraintList_free(temp); |
339 | ||
340 | temp = test->requiresConstraints; | |
470b7798 | 341 | test->requiresConstraints = exprNode_traversRequiresConstraints (test); |
bb25bea6 | 342 | constraintList_free(temp); |
616915dd | 343 | |
bb25bea6 | 344 | |
345 | test->trueEnsuresConstraints = constraintList_substituteFreeTarget(test->trueEnsuresConstraints, test->ensuresConstraints); | |
c3e695ff | 346 | |
abd7f895 | 347 | DPRINTF ((message ("doIf: test ensures %s ", constraintList_print(test->ensuresConstraints)))); |
c3e695ff | 348 | |
abd7f895 | 349 | DPRINTF ((message ("doIf: test true ensures %s ", constraintList_print(test->trueEnsuresConstraints)))); |
bb25bea6 | 350 | |
351 | constraintList_free(e->requiresConstraints); | |
dc7f6a51 | 352 | |
353 | ||
28bf4b0b | 354 | e->requiresConstraints = constraintList_reflectChanges(body->requiresConstraints, test->trueEnsuresConstraints); |
bb25bea6 | 355 | |
28bf4b0b | 356 | e->requiresConstraints = constraintList_reflectChangesFreePre (e->requiresConstraints, |
616915dd | 357 | test->ensuresConstraints); |
bb25bea6 | 358 | temp = e->requiresConstraints; |
470b7798 | 359 | e->requiresConstraints = constraintList_mergeRequires (e->requiresConstraints, test->requiresConstraints); |
bb25bea6 | 360 | constraintList_free(temp); |
361 | ||
362 | ||
b7b694d6 | 363 | /* drl possible problem : warning bad */ |
bb25bea6 | 364 | constraintList_free(e->ensuresConstraints); |
616915dd | 365 | e->ensuresConstraints = constraintList_copy (test->ensuresConstraints); |
90bc41f7 | 366 | |
abd7f895 | 367 | if (exprNode_mayEscape (body)) |
90bc41f7 | 368 | { |
abd7f895 | 369 | DPRINTF ((message("doIf: the if statement body %s returns or exits", exprNode_unparse(body)))); |
bb25bea6 | 370 | e->ensuresConstraints = constraintList_mergeEnsuresFreeFirst (e->ensuresConstraints, |
470b7798 | 371 | test->falseEnsuresConstraints); |
90bc41f7 | 372 | } |
373 | ||
abd7f895 | 374 | DPRINTF ((message ("doIf: if requiers %s ", constraintList_print(e->requiresConstraints)))); |
9280addf | 375 | |
616915dd | 376 | return e; |
377 | } | |
378 | ||
470b7798 | 379 | /*drl added 3/4/2001 |
380 | Also used for condition i.e. ?: operation | |
381 | ||
382 | Precondition | |
383 | This function assumes that p, trueBranch, falseBranch have have all been traversed | |
384 | for constraints i.e. we assume that exprNode_traversEnsuresConstraints, | |
385 | exprNode_traversRequiresConstraints, exprNode_traversTrueEnsuresConstraints, | |
386 | exprNode_traversFalseEnsuresConstraints have all been run | |
387 | */ | |
388 | ||
28bf4b0b | 389 | static exprNode doIfElse (/*@returned@*/ exprNode e, /*@dependent@*/ exprNode p, /*@dependent@*/ exprNode trueBranch, /*@dependent@*/ exprNode falseBranch) |
470b7798 | 390 | { |
b7b694d6 | 391 | constraintList c1, cons, t, t2, f, f2; |
470b7798 | 392 | |
abd7f895 | 393 | llassert (exprNode_isDefined (e)); |
394 | llassert (exprNode_isDefined (p)); | |
395 | llassert (exprNode_isDefined (trueBranch)); | |
396 | llassert (exprNode_isDefined (falseBranch)); | |
397 | DPRINTF ((message ("doIfElse: %s ", exprNode_unparse(e)))); | |
b7b694d6 | 398 | |
399 | /* do requires clauses */ | |
400 | c1 = constraintList_copy (p->ensuresConstraints); | |
401 | ||
402 | t = constraintList_reflectChanges(trueBranch->requiresConstraints, p->trueEnsuresConstraints); | |
403 | t = constraintList_reflectChangesFreePre (t, p->ensuresConstraints); | |
404 | ||
405 | cons = constraintList_reflectChanges(falseBranch->requiresConstraints, p->falseEnsuresConstraints); | |
406 | cons = constraintList_reflectChangesFreePre (cons, c1); | |
407 | ||
abd7f895 | 408 | constraintList_free (e->requiresConstraints); |
b7b694d6 | 409 | e->requiresConstraints = constraintList_mergeRequiresFreeFirst (t, cons); |
410 | e->requiresConstraints = constraintList_mergeRequiresFreeFirst (e->requiresConstraints, p->requiresConstraints); | |
411 | ||
412 | /* do ensures clauses | |
413 | find the the ensures lists for each subbranch | |
414 | */ | |
bb25bea6 | 415 | |
b7b694d6 | 416 | t = constraintList_mergeEnsures (p->trueEnsuresConstraints, trueBranch->ensuresConstraints); |
417 | t2 = t; | |
418 | t = constraintList_mergeEnsures (p->ensuresConstraints, t); | |
419 | constraintList_free(t2); | |
420 | ||
421 | f = constraintList_mergeEnsures (p->falseEnsuresConstraints, falseBranch->ensuresConstraints); | |
422 | f2 = f; | |
423 | f = constraintList_mergeEnsures (p->ensuresConstraints, f); | |
424 | constraintList_free(f2); | |
425 | ||
426 | /* find ensures for whole if/else statement */ | |
427 | ||
428 | constraintList_free(e->ensuresConstraints); | |
429 | ||
430 | e->ensuresConstraints = constraintList_logicalOr (t, f); | |
431 | ||
432 | constraintList_free(t); | |
433 | constraintList_free(f); | |
434 | constraintList_free(cons); | |
435 | constraintList_free(c1); | |
436 | ||
abd7f895 | 437 | DPRINTF ((message ("doIfElse: if requires %q ", constraintList_print(e->requiresConstraints)))); |
438 | DPRINTF ((message ("doIfElse: if ensures %q ", constraintList_print(e->ensuresConstraints)))); | |
b7b694d6 | 439 | |
440 | return e; | |
470b7798 | 441 | } |
9280addf | 442 | |
28bf4b0b | 443 | static exprNode doWhile (/*@returned@*/ exprNode e, /*@dependent@*/ exprNode test, /*@dependent@*/ exprNode body) |
9280addf | 444 | { |
abd7f895 | 445 | DPRINTF ((message ("doWhile: %s ", exprNode_unparse(e)))); |
9280addf | 446 | return doIf (e, test, body); |
447 | } | |
448 | ||
920a3797 | 449 | /*@only@*/ constraintList constraintList_makeFixedArrayConstraints (/*@observer@*/ sRefSet s) |
616915dd | 450 | { |
451 | constraintList ret; | |
470b7798 | 452 | constraint con; |
c3e695ff | 453 | ret = constraintList_makeNew(); |
616915dd | 454 | |
455 | sRefSet_elements (s, el) | |
456 | { | |
abd7f895 | 457 | if (sRef_isFixedArray(el)) |
b7b694d6 | 458 | { |
37ae0b5e | 459 | size_t size; |
bb7c2085 | 460 | DPRINTF((message("%s is a fixed array", |
abd7f895 | 461 | sRef_unparse(el)))); |
b7b694d6 | 462 | size = sRef_getArraySize(el); |
bb7c2085 | 463 | DPRINTF((message("%s is a fixed array with size %d", |
abd7f895 | 464 | sRef_unparse(el), (int)size))); |
e5081f8c | 465 | con = constraint_makeSRefSetBufferSize (el, size_toLong (size - 1)); |
b7b694d6 | 466 | ret = constraintList_add(ret, con); |
467 | } | |
468 | else | |
469 | { | |
bb7c2085 | 470 | DPRINTF((message("%s is not a fixed array", |
abd7f895 | 471 | sRef_unparse(el)))); |
b7b694d6 | 472 | |
473 | ||
abd7f895 | 474 | if (sRef_isExternallyVisible (el)) |
b7b694d6 | 475 | { |
476 | /* | |
bb7c2085 | 477 | DPRINTF((message("%s is externally visible", |
abd7f895 | 478 | sRef_unparse(el)))); |
b7b694d6 | 479 | con = constraint_makeSRefWriteSafeInt(el, 0); |
480 | ret = constraintList_add(ret, con); | |
481 | ||
482 | con = constraint_makeSRefReadSafeInt(el, 0); | |
483 | ||
484 | ret = constraintList_add(ret, con); | |
485 | */ | |
486 | } | |
487 | } | |
616915dd | 488 | } |
b7b694d6 | 489 | end_sRefSet_elements ; |
490 | ||
abd7f895 | 491 | DPRINTF((message("constraintList_makeFixedArrayConstraints returning %s", |
492 | constraintList_print(ret)))); | |
b7b694d6 | 493 | return ret; |
616915dd | 494 | } |
495 | ||
b7b694d6 | 496 | # if 0 |
4ab867d6 | 497 | exprNode makeDataTypeConstraints (/*@returned@*/ exprNode e) |
616915dd | 498 | { |
499 | constraintList c; | |
500 | DPRINTF(("makeDataTypeConstraints")); | |
501 | ||
502 | c = constraintList_makeFixedArrayConstraints (e->uses); | |
503 | ||
4ab867d6 | 504 | e->ensuresConstraints = constraintList_addListFree (e->ensuresConstraints, c); |
616915dd | 505 | |
506 | return e; | |
507 | } | |
b7b694d6 | 508 | # endif |
616915dd | 509 | |
28bf4b0b | 510 | static void doFor (/*@dependent@*/ exprNode e, /*@dependent@*/ exprNode forPred, /*@dependent@*/ exprNode forBody) |
616915dd | 511 | { |
512 | exprNode init, test, inc; | |
b7b694d6 | 513 | /* merge the constraints: modle as if statement */ |
514 | ||
abd7f895 | 515 | /* init |
516 | if (test) | |
517 | for body | |
518 | inc */ | |
b7b694d6 | 519 | |
abd7f895 | 520 | llassert (exprNode_isDefined (e)); |
521 | llassert (exprNode_isDefined (forPred)); | |
522 | llassert (exprNode_isDefined (forBody)); | |
523 | ||
524 | init = exprData_getTripleInit (forPred->edata); | |
525 | test = exprData_getTripleTest (forPred->edata); | |
526 | inc = exprData_getTripleInc (forPred->edata); | |
527 | ||
528 | if (((exprNode_isError (test) /*|| (exprNode_isError(init))*/) || (exprNode_isError (inc)))) | |
b7b694d6 | 529 | { |
abd7f895 | 530 | DPRINTF ((message ("strange for statement:%s, ignoring it", exprNode_unparse(e)))); |
b7b694d6 | 531 | return; |
532 | } | |
533 | ||
534 | exprNode_forLoopHeuristics(e, forPred, forBody); | |
535 | ||
536 | constraintList_free(e->requiresConstraints); | |
537 | e->requiresConstraints = constraintList_reflectChanges(forBody->requiresConstraints, test->ensuresConstraints); | |
538 | e->requiresConstraints = constraintList_reflectChangesFreePre (e->requiresConstraints, test->trueEnsuresConstraints); | |
539 | e->requiresConstraints = constraintList_reflectChangesFreePre (e->requiresConstraints, forPred->ensuresConstraints); | |
540 | ||
541 | if (!forBody->canBreak) | |
542 | { | |
abd7f895 | 543 | e->ensuresConstraints = constraintList_addListFree(e->ensuresConstraints, constraintList_copy(forPred->ensuresConstraints)); |
544 | e->ensuresConstraints = constraintList_addListFree(e->ensuresConstraints,constraintList_copy(test->falseEnsuresConstraints)); | |
b7b694d6 | 545 | } |
546 | else | |
547 | { | |
abd7f895 | 548 | DPRINTF(("Can break")); |
b7b694d6 | 549 | } |
616915dd | 550 | } |
551 | ||
03d670b6 | 552 | static /*@dependent@*/ exprNode exprNode_makeDependent(/*@returned@*/ exprNode e) |
553 | { | |
393e573f | 554 | /* !!! DRL - this is ridiculous! Read the manual on memory annotations please! */ |
03d670b6 | 555 | return e; |
03d670b6 | 556 | } |
557 | ||
3e3ec469 | 558 | static void |
559 | exprNode_doGenerateConstraintSwitch | |
560 | (/*@dependent@*/ exprNode switchExpr, | |
561 | /*@dependent@*/ exprNode body, | |
562 | /*@special@*/ constraintList *currentRequires, | |
563 | /*@special@*/ constraintList *currentEnsures, | |
564 | /*@special@*/ constraintList *savedRequires, | |
565 | /*@special@*/ constraintList *savedEnsures) | |
566 | /*@post:only *currentRequires, *currentEnsures, *savedRequires, *savedEnsures @*/ | |
567 | /*@sets *currentRequires, *currentEnsures, *savedRequires, *savedEnsures @*/ | |
7c9c4a67 | 568 | { |
569 | exprNode stmt, stmtList; | |
570 | ||
abd7f895 | 571 | DPRINTF((message("exprNode_doGenerateConstraintSwitch: (switch %s) %s", |
7c9c4a67 | 572 | exprNode_unparse(switchExpr), exprNode_unparse(body) |
abd7f895 | 573 | ))); |
7c9c4a67 | 574 | |
abd7f895 | 575 | if (exprNode_isError(body)) |
7c9c4a67 | 576 | { |
3e3ec469 | 577 | *currentRequires = constraintList_makeNew (); |
578 | *currentEnsures = constraintList_makeNew (); | |
03d670b6 | 579 | |
3e3ec469 | 580 | *savedRequires = constraintList_makeNew (); |
581 | *savedEnsures = constraintList_makeNew (); | |
03d670b6 | 582 | /*@-onlytrans@*/ |
7c9c4a67 | 583 | return; |
03d670b6 | 584 | /*@=onlytrans@*/ |
7c9c4a67 | 585 | } |
586 | ||
abd7f895 | 587 | if (body->kind != XPR_STMTLIST) |
7c9c4a67 | 588 | { |
dc7f6a51 | 589 | DPRINTF((message("exprNode_doGenerateConstraintSwitch: non stmtlist: %s", |
abd7f895 | 590 | exprNode_unparse(body)))); |
7c9c4a67 | 591 | stmt = body; |
592 | stmtList = exprNode_undefined; | |
03d670b6 | 593 | stmt = exprNode_makeDependent(stmt); |
594 | stmtList = exprNode_makeDependent(stmtList); | |
595 | } | |
596 | else | |
597 | { | |
598 | stmt = exprData_getPairB(body->edata); | |
599 | stmtList = exprData_getPairA(body->edata); | |
600 | stmt = exprNode_makeDependent(stmt); | |
601 | stmtList = exprNode_makeDependent(stmtList); | |
7c9c4a67 | 602 | } |
7c9c4a67 | 603 | |
dc7f6a51 | 604 | DPRINTF((message("exprNode_doGenerateConstraintSwitch: stmtlist: %s stmt: %s", |
abd7f895 | 605 | exprNode_unparse(stmtList), exprNode_unparse(stmt)) |
606 | )); | |
7c9c4a67 | 607 | |
608 | ||
609 | exprNode_doGenerateConstraintSwitch (switchExpr, stmtList, currentRequires, currentEnsures, | |
abd7f895 | 610 | savedRequires, savedEnsures); |
7c9c4a67 | 611 | |
abd7f895 | 612 | if (exprNode_isError(stmt)) |
03d670b6 | 613 | /*@-onlytrans@*/ |
7c9c4a67 | 614 | return; |
03d670b6 | 615 | /*@=onlytrans@*/ |
7c9c4a67 | 616 | |
617 | exprNode_stmt(stmt); | |
03d670b6 | 618 | |
619 | switchExpr = exprNode_makeDependent (switchExpr); | |
620 | ||
abd7f895 | 621 | if (! exprNode_isCaseMarker(stmt)) |
7c9c4a67 | 622 | { |
623 | ||
624 | constraintList temp; | |
625 | ||
abd7f895 | 626 | DPRINTF ((message("Got normal statement %s (requires %s ensures %s)", exprNode_unparse(stmt), |
627 | constraintList_unparse(stmt->requiresConstraints), constraintList_unparse(stmt->ensuresConstraints)))); | |
7c9c4a67 | 628 | |
629 | temp = constraintList_reflectChanges (stmt->requiresConstraints, | |
630 | *currentEnsures); | |
631 | ||
03d670b6 | 632 | *currentRequires = constraintList_mergeRequiresFreeFirst( |
633 | *currentRequires, | |
634 | temp); | |
7c9c4a67 | 635 | |
636 | constraintList_free(temp); | |
637 | ||
638 | *currentEnsures = constraintList_mergeEnsuresFreeFirst | |
639 | (*currentEnsures, | |
640 | stmt->ensuresConstraints); | |
abd7f895 | 641 | DPRINTF((message("returning from exprNode_doGenerateConstraintSwitch: (switch %s) %s currentRequires:" |
7c9c4a67 | 642 | "%s currentEnsures:%s", |
643 | exprNode_unparse(switchExpr), exprNode_unparse(body), | |
644 | constraintList_print(*currentRequires), constraintList_print(*currentEnsures) | |
abd7f895 | 645 | ))); |
03d670b6 | 646 | /*@-onlytrans@*/ |
7c9c4a67 | 647 | return; |
03d670b6 | 648 | /*@=onlytrans@*/ |
649 | ||
7c9c4a67 | 650 | } |
651 | ||
abd7f895 | 652 | if (exprNode_isCaseMarker(stmt) && exprNode_mustEscape(stmtList)) |
7c9c4a67 | 653 | { |
b7b694d6 | 654 | /* |
655 | ** merge current and saved constraint with Logical Or... | |
656 | ** make a constraint for ensures | |
657 | */ | |
7c9c4a67 | 658 | |
659 | constraintList temp; | |
660 | constraint con; | |
661 | ||
abd7f895 | 662 | DPRINTF ((message("Got case marker"))); |
7c9c4a67 | 663 | |
664 | if (constraintList_isUndefined(*savedEnsures) && | |
abd7f895 | 665 | constraintList_isUndefined(*savedRequires)) |
7c9c4a67 | 666 | { |
abd7f895 | 667 | llassert(constraintList_isUndefined(*savedEnsures)); |
668 | llassert(constraintList_isUndefined(*savedRequires)); | |
7c9c4a67 | 669 | *savedEnsures = constraintList_copy(*currentEnsures); |
670 | *savedRequires = constraintList_copy(*currentRequires); | |
671 | } | |
03d670b6 | 672 | else |
673 | { | |
abd7f895 | 674 | DPRINTF ((message("Doing logical or"))); |
03d670b6 | 675 | temp = constraintList_logicalOr (*savedEnsures, *currentEnsures); |
676 | constraintList_free (*savedEnsures); | |
677 | *savedEnsures = temp; | |
678 | ||
679 | *savedRequires = constraintList_mergeRequiresFreeFirst (*savedRequires, *currentRequires); | |
680 | } | |
681 | ||
7c9c4a67 | 682 | con = constraint_makeEnsureEqual (switchExpr, exprData_getSingle |
abd7f895 | 683 | (stmt->edata), exprNode_getfileloc(stmt)); |
7c9c4a67 | 684 | |
685 | ||
686 | constraintList_free(*currentEnsures); | |
687 | *currentEnsures = constraintList_makeNew(); | |
688 | *currentEnsures = constraintList_add(*currentEnsures, con); | |
689 | ||
690 | constraintList_free(*currentRequires); | |
691 | *currentRequires = constraintList_makeNew(); | |
abd7f895 | 692 | DPRINTF((message("exprNode_doGenerateConstraintSwitch: (switch %s) %s savedRequires:" |
7c9c4a67 | 693 | "%s savedEnsures:%s", |
694 | exprNode_unparse(switchExpr), exprNode_unparse(body), | |
695 | constraintList_print(*savedRequires), constraintList_print(*savedEnsures) | |
abd7f895 | 696 | ))); |
7c9c4a67 | 697 | |
698 | } | |
699 | ||
abd7f895 | 700 | else if (exprNode_isCaseMarker(stmt)) |
b7b694d6 | 701 | /* prior case has no break. */ |
7c9c4a67 | 702 | { |
b7b694d6 | 703 | /* |
704 | We don't do anything to the sved constraints because the case hasn't ended | |
705 | The new ensures constraints for the case will be: | |
706 | the constraint for the case statement (CASE_LABEL == SWITCH_EXPR) logicalOr currentEnsures | |
707 | */ | |
708 | ||
7c9c4a67 | 709 | constraintList temp; |
710 | constraint con; | |
711 | ||
712 | constraintList ensuresTemp; | |
713 | ||
abd7f895 | 714 | DPRINTF ((message("Got case marker with no prior break"))); |
7c9c4a67 | 715 | |
716 | con = constraint_makeEnsureEqual (switchExpr, exprData_getSingle | |
abd7f895 | 717 | (stmt->edata), exprNode_getfileloc(stmt)); |
7c9c4a67 | 718 | |
719 | ensuresTemp = constraintList_makeNew(); | |
720 | ||
721 | ensuresTemp = constraintList_add (ensuresTemp, con); | |
722 | ||
abd7f895 | 723 | if (exprNode_isError(stmtList)) |
7c9c4a67 | 724 | { |
725 | constraintList_free(*currentEnsures); | |
7c9c4a67 | 726 | |
03d670b6 | 727 | *currentEnsures = constraintList_copy(ensuresTemp); |
728 | constraintList_free(ensuresTemp); | |
7c9c4a67 | 729 | |
03d670b6 | 730 | } |
731 | else | |
732 | { | |
733 | ||
734 | temp = constraintList_logicalOr (*currentEnsures, ensuresTemp); | |
735 | ||
736 | constraintList_free(*currentEnsures); | |
737 | constraintList_free(ensuresTemp); | |
7c9c4a67 | 738 | |
03d670b6 | 739 | *currentEnsures = temp; |
740 | } | |
7c9c4a67 | 741 | constraintList_free(*currentRequires); |
03d670b6 | 742 | |
7c9c4a67 | 743 | *currentRequires = constraintList_makeNew(); |
744 | } | |
03d670b6 | 745 | else |
746 | { | |
b7b694d6 | 747 | /* |
748 | we handle the case of ! exprNode_isCaseMarker above | |
749 | the else if clause should always be true. | |
750 | */ | |
03d670b6 | 751 | BADEXIT; |
752 | } | |
7c9c4a67 | 753 | |
abd7f895 | 754 | DPRINTF((message("returning from exprNode_doGenerateConstraintSwitch: (switch %s) %s currentRequires:" |
7c9c4a67 | 755 | "%s currentEnsures:%s", |
756 | exprNode_unparse(switchExpr), exprNode_unparse(body), | |
757 | constraintList_print(*currentRequires), constraintList_print(*currentEnsures) | |
abd7f895 | 758 | ))); |
03d670b6 | 759 | /*@-onlytrans@*/ |
7c9c4a67 | 760 | return; |
03d670b6 | 761 | /*@=onlytrans@*/ |
7c9c4a67 | 762 | } |
763 | ||
764 | ||
abd7f895 | 765 | static void exprNode_generateConstraintSwitch (/*@notnull@*/ exprNode switchStmt) |
7c9c4a67 | 766 | { |
767 | constraintList constraintsRequires; | |
768 | constraintList constraintsEnsures; | |
769 | constraintList lastRequires; | |
770 | constraintList lastEnsures; | |
771 | ||
772 | exprNode body; | |
773 | exprNode switchExpr; | |
774 | ||
abd7f895 | 775 | switchExpr = exprData_getPairA (switchStmt->edata); |
776 | body = exprData_getPairB (switchStmt->edata); | |
777 | ||
778 | if (!exprNode_isDefined (body)) | |
779 | { | |
780 | return; | |
781 | } | |
7c9c4a67 | 782 | |
7272a1c1 | 783 | /*@i22*/ |
abd7f895 | 784 | DPRINTF((message(""))); |
a779b61e | 785 | |
abd7f895 | 786 | if (body->kind == XPR_BLOCK) |
7c9c4a67 | 787 | body = exprData_getSingle(body->edata); |
788 | ||
03d670b6 | 789 | /* |
7c9c4a67 | 790 | constraintsRequires = constraintList_undefined; |
791 | constraintsEnsures = constraintList_undefined; | |
792 | ||
793 | lastRequires = constraintList_makeNew(); | |
794 | lastEnsures = constraintList_makeNew(); | |
03d670b6 | 795 | */ |
7c9c4a67 | 796 | |
3e3ec469 | 797 | /*@-mustfree@*/ |
798 | /*@i6534 - evans 2002-01-01: spurious warnings for these becuase of stack allocated storage */ | |
799 | exprNode_doGenerateConstraintSwitch (switchExpr, body, &lastRequires, | |
800 | &lastEnsures, &constraintsRequires, &constraintsEnsures); | |
801 | /*@=mustfree@*/ | |
7c9c4a67 | 802 | |
b7b694d6 | 803 | /* |
804 | merge current and saved constraint with Logical Or... | |
805 | make a constraint for ensures | |
806 | */ | |
7c9c4a67 | 807 | |
808 | constraintList_free(switchStmt->requiresConstraints); | |
809 | constraintList_free(switchStmt->ensuresConstraints); | |
810 | ||
abd7f895 | 811 | if (constraintList_isDefined(constraintsEnsures) && constraintList_isDefined(constraintsRequires)) |
7c9c4a67 | 812 | { |
813 | switchStmt->ensuresConstraints = constraintList_logicalOr(constraintsEnsures, lastEnsures); | |
814 | switchStmt->requiresConstraints = constraintList_mergeRequires(constraintsRequires, lastRequires); | |
815 | constraintList_free (constraintsRequires); | |
816 | constraintList_free (constraintsEnsures); | |
817 | } | |
03d670b6 | 818 | else |
819 | { | |
820 | switchStmt->ensuresConstraints = constraintList_copy(lastEnsures); | |
821 | switchStmt->requiresConstraints = constraintList_copy(lastRequires); | |
822 | } | |
7c9c4a67 | 823 | |
824 | constraintList_free (lastRequires); | |
825 | constraintList_free (lastEnsures); | |
826 | ||
bb7c2085 | 827 | DPRINTF(((message(" exprNode_generateConstraintSwitch returning requires: %s and ensures %s", |
abd7f895 | 828 | constraintList_print(switchStmt->requiresConstraints), |
829 | constraintList_print(switchStmt->ensuresConstraints) | |
830 | ) | |
831 | ))); | |
7c9c4a67 | 832 | } |
833 | ||
abd7f895 | 834 | static exprNode doSwitch (/*@returned@*/ /*@notnull@*/ exprNode e) |
470b7798 | 835 | { |
836 | exprNode body; | |
837 | exprData data; | |
838 | ||
839 | data = e->edata; | |
abd7f895 | 840 | DPRINTF ((message ("doSwitch for: switch (%s) %s", |
2681ee39 | 841 | exprNode_unparse (exprData_getPairA (data)), |
abd7f895 | 842 | exprNode_unparse (exprData_getPairB (data))))); |
7c9c4a67 | 843 | |
470b7798 | 844 | body = exprData_getPairB (data); |
7c9c4a67 | 845 | exprNode_generateConstraintSwitch (e); |
470b7798 | 846 | return e; |
847 | } | |
9280addf | 848 | |
28bf4b0b | 849 | void exprNode_multiStatement (/*@dependent@*/ exprNode e) |
616915dd | 850 | { |
851 | ||
852 | bool ret; | |
853 | exprData data; | |
854 | exprNode e1, e2; | |
855 | exprNode p, trueBranch, falseBranch; | |
856 | exprNode forPred, forBody; | |
470b7798 | 857 | exprNode test; |
bb25bea6 | 858 | |
859 | constraintList temp; | |
860 | ||
abd7f895 | 861 | DPRINTF((message ("exprNode_multistatement Analysising %s %s at", exprNode_unparse(e), |
862 | fileloc_unparse(exprNode_getfileloc(e))))); | |
616915dd | 863 | |
864 | if (exprNode_handleError (e)) | |
865 | { | |
b7b694d6 | 866 | return; |
616915dd | 867 | } |
868 | ||
869 | data = e->edata; | |
870 | ||
871 | ret = TRUE; | |
872 | ||
873 | switch (e->kind) | |
874 | { | |
875 | ||
876 | case XPR_FOR: | |
616915dd | 877 | forPred = exprData_getPairA (data); |
878 | forBody = exprData_getPairB (data); | |
879 | ||
b7b694d6 | 880 | /* First generate the constraints */ |
616915dd | 881 | exprNode_generateConstraints (forPred); |
882 | exprNode_generateConstraints (forBody); | |
883 | ||
884 | ||
885 | doFor (e, forPred, forBody); | |
886 | ||
887 | break; | |
888 | ||
889 | case XPR_FORPRED: | |
abd7f895 | 890 | exprNode_generateConstraints (exprData_getTripleInit (data)); |
616915dd | 891 | test = exprData_getTripleTest (data); |
892 | exprNode_exprTraverse (test,FALSE, FALSE, exprNode_loc(e)); | |
abd7f895 | 893 | exprNode_generateConstraints (exprData_getTripleInc (data)); |
9280addf | 894 | |
abd7f895 | 895 | if (!exprNode_isError(test)) |
bb25bea6 | 896 | { |
897 | constraintList temp2; | |
898 | temp2 = test->trueEnsuresConstraints; | |
899 | test->trueEnsuresConstraints = exprNode_traversTrueEnsuresConstraints(test); | |
900 | constraintList_free(temp2); | |
901 | } | |
902 | ||
616915dd | 903 | exprNode_generateConstraints (exprData_getTripleInc (data)); |
904 | break; | |
9280addf | 905 | |
906 | case XPR_WHILE: | |
907 | e1 = exprData_getPairA (data); | |
908 | e2 = exprData_getPairB (data); | |
909 | ||
910 | exprNode_exprTraverse (e1, | |
911 | FALSE, FALSE, exprNode_loc(e1)); | |
912 | ||
913 | exprNode_generateConstraints (e2); | |
914 | ||
915 | e = doWhile (e, e1, e2); | |
916 | ||
917 | break; | |
918 | ||
616915dd | 919 | case XPR_IF: |
abd7f895 | 920 | DPRINTF(("IF:")); |
921 | DPRINTF ((exprNode_unparse(e))); | |
616915dd | 922 | e1 = exprData_getPairA (data); |
923 | e2 = exprData_getPairB (data); | |
924 | ||
b7b694d6 | 925 | exprNode_exprTraverse (e1, FALSE, FALSE, exprNode_loc(e1)); |
616915dd | 926 | |
927 | exprNode_generateConstraints (e2); | |
616915dd | 928 | e = doIf (e, e1, e2); |
616915dd | 929 | break; |
9280addf | 930 | |
616915dd | 931 | case XPR_IFELSE: |
932 | DPRINTF(("Starting IFELSE")); | |
616915dd | 933 | p = exprData_getTriplePred (data); |
abd7f895 | 934 | |
616915dd | 935 | trueBranch = exprData_getTripleTrue (data); |
936 | falseBranch = exprData_getTripleFalse (data); | |
937 | ||
938 | exprNode_exprTraverse (p, | |
939 | FALSE, FALSE, exprNode_loc(p)); | |
940 | exprNode_generateConstraints (trueBranch); | |
941 | exprNode_generateConstraints (falseBranch); | |
942 | ||
abd7f895 | 943 | llassert (exprNode_isDefined (p)); |
bb25bea6 | 944 | temp = p->ensuresConstraints; |
9280addf | 945 | p->ensuresConstraints = exprNode_traversEnsuresConstraints (p); |
bb25bea6 | 946 | constraintList_free(temp); |
947 | ||
948 | temp = p->requiresConstraints; | |
470b7798 | 949 | p->requiresConstraints = exprNode_traversRequiresConstraints (p); |
bb25bea6 | 950 | constraintList_free(temp); |
951 | ||
952 | temp = p->trueEnsuresConstraints; | |
9280addf | 953 | p->trueEnsuresConstraints = exprNode_traversTrueEnsuresConstraints(p); |
bb25bea6 | 954 | constraintList_free(temp); |
955 | ||
cf38ca4d | 956 | |
957 | ||
958 | DPRINTF((message("p->trueEnsuresConstraints before substitue %s", constraintList_print(p->trueEnsuresConstraints) ) | |
959 | )); | |
960 | ||
961 | /*drl 10/10/2002 this is a bit of a hack but the reason why we do this is so that any function post conditions or similar things get applied correctly to each branch. e.g. in strlen(s) < 5 we want the trueEnsures to be maxRead(s) < 5*/ | |
962 | ||
963 | p->trueEnsuresConstraints = constraintList_substituteFreeTarget (p->trueEnsuresConstraints, | |
964 | p->ensuresConstraints); | |
965 | ||
966 | DPRINTF(( message ("p->trueEnsuresConstraints after substitue %s", constraintList_print(p->trueEnsuresConstraints) ) | |
967 | )); | |
968 | ||
bb25bea6 | 969 | temp = p->falseEnsuresConstraints; |
470b7798 | 970 | p->falseEnsuresConstraints = exprNode_traversFalseEnsuresConstraints(p); |
bb25bea6 | 971 | constraintList_free(temp); |
616915dd | 972 | |
cf38ca4d | 973 | /*See comment on trueEnsures*/ |
974 | p->falseEnsuresConstraints = constraintList_substituteFreeTarget (p->falseEnsuresConstraints, | |
975 | p->ensuresConstraints); | |
976 | ||
abd7f895 | 977 | e = doIfElse (e, p, trueBranch, falseBranch); |
978 | DPRINTF(("Done IFELSE")); | |
616915dd | 979 | break; |
cf38ca4d | 980 | |
616915dd | 981 | case XPR_DOWHILE: |
470b7798 | 982 | |
983 | e2 = (exprData_getPairB (data)); | |
984 | e1 = (exprData_getPairA (data)); | |
985 | ||
abd7f895 | 986 | DPRINTF((message ("do { %s } while (%s)", exprNode_unparse(e2), exprNode_unparse(e1)))); |
470b7798 | 987 | exprNode_generateConstraints (e2); |
988 | exprNode_generateConstraints (e1); | |
989 | e = exprNode_copyConstraints (e, e2); | |
abd7f895 | 990 | DPRINTF ((message ("e = %s ", constraintList_print(e->requiresConstraints)))); |
470b7798 | 991 | |
616915dd | 992 | break; |
993 | ||
994 | case XPR_BLOCK: | |
965143f0 | 995 | { |
996 | exprNode tempExpr; | |
997 | ||
998 | tempExpr = exprData_getSingle (data); | |
999 | ||
1000 | exprNode_generateConstraints (tempExpr); | |
1001 | ||
1002 | if (exprNode_isDefined(tempExpr) ) | |
1003 | { | |
1004 | constraintList_free(e->requiresConstraints); | |
1005 | e->requiresConstraints = constraintList_copy (tempExpr->requiresConstraints); | |
1006 | constraintList_free(e->ensuresConstraints); | |
1007 | e->ensuresConstraints = constraintList_copy (tempExpr->ensuresConstraints); | |
1008 | } | |
1009 | else | |
1010 | { | |
1011 | llassert(FALSE); | |
1012 | } | |
1013 | } | |
616915dd | 1014 | break; |
1015 | ||
470b7798 | 1016 | case XPR_SWITCH: |
1017 | e = doSwitch (e); | |
1018 | break; | |
616915dd | 1019 | case XPR_STMT: |
1020 | case XPR_STMTLIST: | |
84c9ffbf | 1021 | exprNode_stmtList (e); |
1022 | return ; | |
616915dd | 1023 | /*@notreached@*/ |
1024 | break; | |
1025 | default: | |
1026 | ret=FALSE; | |
1027 | } | |
b7b694d6 | 1028 | return; |
616915dd | 1029 | } |
1030 | ||
bb25bea6 | 1031 | static bool lltok_isBoolean_Op (lltok tok) |
616915dd | 1032 | { |
1033 | /*this should really be a switch statement but | |
1034 | I don't want to violate the abstraction | |
1035 | maybe this should go in lltok.c */ | |
1036 | ||
16c024b5 | 1037 | if (lltok_isEqOp (tok)) |
616915dd | 1038 | { |
1039 | return TRUE; | |
1040 | } | |
16c024b5 | 1041 | if (lltok_isAndOp (tok)) |
616915dd | 1042 | |
1043 | { | |
1044 | ||
1045 | return TRUE; | |
1046 | } | |
16c024b5 | 1047 | if (lltok_isOrOp (tok)) |
616915dd | 1048 | { |
1049 | return TRUE; | |
1050 | } | |
1051 | ||
abd7f895 | 1052 | if (lltok_isGt_Op (tok)) |
616915dd | 1053 | { |
1054 | return TRUE; | |
1055 | } | |
abd7f895 | 1056 | if (lltok_isLt_Op (tok)) |
616915dd | 1057 | { |
1058 | return TRUE; | |
1059 | } | |
1060 | ||
abd7f895 | 1061 | if (lltok_isLe_Op (tok)) |
616915dd | 1062 | { |
1063 | return TRUE; | |
1064 | } | |
1065 | ||
abd7f895 | 1066 | if (lltok_isGe_Op (tok)) |
616915dd | 1067 | { |
1068 | return TRUE; | |
1069 | } | |
1070 | ||
1071 | return FALSE; | |
1072 | ||
1073 | } | |
1074 | ||
1075 | ||
28bf4b0b | 1076 | static void exprNode_booleanTraverse (/*@dependent@*/ exprNode e, /*@unused@*/ bool definatelv, /*@unused@*/ bool definaterv, fileloc sequencePoint) |
616915dd | 1077 | { |
b7b694d6 | 1078 | constraint cons; |
1079 | exprNode t1, t2; | |
1080 | exprData data; | |
1081 | lltok tok; | |
1082 | constraintList tempList, temp; | |
965143f0 | 1083 | |
1084 | if (exprNode_isUndefined(e) ) | |
1085 | { | |
1086 | llassert (exprNode_isDefined(e) ); | |
1087 | return; | |
1088 | } | |
1089 | ||
b7b694d6 | 1090 | data = e->edata; |
616915dd | 1091 | |
b7b694d6 | 1092 | tok = exprData_getOpTok (data); |
1093 | t1 = exprData_getOpA (data); | |
1094 | t2 = exprData_getOpB (data); | |
965143f0 | 1095 | |
1096 | /* drl 3/2/2003 we know this because of the type of expression*/ | |
1097 | llassert( exprNode_isDefined(t1) && exprNode_isDefined(t2) ); | |
1098 | ||
616915dd | 1099 | |
b7b694d6 | 1100 | tempList = constraintList_undefined; |
616915dd | 1101 | |
b7b694d6 | 1102 | /* arithmetic tests */ |
616915dd | 1103 | |
16c024b5 | 1104 | if (lltok_isEqOp (tok)) |
b7b694d6 | 1105 | { |
1106 | cons = constraint_makeEnsureEqual (t1, t2, sequencePoint); | |
1107 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); | |
1108 | } | |
616915dd | 1109 | |
b7b694d6 | 1110 | |
abd7f895 | 1111 | if (lltok_isLt_Op (tok)) |
b7b694d6 | 1112 | { |
1113 | cons = constraint_makeEnsureLessThan (t1, t2, sequencePoint); | |
1114 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); | |
1115 | cons = constraint_makeEnsureGreaterThanEqual (t1, t2, sequencePoint); | |
1116 | e->falseEnsuresConstraints = constraintList_add(e->falseEnsuresConstraints, cons); | |
1117 | } | |
616915dd | 1118 | |
abd7f895 | 1119 | if (lltok_isGe_Op (tok)) |
b7b694d6 | 1120 | { |
1121 | cons = constraint_makeEnsureGreaterThanEqual (t1, t2, sequencePoint); | |
1122 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); | |
1123 | ||
1124 | cons = constraint_makeEnsureLessThan (t1, t2, sequencePoint); | |
1125 | e->falseEnsuresConstraints = constraintList_add(e->falseEnsuresConstraints, cons); | |
1126 | } | |
1127 | ||
abd7f895 | 1128 | if (lltok_isGt_Op (tok)) |
b7b694d6 | 1129 | { |
1130 | cons = constraint_makeEnsureGreaterThan (t1, t2, sequencePoint); | |
1131 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); | |
1132 | cons = constraint_makeEnsureLessThanEqual (t1, t2, sequencePoint); | |
1133 | e->falseEnsuresConstraints = constraintList_add(e->falseEnsuresConstraints, cons); | |
1134 | } | |
1135 | ||
abd7f895 | 1136 | if (lltok_isLe_Op (tok)) |
b7b694d6 | 1137 | { |
1138 | cons = constraint_makeEnsureLessThanEqual (t1, t2, sequencePoint); | |
1139 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); | |
1140 | ||
1141 | cons = constraint_makeEnsureGreaterThan (t1, t2, sequencePoint); | |
1142 | e->falseEnsuresConstraints = constraintList_add(e->falseEnsuresConstraints, cons); | |
1143 | } | |
1144 | ||
1145 | /* Logical operations */ | |
1146 | ||
16c024b5 | 1147 | if (lltok_isAndOp (tok)) |
b7b694d6 | 1148 | { |
1149 | /* true ensures */ | |
1150 | tempList = constraintList_copy (t1->trueEnsuresConstraints); | |
1151 | tempList = constraintList_addList (tempList, t2->trueEnsuresConstraints); | |
1152 | e->trueEnsuresConstraints = constraintList_addListFree(e->trueEnsuresConstraints, tempList); | |
1153 | ||
1154 | /* false ensures: fens t1 or tens t1 and fens t2 */ | |
1155 | tempList = constraintList_copy (t1->trueEnsuresConstraints); | |
1156 | tempList = constraintList_addList (tempList, t2->falseEnsuresConstraints); | |
1157 | temp = tempList; | |
1158 | tempList = constraintList_logicalOr (tempList, t1->falseEnsuresConstraints); | |
1159 | constraintList_free (temp); | |
1160 | ||
1b8ae690 | 1161 | /* evans - was constraintList_addList - memory leak detected by splint */ |
b7b694d6 | 1162 | e->falseEnsuresConstraints = constraintList_addListFree (e->falseEnsuresConstraints, tempList); |
1163 | } | |
16c024b5 | 1164 | else if (lltok_isOrOp (tok)) |
b7b694d6 | 1165 | { |
1166 | /* false ensures */ | |
616915dd | 1167 | tempList = constraintList_copy (t1->falseEnsuresConstraints); |
1168 | tempList = constraintList_addList (tempList, t2->falseEnsuresConstraints); | |
4ab867d6 | 1169 | e->falseEnsuresConstraints = constraintList_addListFree(e->falseEnsuresConstraints, tempList); |
616915dd | 1170 | |
b7b694d6 | 1171 | /* true ensures: tens t1 or fens t1 and tens t2 */ |
616915dd | 1172 | tempList = constraintList_copy (t1->falseEnsuresConstraints); |
1173 | tempList = constraintList_addList (tempList, t2->trueEnsuresConstraints); | |
bb25bea6 | 1174 | |
1175 | temp = tempList; | |
616915dd | 1176 | tempList = constraintList_logicalOr (tempList, t1->trueEnsuresConstraints); |
bb25bea6 | 1177 | constraintList_free(temp); |
1178 | ||
60eced23 | 1179 | e->trueEnsuresConstraints = constraintList_addListFree(e->trueEnsuresConstraints, tempList); |
920a3797 | 1180 | tempList = constraintList_undefined; |
616915dd | 1181 | } |
b7b694d6 | 1182 | else |
84c9ffbf | 1183 | { |
abd7f895 | 1184 | DPRINTF((message("%s is not a boolean operation", lltok_unparse(tok)))); |
60eced23 | 1185 | } |
616915dd | 1186 | } |
1187 | ||
965143f0 | 1188 | void exprNode_exprTraverse (/*@dependent@*/ exprNode e, bool definatelv, bool definaterv, /*@observer@*/ /*@temp@*/ fileloc sequencePoint) |
616915dd | 1189 | { |
9280addf | 1190 | exprNode t1, t2, fcn; |
616915dd | 1191 | lltok tok; |
1192 | bool handledExprNode; | |
1193 | exprData data; | |
1194 | constraint cons; | |
1195 | ||
bb25bea6 | 1196 | constraintList temp; |
1197 | ||
abd7f895 | 1198 | if (exprNode_isError(e)) |
470b7798 | 1199 | { |
b7b694d6 | 1200 | return; |
470b7798 | 1201 | } |
1202 | ||
abd7f895 | 1203 | DPRINTF((message ("exprNode_exprTraverset Analysising %s %s at", exprNode_unparse(e), |
1204 | fileloc_unparse(exprNode_getfileloc(e))))); | |
470b7798 | 1205 | |
bb25bea6 | 1206 | /*e->requiresConstraints = constraintList_makeNew(); |
c3e695ff | 1207 | e->ensuresConstraints = constraintList_makeNew(); |
1208 | e->trueEnsuresConstraints = constraintList_makeNew();; | |
1209 | e->falseEnsuresConstraints = constraintList_makeNew();; | |
bb25bea6 | 1210 | */ |
7edb30e6 | 1211 | |
abd7f895 | 1212 | if (exprNode_isUnhandled (e)) |
616915dd | 1213 | { |
b7b694d6 | 1214 | return; |
616915dd | 1215 | } |
b7b694d6 | 1216 | |
1217 | handledExprNode = TRUE; | |
1218 | ||
616915dd | 1219 | data = e->edata; |
1220 | ||
1221 | switch (e->kind) | |
1222 | { | |
616915dd | 1223 | case XPR_WHILEPRED: |
1224 | t1 = exprData_getSingle (data); | |
1225 | exprNode_exprTraverse (t1, definatelv, definaterv, sequencePoint); | |
1226 | e = exprNode_copyConstraints (e, t1); | |
1227 | break; | |
1228 | ||
1229 | case XPR_FETCH: | |
1230 | ||
abd7f895 | 1231 | if (definatelv) |
616915dd | 1232 | { |
abd7f895 | 1233 | t1 = (exprData_getPairA (data)); |
1234 | t2 = (exprData_getPairB (data)); | |
616915dd | 1235 | cons = constraint_makeWriteSafeExprNode (t1, t2); |
1236 | } | |
1237 | else | |
1238 | { | |
abd7f895 | 1239 | t1 = (exprData_getPairA (data)); |
1240 | t2 = (exprData_getPairB (data)); | |
1241 | cons = constraint_makeReadSafeExprNode (t1, t2); | |
616915dd | 1242 | } |
1243 | ||
1244 | e->requiresConstraints = constraintList_add(e->requiresConstraints, cons); | |
1245 | cons = constraint_makeEnsureMaxReadAtLeast (t1, t2, sequencePoint); | |
1246 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); | |
1247 | ||
9280addf | 1248 | cons = constraint_makeEnsureLteMaxRead (t2, t1); |
616915dd | 1249 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); |
1250 | ||
616915dd | 1251 | exprNode_exprTraverse (exprData_getPairA (data), FALSE, TRUE, sequencePoint); |
1252 | exprNode_exprTraverse (exprData_getPairB (data), FALSE, TRUE, sequencePoint); | |
1253 | ||
b7b694d6 | 1254 | /*@i325 Should check which is array/index. */ |
616915dd | 1255 | break; |
1256 | ||
1257 | case XPR_PARENS: | |
1258 | exprNode_exprTraverse (exprData_getUopNode (e->edata), definatelv, definaterv, sequencePoint); | |
616915dd | 1259 | break; |
1260 | case XPR_INIT: | |
920a3797 | 1261 | { |
1262 | /* | |
1263 | idDecl t; | |
1264 | ||
1265 | uentry ue; | |
1266 | exprNode lhs; | |
1267 | ||
1268 | t = exprData_getInitId (data); | |
1269 | ue = usymtab_lookup (idDecl_observeId (t)); | |
1270 | lhs = exprNode_createId (ue); | |
1271 | */ | |
1272 | t2 = exprData_getInitNode (data); | |
1273 | ||
bb7c2085 | 1274 | /* DPRINTF(((message("initialization: %s = %s", |
920a3797 | 1275 | exprNode_unparse(lhs), |
1276 | exprNode_unparse(t2) | |
abd7f895 | 1277 | ) |
1278 | ))); */ | |
920a3797 | 1279 | |
abd7f895 | 1280 | exprNode_exprTraverse (t2, definatelv, TRUE, sequencePoint); |
920a3797 | 1281 | |
1282 | /* this test is nessecary because some expressions generate a null expression node. function pointer do that -- drl */ | |
abd7f895 | 1283 | if ((!exprNode_isError (e)) && (!exprNode_isError(t2))) |
920a3797 | 1284 | { |
1285 | cons = constraint_makeEnsureEqual (e, t2, sequencePoint); | |
1286 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); | |
1287 | } | |
1288 | } | |
616915dd | 1289 | |
1290 | break; | |
1291 | case XPR_ASSIGN: | |
1292 | t1 = exprData_getOpA (data); | |
1293 | t2 = exprData_getOpB (data); | |
abd7f895 | 1294 | exprNode_exprTraverse (t1, TRUE, definaterv, sequencePoint); |
1295 | exprNode_exprTraverse (t2, definatelv, TRUE, sequencePoint); | |
616915dd | 1296 | |
1297 | /* this test is nessecary because some expressions generate a null expression node. function pointer do that -- drl */ | |
abd7f895 | 1298 | if ((!exprNode_isError (t1)) && (!exprNode_isError(t2))) |
616915dd | 1299 | { |
1300 | cons = constraint_makeEnsureEqual (t1, t2, sequencePoint); | |
1301 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); | |
1302 | } | |
1303 | break; | |
1304 | case XPR_OP: | |
1305 | t1 = exprData_getOpA (data); | |
1306 | t2 = exprData_getOpB (data); | |
abd7f895 | 1307 | tok = exprData_getOpTok (data); |
920a3797 | 1308 | |
80489f0a | 1309 | if (lltok_getTok (tok) == ADD_ASSIGN) |
2934b455 | 1310 | { |
abd7f895 | 1311 | exprNode_exprTraverse (t1, TRUE, definaterv, sequencePoint); |
1312 | exprNode_exprTraverse (t2, definatelv, TRUE, sequencePoint); | |
920a3797 | 1313 | |
abd7f895 | 1314 | cons = constraint_makeAddAssign (t1, t2, sequencePoint); |
2934b455 | 1315 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); |
1316 | } | |
80489f0a | 1317 | else if (lltok_getTok (tok) == SUB_ASSIGN) |
2934b455 | 1318 | { |
abd7f895 | 1319 | exprNode_exprTraverse (t1, TRUE, definaterv, sequencePoint); |
1320 | exprNode_exprTraverse (t2, definatelv, TRUE, sequencePoint); | |
920a3797 | 1321 | |
abd7f895 | 1322 | cons = constraint_makeSubtractAssign (t1, t2, sequencePoint); |
2934b455 | 1323 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); |
1324 | } | |
920a3797 | 1325 | else |
1326 | { | |
abd7f895 | 1327 | exprNode_exprTraverse (t1, definatelv, definaterv, sequencePoint); |
1328 | exprNode_exprTraverse (t2, definatelv, definaterv, sequencePoint); | |
920a3797 | 1329 | } |
2934b455 | 1330 | |
abd7f895 | 1331 | if (lltok_isBoolean_Op (tok)) |
616915dd | 1332 | exprNode_booleanTraverse (e, definatelv, definaterv, sequencePoint); |
1333 | ||
616915dd | 1334 | break; |
1335 | case XPR_SIZEOFT: | |
b7b694d6 | 1336 | /*@i43 drl possible problem : warning make sure the case can be ignored.. */ |
616915dd | 1337 | |
1338 | break; | |
1339 | ||
b4085262 | 1340 | case XPR_SIZEOF: |
1341 | /* drl 7-16-01 | |
1342 | C standard says operand to sizeof isn't evaluated unless | |
1343 | its a variable length array. So we don't generate constraints. | |
1344 | */ | |
1345 | ||
616915dd | 1346 | break; |
1347 | ||
1348 | case XPR_CALL: | |
9280addf | 1349 | fcn = exprData_getFcn(data); |
1350 | ||
abd7f895 | 1351 | exprNode_exprTraverse (fcn, definatelv, definaterv, sequencePoint); |
1352 | DPRINTF ((message ("Got call that %s (%s) ", exprNode_unparse(fcn), exprNodeList_unparse (exprData_getArgs (data))))); | |
616915dd | 1353 | |
965143f0 | 1354 | llassert( exprNode_isDefined(fcn) ); |
1355 | ||
4ab867d6 | 1356 | fcn->requiresConstraints = constraintList_addListFree (fcn->requiresConstraints, |
abd7f895 | 1357 | checkCall (fcn, exprData_getArgs (data) )); |
616915dd | 1358 | |
4ab867d6 | 1359 | fcn->ensuresConstraints = constraintList_addListFree (fcn->ensuresConstraints, |
abd7f895 | 1360 | exprNode_getPostConditions(fcn, exprData_getArgs (data),e )); |
9280addf | 1361 | |
abd7f895 | 1362 | t1 = exprNode_createNew (exprNode_getType (e)); |
9280addf | 1363 | checkArgumentList (t1, exprData_getArgs(data), sequencePoint); |
28bf4b0b | 1364 | exprNode_mergeResolve (e, t1, fcn); |
920a3797 | 1365 | exprNode_free(t1); |
616915dd | 1366 | break; |
1367 | ||
1368 | case XPR_RETURN: | |
abd7f895 | 1369 | exprNode_exprTraverse (exprData_getSingle (data), definatelv, definaterv, sequencePoint); |
616915dd | 1370 | break; |
1371 | ||
1372 | case XPR_NULLRETURN: | |
84c9ffbf | 1373 | |
616915dd | 1374 | break; |
1375 | ||
1376 | ||
1377 | case XPR_FACCESS: | |
abd7f895 | 1378 | exprNode_exprTraverse (exprData_getFieldNode (data), definatelv, definaterv, sequencePoint); |
616915dd | 1379 | break; |
1380 | ||
1381 | case XPR_ARROW: | |
abd7f895 | 1382 | exprNode_exprTraverse (exprData_getFieldNode (data), definatelv, definaterv, sequencePoint); |
616915dd | 1383 | break; |
1384 | ||
1385 | case XPR_STRINGLITERAL: | |
84c9ffbf | 1386 | |
616915dd | 1387 | break; |
1388 | ||
1389 | case XPR_NUMLIT: | |
84c9ffbf | 1390 | |
616915dd | 1391 | break; |
1392 | ||
1393 | case XPR_PREOP: | |
1394 | t1 = exprData_getUopNode(data); | |
965143f0 | 1395 | |
1396 | ||
1397 | /* drl 3/2/2003 we know this because of the type of expression*/ | |
1398 | llassert( exprNode_isDefined(t1) ); | |
1399 | ||
1400 | ||
616915dd | 1401 | tok = (exprData_getUopTok (data)); |
abd7f895 | 1402 | exprNode_exprTraverse (t1, definatelv, definaterv, sequencePoint); |
616915dd | 1403 | /*handle * pointer access */ |
16c024b5 | 1404 | if (lltok_isIncOp (tok)) |
616915dd | 1405 | { |
1406 | DPRINTF(("doing ++(var)")); | |
1407 | t1 = exprData_getUopNode (data); | |
abd7f895 | 1408 | cons = constraint_makeMaxSetSideEffectPostIncrement (t1, sequencePoint); |
616915dd | 1409 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); |
1410 | } | |
16c024b5 | 1411 | else if (lltok_isDecOp (tok)) |
616915dd | 1412 | { |
1413 | DPRINTF(("doing --(var)")); | |
1414 | t1 = exprData_getUopNode (data); | |
abd7f895 | 1415 | cons = constraint_makeMaxSetSideEffectPostDecrement (t1, sequencePoint); |
616915dd | 1416 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); |
1417 | } | |
abd7f895 | 1418 | else if (lltok_isMult(tok )) |
616915dd | 1419 | { |
1420 | if (definatelv) | |
1421 | { | |
1422 | cons = constraint_makeWriteSafeInt (t1, 0); | |
1423 | } | |
1424 | else | |
1425 | { | |
1426 | cons = constraint_makeReadSafeInt (t1, 0); | |
1427 | } | |
1428 | e->requiresConstraints = constraintList_add(e->requiresConstraints, cons); | |
1429 | } | |
16c024b5 | 1430 | else if (lltok_isNotOp (tok)) |
84c9ffbf | 1431 | /* ! expr */ |
616915dd | 1432 | { |
bb25bea6 | 1433 | constraintList_free(e->trueEnsuresConstraints); |
1434 | ||
616915dd | 1435 | e->trueEnsuresConstraints = constraintList_copy (t1->falseEnsuresConstraints); |
bb25bea6 | 1436 | constraintList_free(e->falseEnsuresConstraints); |
616915dd | 1437 | e->falseEnsuresConstraints = constraintList_copy (t1->trueEnsuresConstraints); |
1438 | } | |
bb25bea6 | 1439 | |
abd7f895 | 1440 | else if (lltok_isAmpersand_Op (tok)) |
84c9ffbf | 1441 | { |
1442 | break; | |
1443 | } | |
abd7f895 | 1444 | else if (lltok_isMinus_Op (tok)) |
bb25bea6 | 1445 | { |
1446 | break; | |
1447 | } | |
abd7f895 | 1448 | else if (lltok_isExcl_Op (tok)) |
4ab867d6 | 1449 | { |
1450 | break; | |
1451 | } | |
abd7f895 | 1452 | else if (lltok_isTilde_Op (tok)) |
4ab867d6 | 1453 | { |
1454 | break; | |
1455 | } | |
84c9ffbf | 1456 | else |
1457 | { | |
abd7f895 | 1458 | llcontbug (message("Unsupported preop in %s", exprNode_unparse(e))); |
84c9ffbf | 1459 | BADEXIT; |
1460 | } | |
616915dd | 1461 | break; |
1462 | ||
1463 | case XPR_POSTOP: | |
abd7f895 | 1464 | exprNode_exprTraverse (exprData_getUopNode (data), TRUE, |
1465 | definaterv, sequencePoint); | |
616915dd | 1466 | |
16c024b5 | 1467 | if (lltok_isIncOp (exprData_getUopTok (data))) |
616915dd | 1468 | { |
1469 | DPRINTF(("doing ++")); | |
1470 | t1 = exprData_getUopNode (data); | |
abd7f895 | 1471 | cons = constraint_makeMaxSetSideEffectPostIncrement (t1, sequencePoint); |
616915dd | 1472 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); |
1473 | } | |
16c024b5 | 1474 | if (lltok_isDecOp (exprData_getUopTok (data))) |
616915dd | 1475 | { |
1476 | DPRINTF(("doing --")); | |
1477 | t1 = exprData_getUopNode (data); | |
abd7f895 | 1478 | cons = constraint_makeMaxSetSideEffectPostDecrement (t1, sequencePoint); |
616915dd | 1479 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); |
1480 | } | |
1481 | break; | |
470b7798 | 1482 | case XPR_CAST: |
920a3797 | 1483 | { |
1484 | t2 = exprData_getCastNode (data); | |
abd7f895 | 1485 | DPRINTF ((message ("Examining cast (%q)%s", |
920a3797 | 1486 | qtype_unparse (exprData_getCastType (data)), |
abd7f895 | 1487 | exprNode_unparse (t2)) |
1488 | )); | |
1489 | exprNode_exprTraverse (t2, definatelv, definaterv, sequencePoint); | |
920a3797 | 1490 | } |
470b7798 | 1491 | break; |
920a3797 | 1492 | |
470b7798 | 1493 | case XPR_COND: |
1494 | { | |
28bf4b0b | 1495 | exprNode pred, trueBranch, falseBranch; |
abd7f895 | 1496 | llassert(FALSE); |
1497 | pred = exprData_getTriplePred (data); | |
1498 | trueBranch = exprData_getTripleTrue (data); | |
1499 | falseBranch = exprData_getTripleFalse (data); | |
1500 | ||
1501 | llassert (exprNode_isDefined (pred)); | |
1502 | llassert (exprNode_isDefined (trueBranch)); | |
1503 | llassert (exprNode_isDefined (falseBranch)); | |
470b7798 | 1504 | |
abd7f895 | 1505 | exprNode_exprTraverse (pred, FALSE, TRUE, sequencePoint); |
1506 | ||
1507 | temp = pred->ensuresConstraints; | |
1508 | pred->ensuresConstraints = exprNode_traversEnsuresConstraints(pred); | |
1509 | constraintList_free(temp); | |
1510 | ||
1511 | temp = pred->requiresConstraints; | |
1512 | pred->requiresConstraints = exprNode_traversRequiresConstraints(pred); | |
1513 | constraintList_free(temp); | |
1514 | ||
1515 | temp = pred->trueEnsuresConstraints; | |
1516 | pred->trueEnsuresConstraints = exprNode_traversTrueEnsuresConstraints(pred); | |
1517 | constraintList_free(temp); | |
1518 | ||
1519 | temp = pred->falseEnsuresConstraints; | |
1520 | pred->falseEnsuresConstraints = exprNode_traversFalseEnsuresConstraints(pred); | |
1521 | constraintList_free(temp); | |
1522 | ||
1523 | exprNode_exprTraverse (trueBranch, FALSE, TRUE, sequencePoint); | |
1524 | ||
1525 | temp = trueBranch->ensuresConstraints; | |
1526 | trueBranch->ensuresConstraints = exprNode_traversEnsuresConstraints(trueBranch); | |
1527 | constraintList_free(temp); | |
1528 | ||
1529 | temp = trueBranch->requiresConstraints; | |
1530 | trueBranch->requiresConstraints = exprNode_traversRequiresConstraints(trueBranch); | |
1531 | constraintList_free(temp); | |
1532 | ||
1533 | ||
1534 | temp = trueBranch->trueEnsuresConstraints; | |
1535 | trueBranch->trueEnsuresConstraints = exprNode_traversTrueEnsuresConstraints(trueBranch); | |
1536 | constraintList_free(temp); | |
1537 | ||
1538 | temp = trueBranch->falseEnsuresConstraints; | |
1539 | trueBranch->falseEnsuresConstraints = exprNode_traversFalseEnsuresConstraints(trueBranch); | |
1540 | constraintList_free(temp); | |
1541 | ||
1542 | exprNode_exprTraverse (falseBranch, FALSE, TRUE, sequencePoint); | |
1543 | ||
1544 | temp = falseBranch->ensuresConstraints; | |
1545 | falseBranch->ensuresConstraints = exprNode_traversEnsuresConstraints(falseBranch); | |
1546 | constraintList_free(temp); | |
1547 | ||
1548 | ||
1549 | temp = falseBranch->requiresConstraints; | |
1550 | falseBranch->requiresConstraints = exprNode_traversRequiresConstraints(falseBranch); | |
1551 | constraintList_free(temp); | |
1552 | ||
1553 | temp = falseBranch->trueEnsuresConstraints; | |
1554 | falseBranch->trueEnsuresConstraints = exprNode_traversTrueEnsuresConstraints(falseBranch); | |
1555 | constraintList_free(temp); | |
1556 | ||
1557 | temp = falseBranch->falseEnsuresConstraints; | |
1558 | falseBranch->falseEnsuresConstraints = exprNode_traversFalseEnsuresConstraints(falseBranch); | |
1559 | constraintList_free(temp); | |
1560 | ||
1561 | /* if pred is true e equals true otherwise pred equals false */ | |
1562 | ||
1563 | cons = constraint_makeEnsureEqual (e, trueBranch, sequencePoint); | |
1564 | trueBranch->ensuresConstraints = constraintList_add(trueBranch->ensuresConstraints, cons); | |
1565 | ||
1566 | cons = constraint_makeEnsureEqual (e, trueBranch, sequencePoint); | |
1567 | falseBranch->ensuresConstraints = constraintList_add(falseBranch->ensuresConstraints, cons); | |
1568 | ||
1569 | e = doIfElse (e, pred, trueBranch, falseBranch); | |
470b7798 | 1570 | } |
1571 | break; | |
1572 | case XPR_COMMA: | |
1573 | llassert(FALSE); | |
1574 | t1 = exprData_getPairA (data); | |
1575 | t2 = exprData_getPairB (data); | |
1576 | /* we essiantially treat this like expr1; expr2 | |
1577 | of course sequencePoint isn't adjusted so this isn't completely accurate | |
1578 | problems../ */ | |
abd7f895 | 1579 | exprNode_exprTraverse (t1, FALSE, FALSE, sequencePoint); |
1580 | exprNode_exprTraverse (t2, definatelv, definaterv, sequencePoint); | |
28bf4b0b | 1581 | exprNode_mergeResolve (e, t1, t2); |
470b7798 | 1582 | break; |
920a3797 | 1583 | |
616915dd | 1584 | default: |
1585 | handledExprNode = FALSE; | |
1586 | } | |
1587 | ||
abd7f895 | 1588 | e->requiresConstraints = constraintList_preserveOrig (e->requiresConstraints); |
1589 | e->ensuresConstraints = constraintList_preserveOrig (e->ensuresConstraints); | |
1590 | e->requiresConstraints = constraintList_addGeneratingExpr (e->requiresConstraints, e); | |
9280addf | 1591 | |
abd7f895 | 1592 | e->ensuresConstraints = constraintList_addGeneratingExpr (e->ensuresConstraints, e); |
9280addf | 1593 | |
7edb30e6 | 1594 | |
abd7f895 | 1595 | e->requiresConstraints = constraintList_removeSurpressed(e->requiresConstraints); |
7edb30e6 | 1596 | |
abd7f895 | 1597 | DPRINTF((message ("ensures constraints for %s are %s", exprNode_unparse(e), constraintList_printDetailed(e->ensuresConstraints)))); |
d46ce6a4 | 1598 | |
abd7f895 | 1599 | DPRINTF((message ("Requires constraints for %s are %s", exprNode_unparse(e), constraintList_printDetailed(e->ensuresConstraints)))); |
616915dd | 1600 | |
abd7f895 | 1601 | DPRINTF((message ("trueEnsures constraints for %s are %s", exprNode_unparse(e), constraintList_printDetailed(e->trueEnsuresConstraints)))); |
bb25bea6 | 1602 | |
abd7f895 | 1603 | DPRINTF((message ("falseEnsures constraints for %s are %s", exprNode_unparse(e), constraintList_printDetailed(e->falseEnsuresConstraints)))); |
bb25bea6 | 1604 | |
b7b694d6 | 1605 | return; |
616915dd | 1606 | } |
1607 | ||
1608 | ||
1609 | constraintList exprNode_traversTrueEnsuresConstraints (exprNode e) | |
1610 | { | |
470b7798 | 1611 | exprNode t1; |
616915dd | 1612 | |
1613 | bool handledExprNode; | |
616915dd | 1614 | exprData data; |
1615 | constraintList ret; | |
1616 | ||
2681ee39 | 1617 | if (exprNode_handleError (e)) |
1618 | { | |
1619 | ret = constraintList_makeNew(); | |
1620 | return ret; | |
1621 | } | |
abd7f895 | 1622 | |
1623 | ret = constraintList_copy (e->trueEnsuresConstraints); | |
616915dd | 1624 | |
2681ee39 | 1625 | handledExprNode = TRUE; |
616915dd | 1626 | |
1627 | data = e->edata; | |
1628 | ||
1629 | switch (e->kind) | |
1630 | { | |
9280addf | 1631 | case XPR_WHILEPRED: |
1632 | t1 = exprData_getSingle (data); | |
abd7f895 | 1633 | ret = constraintList_addListFree (ret, exprNode_traversTrueEnsuresConstraints (t1)); |
9280addf | 1634 | break; |
616915dd | 1635 | |
1636 | case XPR_FETCH: | |
1637 | ||
4ab867d6 | 1638 | ret = constraintList_addListFree (ret, |
616915dd | 1639 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1640 | (exprData_getPairA (data))); |
616915dd | 1641 | |
4ab867d6 | 1642 | ret = constraintList_addListFree (ret, |
616915dd | 1643 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1644 | (exprData_getPairB (data))); |
616915dd | 1645 | break; |
1646 | case XPR_PREOP: | |
1647 | ||
4ab867d6 | 1648 | ret = constraintList_addListFree (ret, |
616915dd | 1649 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1650 | (exprData_getUopNode (data))); |
616915dd | 1651 | break; |
1652 | ||
1653 | case XPR_PARENS: | |
4ab867d6 | 1654 | ret = constraintList_addListFree (ret, exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1655 | (exprData_getUopNode (data))); |
616915dd | 1656 | break; |
2681ee39 | 1657 | |
1658 | case XPR_INIT: | |
1659 | ret = constraintList_addListFree (ret, | |
1660 | exprNode_traversTrueEnsuresConstraints | |
abd7f895 | 1661 | (exprData_getInitNode (data))); |
2681ee39 | 1662 | break; |
1663 | ||
1664 | ||
616915dd | 1665 | case XPR_ASSIGN: |
4ab867d6 | 1666 | ret = constraintList_addListFree (ret, |
616915dd | 1667 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1668 | (exprData_getOpA (data))); |
616915dd | 1669 | |
4ab867d6 | 1670 | ret = constraintList_addListFree (ret, |
616915dd | 1671 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1672 | (exprData_getOpB (data))); |
616915dd | 1673 | break; |
1674 | case XPR_OP: | |
4ab867d6 | 1675 | ret = constraintList_addListFree (ret, |
616915dd | 1676 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1677 | (exprData_getOpA (data))); |
616915dd | 1678 | |
4ab867d6 | 1679 | ret = constraintList_addListFree (ret, |
616915dd | 1680 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1681 | (exprData_getOpB (data))); |
616915dd | 1682 | break; |
1683 | case XPR_SIZEOFT: | |
616915dd | 1684 | break; |
1685 | ||
1686 | case XPR_SIZEOF: | |
1687 | ||
4ab867d6 | 1688 | ret = constraintList_addListFree (ret, |
1689 | exprNode_traversTrueEnsuresConstraints | |
abd7f895 | 1690 | (exprData_getSingle (data))); |
616915dd | 1691 | break; |
1692 | ||
1693 | case XPR_CALL: | |
4ab867d6 | 1694 | ret = constraintList_addListFree (ret, |
616915dd | 1695 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1696 | (exprData_getFcn (data))); |
1697 | /*@i11*/ /* exprNodeList_unparse (exprData_getArgs (data)); */ | |
b7b694d6 | 1698 | break; |
616915dd | 1699 | |
1700 | case XPR_RETURN: | |
4ab867d6 | 1701 | ret = constraintList_addListFree (ret, |
616915dd | 1702 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1703 | (exprData_getSingle (data))); |
616915dd | 1704 | break; |
1705 | ||
1706 | case XPR_NULLRETURN: | |
616915dd | 1707 | break; |
1708 | ||
1709 | case XPR_FACCESS: | |
b7b694d6 | 1710 | ret = constraintList_addListFree (ret, |
1711 | exprNode_traversTrueEnsuresConstraints | |
abd7f895 | 1712 | (exprData_getFieldNode (data))); |
616915dd | 1713 | break; |
1714 | ||
1715 | case XPR_ARROW: | |
b7b694d6 | 1716 | ret = constraintList_addListFree (ret, |
1717 | exprNode_traversTrueEnsuresConstraints | |
abd7f895 | 1718 | (exprData_getFieldNode (data))); |
616915dd | 1719 | break; |
1720 | ||
1721 | case XPR_STRINGLITERAL: | |
616915dd | 1722 | break; |
1723 | ||
1724 | case XPR_NUMLIT: | |
616915dd | 1725 | break; |
1726 | case XPR_POSTOP: | |
1727 | ||
4ab867d6 | 1728 | ret = constraintList_addListFree (ret, |
616915dd | 1729 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1730 | (exprData_getUopNode (data))); |
616915dd | 1731 | break; |
470b7798 | 1732 | |
1733 | case XPR_CAST: | |
1734 | ||
4ab867d6 | 1735 | ret = constraintList_addListFree (ret, |
470b7798 | 1736 | exprNode_traversTrueEnsuresConstraints |
abd7f895 | 1737 | (exprData_getCastNode (data))); |
470b7798 | 1738 | break; |
84c9ffbf | 1739 | |
616915dd | 1740 | default: |
1741 | break; | |
1742 | } | |
1743 | ||
1744 | return ret; | |
1745 | } | |
1746 | ||
9280addf | 1747 | constraintList exprNode_traversFalseEnsuresConstraints (exprNode e) |
1748 | { | |
b7b694d6 | 1749 | exprNode t1; |
9280addf | 1750 | bool handledExprNode; |
9280addf | 1751 | exprData data; |
1752 | constraintList ret; | |
abd7f895 | 1753 | |
1754 | if (exprNode_handleError (e)) | |
1755 | { | |
1756 | ret = constraintList_makeNew(); | |
1757 | return ret; | |
1758 | } | |
1759 | ||
1760 | ret = constraintList_copy (e->falseEnsuresConstraints); | |
1761 | handledExprNode = TRUE; | |
9280addf | 1762 | data = e->edata; |
1763 | ||
1764 | switch (e->kind) | |
1765 | { | |
1766 | case XPR_WHILEPRED: | |
1767 | t1 = exprData_getSingle (data); | |
abd7f895 | 1768 | ret = constraintList_addListFree (ret,exprNode_traversFalseEnsuresConstraints (t1)); |
9280addf | 1769 | break; |
1770 | ||
1771 | case XPR_FETCH: | |
1772 | ||
4ab867d6 | 1773 | ret = constraintList_addListFree (ret, |
9280addf | 1774 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1775 | (exprData_getPairA (data))); |
9280addf | 1776 | |
4ab867d6 | 1777 | ret = constraintList_addListFree (ret, |
9280addf | 1778 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1779 | (exprData_getPairB (data))); |
9280addf | 1780 | break; |
1781 | case XPR_PREOP: | |
1782 | ||
4ab867d6 | 1783 | ret = constraintList_addListFree (ret, |
9280addf | 1784 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1785 | (exprData_getUopNode (data))); |
9280addf | 1786 | break; |
1787 | ||
1788 | case XPR_PARENS: | |
4ab867d6 | 1789 | ret = constraintList_addListFree (ret, exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1790 | (exprData_getUopNode (data))); |
9280addf | 1791 | break; |
2681ee39 | 1792 | case XPR_INIT: |
1793 | ret = constraintList_addListFree (ret, | |
1794 | exprNode_traversFalseEnsuresConstraints | |
abd7f895 | 1795 | ( exprData_getInitNode (data))); |
2681ee39 | 1796 | break; |
1797 | ||
9280addf | 1798 | case XPR_ASSIGN: |
4ab867d6 | 1799 | ret = constraintList_addListFree (ret, |
9280addf | 1800 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1801 | (exprData_getOpA (data))); |
9280addf | 1802 | |
4ab867d6 | 1803 | ret = constraintList_addListFree (ret, |
9280addf | 1804 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1805 | (exprData_getOpB (data))); |
9280addf | 1806 | break; |
1807 | case XPR_OP: | |
4ab867d6 | 1808 | ret = constraintList_addListFree (ret, |
9280addf | 1809 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1810 | (exprData_getOpA (data))); |
9280addf | 1811 | |
4ab867d6 | 1812 | ret = constraintList_addListFree (ret, |
9280addf | 1813 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1814 | (exprData_getOpB (data))); |
9280addf | 1815 | break; |
1816 | case XPR_SIZEOFT: | |
9280addf | 1817 | break; |
1818 | ||
1819 | case XPR_SIZEOF: | |
1820 | ||
4ab867d6 | 1821 | ret = constraintList_addListFree (ret, |
9280addf | 1822 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1823 | (exprData_getSingle (data))); |
9280addf | 1824 | break; |
1825 | ||
1826 | case XPR_CALL: | |
4ab867d6 | 1827 | ret = constraintList_addListFree (ret, |
9280addf | 1828 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1829 | (exprData_getFcn (data))); |
1830 | /*@i11*/ /* exprNodeList_unparse (exprData_getArgs (data)); */ | |
b7b694d6 | 1831 | break; |
9280addf | 1832 | |
1833 | case XPR_RETURN: | |
4ab867d6 | 1834 | ret = constraintList_addListFree (ret, |
9280addf | 1835 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1836 | (exprData_getSingle (data))); |
9280addf | 1837 | break; |
1838 | ||
1839 | case XPR_NULLRETURN: | |
9280addf | 1840 | break; |
1841 | ||
1842 | case XPR_FACCESS: | |
b7b694d6 | 1843 | ret = constraintList_addListFree (ret, |
1844 | exprNode_traversFalseEnsuresConstraints | |
abd7f895 | 1845 | (exprData_getFieldNode (data))); |
9280addf | 1846 | break; |
b7b694d6 | 1847 | |
9280addf | 1848 | case XPR_ARROW: |
b7b694d6 | 1849 | ret = constraintList_addListFree (ret, |
1850 | exprNode_traversFalseEnsuresConstraints | |
abd7f895 | 1851 | (exprData_getFieldNode (data))); |
9280addf | 1852 | break; |
1853 | ||
1854 | case XPR_STRINGLITERAL: | |
9280addf | 1855 | break; |
1856 | ||
1857 | case XPR_NUMLIT: | |
9280addf | 1858 | break; |
1859 | case XPR_POSTOP: | |
1860 | ||
4ab867d6 | 1861 | ret = constraintList_addListFree (ret, |
9280addf | 1862 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1863 | (exprData_getUopNode (data))); |
9280addf | 1864 | break; |
470b7798 | 1865 | |
1866 | case XPR_CAST: | |
1867 | ||
4ab867d6 | 1868 | ret = constraintList_addListFree (ret, |
470b7798 | 1869 | exprNode_traversFalseEnsuresConstraints |
abd7f895 | 1870 | (exprData_getCastNode (data))); |
470b7798 | 1871 | break; |
1872 | ||
9280addf | 1873 | default: |
1874 | break; | |
1875 | } | |
1876 | ||
1877 | return ret; | |
1878 | } | |
1879 | ||
616915dd | 1880 | |
1881 | /* walk down the tree and get all requires Constraints in each subexpression*/ | |
d46ce6a4 | 1882 | /*@only@*/ constraintList exprNode_traversRequiresConstraints (exprNode e) |
616915dd | 1883 | { |
470b7798 | 1884 | exprNode t1; |
616915dd | 1885 | |
1886 | bool handledExprNode; | |
616915dd | 1887 | exprData data; |
1888 | constraintList ret; | |
1889 | ||
1890 | if (exprNode_handleError (e)) | |
1891 | { | |
c3e695ff | 1892 | ret = constraintList_makeNew(); |
616915dd | 1893 | return ret; |
1894 | } | |
abd7f895 | 1895 | |
1896 | ret = constraintList_copy (e->requiresConstraints); | |
1897 | handledExprNode = TRUE; | |
616915dd | 1898 | data = e->edata; |
1899 | ||
1900 | switch (e->kind) | |
1901 | { | |
9280addf | 1902 | case XPR_WHILEPRED: |
1903 | t1 = exprData_getSingle (data); | |
abd7f895 | 1904 | ret = constraintList_addListFree (ret, exprNode_traversRequiresConstraints (t1)); |
9280addf | 1905 | break; |
616915dd | 1906 | |
1907 | case XPR_FETCH: | |
1908 | ||
4ab867d6 | 1909 | ret = constraintList_addListFree (ret, |
616915dd | 1910 | exprNode_traversRequiresConstraints |
abd7f895 | 1911 | (exprData_getPairA (data))); |
616915dd | 1912 | |
4ab867d6 | 1913 | ret = constraintList_addListFree (ret, |
616915dd | 1914 | exprNode_traversRequiresConstraints |
abd7f895 | 1915 | (exprData_getPairB (data))); |
616915dd | 1916 | break; |
1917 | case XPR_PREOP: | |
1918 | ||
4ab867d6 | 1919 | ret = constraintList_addListFree (ret, |
616915dd | 1920 | exprNode_traversRequiresConstraints |
abd7f895 | 1921 | (exprData_getUopNode (data))); |
616915dd | 1922 | break; |
1923 | ||
1924 | case XPR_PARENS: | |
4ab867d6 | 1925 | ret = constraintList_addListFree (ret, exprNode_traversRequiresConstraints |
abd7f895 | 1926 | (exprData_getUopNode (data))); |
616915dd | 1927 | break; |
2681ee39 | 1928 | case XPR_INIT: |
1929 | ret = constraintList_addListFree (ret, | |
1930 | exprNode_traversRequiresConstraints | |
abd7f895 | 1931 | (exprData_getInitNode (data))); |
2681ee39 | 1932 | break; |
1933 | ||
616915dd | 1934 | case XPR_ASSIGN: |
4ab867d6 | 1935 | ret = constraintList_addListFree (ret, |
616915dd | 1936 | exprNode_traversRequiresConstraints |
abd7f895 | 1937 | (exprData_getOpA (data))); |
616915dd | 1938 | |
4ab867d6 | 1939 | ret = constraintList_addListFree (ret, |
616915dd | 1940 | exprNode_traversRequiresConstraints |
abd7f895 | 1941 | (exprData_getOpB (data))); |
616915dd | 1942 | break; |
1943 | case XPR_OP: | |
4ab867d6 | 1944 | ret = constraintList_addListFree (ret, |
616915dd | 1945 | exprNode_traversRequiresConstraints |
abd7f895 | 1946 | (exprData_getOpA (data))); |
616915dd | 1947 | |
4ab867d6 | 1948 | ret = constraintList_addListFree (ret, |
616915dd | 1949 | exprNode_traversRequiresConstraints |
abd7f895 | 1950 | (exprData_getOpB (data))); |
616915dd | 1951 | break; |
1952 | case XPR_SIZEOFT: | |
616915dd | 1953 | break; |
1954 | ||
1955 | case XPR_SIZEOF: | |
1956 | ||
4ab867d6 | 1957 | ret = constraintList_addListFree (ret, |
616915dd | 1958 | exprNode_traversRequiresConstraints |
abd7f895 | 1959 | (exprData_getSingle (data))); |
616915dd | 1960 | break; |
1961 | ||
1962 | case XPR_CALL: | |
4ab867d6 | 1963 | ret = constraintList_addListFree (ret, |
616915dd | 1964 | exprNode_traversRequiresConstraints |
abd7f895 | 1965 | (exprData_getFcn (data))); |
1966 | /*@i11*/ /* exprNodeList_unparse (exprData_getArgs (data)); */ | |
b7b694d6 | 1967 | break; |
616915dd | 1968 | |
1969 | case XPR_RETURN: | |
4ab867d6 | 1970 | ret = constraintList_addListFree (ret, |
616915dd | 1971 | exprNode_traversRequiresConstraints |
abd7f895 | 1972 | (exprData_getSingle (data))); |
616915dd | 1973 | break; |
1974 | ||
1975 | case XPR_NULLRETURN: | |
616915dd | 1976 | break; |
1977 | ||
1978 | case XPR_FACCESS: | |
b7b694d6 | 1979 | ret = constraintList_addListFree (ret, |
1980 | exprNode_traversRequiresConstraints | |
abd7f895 | 1981 | (exprData_getFieldNode (data))); |
616915dd | 1982 | break; |
b7b694d6 | 1983 | |
616915dd | 1984 | case XPR_ARROW: |
b7b694d6 | 1985 | ret = constraintList_addListFree (ret, |
1986 | exprNode_traversRequiresConstraints | |
abd7f895 | 1987 | (exprData_getFieldNode (data))); |
616915dd | 1988 | break; |
1989 | ||
1990 | case XPR_STRINGLITERAL: | |
616915dd | 1991 | break; |
1992 | ||
1993 | case XPR_NUMLIT: | |
616915dd | 1994 | break; |
1995 | case XPR_POSTOP: | |
1996 | ||
4ab867d6 | 1997 | ret = constraintList_addListFree (ret, |
616915dd | 1998 | exprNode_traversRequiresConstraints |
abd7f895 | 1999 | (exprData_getUopNode (data))); |
616915dd | 2000 | break; |
470b7798 | 2001 | |
2002 | case XPR_CAST: | |
2003 | ||
4ab867d6 | 2004 | ret = constraintList_addListFree (ret, |
470b7798 | 2005 | exprNode_traversRequiresConstraints |
abd7f895 | 2006 | (exprData_getCastNode (data))); |
470b7798 | 2007 | break; |
2008 | ||
616915dd | 2009 | default: |
2010 | break; | |
2011 | } | |
2012 | ||
2013 | return ret; | |
2014 | } | |
2015 | ||
2016 | ||
2017 | /* walk down the tree and get all Ensures Constraints in each subexpression*/ | |
d46ce6a4 | 2018 | /*@only@*/ constraintList exprNode_traversEnsuresConstraints (exprNode e) |
616915dd | 2019 | { |
470b7798 | 2020 | exprNode t1; |
616915dd | 2021 | |
2022 | bool handledExprNode; | |
616915dd | 2023 | exprData data; |
616915dd | 2024 | constraintList ret; |
2025 | ||
abd7f895 | 2026 | if (exprNode_handleError (e)) |
2027 | { | |
2028 | ret = constraintList_makeNew(); | |
2029 | return ret; | |
2030 | } | |
2031 | ||
2032 | ret = constraintList_copy (e->ensuresConstraints); | |
2033 | handledExprNode = TRUE; | |
2034 | ||
616915dd | 2035 | data = e->edata; |
abd7f895 | 2036 | |
2037 | DPRINTF ((message ("exprnode_traversEnsuresConstraints call for %s with " | |
2038 | "constraintList of %s", | |
616915dd | 2039 | exprNode_unparse (e), |
2040 | constraintList_print(e->ensuresConstraints) | |
2041 | ) | |
2042 | )); | |
2043 | ||
2044 | ||
2045 | switch (e->kind) | |
2046 | { | |
abd7f895 | 2047 | case XPR_WHILEPRED: |
9280addf | 2048 | t1 = exprData_getSingle (data); |
abd7f895 | 2049 | ret = constraintList_addListFree (ret,exprNode_traversEnsuresConstraints (t1)); |
9280addf | 2050 | break; |
616915dd | 2051 | |
2052 | case XPR_FETCH: | |
4ab867d6 | 2053 | ret = constraintList_addListFree (ret, |
abd7f895 | 2054 | exprNode_traversEnsuresConstraints |
2055 | (exprData_getPairA (data))); | |
2056 | ||
4ab867d6 | 2057 | ret = constraintList_addListFree (ret, |
abd7f895 | 2058 | exprNode_traversEnsuresConstraints |
2059 | (exprData_getPairB (data))); | |
616915dd | 2060 | break; |
2061 | case XPR_PREOP: | |
4ab867d6 | 2062 | ret = constraintList_addListFree (ret, |
abd7f895 | 2063 | exprNode_traversEnsuresConstraints |
2064 | (exprData_getUopNode (data))); | |
616915dd | 2065 | break; |
2066 | ||
2067 | case XPR_PARENS: | |
4ab867d6 | 2068 | ret = constraintList_addListFree (ret, exprNode_traversEnsuresConstraints |
abd7f895 | 2069 | (exprData_getUopNode (data))); |
616915dd | 2070 | break; |
2681ee39 | 2071 | |
2072 | case XPR_INIT: | |
2073 | ret = constraintList_addListFree (ret, | |
2074 | exprNode_traversEnsuresConstraints | |
abd7f895 | 2075 | (exprData_getInitNode (data))); |
2076 | break; | |
2077 | ||
2078 | ||
616915dd | 2079 | case XPR_ASSIGN: |
abd7f895 | 2080 | ret = constraintList_addListFree (ret, |
2081 | exprNode_traversEnsuresConstraints | |
2082 | (exprData_getOpA (data))); | |
2083 | ||
2084 | ret = constraintList_addListFree (ret, | |
2085 | exprNode_traversEnsuresConstraints | |
2086 | (exprData_getOpB (data))); | |
2087 | break; | |
616915dd | 2088 | case XPR_OP: |
abd7f895 | 2089 | ret = constraintList_addListFree (ret, |
2090 | exprNode_traversEnsuresConstraints | |
2091 | (exprData_getOpA (data))); | |
2092 | ||
2093 | ret = constraintList_addListFree (ret, | |
2094 | exprNode_traversEnsuresConstraints | |
2095 | (exprData_getOpB (data))); | |
2096 | break; | |
616915dd | 2097 | case XPR_SIZEOFT: |
616915dd | 2098 | break; |
2099 | ||
2100 | case XPR_SIZEOF: | |
abd7f895 | 2101 | ret = constraintList_addListFree (ret, |
2102 | exprNode_traversEnsuresConstraints | |
2103 | (exprData_getSingle (data))); | |
2104 | break; | |
616915dd | 2105 | case XPR_CALL: |
4ab867d6 | 2106 | ret = constraintList_addListFree (ret, |
abd7f895 | 2107 | exprNode_traversEnsuresConstraints |
2108 | (exprData_getFcn (data))); | |
2109 | /*@i11*/ /* exprNodeList_unparse (exprData_getArgs (data)); */ | |
b7b694d6 | 2110 | break; |
616915dd | 2111 | case XPR_RETURN: |
4ab867d6 | 2112 | ret = constraintList_addListFree (ret, |
abd7f895 | 2113 | exprNode_traversEnsuresConstraints |
2114 | (exprData_getSingle (data))); | |
616915dd | 2115 | break; |
616915dd | 2116 | case XPR_NULLRETURN: |
616915dd | 2117 | break; |
616915dd | 2118 | case XPR_FACCESS: |
b7b694d6 | 2119 | ret = constraintList_addListFree (ret, |
2120 | exprNode_traversEnsuresConstraints | |
abd7f895 | 2121 | (exprData_getFieldNode (data))); |
616915dd | 2122 | break; |
616915dd | 2123 | case XPR_ARROW: |
b7b694d6 | 2124 | ret = constraintList_addListFree (ret, |
2125 | exprNode_traversEnsuresConstraints | |
abd7f895 | 2126 | (exprData_getFieldNode (data))); |
616915dd | 2127 | break; |
616915dd | 2128 | case XPR_STRINGLITERAL: |
616915dd | 2129 | break; |
616915dd | 2130 | case XPR_NUMLIT: |
616915dd | 2131 | break; |
2132 | case XPR_POSTOP: | |
abd7f895 | 2133 | ret = constraintList_addListFree (ret, |
2134 | exprNode_traversEnsuresConstraints | |
2135 | (exprData_getUopNode (data))); | |
2136 | break; | |
470b7798 | 2137 | case XPR_CAST: |
4ab867d6 | 2138 | ret = constraintList_addListFree (ret, |
abd7f895 | 2139 | exprNode_traversEnsuresConstraints |
2140 | (exprData_getCastNode (data))); | |
470b7798 | 2141 | break; |
616915dd | 2142 | default: |
2143 | break; | |
2144 | } | |
abd7f895 | 2145 | |
2146 | DPRINTF((message ("exprnode_traversEnsuresConstraints call for %s with " | |
2147 | "constraintList of is returning %s", | |
2148 | exprNode_unparse (e), | |
2149 | constraintList_print(ret)))); | |
616915dd | 2150 | |
616915dd | 2151 | return ret; |
2152 | } | |
2153 | ||
28bf4b0b | 2154 | /*drl moved out of constraintResolve.c 07-02-001 */ |
abd7f895 | 2155 | void checkArgumentList (/*@out@*/ exprNode temp, exprNodeList arglist, |
2156 | fileloc sequencePoint) | |
28bf4b0b | 2157 | { |
965143f0 | 2158 | |
2159 | llassert(temp != NULL ); | |
2160 | ||
28bf4b0b | 2161 | temp->requiresConstraints = constraintList_makeNew(); |
2162 | temp->ensuresConstraints = constraintList_makeNew(); | |
2163 | temp->trueEnsuresConstraints = constraintList_makeNew(); | |
2164 | temp->falseEnsuresConstraints = constraintList_makeNew(); | |
2165 | ||
2166 | exprNodeList_elements (arglist, el) | |
2167 | { | |
2168 | constraintList temp2; | |
965143f0 | 2169 | |
2170 | llassert(exprNode_isDefined(el) ); | |
2171 | ||
28bf4b0b | 2172 | exprNode_exprTraverse (el, FALSE, FALSE, sequencePoint); |
2173 | temp2 = el->requiresConstraints; | |
2174 | el->requiresConstraints = exprNode_traversRequiresConstraints(el); | |
2175 | constraintList_free(temp2); | |
2176 | ||
2177 | temp2 = el->ensuresConstraints; | |
2178 | el->ensuresConstraints = exprNode_traversEnsuresConstraints(el); | |
2179 | constraintList_free(temp2); | |
2180 | ||
2181 | temp->requiresConstraints = constraintList_addList(temp->requiresConstraints, | |
2182 | el->requiresConstraints); | |
2183 | ||
2184 | temp->ensuresConstraints = constraintList_addList(temp->ensuresConstraints, | |
2185 | el->ensuresConstraints); | |
2186 | } | |
2187 | end_exprNodeList_elements; | |
2188 | ||
2189 | } | |
2190 | ||
2191 | /*drl moved out of constraintResolve.c 07-03-001 */ | |
2192 | constraintList exprNode_getPostConditions (exprNode fcn, exprNodeList arglist, exprNode fcnCall) | |
2193 | { | |
2194 | constraintList postconditions; | |
2195 | uentry temp; | |
abd7f895 | 2196 | DPRINTF((message ("Got call that %s (%s) ", exprNode_unparse(fcn), exprNodeList_unparse (arglist)))); |
28bf4b0b | 2197 | |
2198 | temp = exprNode_getUentry (fcn); | |
2199 | ||
2200 | postconditions = uentry_getFcnPostconditions (temp); | |
2201 | ||
ccf0a4a8 | 2202 | if (constraintList_isDefined (postconditions)) |
28bf4b0b | 2203 | { |
2204 | postconditions = constraintList_doSRefFixConstraintParam (postconditions, arglist); | |
2205 | postconditions = constraintList_doFixResult (postconditions, fcnCall); | |
2206 | } | |
2207 | else | |
2208 | { | |
2209 | postconditions = constraintList_makeNew(); | |
2210 | } | |
2211 | ||
2212 | return postconditions; | |
2213 | } | |
2214 | ||
86d93ed3 | 2215 | /* |
2216 | comment this out for now | |
2217 | we'll include it in a production release when its stable... | |
2218 | ||
abd7f895 | 2219 | void findStructs (exprNodeList arglist) |
86d93ed3 | 2220 | { |
2221 | ||
2222 | ctype ct, rt; | |
2223 | ||
24633cea | 2224 | DPRINTF(( |
abd7f895 | 2225 | message("doing findStructs: %s", exprNodeList_unparse(arglist)) |
2226 | )); | |
86d93ed3 | 2227 | |
2228 | ||
2229 | exprNodeList_elements(arglist, expr) | |
2230 | { | |
2231 | ct = exprNode_getType(expr); | |
2232 | ||
2233 | rt = ctype_realType (ct); | |
2234 | ||
abd7f895 | 2235 | if (ctype_isStruct (rt)) |
2236 | TPRINTF((message("Found structure %s", exprNode_unparse(expr)) | |
2237 | )); | |
2238 | if (hasInvariants(ct)) | |
86d93ed3 | 2239 | { |
2240 | constraintList invars; | |
2241 | ||
2242 | invars = getInvariants(ct); | |
2243 | ||
2244 | ||
abd7f895 | 2245 | TPRINTF((message ("findStructs has invariants %s ", constraintList_print (invars)) |
2246 | )); | |
86d93ed3 | 2247 | |
abd7f895 | 2248 | invars = constraintList_doSRefFixStructConstraint(invars, exprNode_getSref(expr), ct); |
86d93ed3 | 2249 | |
2250 | ||
abd7f895 | 2251 | TPRINTF((message ("findStructs finded invariants to be %s ", constraintList_print (invars)) |
2252 | )); | |
86d93ed3 | 2253 | } |
2254 | } | |
2255 | end_exprNodeList_elements; | |
2256 | } | |
2257 | ||
2258 | */ | |
28bf4b0b | 2259 | |
2260 | /*drl moved out of constraintResolve.c 07-02-001 */ | |
2261 | constraintList checkCall (/*@dependent@*/ exprNode fcn, exprNodeList arglist) | |
2262 | { | |
2263 | constraintList preconditions; | |
2264 | uentry temp; | |
abd7f895 | 2265 | DPRINTF((message ("Got call that %s (%s) ", exprNode_unparse(fcn), exprNodeList_unparse (arglist)))); |
28bf4b0b | 2266 | |
2267 | temp = exprNode_getUentry (fcn); | |
2268 | ||
2269 | preconditions = uentry_getFcnPreconditions (temp); | |
2270 | ||
abd7f895 | 2271 | if (constraintList_isDefined(preconditions)) |
28bf4b0b | 2272 | { |
2273 | preconditions = constraintList_togglePost (preconditions); | |
2274 | preconditions = constraintList_preserveCallInfo(preconditions, fcn); | |
2275 | preconditions = constraintList_doSRefFixConstraintParam (preconditions, arglist); | |
2276 | } | |
2277 | else | |
2278 | { | |
abd7f895 | 2279 | if (constraintList_isUndefined(preconditions)) |
28bf4b0b | 2280 | preconditions = constraintList_makeNew(); |
2281 | } | |
312c9815 | 2282 | |
312c9815 | 2283 | if (context_getFlag (FLG_IMPLICTCONSTRAINT) ) |
2284 | { | |
4287634e | 2285 | |
2286 | /* | |
2287 | uentryList_elements (arglist, el) | |
312c9815 | 2288 | { |
4287634e | 2289 | sRef s; |
2290 | TPRINTF((message("setImplictfcnConstraints doing: %s", uentry_unparse(el) ) )); | |
312c9815 | 2291 | |
2292 | s = uentry_getSref(el); | |
2293 | if (sRef_isReference (s) ) | |
2294 | { | |
4287634e | 2295 | TPRINTF((message ("%s is a pointer", sRef_unparse(s) ) )); |
312c9815 | 2296 | } |
2297 | else | |
2298 | { | |
4287634e | 2299 | TPRINTF((message ("%s is NOT a pointer", sRef_unparse(s) ) )); |
312c9815 | 2300 | } |
2301 | //drl 4/26/01 | |
2302 | //chagned this from MaxSet(s) == 0 to MaxSet(s) >= 0 | |
2303 | c = constraint_makeSRefWriteSafeInt (s, 0); | |
2304 | ||
2305 | implicitFcnConstraints = constraintList_add(implicitFcnConstraints , c); | |
2306 | ||
2307 | //drl 10/23/2002 added support for out | |
2308 | if (!uentry_isOut(el) ) | |
2309 | { | |
2310 | c = constraint_makeSRefReadSafeInt (s, 0); | |
312c9815 | 2311 | implicitFcnConstraints = constraintList_add(implicitFcnConstraints , c); |
2312 | } | |
4287634e | 2313 | |
312c9815 | 2314 | |
2315 | } | |
4287634e | 2316 | */ |
312c9815 | 2317 | } |
4287634e | 2318 | |
abd7f895 | 2319 | DPRINTF ((message("Done checkCall\n"))); |
2320 | DPRINTF ((message("Returning list %q ", constraintList_printDetailed(preconditions)))); | |
86d93ed3 | 2321 | |
2322 | /* | |
2323 | drl we're going to comment this out for now | |
2324 | we'll include it if we're sure it's working | |
2325 | ||
2326 | findStructs(arglist); | |
2327 | */ | |
2328 | ||
28bf4b0b | 2329 | return preconditions; |
2330 | } | |
e5f31c00 | 2331 | |
2332 | /*drl added this function 10.29.001 | |
2333 | takes an exprNode of the form const + const | |
2334 | and sets the value | |
2335 | */ | |
2336 | /*drl | |
2337 | I'm a bit nervous about modifying the exprNode | |
2338 | but this is the easy way to do this | |
2339 | If I have time I'd like to cause the exprNode to get created correctly in the first place */ | |
2340 | /*@i223*/ | |
abd7f895 | 2341 | void exprNode_findValue(exprNode e) |
e5f31c00 | 2342 | { |
2343 | exprData data; | |
2344 | ||
2345 | exprNode t1, t2; | |
2346 | lltok tok; | |
2347 | ||
965143f0 | 2348 | llassert(exprNode_isDefined(e) ); |
2349 | ||
e5f31c00 | 2350 | data = e->edata; |
2351 | ||
abd7f895 | 2352 | if (exprNode_hasValue(e)) |
e5f31c00 | 2353 | return; |
2354 | ||
2355 | if (e->kind == XPR_OP) | |
2356 | { | |
2357 | t1 = exprData_getOpA (data); | |
2358 | t2 = exprData_getOpB (data); | |
2359 | tok = exprData_getOpTok (data); | |
2360 | ||
2361 | exprNode_findValue(t1); | |
2362 | exprNode_findValue(t2); | |
2363 | ||
abd7f895 | 2364 | if (!(exprNode_knownIntValue(t1) && (exprNode_knownIntValue(t2)))) |
e5f31c00 | 2365 | return; |
2366 | ||
abd7f895 | 2367 | if (lltok_isPlus_Op (tok)) |
e5f31c00 | 2368 | { |
2369 | long v1, v2; | |
2370 | ||
2371 | v1 = exprNode_getLongValue(t1); | |
2372 | v2 = exprNode_getLongValue(t2); | |
2373 | ||
abd7f895 | 2374 | if (multiVal_isDefined(e->val)) |
e5f31c00 | 2375 | multiVal_free (e->val); |
2376 | ||
2377 | e->val = multiVal_makeInt (v1 + v2); | |
2378 | } | |
2379 | ||
abd7f895 | 2380 | if (lltok_isMinus_Op (tok)) |
e5f31c00 | 2381 | { |
2382 | long v1, v2; | |
2383 | ||
2384 | v1 = exprNode_getLongValue(t1); | |
2385 | v2 = exprNode_getLongValue(t2); | |
2386 | ||
abd7f895 | 2387 | if (multiVal_isDefined(e->val)) |
2388 | { | |
2389 | multiVal_free (e->val); | |
2390 | } | |
e5f31c00 | 2391 | |
2392 | e->val = multiVal_makeInt (v1 - v2); | |
2393 | } | |
2394 | ||
2395 | /*drl I should really do * and / at some point */ | |
2396 | ||
2397 | } | |
2398 | ||
2399 | } | |
2400 |