Skip to content

Commit 65f0ec0

Browse files
committed
Provide a source location when analysis finds constness is lost
1 parent 6f72d9b commit 65f0ec0

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
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/goto-programs/remove_function_pointers.cpp

Lines changed: 4 additions & 2 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
}

0 commit comments

Comments
 (0)