Skip to content

Commit 9c54d37

Browse files
authored
Merge pull request #5282 from tautschnig/cpp-gcc-attribute
C++ front-end: support GCC type attributes
2 parents 5a41cb6 + 1d663f0 commit 9c54d37

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifdef __GNUC__
2+
typedef int my_int16_t __attribute__((__mode__(__HI__)));
3+
static_assert(sizeof(my_int16_t) == 2, "16 bit");
4+
#endif
5+
6+
int main()
7+
{
8+
return 0;
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.cpp
3+
-std=c++11
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

src/cpp/cpp_typecheck_type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ void cpp_typecheckt::typecheck_type(typet &type)
272272
{
273273
c_typecheck_baset::typecheck_type(type);
274274
}
275+
else if(type.id() == ID_gcc_attribute_mode)
276+
{
277+
c_typecheck_baset::typecheck_type(type);
278+
}
275279
else
276280
{
277281
error().source_location=type.source_location();

src/cpp/parse.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,7 @@ bool Parser::rAttribute(typet &t)
22622262

22632263
typet attr(ID_gcc_attribute_mode);
22642264
set_location(attr, tk);
2265-
attr.set(ID_size, name.get(ID_identifier));
2265+
attr.set(ID_size, to_cpp_name(name).get_base_name());
22662266
merge_types(attr, t);
22672267
break;
22682268
}
@@ -2880,7 +2880,7 @@ bool Parser::rDeclaratorWithInit(
28802880
bit_field_type.subtype().make_nil();
28812881
set_location(bit_field_type, tk);
28822882

2883-
// merge_types(bit_field_type, declarator.type());
2883+
merge_types(bit_field_type, dw.type());
28842884

28852885
return true;
28862886
}
@@ -3226,6 +3226,15 @@ bool Parser::rDeclarator(
32263226
}
32273227

32283228
optCvQualify(d_outer);
3229+
if(d_outer.is_not_nil() && !d_outer.has_subtypes())
3230+
{
3231+
merged_typet merged_type;
3232+
merged_type.move_to_subtypes(d_outer);
3233+
typet nil;
3234+
nil.make_nil();
3235+
merged_type.move_to_sub(nil);
3236+
d_outer.swap(merged_type);
3237+
}
32293238

32303239
#ifdef DEBUG
32313240
std::cout << std::string(__indent, ' ') << "Parser::rDeclarator2 13\n";

0 commit comments

Comments
 (0)