Skip to content

Commit d546c4b

Browse files
committed
Code contracts: add source location to function pointer contracts
The expression constructed in the parser never got a source location assigned, yet it was this sub-expression that was actually retained by type checking. Consequently, properties were printed without a source location.
1 parent 16240af commit d546c4b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

regression/contracts/function-pointer-contracts-replace/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
main.c
33
--replace-call-with-contract foo
4-
^\[precondition.\d+] Assert function pointer 'infun' obeys contract 'contract': SUCCESS$
4+
^\[precondition.\d+] file main.c line 19 Assert function pointer 'infun' obeys contract 'contract': SUCCESS$
55
^\[main.assertion.\d+].* assertion outfun1 == contract: SUCCESS$
66
^\[main.assertion.\d+].* assertion outfun2 == contract: SUCCESS$
77
^EXIT=0$

src/ansi-c/parser.y

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,6 +3303,7 @@ cprover_function_contract:
33033303
exprt tmp(ID_function_pointer_obeys_contract);
33043304
tmp.add_to_operands(std::move(parser_stack($3)));
33053305
tmp.add_to_operands(std::move(parser_stack($5)));
3306+
tmp.add_source_location()=parser_stack($$).source_location();
33063307
parser_stack($$).add_to_operands(std::move(tmp));
33073308
}
33083309
| TOK_CPROVER_REQUIRES_CONTRACT '(' unary_expression ',' unary_expression ')'
@@ -3312,6 +3313,7 @@ cprover_function_contract:
33123313
exprt tmp(ID_function_pointer_obeys_contract);
33133314
tmp.add_to_operands(std::move(parser_stack($3)));
33143315
tmp.add_to_operands(std::move(parser_stack($5)));
3316+
tmp.add_source_location()=parser_stack($$).source_location();
33153317
parser_stack($$).add_to_operands(std::move(tmp));
33163318
}
33173319
| cprover_contract_assigns

0 commit comments

Comments
 (0)