Simplify member access into a compound literal#9060
Open
tautschnig wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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_memberto unwrap single-operandcompound_literalexpressions 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.
a969923 to
2f90b71
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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>
2f90b71 to
3c0f01c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
simplify_member now folds
member(compound_literal(v), .m)by unwrapping the compound literal to its single initializer operandvand 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
_ddebugdescriptor initialises its.keyunion from theSTATIC_KEY_FALSE_INITcompound literal (under CONFIG_JUMP_LABEL), which projected tomember(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.