Skip to content

Commit 2ff8e7a

Browse files
committed
Only use source_locationt's get_function() for user output
A source location is a place in a text file, and the function information stored in there need not coincide with the name we use in the goto model. Part 1: label_properties should use the actual function name so that properties in different instantiations of a function (as may happen when linking static functions) get unique names.
1 parent c7b962f commit 2ff8e7a

File tree

11 files changed

+55
-23
lines changed

11 files changed

+55
-23
lines changed

jbmc/src/jbmc/jbmc_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ void jbmc_parse_optionst::process_goto_function(
869869
if(using_symex_driven_loading)
870870
{
871871
// label the assertions
872-
label_properties(goto_function.body);
872+
label_properties(goto_function.body, function.get_function_id());
873873

874874
goto_function.body.update();
875875
function.compute_location_numbers();

regression/cbmc/unique_labels1/bar.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <assert.h>
2+
3+
static int foo()
4+
{
5+
assert(1 < 0);
6+
}
7+
8+
void bar()
9+
{
10+
foo();
11+
}

regression/cbmc/unique_labels1/main.c

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <assert.h>
2+
3+
static int foo()
4+
{
5+
assert(0);
6+
}
7+
8+
void bar();
9+
10+
int main()
11+
{
12+
foo();
13+
bar();
14+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
bar.c
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
9+
assertion\.2
10+
--
11+
Each of the assertions in the two functions named "foo" should have a unique
12+
prefix, and thus be numbered "<prefix>.assertion.1."

regression/contracts/function_check_04/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
main.c
33
--apply-code-contracts
44
^\[main.assertion.1\] .* assertion x == 0: SUCCESS$
5-
^\[foo.1\] line 9 .*: FAILURE$
5+
^\[__CPROVER_initialize.1\] line 9 .*: FAILURE$
66
^VERIFICATION FAILED$
77
--
88
--

src/goto-instrument/aggressive_slicer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void aggressive_slicert::doit()
9292
auto property_loc = find_property(p, goto_model.goto_functions);
9393
if(!property_loc.has_value())
9494
throw "unable to find property in call graph";
95-
note_functions_to_keep(property_loc.value().get_function());
95+
note_functions_to_keep(property_loc->first);
9696
}
9797

9898
// Add functions within distance of shortest path functions

src/goto-programs/set_properties.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void label_properties(goto_modelt &goto_model)
4747

4848
void label_properties(
4949
goto_programt &goto_program,
50+
const irep_idt &function_id,
5051
std::map<irep_idt, std::size_t> &property_counters)
5152
{
5253
for(goto_programt::instructionst::iterator
@@ -57,9 +58,7 @@ void label_properties(
5758
if(!it->is_assert())
5859
continue;
5960

60-
irep_idt function=it->source_location.get_function();
61-
62-
std::string prefix=id2string(function);
61+
std::string prefix = id2string(function_id);
6362
if(it->source_location.get_property_class()!="")
6463
{
6564
if(prefix!="")
@@ -87,10 +86,10 @@ void label_properties(
8786
}
8887
}
8988

90-
void label_properties(goto_programt &goto_program)
89+
void label_properties(goto_programt &goto_program, const irep_idt &function_id)
9190
{
9291
std::map<irep_idt, std::size_t> property_counters;
93-
label_properties(goto_program, property_counters);
92+
label_properties(goto_program, function_id, property_counters);
9493
}
9594

9695
void set_properties(
@@ -126,7 +125,7 @@ void label_properties(goto_functionst &goto_functions)
126125
it=goto_functions.function_map.begin();
127126
it!=goto_functions.function_map.end();
128127
it++)
129-
label_properties(it->second.body, property_counters);
128+
label_properties(it->second.body, it->first, property_counters);
130129
}
131130

132131
void make_assertions_false(goto_modelt &goto_model)

src/goto-programs/set_properties.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void make_assertions_false(goto_functionst &);
2626
void make_assertions_false(goto_modelt &);
2727

2828
void label_properties(goto_functionst &);
29-
void label_properties(goto_programt &);
29+
void label_properties(goto_programt &, const irep_idt &);
3030
void label_properties(goto_modelt &);
3131

3232
#endif // CPROVER_GOTO_PROGRAMS_SET_PROPERTIES_H

src/goto-programs/show_properties.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ Author: Daniel Kroening, [email protected]
2121
#include "goto_functions.h"
2222
#include "goto_model.h"
2323

24-
25-
optionalt<source_locationt> find_property(
26-
const irep_idt &property,
27-
const goto_functionst & goto_functions)
24+
optionalt<std::pair<irep_idt, source_locationt>>
25+
find_property(const irep_idt &property, const goto_functionst &goto_functions)
2826
{
2927
for(const auto &fct : goto_functions.function_map)
3028
{
@@ -36,7 +34,7 @@ optionalt<source_locationt> find_property(
3634
{
3735
if(ins.source_location.get_property_id() == property)
3836
{
39-
return ins.source_location;
37+
return std::make_pair(fct.first, ins.source_location);
4038
}
4139
}
4240
}

src/goto-programs/show_properties.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ void show_properties(
4646
/// \param property: irep_idt that identifies property
4747
/// \param goto_functions: program in which to search for
4848
/// the property
49-
/// \return optional<source_locationt> the location of the
49+
/// \return A pair of function identifier and source location of the
5050
/// property, if found.
51-
optionalt<source_locationt> find_property(
52-
const irep_idt &property,
53-
const goto_functionst &goto_functions);
51+
optionalt<std::pair<irep_idt, source_locationt>>
52+
find_property(const irep_idt &property, const goto_functionst &goto_functions);
5453

5554
/// \brief Collects the properties in the goto program into a `json_arrayt`
5655
/// \param json_properties: JSON array to hold the properties

src/goto-symex/symex_target_equation.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -992,14 +992,13 @@ irep_idt symex_target_equationt::SSA_stept::get_property_id() const
992992
else if(source.pc->is_goto())
993993
{
994994
// this is likely an unwinding assertion
995-
property_id = id2string(source.pc->source_location.get_function()) +
996-
".unwind." + std::to_string(source.pc->loop_number);
995+
property_id = id2string(source.function_id) + ".unwind." +
996+
std::to_string(source.pc->loop_number);
997997
}
998998
else if(source.pc->is_function_call())
999999
{
10001000
// this is likely a recursion unwinding assertion
1001-
property_id =
1002-
id2string(source.pc->source_location.get_function()) + ".recursion";
1001+
property_id = id2string(source.function_id) + ".recursion";
10031002
}
10041003
else
10051004
{

0 commit comments

Comments
 (0)