Skip to content

Commit 1360b78

Browse files
authored
Merge pull request #7589 from tautschnig/bugfixes/vector-name
C front-end: fix type2name for vectors
2 parents 9be731d + 05c3dea commit 1360b78

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

regression/ansi-c/gcc_vector2/main.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
typedef int __v4 __attribute__((__vector_size__(16)));
2+
typedef int __v8 __attribute__((__vector_size__(32)));
3+
typedef int __v16 __attribute__((__vector_size__(64)));
4+
5+
__v8 foo(__v16 __A)
6+
{
7+
union
8+
{
9+
__v8 __a[2];
10+
__v16 __v;
11+
} __u = {.__v = __A};
12+
return __u.__a[0];
13+
}
14+
15+
__v4 bar(__v8 __A)
16+
{
17+
union
18+
{
19+
__v4 __a[2];
20+
__v8 __v;
21+
} __u = {.__v = __A};
22+
return __u.__a[0];
23+
}
24+
25+
int main()
26+
{
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE gcc-only
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$
9+
--
10+
We previously got a spurious type conflict for both unions got the same tag name
11+
(as type2name did not correctly name vectors of different size).

regression/goto-instrument/bitfield_naming/test.desc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ main.c
33
--show-goto-functions --json-ui
44
^EXIT=0$
55
^SIGNAL=0$
6-
BF1\{U8\}\$U8\$\'b11\'
7-
BF1\{U8\}\$U8\$\'b22\'
8-
BF2\{U8\}\$U8\$\'b34\'
9-
BF4\{U8\}\$U8\$\'b58\'
6+
BF1\{U8\}\'b11\'
7+
BF1\{U8\}\'b22\'
8+
BF2\{U8\}\'b34\'
9+
BF4\{U8\}\'b58\'
1010
--
1111
--
1212

src/ansi-c/type2name.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ static std::string type2name(
245245
else if(type.id()==ID_c_bit_field)
246246
result+="BF"+pointer_offset_bits_as_string(type, ns);
247247
else if(type.id()==ID_vector)
248-
result+="VEC"+type.get_string(ID_size);
248+
{
249+
const constant_exprt &size = to_vector_type(type).size();
250+
const auto size_int = numeric_cast_v<mp_integer>(size);
251+
result += "VEC" + integer2string(size_int);
252+
}
249253
else
250254
throw "unknown type '"+type.id_string()+"' encountered";
251255

@@ -256,8 +260,7 @@ static std::string type2name(
256260
type2name(to_type_with_subtype(type).subtype(), ns, symbol_number);
257261
result+='}';
258262
}
259-
260-
if(type.has_subtypes())
263+
else if(type.has_subtypes())
261264
{
262265
result+='$';
263266
for(const typet &subtype : to_type_with_subtypes(type).subtypes())

0 commit comments

Comments
 (0)