Skip to content

Support anonymous struct embedding via -fms-extensions#9022

Merged
tautschnig merged 1 commit into
diffblue:developfrom
chaosape:plan9-extensions
Jun 25, 2026
Merged

Support anonymous struct embedding via -fms-extensions#9022
tautschnig merged 1 commit into
diffblue:developfrom
chaosape:plan9-extensions

Conversation

@chaosape

@chaosape chaosape commented May 28, 2026

Copy link
Copy Markdown
Contributor

When -fms-extensions is passed, tagged struct/union members without a declarator name are treated as anonymous embedding (Plan 9 C extension). This allows code using the GCC extension where 'struct tag;' inside another struct inlines the tagged struct's fields.

The implementation lets the tagged anonymous member fall through to the existing anonymous member handling (the $anon naming + set_anonymous pass), rather than skipping it with 'continue'.

Only this one behavior is implemented — no other MSVC or Plan 9 extensions. The internal config field is named
allow_anonymous_struct_embedding to be explicit about scope.

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

@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.69%. Comparing base (7483d0d) to head (8206334).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #9022   +/-   ##
========================================
  Coverage    80.68%   80.69%           
========================================
  Files         1714     1714           
  Lines       189593   189596    +3     
  Branches        73       73           
========================================
+ Hits        152979   152987    +8     
+ Misses       36614    36609    -5     

☔ 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

Copy link
Copy Markdown
Collaborator

Could you please add test(s) and address the clang-format error for a start?

@tautschnig tautschnig force-pushed the plan9-extensions branch 2 times, most recently from 1382f80 to 167c93b Compare June 24, 2026 11:17
A *tagged* struct/union used as an unnamed (anonymous) member -- e.g.
the Linux kernel's `struct __filename_head;` embedded in struct filename
-- was silently dropped by the C front-end in GCC/Clang mode: it
contributed no bytes (so sizeof was wrong, breaking the kernel's
static_assert(sizeof(struct filename) % 64 == 0)) and its members were
not injected (inaccessible by name).

GCC/Clang accept this only with -fms-extensions (the Plan 9 C
extension); without it they ignore the member, matching the existing
regression/ansi-c/anonymous_member* tests. So:
- config: add ansi_c.allow_anonymous_struct_embedding (default false),
  named to be explicit that only this one MS/Plan 9 extension is
  implemented, not all of -fms-extensions;
- gcc_mode: set it when -fms-extensions is passed (queried as
  "fms-extensions" -- goto_cc_cmdlinet stores long options without the
  leading '-');
- c_typecheck_type: in GCC/Clang mode accept an *untagged* struct/union
  anonymous member always (C11) and a *tagged* one only under
  -fms-extensions; a non-struct/union unnamed member, or a tagged one
  without the flag, keeps the previous "ignore" behaviour.

With the flag the member now contributes its size and its fields are
injected (reachable by name). The new behaviour is documented in the
goto-cc section of the CPROVER manual, and exercised from both sides:
goto-gcc/ms_extensions_anonymous_member checks exact layout and member
access with the flag, and goto-gcc/ms_extensions_anonymous_member_ignored
checks the member is ignored without it. The existing anonymous_member*
tests confirm the default cbmc behaviour is preserved.

Co-authored-by: Michael Tautschnig <tautschn@amazon.com>
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig merged commit 1fedc90 into diffblue:develop Jun 25, 2026
43 checks passed
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