Skip to content

Commit

Permalink
Fixes printing of struct fields in ACSL contracts.
Browse files Browse the repository at this point in the history
  • Loading branch information
zafer-esen committed May 15, 2024
1 parent 0aad60c commit 2736b6c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
13 changes: 13 additions & 0 deletions regression-tests/horn-contracts/Answers
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,16 @@ UNSAFE

stackptr.hcc
UNKNOWN (Unsupported C fragment. Function contracts are currently not supported together with stack pointers (10:5))

struct-name-bug.hcc

Inferred ACSL annotations
================================================================================
/* contracts for foo */
/*@
requires s.f == 21;
ensures \old(s).f == 21 && 2*21 == \result;
*/
================================================================================

SAFE
3 changes: 2 additions & 1 deletion regression-tests/horn-contracts/runtests
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ TESTS="contract1.hcc \
takeuchi.hcc \
assert.hcc \
fib.hcc \
stackptr.hcc"
stackptr.hcc \
struct-name-bug.hcc"

for name in $TESTS; do
echo
Expand Down
15 changes: 15 additions & 0 deletions regression-tests/horn-contracts/struct-name-bug.hcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
struct S {
int f;
};

/*@ contract @*/
int foo(struct S s) {
return s.f*2;
}

int main() {
struct S s;
s.f = 21;
assert(foo(s) == 42);
return 0;
}
2 changes: 1 addition & 1 deletion src/tricera/postprocessor/ACSLLineariser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object ACSLLineariser {
def asString(e : IExpression) : String =
ap.DialogUtil.asString { printExpression(e) }

private def fun2Identifier(fun : IFunction) = fun.name
private def fun2Identifier(fun : IFunction) = fun.name.split("::").last

//////////////////////////////////////////////////////////////////////////////

Expand Down

0 comments on commit 2736b6c

Please sign in to comment.