Skip to content

Commit c166b39

Browse files
authored
Merge pull request #6902 from diffblue/label_properties_source_location
label_properties now generates a source location if there is none
2 parents d55ac1d + 3339de3 commit c166b39

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ void jbmc_parse_optionst::process_goto_function(
720720
if(using_symex_driven_loading)
721721
{
722722
// label the assertions
723-
label_properties(goto_function.body);
723+
label_properties(function.get_function_id(), goto_function.body);
724724

725725
goto_function.body.update();
726726
function.compute_location_numbers();

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

src/goto-programs/set_properties.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void label_properties(goto_modelt &goto_model)
4848
}
4949

5050
void label_properties(
51+
const irep_idt function_identifier,
5152
goto_programt &goto_program,
5253
std::map<irep_idt, std::size_t> &property_counters)
5354
{
@@ -59,6 +60,13 @@ void label_properties(
5960
if(!it->is_assert())
6061
continue;
6162

63+
// No source location? Create one.
64+
if(it->source_location().is_nil())
65+
{
66+
it->source_location_nonconst() = source_locationt{};
67+
it->source_location_nonconst().set_function(function_identifier);
68+
}
69+
6270
irep_idt function = it->source_location().get_function();
6371

6472
std::string prefix=id2string(function);
@@ -89,10 +97,10 @@ void label_properties(
8997
}
9098
}
9199

92-
void label_properties(goto_programt &goto_program)
100+
void label_properties(irep_idt function_identifier, goto_programt &goto_program)
93101
{
94102
std::map<irep_idt, std::size_t> property_counters;
95-
label_properties(goto_program, property_counters);
103+
label_properties(function_identifier, goto_program, property_counters);
96104
}
97105

98106
void set_properties(
@@ -127,5 +135,5 @@ void label_properties(goto_functionst &goto_functions)
127135
it=goto_functions.function_map.begin();
128136
it!=goto_functions.function_map.end();
129137
it++)
130-
label_properties(it->second.body, property_counters);
138+
label_properties(it->first, it->second.body, property_counters);
131139
}

src/goto-programs/set_properties.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ Author: Daniel Kroening, [email protected]
1212
#ifndef CPROVER_GOTO_PROGRAMS_SET_PROPERTIES_H
1313
#define CPROVER_GOTO_PROGRAMS_SET_PROPERTIES_H
1414

15+
#include <util/irep.h>
16+
1517
#include <list>
16-
#include <string>
1718

1819
class goto_functionst;
1920
class goto_modelt;
@@ -28,7 +29,7 @@ void set_properties(
2829
const std::list<std::string> &properties);
2930

3031
void label_properties(goto_functionst &);
31-
void label_properties(goto_programt &);
32+
void label_properties(irep_idt function_identifier, goto_programt &);
3233
void label_properties(goto_modelt &);
3334

3435
#endif // CPROVER_GOTO_PROGRAMS_SET_PROPERTIES_H

0 commit comments

Comments
 (0)