Skip to content

Commit 8c8c6be

Browse files
committed
Support type attributes for enum, complex
1 parent 078d2dc commit 8c8c6be

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

regression/ansi-c/gcc_attributes6/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=0$

src/ansi-c/c_typecheck_type.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ void c_typecheck_baset::typecheck_type(typet &type)
109109
typecheck_type(type.subtype());
110110

111111
typet underlying_type=type.subtype();
112+
113+
// gcc allows this, but clang doesn't; it's a compiler hint only,
114+
// but we'll try to interpret it the GCC way
115+
if(underlying_type.id()==ID_c_enum_tag)
116+
{
117+
underlying_type=
118+
follow_tag(to_c_enum_tag_type(underlying_type)).subtype();
119+
120+
assert(underlying_type.id()==ID_signedbv ||
121+
underlying_type.id()==ID_unsignedbv);
122+
}
112123

113124
if(underlying_type.id()==ID_signedbv ||
114125
underlying_type.id()==ID_unsignedbv)
@@ -151,18 +162,20 @@ void c_typecheck_baset::typecheck_type(typet &type)
151162
// save the location
152163
result.add_source_location()=type.source_location();
153164

165+
if(type.subtype().id()==ID_c_enum_tag)
166+
{
167+
const irep_idt &tag_name=
168+
to_c_enum_tag_type(type.subtype()).get_identifier();
169+
170+
symbol_tablet::symbolst::iterator entry=
171+
symbol_table.symbols.find(tag_name);
172+
assert(entry!=symbol_table.symbols.end());
173+
174+
entry->second.type.subtype()=result;
175+
}
176+
154177
type=result;
155178
}
156-
else if(underlying_type.id()==ID_c_enum_tag ||
157-
underlying_type.id()==ID_complex)
158-
{
159-
// gcc allows this, but clang doesn't.
160-
// We ignore for now.
161-
if(underlying_type.id()==ID_c_enum_tag)
162-
type=follow_tag(to_c_enum_tag_type(underlying_type)).subtype();
163-
else
164-
type=type.subtype();
165-
}
166179
else if(underlying_type.id()==ID_floatbv)
167180
{
168181
typet result;
@@ -189,6 +202,25 @@ void c_typecheck_baset::typecheck_type(typet &type)
189202

190203
type=result;
191204
}
205+
else if(underlying_type.id()==ID_complex)
206+
{
207+
// gcc allows this, but clang doesn't -- see enums above
208+
typet result;
209+
210+
if(mode=="__SC__") // 32 bits
211+
result=float_type();
212+
else if(mode=="__DC__") // 64 bits
213+
result=double_type();
214+
else if(mode=="__TC__") // 128 bits
215+
result=gcc_float128_type();
216+
else // give up, just use subtype
217+
result=type.subtype();
218+
219+
// save the location
220+
result.add_source_location()=type.source_location();
221+
222+
type=complex_typet(result);
223+
}
192224
else
193225
{
194226
err_location(type);

0 commit comments

Comments
 (0)