Skip to content

Commit ffbf8be

Browse files
authored
Merge pull request #4916 from MatWise/bugfix/stl-goto-conversion
STL frontend: Fix goto conversion issues
2 parents bfd1f5c + 3eb4962 commit ffbf8be

File tree

5 files changed

+43
-42
lines changed

5 files changed

+43
-42
lines changed

src/goto-programs/goto_convert_functions.cpp

+33-32
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Date: June 2003
2222

2323
goto_convert_functionst::goto_convert_functionst(
2424
symbol_table_baset &_symbol_table,
25-
message_handlert &_message_handler):
26-
goto_convertt(_symbol_table, _message_handler)
25+
message_handlert &_message_handler)
26+
: goto_convertt(_symbol_table, _message_handler)
2727
{
2828
}
2929

@@ -44,7 +44,9 @@ void goto_convert_functionst::goto_convert(goto_functionst &functions)
4444
!symbol_pair.second.is_type && !symbol_pair.second.is_macro &&
4545
symbol_pair.second.type.id() == ID_code &&
4646
(symbol_pair.second.mode == ID_C || symbol_pair.second.mode == ID_cpp ||
47-
symbol_pair.second.mode == ID_java || symbol_pair.second.mode == "jsil"))
47+
symbol_pair.second.mode == ID_java ||
48+
symbol_pair.second.mode == "jsil" ||
49+
symbol_pair.second.mode == ID_statement_list))
4850
{
4951
symbol_list.push_back(symbol_pair.first);
5052
}
@@ -57,8 +59,8 @@ void goto_convert_functionst::goto_convert(goto_functionst &functions)
5759

5860
functions.compute_location_numbers();
5961

60-
// this removes the parse tree of the bodies from memory
61-
#if 0
62+
// this removes the parse tree of the bodies from memory
63+
#if 0
6264
for(const auto &symbol_pair, symbol_table.symbols)
6365
{
6466
if(!symbol_pair.second.is_type &&
@@ -68,7 +70,7 @@ void goto_convert_functionst::goto_convert(goto_functionst &functions)
6870
symbol_pair.second.value=codet();
6971
}
7072
}
71-
#endif
73+
#endif
7274
}
7375

7476
bool goto_convert_functionst::hide(const goto_programt &goto_program)
@@ -87,7 +89,7 @@ void goto_convert_functionst::add_return(
8789
goto_functionst::goto_functiont &f,
8890
const source_locationt &source_location)
8991
{
90-
#if 0
92+
#if 0
9193
if(!f.body.instructions.empty() &&
9294
f.body.instructions.back().is_return())
9395
return; // not needed, we have one already
@@ -97,12 +99,11 @@ void goto_convert_functionst::add_return(
9799
f.body.instructions.back().is_goto() &&
98100
f.body.instructions.back().guard.is_true())
99101
return;
100-
#else
102+
#else
101103

102104
if(!f.body.instructions.empty())
103105
{
104-
goto_programt::const_targett last_instruction=
105-
f.body.instructions.end();
106+
goto_programt::const_targett last_instruction = f.body.instructions.end();
106107
last_instruction--;
107108

108109
while(true)
@@ -120,16 +121,17 @@ void goto_convert_functionst::add_return(
120121
return;
121122

122123
// advance if it's a 'dead' without branch target
123-
if(last_instruction->is_dead() &&
124-
last_instruction!=f.body.instructions.begin() &&
125-
!last_instruction->is_target())
124+
if(
125+
last_instruction->is_dead() &&
126+
last_instruction != f.body.instructions.begin() &&
127+
!last_instruction->is_target())
126128
last_instruction--;
127129
else
128130
break; // give up
129131
}
130132
}
131133

132-
#endif
134+
#endif
133135

134136
side_effect_expr_nondett rhs(f.type.return_type(), source_location);
135137

@@ -141,22 +143,23 @@ void goto_convert_functionst::convert_function(
141143
const irep_idt &identifier,
142144
goto_functionst::goto_functiont &f)
143145
{
144-
const symbolt &symbol=ns.lookup(identifier);
146+
const symbolt &symbol = ns.lookup(identifier);
145147
const irep_idt mode = symbol.mode;
146148

147149
if(f.body_available())
148150
return; // already converted
149151

150152
// make tmp variables local to function
151-
tmp_symbol_prefix=id2string(symbol.name)+"::$tmp";
153+
tmp_symbol_prefix = id2string(symbol.name) + "::$tmp";
152154

153155
// store the parameter identifiers in the goto functions
154156
const code_typet &code_type = to_code_type(symbol.type);
155157
f.type = code_type;
156158
f.set_parameter_identifiers(code_type);
157159

158-
if(symbol.value.is_nil() ||
159-
symbol.is_compiled()) /* goto_inline may have removed the body */
160+
if(
161+
symbol.value.is_nil() ||
162+
symbol.is_compiled()) /* goto_inline may have removed the body */
160163
return;
161164

162165
// we have a body, make sure all parameter names are valid
@@ -172,25 +175,24 @@ void goto_convert_functionst::convert_function(
172175
lifetime = identifier == INITIALIZE_FUNCTION ? lifetimet::STATIC_GLOBAL
173176
: lifetimet::AUTOMATIC_LOCAL;
174177

175-
const codet &code=to_code(symbol.value);
178+
const codet &code = to_code(symbol.value);
176179

177180
source_locationt end_location;
178181

179-
if(code.get_statement()==ID_block)
180-
end_location=to_code_block(code).end_location();
182+
if(code.get_statement() == ID_block)
183+
end_location = to_code_block(code).end_location();
181184
else
182185
end_location.make_nil();
183186

184187
goto_programt tmp_end_function;
185188
goto_programt::targett end_function =
186189
tmp_end_function.add(goto_programt::make_end_function(end_location));
187190

188-
targets=targetst();
191+
targets = targetst();
189192
targets.set_return(end_function);
190-
targets.has_return_value=
191-
f.type.return_type().id()!=ID_empty &&
192-
f.type.return_type().id()!=ID_constructor &&
193-
f.type.return_type().id()!=ID_destructor;
193+
targets.has_return_value = f.type.return_type().id() != ID_empty &&
194+
f.type.return_type().id() != ID_constructor &&
195+
f.type.return_type().id() != ID_destructor;
194196

195197
goto_convert_rec(code, f.body, mode);
196198

@@ -199,12 +201,13 @@ void goto_convert_functionst::convert_function(
199201
add_return(f, end_location);
200202

201203
// handle SV-COMP's __VERIFIER_atomic_
202-
if(!f.body.instructions.empty() &&
203-
has_prefix(id2string(identifier), "__VERIFIER_atomic_"))
204+
if(
205+
!f.body.instructions.empty() &&
206+
has_prefix(id2string(identifier), "__VERIFIER_atomic_"))
204207
{
205208
goto_programt::instructiont a_begin;
206209
a_begin = goto_programt::make_atomic_begin();
207-
a_begin.source_location=f.body.instructions.front().source_location;
210+
a_begin.source_location = f.body.instructions.front().source_location;
208211
f.body.insert_before_swap(f.body.instructions.begin(), a_begin);
209212

210213
goto_programt::targett a_end =
@@ -231,9 +234,7 @@ void goto_convert_functionst::convert_function(
231234
lifetime = parent_lifetime;
232235
}
233236

234-
void goto_convert(
235-
goto_modelt &goto_model,
236-
message_handlert &message_handler)
237+
void goto_convert(goto_modelt &goto_model, message_handlert &message_handler)
237238
{
238239
symbol_table_buildert symbol_table_builder =
239240
symbol_table_buildert::wrap(goto_model.symbol_table);

src/statement-list/statement_list_entry_point.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static void add_main_function_block_call(
108108
id2string(data_block_interface.get_base_name()) + DB_ENTRY_POINT_POSTFIX;
109109
instance_data_block.type = data_block_interface.type().subtype();
110110
instance_data_block.is_static_lifetime = true;
111-
instance_data_block.mode = STATEMENT_LIST_MODE;
111+
instance_data_block.mode = ID_statement_list;
112112
symbol_table.add(instance_data_block);
113113
const address_of_exprt data_block_ref{instance_data_block.symbol_expr()};
114114

@@ -124,6 +124,7 @@ static void generate_statement_list_init_function(symbol_tablet &symbol_table)
124124
{
125125
symbolt init;
126126
init.name = INITIALIZE_FUNCTION;
127+
init.mode = ID_statement_list;
127128
init.type = code_typet({}, empty_typet{});
128129

129130
code_blockt dest;

src/statement-list/statement_list_typecheck.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void statement_list_typecheckt::typecheck_function_block_declaration(
118118
function_block_sym.name = function_block.name;
119119
function_block_sym.base_name = function_block_sym.name;
120120
function_block_sym.pretty_name = function_block_sym.name;
121-
function_block_sym.mode = STATEMENT_LIST_MODE;
121+
function_block_sym.mode = ID_statement_list;
122122

123123
// When calling function blocks, the passed parameters are value-copied to a
124124
// corresponding instance data block. This block contains all input, inout,
@@ -134,7 +134,7 @@ void statement_list_typecheckt::typecheck_function_block_declaration(
134134
data_block.name =
135135
id2string(function_block_sym.name) + DATA_BLOCK_TYPE_POSTFIX;
136136
data_block.base_name = data_block.name;
137-
data_block.mode = STATEMENT_LIST_MODE;
137+
data_block.mode = ID_statement_list;
138138
symbol_table.add(data_block);
139139

140140
// Create and add parameter symbol.
@@ -146,7 +146,7 @@ void statement_list_typecheckt::typecheck_function_block_declaration(
146146
param_sym.name = param.get_identifier();
147147
param_sym.base_name = DATA_BLOCK_PARAMETER_NAME;
148148
param_sym.pretty_name = param_sym.base_name;
149-
param_sym.mode = STATEMENT_LIST_MODE;
149+
param_sym.mode = ID_statement_list;
150150
symbol_table.add(param_sym);
151151

152152
// Setup FB symbol type and value.
@@ -166,7 +166,7 @@ void statement_list_typecheckt::typecheck_function_declaration(
166166
function_sym.name = function.name;
167167
function_sym.base_name = function_sym.name;
168168
function_sym.pretty_name = function_sym.name;
169-
function_sym.mode = STATEMENT_LIST_MODE;
169+
function_sym.mode = ID_statement_list;
170170
code_typet::parameterst params;
171171
typecheck_function_var_decls(
172172
function.var_input, params, function.name, ID_statement_list_var_input);
@@ -192,7 +192,7 @@ void statement_list_typecheckt::typecheck_tag_list()
192192
tag_sym.base_name = tag_sym.name;
193193
tag_sym.pretty_name = tag_sym.name;
194194
tag_sym.type = tag.type();
195-
tag_sym.mode = STATEMENT_LIST_MODE;
195+
tag_sym.mode = ID_statement_list;
196196
symbol_table.add(tag_sym);
197197
}
198198
}
@@ -245,7 +245,7 @@ void statement_list_typecheckt::typecheck_function_var_decls(
245245
"::" + id2string(declaration.variable.get_identifier());
246246
param_sym.base_name = declaration.variable.get_identifier();
247247
param_sym.pretty_name = param_sym.base_name;
248-
param_sym.mode = STATEMENT_LIST_MODE;
248+
param_sym.mode = ID_statement_list;
249249
symbol_table.add(param_sym);
250250

251251
code_typet::parametert param{declaration.variable.type()};
@@ -269,7 +269,7 @@ void statement_list_typecheckt::typecheck_temp_var_decls(
269269
temp_sym.base_name = declaration.variable.get_identifier();
270270
temp_sym.pretty_name = temp_sym.base_name;
271271
temp_sym.type = declaration.variable.type();
272-
temp_sym.mode = STATEMENT_LIST_MODE;
272+
temp_sym.mode = ID_statement_list;
273273
temp_sym.module = module;
274274
symbol_table.add(temp_sym);
275275

src/statement-list/statement_list_typecheck.h

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Author: Matthias Weiss, [email protected]
1717

1818
#include "statement_list_parse_tree.h"
1919

20-
#define STATEMENT_LIST_MODE "Statement List"
21-
2220
/// Create a new statement_list_typecheckt object and perform a type check to
2321
/// fill the symbol table.
2422
/// \param parse_tree: Parse tree generated by parsing a Statement List file.

src/util/irep_ids.def

+1
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ IREP_ID_ONE(__sync_or_and_fetch)
762762
IREP_ID_ONE(__sync_sub_and_fetch)
763763
IREP_ID_ONE(__sync_val_compare_and_swap)
764764
IREP_ID_ONE(__sync_xor_and_fetch)
765+
IREP_ID_TWO(statement_list, Statement List)
765766
IREP_ID_ONE(statement_list_type)
766767
IREP_ID_ONE(statement_list_function)
767768
IREP_ID_ONE(statement_list_function_block)

0 commit comments

Comments
 (0)