ansi-c: support qualified __auto_type#9053
Conversation
|
All tests for |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates the ANSI-C parser to accept GCC’s qualified __auto_type declarations (e.g., const __auto_type x = init;) by treating them as qualified typeof(initializer) types, and adds a regression test to prevent future breakage.
Changes:
- Extend
declaring_listto parsetype_qualifier_list TOK_GCC_AUTO_TYPE ... = initializerand build atypeof(initializer)type merged with qualifiers. - Add a regression test that exercises
const __auto_typeand expects successful verification without parsing errors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ansi-c/parser.y | Adds a new grammar production + semantic action to support qualified __auto_type by rewriting to qualified typeof(initializer). |
| regression/ansi-c/auto_type_qualified/test.desc | Defines a regression test that must not emit parsing errors and must verify successfully. |
| regression/ansi-c/auto_type_qualified/main.c | Minimal C program using const __auto_type to validate parsing and type deduction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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); |
| | 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); | ||
|
|
||
| $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)); | ||
| } |
00e1abf to
e0ecfdc
Compare
e0ecfdc to
715f9ab
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #9053 +/- ##
========================================
Coverage 80.68% 80.68%
========================================
Files 1714 1714
Lines 189501 189510 +9
Branches 73 73
========================================
+ Hits 152902 152914 +12
+ Misses 36599 36596 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
GCC allows __auto_type with type qualifiers, e.g.
const __auto_type x = init;
which is equivalent to
const typeof(init) x = init;
The parser only had a production for the unqualified '__auto_type var =
init;' form, so a qualified __auto_type -- as used by the Linux 6.12
kernel in arch/x86/include/asm/string_64.h -- failed with a syntax
error.
Add a declaring_list production for
type_qualifier_list TOK_GCC_AUTO_TYPE declarator
post_declarator_attributes_opt '=' initializer
whose semantic action builds the typeof-of-initializer node and merges
the qualifier list into it, mirroring GCC's documented semantics.
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
715f9ab to
b657866
Compare
GCC allows __auto_type with type qualifiers, e.g.
const __auto_type x = init;
which is equivalent to
const typeof(init) x = init;
The parser only had a production for the unqualified '__auto_type var = init;' form, so a qualified __auto_type -- as used by the Linux 6.12 kernel in arch/x86/include/asm/string_64.h -- failed with a syntax error.
Add a declaring_list production for
type_qualifier_list TOK_GCC_AUTO_TYPE declarator
post_declarator_attributes_opt '=' initializer
whose semantic action builds the typeof-of-initializer node and merges the qualifier list into it, mirroring GCC's documented semantics.