Skip to content

Commit 55ce40e

Browse files
author
Thomas Kiley
authored
Merge pull request #167 from diffblue/goto_location_storing
[TYT-3] Store the original GOTO location in a GOTO binary
2 parents 71366aa + a12831a commit 55ce40e

File tree

13 files changed

+97
-1
lines changed

13 files changed

+97
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main(int argc, char **argv)
2+
{
3+
return 0;
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --store-goto-locations
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
Original GOTO location
7+
--
8+
--

src/analyses/ai.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ jsont ai_baset::output_json(
169169
location["sourceLocation"]=
170170
json_stringt(i_it->source_location.as_string());
171171
location["abstractState"]=find_state(i_it).output_json(*this, ns);
172+
auto original_location = i_it->source_location.get_goto_location();
173+
if(original_location!="")
174+
location["originalGOTOLocation"]=json_stringt(id2string(original_location));
172175

173176
// Ideally we need output_instruction_json
174177
std::ostringstream out;
@@ -228,6 +231,13 @@ xmlt ai_baset::output_xml(
228231
location.set_attribute(
229232
"source_location",
230233
i_it->source_location.as_string());
234+
auto original_location = i_it->source_location.get_goto_location();
235+
if(original_location!="")
236+
{
237+
location.set_attribute(
238+
"original_GOTO_Location",
239+
id2string(original_location));
240+
}
231241

232242
location.new_element(find_state(i_it).output_xml(*this, ns));
233243

src/goto-instrument/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SRC = accelerate/accelerate.cpp \
5151
undefined_functions.cpp \
5252
uninitialized.cpp \
5353
unwind.cpp \
54+
store_goto_location.cpp \
5455
wmm/abstract_event.cpp \
5556
wmm/cycle_collection.cpp \
5657
wmm/data_dp.cpp \

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Author: Daniel Kroening, [email protected]
9595
#include "model_argc_argv.h"
9696
#include "undefined_functions.h"
9797
#include "remove_function.h"
98+
#include "store_goto_location.h"
99+
98100
void goto_instrument_parse_optionst::eval_verbosity()
99101
{
100102
unsigned int v=8;
@@ -432,6 +434,14 @@ int goto_instrument_parse_optionst::doit()
432434
return 0;
433435
}
434436

437+
if(cmdline.isset("store-goto-locations"))
438+
{
439+
for(auto &function : goto_functions.function_map)
440+
{
441+
store_goto_locations(function.second.body);
442+
}
443+
}
444+
435445
if(cmdline.isset("check-call-sequence"))
436446
{
437447
do_remove_returns();

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Author: Daniel Kroening, [email protected]
7878
"(show-threaded)(list-calls-args)(print-path-lengths)" \
7979
"(undefined-function-is-assume-false)" \
8080
"(remove-function-body):" \
81+
"(store-goto-locations)" \
8182
"(remove-calls-nobody)"
8283

8384
class goto_instrument_parse_optionst:

src/goto-instrument/show_locations.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ void show_locations(
4545
l.new_element("file").data=id2string(source_location.get_file());
4646
l.new_element("function").data=
4747
id2string(source_location.get_function());
48+
l.new_element("original_goto_location").data=
49+
id2string(source_location.get_goto_location());
4850

4951
std::cout << xml << '\n';
5052
}
@@ -53,7 +55,9 @@ void show_locations(
5355
case ui_message_handlert::uit::PLAIN:
5456
std::cout << function_id << " "
5557
<< it->location_number << " "
56-
<< it->source_location << '\n';
58+
<< it->source_location << " "
59+
<< "(Original GOTO Location:" << " "
60+
<< it->source_location.get_goto_location() << ") \n";
5761
break;
5862

5963
default:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "store_goto_location.h"
2+
3+
#include <goto-programs/goto_program.h>
4+
#include <util/source_location.h>
5+
6+
void store_goto_locations(goto_programt &goto_program)
7+
{
8+
for(auto it=goto_program.instructions.begin();
9+
it!=goto_program.instructions.end();
10+
it++)
11+
{
12+
auto &source_location=it->source_location;
13+
auto location_number=it->location_number;
14+
15+
source_location.set_goto_location(location_number);
16+
}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*******************************************************************\
2+
3+
Module: Store the location of instructions in the GOTO binary
4+
5+
Author: Diffblue Limited (c) 2017
6+
7+
Date: August 2017
8+
9+
\*******************************************************************/
10+
11+
#ifndef CPROVER_GOTO_INSTRUMENT_STORE_GOTO_LOCATION_H
12+
#define CPROVER_GOTO_INSTRUMENT_STORE_GOTO_LOCATION_H
13+
14+
15+
#include <goto-programs/goto_program.h>
16+
17+
void store_goto_locations(goto_programt &goto_program);
18+
19+
#endif // CPROVER_GOTO_INSTRUMENT_STORE_GOTO_LOCATION_H

src/goto-programs/goto_program.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ std::ostream &goto_programt::output_instruction(
4949
const goto_program_templatet::instructiont &instruction) const
5050
{
5151
out << " // " << instruction.location_number << " ";
52+
auto original_location=instruction.source_location.get_goto_location();
53+
if(original_location!="")
54+
{
55+
out << "(Original GOTO location: " << original_location << ") ";
56+
}
5257

5358
if(!instruction.source_location.is_nil())
5459
out << instruction.source_location.as_string();

src/goto-programs/show_goto_functions_json.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ json_objectt show_goto_functions_jsont::convert(
6767
{
6868
instruction_entry["sourceLocation"]=
6969
json(instruction.code.source_location());
70+
71+
if(instruction.code.source_location().get_goto_location()!="")
72+
{
73+
instruction_entry["originalGOTOLocation"]=
74+
json_stringt(id2string(instruction.code.source_location().get_goto_location()));
75+
}
7076
}
7177

7278
std::ostringstream instruction_builder;

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ IREP_ID_ONE(cprover_string_to_upper_case_func)
810810
IREP_ID_ONE(cprover_string_trim_func)
811811
IREP_ID_ONE(cprover_string_value_of_func)
812812
IREP_ID_ONE(array_replace)
813+
IREP_ID_ONE(original_GOTO_location)
813814

814815
#undef IREP_ID_ONE
815816
#undef IREP_ID_TWO

src/util/source_location.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ class source_locationt:public irept
140140
return get_bool(ID_hide);
141141
}
142142

143+
void set_goto_location(unsigned location)
144+
{
145+
set(ID_original_GOTO_location, location);
146+
}
147+
148+
const irep_idt get_goto_location() const
149+
{
150+
return get(ID_original_GOTO_location);
151+
}
152+
143153
static bool is_built_in(const std::string &s)
144154
{
145155
std::string built_in1="<built-in-"; // "<built-in-additions>";

0 commit comments

Comments
 (0)