Skip to content

Commit 52b1b40

Browse files
authored
Merge pull request #7142 from tautschnig/features/CPROVER_ID
Test __CPROVER_ID support in the C front-end
2 parents 29d432c + 2367b39 commit 52b1b40

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

regression/cbmc/cprover_id1/main.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
3+
void foo()
4+
{
5+
static int local;
6+
local = 1;
7+
}
8+
9+
int main()
10+
{
11+
// foo::1::local is the fully qualified name generated by the C front-end at
12+
// this time. This is an implementation detail that could change at any time,
13+
// and the test would need to be adjusted accordingly.
14+
assert(__CPROVER_ID "foo::1::local" == 0);
15+
foo();
16+
assert(__CPROVER_ID "foo::1::local" == 1);
17+
}

regression/cbmc/cprover_id1/test.desc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
This test demonstrates the use of __CPROVER_ID to form identifier names that
11+
would not otherwise constitute syntactically identifiers in C code.

src/ansi-c/parser.y

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ identifier:
297297
TOK_IDENTIFIER
298298
| TOK_CPROVER_ID TOK_STRING
299299
{
300+
// construct an identifier from a string that would otherwise not be a
301+
// valid identifier in C
300302
$$=$1;
301303
parser_stack($$).id(ID_symbol);
302304
irep_idt value=parser_stack($2).get(ID_value);

0 commit comments

Comments
 (0)