Skip to content

ansi-c: support qualified __auto_type#9053

Open
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:extract/ansi-c-parser-compat
Open

ansi-c: support qualified __auto_type#9053
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:extract/ansi-c-parser-compat

Conversation

@tautschnig

@tautschnig tautschnig commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

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.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig self-assigned this Jun 18, 2026
Copilot AI review requested due to automatic review settings June 18, 2026 15:50
@kroening

Copy link
Copy Markdown
Collaborator

All tests for __auto_type in one directory, please!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_list to parse type_qualifier_list TOK_GCC_AUTO_TYPE ... = initializer and build a typeof(initializer) type merged with qualifiers.
  • Add a regression test that exercises const __auto_type and 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.

Comment thread src/ansi-c/parser.y Outdated
Comment thread src/ansi-c/parser.y
@tautschnig tautschnig force-pushed the extract/ansi-c-parser-compat branch from 00e1abf to e0ecfdc Compare June 18, 2026 17:56
@tautschnig tautschnig force-pushed the extract/ansi-c-parser-compat branch from e0ecfdc to 715f9ab Compare June 18, 2026 18:55
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.68%. Comparing base (d452071) to head (929f463).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tautschnig tautschnig force-pushed the extract/ansi-c-parser-compat branch 3 times, most recently from bda4114 to 74ab7ca Compare June 23, 2026 08:32
@tautschnig

Copy link
Copy Markdown
Collaborator Author

All tests for __auto_type in one directory, please!

Done.

@tautschnig tautschnig assigned kroening and unassigned tautschnig Jun 23, 2026
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>
@tautschnig tautschnig force-pushed the extract/ansi-c-parser-compat branch from 74ab7ca to 929f463 Compare June 23, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants