Skip to content

Simplify member access into a compound literal#9060

Open
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:extract/simplify-member-compound-literal
Open

Simplify member access into a compound literal#9060
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:extract/simplify-member-compound-literal

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

simplify_member now folds member(compound_literal(v), .m) by unwrapping the compound literal to its single initializer operand v and recursing, so the existing struct/union member-extraction rules apply.

This fixes a constant-folding gap that made the C front-end reject valid constant static initializers nesting a compound literal: the kernel's dynamic-debug _ddebug descriptor initialises its .key union from the STATIC_KEY_FALSE_INIT compound literal (under CONFIG_JUMP_LABEL), which projected to member(compound_literal{...}, .key.enabled.counter). That member-of-compound-literal was not simplified, so make_constant's is_compile_time_constantt rejected it with "expected constant expression" -- blocking goto-cc on every linux-6.12 translation unit that uses dynamic debug (sound/usb, fs/hfsplus, fs/jfs, ...). With the fix sound/usb/format.c (and the rest) goto-cc cleanly.

regression/ansi-c/compound_literal_member_static reproduces the _ddebug shape (a static struct whose union field is initialised from a compound literal) and checks the projected member folds to its constant.

  • 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:54

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.

Fixes a constant-folding gap in the C front-end by simplifying member access on compound literals so nested static initializers (e.g., Linux kernel dynamic-debug _ddebug patterns) typecheck and constant-fold correctly.

Changes:

  • Extend simplify_member to unwrap single-operand compound_literal expressions and recurse, enabling existing struct/union member folding.
  • Add a regression test reproducing a static initializer that projects through a union member from a compound literal.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/util/simplify_expr_struct.cpp Unwraps member(compound_literal(v), .m) into member(v, .m) and reuses existing folding logic.
regression/ansi-c/compound_literal_member_static/test.desc Registers a new CORE regression test for the compound-literal member folding case.
regression/ansi-c/compound_literal_member_static/main.c Adds a C repro mirroring the kernel _ddebug initializer shape and asserts the folded constant.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tautschnig tautschnig force-pushed the extract/simplify-member-compound-literal branch from a969923 to 2f90b71 Compare June 18, 2026 19:24
@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.69%. Comparing base (321ba11) to head (3c0f01c).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9060      +/-   ##
===========================================
+ Coverage    80.68%   80.69%   +0.01%     
===========================================
  Files         1714     1714              
  Lines       189501   189505       +4     
  Branches        73       73              
===========================================
+ Hits        152902   152925      +23     
+ Misses       36599    36580      -19     

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

simplify_member now folds `member(compound_literal(v), .m)` by
unwrapping the compound literal to its single initializer operand `v`
and recursing, so the existing struct/union member-extraction rules
apply.

This fixes a constant-folding gap that made the C front-end reject valid
constant static initializers nesting a compound literal: the kernel's
dynamic-debug `_ddebug` descriptor initialises its `.key` union from the
`STATIC_KEY_FALSE_INIT` compound literal (under CONFIG_JUMP_LABEL),
which projected to `member(compound_literal{...},
.key.enabled.counter)`.  That member-of-compound-literal was not
simplified, so make_constant's is_compile_time_constantt rejected it
with "expected constant expression" -- blocking goto-cc on every
linux-6.12 translation unit that uses dynamic debug (sound/usb,
fs/hfsplus, fs/jfs, ...).  With the fix sound/usb/format.c (and the
rest) goto-cc cleanly.

regression/ansi-c/compound_literal_member_static reproduces the _ddebug
shape (a static struct whose union field is initialised from a compound
literal) and checks the projected member folds to its constant.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig force-pushed the extract/simplify-member-compound-literal branch from 2f90b71 to 3c0f01c Compare June 19, 2026 08:12
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.

2 participants