Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions regression/cbmc/auto_type_qualified/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
int main()
{
int s = 42;
// 'const __auto_type x = s;' is equivalent to 'const typeof(s) x = s;'.
// The parser previously only handled the unqualified
// '__auto_type x = s;' form and rejected the qualified one.
const __auto_type x = s;
__CPROVER_assert(
x == 42, "qualified __auto_type deduces the initializer type");
return 0;
}
10 changes: 10 additions & 0 deletions regression/cbmc/auto_type_qualified/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE gcc-only
main.c

^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
^PARSING ERROR$
^syntax error
20 changes: 20 additions & 0 deletions src/ansi-c/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,26 @@ declaring_list:
// add the initializer
to_ansi_c_declaration(parser_stack($$)).add_initializer(parser_stack($5));
}
| type_qualifier_list TOK_GCC_AUTO_TYPE declarator
post_declarator_attributes_opt '=' initializer
{
// Qualified __auto_type: 'const/volatile/... __auto_type
// var = initializer;' is equivalent to
// '<qualifiers> typeof(initializer) var = initializer;'.
// Build the typeof-of-initializer node, then wrap it with
// the qualifiers.
parser_stack($2).id(ID_typeof);
parser_stack($2).copy_to_operands(parser_stack($6));
// Merge qualifiers into the typeof type.
$2 = merge($1, $2);
Comment on lines +1125 to +1128

$3 = merge($4, $3);

init($$, ID_declaration);
parser_stack($$).type().swap(parser_stack($2));
PARSER.add_declarator(parser_stack($$), parser_stack($3));
to_ansi_c_declaration(parser_stack($$)).add_initializer(parser_stack($6));
}
Comment on lines +1117 to +1136
| declaring_list ',' gcc_type_attribute_opt declarator
post_declarator_attributes_opt
{
Expand Down
Loading