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

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.
  • 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).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • 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
Comment on lines +1125 to +1128
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 thread src/ansi-c/parser.y
Comment on lines +1117 to +1136
| 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));
}
@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 (321ba11) to head (b657866).

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.
📢 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.

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>
@tautschnig tautschnig force-pushed the extract/ansi-c-parser-compat branch from 715f9ab to b657866 Compare June 19, 2026 08:30
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