ansi-c: fix self-referential enum from __attribute__((mode)) fallback#9051
Open
tautschnig wants to merge 1 commit into
Open
ansi-c: fix self-referential enum from __attribute__((mode)) fallback#9051tautschnig wants to merge 1 commit into
tautschnig wants to merge 1 commit into
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 crash in the ANSI-C typechecker when handling enums with __attribute__((mode(...))) for non-special-cased mode names by preventing creation of a cyclic/self-referential underlying enum type.
Changes:
- Adjust enum
mode(...)fallback handling to use the already-resolved underlying bitvector type instead of the enum tag subtype. - Add a regression test covering both a special-cased mode (
__QI__) and a fallback mode name (byte).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/ansi-c/c_typecheck_type.cpp | Prevents cyclic enum underlying types by falling back to the resolved underlying bitvector type. |
| regression/ansi-c/gcc_enum_mode_attribute/test.desc | Adds a new regression test descriptor to ensure successful verification and no conversion errors/warnings for this case. |
| regression/ansi-c/gcc_enum_mode_attribute/main.c | Adds a C testcase reproducing the enum mode(...) scenario that previously triggered crashes during layout/alignment computation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
For an enum with __attribute__((mode(M))), when M is not one of the special-cased mode names (e.g. plain "byte" rather than "__byte__"), the handler fell back to `result = subtype`, where the subtype is the c_enum_tag. It then wrote that back as the enum symbol's underlying type, making the enum's underlying type its own tag -- a cyclic, malformed type. This later caused infinite recursion in alignment() (a stack-overflow segfault) and a to_bitvector_type precondition abort in pointer_offset_bits(), crashing goto-cc on real kernel objects (net/rxrpc/rxgk, rxkad, af_rxrpc via crypto/krb5 headers). Fall back to the already-resolved underlying bitvector type instead of the c_enum_tag subtype. For a non-enum bitvector subtype this is unchanged (underlying_type == subtype); for an enum subtype it uses the enum's underlying integer type, so no cycle is created. Regression test gcc_enum_mode_attribute covers a special-cased mode (__QI__) and a fall-back mode name (byte). Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
56d20ab to
a631ed4
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #9051 +/- ##
========================================
Coverage 80.68% 80.68%
========================================
Files 1714 1714
Lines 189501 189501
Branches 73 73
========================================
+ Hits 152902 152908 +6
+ Misses 36599 36593 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
For an enum with attribute((mode(M))), when M is not one of the special-cased mode names (e.g. plain "byte" rather than "byte"), the handler fell back to
result = subtype, where the subtype is the c_enum_tag. It then wrote that back as the enum symbol's underlying type, making the enum's underlying type its own tag -- a cyclic, malformed type. This later caused infinite recursion in alignment() (a stack-overflow segfault) and a to_bitvector_type precondition abort in pointer_offset_bits(), crashing goto-cc on real kernel objects (net/rxrpc/rxgk, rxkad, af_rxrpc via crypto/krb5 headers).Fall back to the already-resolved underlying bitvector type instead of the c_enum_tag subtype. For a non-enum bitvector subtype this is unchanged (underlying_type == subtype); for an enum subtype it uses the enum's underlying integer type, so no cycle is created.
Regression test gcc_enum_mode_attribute covers a special-cased mode (QI) and a fall-back mode name (byte).