You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
emit-c silently skips all non-Vec destructors (Drop emitted as comment) #983
Silent backend semantic divergence (audit finding CCGEN-002). LLVM-vs-C behavioral split with no diagnostic and no documented limitation.
Source chain
StmtKind.Drop (src/CCodegen.w:8155-8160) and TK_DROP_AND_GOTO (:8232-8241) emit /* drop(p); */ COMMENTS for every non-Vec type — the C backend runs NO user destructors (files, sockets, mutexes, Boxes) and frees nothing. requirements.md calls --emit-c THE C source backend for bootstrapping new platforms, i.e. a real execution path, not a debug view; no documented limitation was found. Mission-level leak/defect gap on the C path, plus behavior divergence (RAII guards that release on LLVM never release on C).
Repair boundary
Either implement drop glue in the C backend or make --emit-c refuse programs with non-Vec Drop obligations loudly (and document the lane's exact semantic subset).
Verdict. Established on current main by running both backends. For every non-Vec type, the C backend emits /* drop(p); */ as a comment for StmtKind.Drop and TK_DROP_AND_GOTO, so user Drop impls never run and nothing they own is released. The LLVM binary and the C binary of the same program produce different output, and --emit-c reports success with no diagnostic. The report's framing (silent semantic divergence with no documented limitation) holds; docs/requirements.md line 11193 describes --emit-c as "C source backend, used for bootstrapping new platforms", and docs/with-build.md line 328 as "emit C (cross-compilation)", neither of which mentions a destructor subset.
Tested revision and compiler
item
value
source
main @ 5809ac1 (2026-09-14); the two /* drop( sites are unchanged since 450733e
compiler
with build of 5809ac1 in a detached worktree, self-reports with v0.15.2.1
C compiler for the emitted source
Apple cc, linked against the worktree's own out/lib/{rt_core,rt_darwin_aarch64,compat_runtime,panic_runtime,fiber_stubs,cimport_stubs}.o, the same object set build/emit_c.w:582-587 uses
platform
macOS Darwin 25.6.0, arm64
Repro
type Guard { name: str }
impl Drop for Guard:
move fn drop():
print("drop " ++ self.name)
fn make(n: str) -> Guard: Guard { name: n }
fn main:
let a = make("a")
if true:
let b = make("b")
print("inner")
var v: Vec[i32] = Vec.new()
v.push(1)
print("vec")
print("end")
backend
output
with run drop3.w (LLVM)
inner, drop b, vec, end, drop a
with build drop3.w --emit-c (rc 0, warnings only), then cc + runtime objects, run
inner, vec, end
In the emitted C: Guard_drop__13904 is declared and defined but has zero call sites; main's block bb6 contains /* drop(_3); */ where the LLVM path runs b's destructor; the Vec is handled ((with_vec){0} / with_vec_clear).
Two notes for repeaters: --emit-c must be run from a tree with the generated std.re modules (a scratch cwd fails with "import module not found: std.re.defs"), and a Vec literal makes the backend fail loudly with "emit-c does not support generic intrinsic __collection_literal", which is the correct behaviour this issue asks for on the drop path.
Source
src/CCodegen.w:8146-8151: StmtKind.Drop emits with_vec_clear only for CC_PSEUDO_TID_VEC; every other type gets the comment.
Contrast :8154 (self.fail("unsupported statement kind")) and :8234 (self.fail("unsupported terminator kind")): the fail-loud plumbing exists in the same function and is bypassed for drops.
docs/mission.md line 9: an allocation "is released when the scope ends ... With calls [leaking] a defect". AGENTS.md §No Silent Fallbacks: "Silently dropping a clause, arm, or statement the translator can't lower" is forbidden, and emitting a comment in place of a statement is that exactly. No decision-log entry scopes the C backend to a drop-free subset.
Related PRs
None merged or open address drop emission in the C backend.
Would I champion a fix? Yes.
Either path is acceptable; silence is not. Acceptance criteria:
Preferred: the C backend emits a call to the type's drop glue (the same Drop dispatch the LLVM backend uses, including field drops) for StmtKind.Drop and TK_DROP_AND_GOTO; the repro prints identical output on both backends, and the emit-c roundtrip lane (:emit-c-roundtrip) proves it on the compiler itself.
Minimum: self.fail("emit-c does not support Drop for <type>") at both sites for any non-Vec type that needs a drop, so --emit-c exits non-zero on the repro, plus a sentence in docs/with-build.md naming the subset.
A behaviour test that builds a small Drop program through both backends and compares stdout.
Untested
Linux and Windows not executed. Whether types with Drop reach the C backend in the compiler's own self-host lane (and therefore leak or skip cleanup there) was not measured; with the compiler's use of Mutex, JsonDocument, and file handles it almost certainly does.
Activity
ehartford commentedon Sep 16, 2026
Review: reproduced
Verdict. Established on current
mainby running both backends. For every non-Vectype, the C backend emits/* drop(p); */as a comment forStmtKind.DropandTK_DROP_AND_GOTO, so userDropimpls never run and nothing they own is released. The LLVM binary and the C binary of the same program produce different output, and--emit-creports success with no diagnostic. The report's framing (silent semantic divergence with no documented limitation) holds;docs/requirements.mdline 11193 describes--emit-cas "C source backend, used for bootstrapping new platforms", anddocs/with-build.mdline 328 as "emit C (cross-compilation)", neither of which mentions a destructor subset.Tested revision and compiler
main@ 5809ac1 (2026-09-14); the two/* drop(sites are unchanged since 450733ewith buildof 5809ac1 in a detached worktree, self-reportswith v0.15.2.1cc, linked against the worktree's ownout/lib/{rt_core,rt_darwin_aarch64,compat_runtime,panic_runtime,fiber_stubs,cimport_stubs}.o, the same object setbuild/emit_c.w:582-587usesRepro
with run drop3.w(LLVM)inner,drop b,vec,end,drop awith build drop3.w --emit-c(rc 0, warnings only), thencc+ runtime objects, runinner,vec,endIn the emitted C:
Guard_drop__13904is declared and defined but has zero call sites;main's blockbb6contains/* drop(_3); */where the LLVM path runsb's destructor; theVecis handled ((with_vec){0}/with_vec_clear).Two notes for repeaters:
--emit-cmust be run from a tree with the generatedstd.remodules (a scratch cwd fails with "import module not found: std.re.defs"), and aVecliteral makes the backend fail loudly with "emit-c does not support generic intrinsic __collection_literal", which is the correct behaviour this issue asks for on the drop path.Source
src/CCodegen.w:8146-8151:StmtKind.Dropemitswith_vec_clearonly forCC_PSEUDO_TID_VEC; every other type gets the comment.src/CCodegen.w:8223-8232: the same forTK_DROP_AND_GOTO.:8154(self.fail("unsupported statement kind")) and:8234(self.fail("unsupported terminator kind")): the fail-loud plumbing exists in the same function and is bypassed for drops.CCodegen.wsince 450733e (runtime/with_runtime.h disagrees with the runtime (with_arg_at, with_fs_read_file): emitted C of a std.process program does not compile #1038 prototypes, emit-C lane cannot build a compiler from C: emission stops at a tuple map key, and the in-unit pcre2 C had 165 errors #955 libc names, edca805 global-proxy marks) do not touch drop emission.Spec / mission
docs/mission.mdline 9: an allocation "is released when the scope ends ... With calls [leaking] a defect". AGENTS.md §No Silent Fallbacks: "Silently dropping a clause, arm, or statement the translator can't lower" is forbidden, and emitting a comment in place of a statement is that exactly. No decision-log entry scopes the C backend to a drop-free subset.Related PRs
None merged or open address drop emission in the C backend.
Would I champion a fix? Yes.
Either path is acceptable; silence is not. Acceptance criteria:
Dropdispatch the LLVM backend uses, including field drops) forStmtKind.DropandTK_DROP_AND_GOTO; the repro prints identical output on both backends, and the emit-c roundtrip lane (:emit-c-roundtrip) proves it on the compiler itself.self.fail("emit-c does not support Drop for <type>")at both sites for any non-Vectype that needs a drop, so--emit-cexits non-zero on the repro, plus a sentence indocs/with-build.mdnaming the subset.Dropprogram through both backends and compares stdout.Untested
Linux and Windows not executed. Whether types with
Dropreach the C backend in the compiler's own self-host lane (and therefore leak or skip cleanup there) was not measured; with the compiler's use ofMutex,JsonDocument, and file handles it almost certainly does.ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): reproduced. A userDropruns under LLVM and is a comment in the emitted C.post-release: part of the emit-C lane campaign (#955); the C backend is not on a user's default path.
emitc selfbuild (#2819)