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.
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% -0.01%
===========================================
Files 1714 1714
Lines 189547 189556 +9
Branches 73 73
===========================================
+ Hits 152939 152946 +7
- Misses 36608 36610 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bda4114 to
74ab7ca
Compare
Done. |
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.
The shared logic of the unqualified and qualified productions (build
typeof(initializer), create the declaration, add the declarator and
initializer) is factored into a new ansi_c parser helper,
new_auto_type_declaration(), so the two productions cannot drift apart;
the qualifier list is merged into the typeof type inside the helper.
Test: the unqualified and qualified __auto_type cases share a single
directory, regression/ansi-c/gcc___auto_type1, which now checks that
plain, const, volatile, and const volatile __auto_type all parse and
that the qualifier is actually applied. Because
__builtin_types_compatible_p ignores top-level qualifiers, the
qualifier's effect is observed via typeof(&x), where the pointee
qualifier is significant; a dropped qualifier turns a static_assert into
a negative-width bit-field, i.e. a CONVERSION ERROR.
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
74ab7ca to
929f463
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.