Repository navigation
self-host: gen-c uses assert without #include <assert.h> in a module with no tests #6051
Description
Profile (read first)
You are working as Gamma (Compiler Core) on epic #5980: rewrite t27c in t27 itself.
The self-hosted core (specs/compiler/core/t27core.t27, PR #6041) must write exactly the
bytes t27c gen-c writes, so every gen-c defect is a defect the core has to refuse instead of
learn. Fixing it here is what lets the core grow. Rules for this task:
- Change the Rust emitter only inside the Boundary below.
gen/is generated: never hand-edit it. - Build with
cargo build --release -p t27cand use./target/release/t27cfrom the repository
root, not at27con PATH. - Write the regression test first and watch it fail on the unfixed compiler. Then fix, and
revert the fix once to watch the test go red again. Say in the PR that you did both. - Any other spec whose generated C changes must be listed in the PR by path, with one line on
why the new bytes are right. A silent corpus change is a failed task. - The PR body says
Closes #plus this issue's number andPart of #5980. ASCII only in source files.
Context
A function that calls assert in a module with no test block compiles to C that calls assert without including <assert.h>, so a C99 compiler rejects it (call to undeclared function 'assert'). The self-hosted core refuses assert outside a tested module (E_CALL).
Reproduce
cargo build --release -p t27c
printf 'module m;\nfn f(x: i64) -> i64 {\n assert(x > 0);\n return x;\n}\n' > /tmp/asrt.t27
./target/release/t27c gen-c /tmp/asrt.t27
Today the relevant output is:
assert((x > 0)); <- no #include <assert.h> anywhere in the file
Original checks (kept for history; the Queen does not run these)
-
./target/release/t27c gen-c /tmp/asrt.t27 | grep -c 'assert.h'prints at least1(today0)
-
./target/release/t27c gen-c /tmp/asrt.t27 > /tmp/asrt.c && cc -std=c99 -Werror=implicit-function-declaration -c -o /tmp/asrt.o /tmp/asrt.c; echo $?prints0
-
cargo test --release -p t27c --test genc_assert_includepasses
Original file list
bootstrap/src/compiler.rsbootstrap/tests/genc_assert_include.rs
Original scenarios
- Given
/tmp/asrt.t27written by the Reproduce block,
when./target/release/t27c gen-c /tmp/asrt.t27runs and its output is compiled withcc,
then the file compiles under-std=c99 -Werror=implicit-function-declaration.
Original requirements
- FR-001: the include MUST follow the use of
assert, not the presence of atestblock. - FR-900:
cargo test --release -p t27c --test genc_assert_includeMUST pass, and MUST fail with the fix reverted. - FR-901: if
bootstrap/tests/core_selfhost.rsexists on your base,cargo test --release -p t27c --test core_selfhostMUST still pass.
Queen-runnable restatement (2026-10-05)
The bee branch queen-6051 fixes bootstrap/src/compiler.rs and adds a Rust test, which the only-t27 rule refuses. Following specs/compiler/zig_test_shadowing.t27, the t27 part is a compiler rule spec that states when gen-c must include <assert.h>, with tests.
Boundary
specs/compiler/c_assert_include.t27
User Scenarios & Testing
- Given master, where gen-c adds
#include <assert.h>only when the module has atestblock (compiler.rs,has_tests), when the rule spec lands, thent27c test-reportruns its tests and they state that the include follows the use ofassert.
Requirements
- FR-001:
specs/compiler/c_assert_include.t27MUST declarefn needs_assert_include(uses_assert: bool, has_test_block: bool) -> boolthat returns true wheneveruses_assertis true, whateverhas_test_blockis, and MUST carry at least 2 tests, one of them the defect caseneeds_assert_include(true, false) == true. - FR-002: The change MUST NOT add or modify non-t27 hand-written code (specs/policy/own_language.t27).
- FR-003: A comment in the spec MUST name the reproduction from this issue (a function calling
assertin a module with notestblock) so the Rust fix can be checked against it later.
Success Criteria
grep -c 'fn needs_assert_include' specs/compiler/c_assert_include.t27prints1grep -cE '^[[:space:]]*test ' specs/compiler/c_assert_include.t27prints at least2t27c test-report specs/compiler/c_assert_include.t27 2>&1 | grep -cE '^ (FAIL +0|pass +[1-9][0-9]*)$'prints2
Activity
gHashTag commentedon Oct 5, 2026
The branch queen-6051 carries bootstrap/src/compiler.rs and bootstrap/tests/genc_assert_include.rs, hand-written Rust that cannot land under only-t27 without the owner-approved-foreign label. A t27 version is specs/compiler/c_assert_include.t27 stating that the include follows the use of assert, with tests including the defect case. The issue was restated to that scope; the branch is not deleted.
fix(gen-c): include <assert.h> where `assert` is used, not only with …
chore(seals): reseal specs whose gen-c output changed (Refs #6050 #6051
fix(gen-c): include <assert.h> where `assert` is used, not only with …
chore(seals): reseal specs whose gen-c output changed (Refs #6050 #6051
fix(gen-c): include <assert.h> where `assert` is used, not only with …
chore(seals): reseal specs whose gen-c output changed (Refs #6050 #6051