Skip to content

Commit d877f19

Browse files
chrisr-diffblueChris Ryder
authored and
Chris Ryder
committed
WIP: Refine symbol well-formedness checks to handle special cases
1 parent f066e08 commit d877f19

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/util/symbol.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <ostream>
1212

13+
#include <iostream>
14+
1315
#include "source_location.h"
1416
#include "std_expr.h"
17+
#include "string_utils.h"
1518
#include "suffix.h"
1619

1720
/// Dump the state of a symbol object to a given output stream.
@@ -139,7 +142,51 @@ bool symbolt::is_well_formed() const
139142
// general name.
140143
if(!has_suffix(id2string(name), id2string(base_name)))
141144
{
142-
return false;
145+
bool criterion_must_hold = true;
146+
147+
// There are some special cases where this criterion doesn't hold, check
148+
// to see if we have one of those cases
149+
150+
if (is_type)
151+
{
152+
// Typedefs
153+
if (type.find(ID_C_typedef).is_not_nil())
154+
{
155+
// FIXME: Is there an additional check that can be made here, like for tag types below?
156+
criterion_must_hold = false;
157+
}
158+
159+
// Tag types
160+
if (type.find(ID_tag).is_not_nil() && type.find(ID_tag).id() == base_name)
161+
{
162+
criterion_must_hold = false;
163+
}
164+
}
165+
166+
// Linker renaming may have added $linkN suffixes to the name, and other
167+
// suffixes such as #return_value may have then be subsequently added.
168+
// Strip out the first $linkN substring and then see if the criterion holds
169+
170+
const auto split_name = split_string(id2string(name), '$');
171+
if(
172+
split_name.size() > 1 && has_prefix(split_name[1], "link")) // FIXME: Should loop for all delimited?
173+
{
174+
175+
size_t post_link_start = 4;
176+
while (post_link_start < split_name[1].size() && std::isdigit(split_name[1][post_link_start]))
177+
++post_link_start;
178+
179+
const auto stripped_name = split_name[0] + split_name[1].substr(post_link_start,split_name[1].size());
180+
181+
if (has_suffix(stripped_name, id2string(base_name)))
182+
criterion_must_hold = false;
183+
}
184+
185+
if (criterion_must_hold)
186+
{
187+
// For all other cases this criterion should hold
188+
return false;
189+
}
143190
}
144191

145192
return true;

0 commit comments

Comments
 (0)