Skip to content

Commit bb1bae9

Browse files
authored
Merge pull request #2184 from tautschnig/human-readable-output
Cleanup and extend user-directed output
2 parents 1a4fc92 + 6f51513 commit bb1bae9

14 files changed

+141
-22
lines changed

src/analyses/does_remove_const.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ does_remove_constt::does_remove_constt(
3131

3232
/// A naive analysis to look for casts that remove const-ness from pointers.
3333
/// \return Returns true if the program contains a const-removing cast
34-
bool does_remove_constt::operator()() const
34+
std::pair<bool, source_locationt> does_remove_constt::operator()() const
3535
{
3636
for(const goto_programt::instructiont &instruction :
3737
goto_program.instructions)
@@ -49,16 +49,16 @@ bool does_remove_constt::operator()() const
4949
// const that the lhs
5050
if(!does_type_preserve_const_correctness(&lhs_type, &rhs_type))
5151
{
52-
return true;
52+
return {true, assign.find_source_location()};
5353
}
5454

5555
if(does_expr_lose_const(assign.rhs()))
5656
{
57-
return true;
57+
return {true, assign.rhs().find_source_location()};
5858
}
5959
}
6060

61-
return false;
61+
return {false, source_locationt()};
6262
}
6363

6464
/// Search the expression tree to look for any children that have the same base

src/analyses/does_remove_const.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class does_remove_constt
2222
{
2323
public:
2424
does_remove_constt(const goto_programt &goto_program, const namespacet &ns);
25-
bool operator()() const;
25+
std::pair<bool, source_locationt> operator()() const;
2626

2727
private:
2828
bool does_expr_lose_const(const exprt &expr) const;

src/cbmc/symex_bmc.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ void symex_bmct::symex_step(
3838

3939
if(!source_location.is_nil() && last_source_location!=source_location)
4040
{
41-
log.debug() << "BMC at file " << source_location.get_file() << " line "
42-
<< source_location.get_line() << " function "
43-
<< source_location.get_function() << log.eom;
41+
log.debug() << "BMC at " << source_location.as_string()
42+
<< " (depth " << state.depth << ')' << log.eom;
4443

4544
last_source_location=source_location;
4645
}

src/goto-programs/goto_trace.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,18 @@ std::string trace_value_binary(
122122
type.id()==ID_c_enum ||
123123
type.id()==ID_c_enum_tag)
124124
{
125-
return expr.get_string(ID_value);
125+
const std::string & str = expr.get_string(ID_value);
126+
127+
std::ostringstream oss;
128+
std::string::size_type i = 0;
129+
for(const auto c : str)
130+
{
131+
oss << c;
132+
if(++i % 8 == 0 && str.size() != i)
133+
oss << ' ';
134+
}
135+
136+
return oss.str();
126137
}
127138
else if(type.id()==ID_bool)
128139
{

src/goto-programs/json_goto_trace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void convert_decl(
8484
if(!json_location.is_null())
8585
json_assignment["sourceLocation"] = json_location;
8686

87-
std::string value_string, binary_string, type_string, full_lhs_string;
87+
std::string value_string, type_string, full_lhs_string;
8888
json_objectt full_lhs_value;
8989

9090
DATA_INVARIANT(

src/goto-programs/remove_const_function_pointers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ bool remove_const_function_pointerst::try_resolve_function_call(
160160
{
161161
if(simplified_expr.type().id()==ID_code)
162162
{
163-
resolved_functions.insert(simplified_expr);
163+
resolved_functions.insert(to_symbol_expr(simplified_expr));
164164
resolved=true;
165165
}
166166
else

src/goto-programs/remove_const_function_pointers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class typecast_exprt;
3232
class remove_const_function_pointerst:public messaget
3333
{
3434
public:
35-
typedef std::unordered_set<exprt, irep_hash> functionst;
35+
typedef std::unordered_set<symbol_exprt, irep_hash> functionst;
3636
typedef std::list<exprt> expressionst;
3737
remove_const_function_pointerst(
3838
message_handlert &message_handler,

src/goto-programs/remove_function_pointers.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ void remove_function_pointerst::remove_function_pointer(
285285
const exprt &pointer=function.op0();
286286
remove_const_function_pointerst::functionst functions;
287287
does_remove_constt const_removal_check(goto_program, ns);
288-
if(const_removal_check())
288+
const auto does_remove_const = const_removal_check();
289+
if(does_remove_const.first)
289290
{
290-
warning() << "Cast from const to non-const pointer found, only worst case"
291+
warning().source_location = does_remove_const.second;
292+
warning() << "cast from const to non-const pointer found, only worst case"
291293
<< " function pointer removal will be done." << eom;
292294
found_functions=false;
293295
}
@@ -341,10 +343,8 @@ void remove_function_pointerst::remove_function_pointer(
341343
if(t.first=="pthread_mutex_cleanup")
342344
continue;
343345

344-
symbol_exprt expr;
345-
expr.type()=t.second;
346-
expr.set_identifier(t.first);
347-
functions.insert(expr);
346+
symbol_exprt expr(t.first, t.second);
347+
functions.insert(expr);
348348
}
349349
}
350350

@@ -430,6 +430,25 @@ void remove_function_pointerst::remove_function_pointer(
430430
statistics().source_location=target->source_location;
431431
statistics() << "replacing function pointer by "
432432
<< functions.size() << " possible targets" << eom;
433+
434+
// list the names of functions when verbosity is at debug level
435+
conditional_output(
436+
debug(),
437+
[this, &functions](mstreamt &mstream) {
438+
mstream << "targets: ";
439+
440+
bool first = true;
441+
for(const auto &function : functions)
442+
{
443+
if(!first)
444+
mstream << ", ";
445+
446+
mstream << function.get_identifier();
447+
first = false;
448+
}
449+
450+
mstream << eom;
451+
});
433452
}
434453

435454
bool remove_function_pointerst::remove_function_pointers(

src/goto-programs/xml_goto_trace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void convert(
7676
if(xml_location.name!="")
7777
xml_assignment.new_element().swap(xml_location);
7878

79-
std::string value_string, binary_string, type_string,
79+
std::string value_string, type_string,
8080
full_lhs_string, full_lhs_value_string;
8181

8282
if(step.lhs_object_value.is_not_nil())

src/goto-symex/symex_assign.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Author: Daniel Kroening, [email protected]
1212
#include "goto_symex.h"
1313

1414
#include <util/byte_operators.h>
15-
#include <util/cprover_prefix.h>
16-
1715
#include <util/c_types.h>
16+
#include <util/cprover_prefix.h>
17+
#include <util/pointer_offset_size.h>
1818

1919
#include "goto_symex_state.h"
2020

@@ -251,6 +251,14 @@ void goto_symext::symex_assign_symbol(
251251
if(symbol.is_auxiliary)
252252
assignment_type=symex_targett::assignment_typet::HIDDEN;
253253

254+
log.conditional_output(
255+
log.debug(),
256+
[this, &ssa_lhs](messaget::mstreamt &mstream) {
257+
mstream << "Assignment to " << ssa_lhs.get_identifier()
258+
<< " [" << pointer_offset_bits(ssa_lhs.type(), ns) << " bits]"
259+
<< messaget::eom;
260+
});
261+
254262
target.assignment(
255263
tmp_guard.as_expr(),
256264
ssa_lhs,

0 commit comments

Comments
 (0)