Skip to content

Commit 25bd89d

Browse files
committed
label_properties: do not rely on source_locationt's get_function()
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. In this vein, 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 40e0123 commit 25bd89d

File tree

9 files changed

+52
-20
lines changed

9 files changed

+52
-20
lines changed

regression/cbmc/unique_labels1/bar.c

Lines changed: 11 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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+
}
Lines changed: 12 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ main.c
44
^EXIT=10$
55
^SIGNAL=0$
66
^\[main.assertion.1\] .* assertion x == 0: SUCCESS$
7-
^\[foo.1\] line 9 .*: FAILURE$
7+
^\[__CPROVER_initialize.1\] line 9 .*: FAILURE$
88
^VERIFICATION FAILED$
99
--
1010
--

src/goto-instrument/aggressive_slicer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void aggressive_slicert::doit()
100100
auto property_loc = find_property(p, goto_model.goto_functions);
101101
if(!property_loc.has_value())
102102
throw "unable to find property in call graph";
103-
note_functions_to_keep(property_loc.value().get_function());
103+
note_functions_to_keep(property_loc->first);
104104
}
105105

106106
// Add functions within distance of shortest path functions

src/goto-programs/set_properties.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,12 @@ void label_properties(
6767
it->source_location_nonconst().set_function(function_identifier);
6868
}
6969

70-
irep_idt function = it->source_location().get_function();
70+
PRECONDITION(!function_identifier.empty());
71+
std::string prefix = id2string(function_identifier);
7172

72-
std::string prefix=id2string(function);
7373
if(!it->source_location().get_property_class().empty())
7474
{
75-
if(!prefix.empty())
76-
prefix+=".";
75+
prefix += ".";
7776

7877
std::string class_infix =
7978
id2string(it->source_location().get_property_class());
@@ -84,8 +83,7 @@ void label_properties(
8483
prefix+=class_infix;
8584
}
8685

87-
if(!prefix.empty())
88-
prefix+=".";
86+
prefix += ".";
8987

9088
std::size_t &count=property_counters[prefix];
9189

src/goto-programs/show_properties.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ Author: Daniel Kroening, [email protected]
1919

2020
#include "goto_model.h"
2121

22-
optionalt<source_locationt> find_property(
23-
const irep_idt &property,
24-
const goto_functionst & goto_functions)
22+
optionalt<std::pair<irep_idt, source_locationt>>
23+
find_property(const irep_idt &property, const goto_functionst &goto_functions)
2524
{
2625
for(const auto &fct : goto_functions.function_map)
2726
{
@@ -33,7 +32,7 @@ optionalt<source_locationt> find_property(
3332
{
3433
if(ins.source_location().get_property_id() == property)
3534
{
36-
return ins.source_location();
35+
return std::make_pair(fct.first, ins.source_location());
3736
}
3837
}
3938
}

src/goto-programs/show_properties.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ void show_properties(
4545
/// \param property: irep_idt that identifies property
4646
/// \param goto_functions: program in which to search for
4747
/// the property
48-
/// \return optional<source_locationt> the location of the
48+
/// \return A pair of function identifier and source location of the
4949
/// property, if found.
50-
optionalt<source_locationt> find_property(
51-
const irep_idt &property,
52-
const goto_functionst &goto_functions);
50+
optionalt<std::pair<irep_idt, source_locationt>>
51+
find_property(const irep_idt &property, const goto_functionst &goto_functions);
5352

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

src/goto-symex/ssa_step.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,13 @@ irep_idt SSA_stept::get_property_id() const
197197
else if(source.pc->is_goto())
198198
{
199199
// this is likely an unwinding assertion
200-
property_id = id2string(source.pc->source_location().get_function()) +
201-
".unwind." + std::to_string(source.pc->loop_number);
200+
property_id = id2string(source.function_id) + ".unwind." +
201+
std::to_string(source.pc->loop_number);
202202
}
203203
else if(source.pc->is_function_call())
204204
{
205205
// this is likely a recursion unwinding assertion
206-
property_id =
207-
id2string(source.pc->source_location().get_function()) + ".recursion";
206+
property_id = id2string(source.function_id) + ".recursion";
208207
}
209208
else
210209
{

0 commit comments

Comments
 (0)