Skip to content

Check _Static_assert#209

Open
sim642 wants to merge 11 commits intodevelopfrom
static-assert-check
Open

Check _Static_assert#209
sim642 wants to merge 11 commits intodevelopfrom
static-assert-check

Conversation

@sim642
Copy link
Member

@sim642 sim642 commented Jan 15, 2026

Closes #65.

This makes it much easier to write some tests, e.g. for #207.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the front-end to evaluate and enforce _Static_assert at CIL-time (including inside structs), and adds regression tests for passing/failing asserts.

Changes:

  • Represent struct members as a richer struct_decl AST to include _Static_assert inside struct/union bodies.
  • Evaluate _Static_assert expressions during CABS→CIL conversion and error out on failure / non-constant conditions.
  • Add new regression tests for failing _Static_assert cases (global/local/struct).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/testcil.pl Registers new failing _Static_assert tests in the C11 run suite.
test/small1/c11-static-assert.c Expands the passing static-assert coverage (including message-less form).
test/small1/c11-static-assert-fail1.c New failing global _Static_assert test.
test/small1/c11-static-assert-fail2.c New failing local _Static_assert test.
test/small1/c11-static-assert-fail3.c New failing struct-member _Static_assert test.
src/frontc/cabs.ml Adds struct_decl node and makes _Static_assert message optional.
src/frontc/cparser.mly Parses struct-member _Static_assert and supports C23 message-less form.
src/frontc/cabsvisit.ml Visits the new struct_decl AST shape and _Static_assert expressions.
src/frontc/cabs2cil.ml Enforces _Static_assert by constant-folding and erroring on failure.
src/frontc/cprint.ml Prints _Static_assert with optional message, including inside structs.
src/frontc/patch.ml Updates patch unification to account for struct_decl nodes.

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

sim642 and others added 4 commits March 12, 2026 15:21
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…e in struct_decl_list

Already handled by base case.
Also allowed static_assert_declaration without semicolon, which is wrong.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check whether static asserts actually hold at CIL-time

2 participants