Skip to content

Commit

Permalink
Fix CPROVER counterexample translation
Browse files Browse the repository at this point in the history
In some versions of CBMC, the full array is printed to
the counterexample every time an assignment to the  array
is performed. We use the line number information to detect
this and avoid printing the whole thing.
  • Loading branch information
lou1306 committed Oct 1, 2021
1 parent 443436f commit 75d8e56
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cex.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def fmt(match, store_name, tid):
s[1] for s in states
if s[0]["function"] == "init" and not(LTSTAMP.match(s[1][0])))
others = [
(s[0]["function"], *s[1]) for s in states
(s[0]["function"], s[0]["line"], *s[1]) for s in states
if s[0]["function"] not in ("init", "__CPROVER_initialize")]
yield "<initialization>"
for i in inits:
Expand All @@ -92,7 +92,8 @@ def fmt(match, store_name, tid):

agent = ""
system = None
for i, (func, var, value) in enumerate(others):
last_line = None
for i, (func, line, var, value) in enumerate(others):
if var == "__LABS_step":
if system:
yield f"\n<end {system}>"
Expand All @@ -102,12 +103,11 @@ def fmt(match, store_name, tid):
yield f"\n<{pprint_agent(info, agent)}: {func} '{info.lstig[int(value)].name}'>" # noqa: E501
elif var in ("firstAgent", "guessedcomp"):
agent = value
else:
if (len(others) > i + 1 and LSTIG.match(var) and
LTSTAMP.match(others[i + 1][0])):
pprint = pprint_assign(var, value, agent, endline=" ")
else:
pprint = pprint_assign(var, value, agent)
# If multiple assignments correspond to the same line, it's because
# we assigned to an array and CBMC is printing out the whole thing
elif last_line != line:
pprint = pprint_assign(var, value, agent)
last_line = line
if pprint:
yield pprint

Expand Down

0 comments on commit 75d8e56

Please sign in to comment.