Skip to content

Fix wrong name __CPROVER_invariant of invariant clauses #7107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions regression/crangler/loop-invariant-01/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
int foo(int *arr, int size)
{
arr[0] = 0;
arr[size - 1] = 0;

for(int i = 0; i < 2; i++)
{
arr[i] = 0;
}

int i = 0;
while(i < 2)
{
arr[i] = 0;
i++;
}

return size < 10 ? 0 : arr[5];
}

int main()
{
int arr[10];
int retval = foo(arr, 10);
__CPROVER_assert(retval == arr[5], "should succeed");
return 0;
}
10 changes: 10 additions & 0 deletions regression/crangler/loop-invariant-01/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
test.json

^\s+while\(i \< 2\) \_\_CPROVER\_loop\_invariant
^EXIT=0$
^SIGNAL=0$
--
^\s+for\(int i = 0; i \< 2; i\+\+\) \_\_CPROVER
--
Annotate loop invariant only to the for-loop.
13 changes: 13 additions & 0 deletions regression/crangler/loop-invariant-01/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"sources": [
"main.c"
],
"functions": [
{
"foo": [
"while 1 invariant 1==1"
]
}
],
"output": "stdout"
}
26 changes: 26 additions & 0 deletions regression/crangler/loop-invariant-02/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
int foo(int *arr, int size)
{
arr[0] = 0;
arr[size - 1] = 0;
for(int i = 0; i < 2; i++)
{
arr[i] = 0;
}

int i = 0;
while(i < 2)
{
arr[i] = 0;
i++;
}

return size < 10 ? 0 : arr[5];
}

int main()
{
int arr[10];
int retval = foo(arr, 10);
__CPROVER_assert(retval == arr[5], "should succeed");
return 0;
}
10 changes: 10 additions & 0 deletions regression/crangler/loop-invariant-02/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
test.json

^\s+for\(int i = 0; i \< 2; i\+\+\) \_\_CPROVER\_loop\_invariant
^EXIT=0$
^SIGNAL=0$
--
^\s+while\(i \< 2\) \_\_CPROVER
--
Annotate loop invariant only to the while-loop.
13 changes: 13 additions & 0 deletions regression/crangler/loop-invariant-02/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"sources": [
"main.c"
],
"functions": [
{
"foo": [
"for 1 invariant 1==1"
]
}
],
"output": "stdout"
}
4 changes: 2 additions & 2 deletions src/crangler/c_wrangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ static void mangle_function(
auto t_end = match_bracket(t, '(', ')');
for(; t != t_end; t++)
out << t->text;
out << ' ' << CPROVER_PREFIX << "invariant(" << defines(invariant)
<< ')';
out << ' ' << CPROVER_PREFIX << "loop_invariant("
<< defines(invariant) << ')';
}
}
}
Expand Down