Skip to content

Commit 25ba4e6

Browse files
tautschnigDaniel Kroening
authored and
Daniel Kroening
committed
Include tags in type-to-identifier conversion
Within the same translation unit multiple incomplete structs/unions with different names (tags) must be distinguished. Symbol numbering helps to keep untagged types unique, but for tagged ones we need to take their names into account. Fixes: diffblue#4019
1 parent c78f239 commit 25ba4e6

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
int main()
2+
{
3+
typedef struct onet
4+
{
5+
union {
6+
struct onet *next;
7+
} abc;
8+
} onet;
9+
10+
typedef struct twot
11+
{
12+
union {
13+
struct twot *next;
14+
} xyz;
15+
} twot;
16+
twot two;
17+
18+
two.xyz.next->xyz.next = 0;
19+
return 0;
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

src/ansi-c/type2name.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,40 +44,25 @@ static std::string type2name_tag(
4444
symbol->type.id()!=ID_union)
4545
return type2name(symbol->type, ns, symbol_number);
4646

47-
std::string result;
48-
4947
// assign each symbol a number when seen for the first time
5048
std::pair<symbol_numbert::iterator, bool> entry=
5149
symbol_number.insert(std::make_pair(
5250
identifier,
5351
std::make_pair(symbol_number.size(), true)));
5452

53+
std::string result = "SYM" +
54+
id2string(to_struct_union_type(symbol->type).get_tag()) +
55+
'#' + std::to_string(entry.first->second.first);
56+
5557
// new entry, add definition
5658
if(entry.second)
5759
{
58-
result="SYM#"+std::to_string(entry.first->second.first);
5960
result+="={";
6061
result+=type2name(symbol->type, ns, symbol_number);
6162
result+='}';
6263

6364
entry.first->second.second=false;
6465
}
65-
#if 0
66-
// in recursion, print the shorthand only
67-
else if(entry.first->second.second)
68-
result="SYM#"+std::to_string(entry.first->second.first);
69-
// entering recursion
70-
else
71-
{
72-
entry.first->second.second=true;
73-
result=type2name(symbol->type, ns, symbol_number);
74-
entry.first->second.second=false;
75-
}
76-
#else
77-
// shorthand only as structs/unions are always symbols
78-
else
79-
result="SYM#"+std::to_string(entry.first->second.first);
80-
#endif
8166

8267
return result;
8368
}

0 commit comments

Comments
 (0)