diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-01-06 00:52:10 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-01-06 00:52:10 -0700 |
| commit | 8c6175c1343a00278efc029a0be4091ff505dc3d (patch) | |
| tree | 63f9c87d0f37757f5c0c0b543fc94ea4fe68ae22 /src/codegen/c.zig | |
| parent | 713d2a9b3883942491b40738245232680877cc66 (diff) | |
| download | zig-8c6175c1343a00278efc029a0be4091ff505dc3d.tar.gz zig-8c6175c1343a00278efc029a0be4091ff505dc3d.zip | |
Sema: const inferred alloc infers comptime-ness
const locals now detect if the value ends up being comptime known. In
such case, it replaces the runtime AIR instructions with a decl_ref
const.
In the backends, some more sophisticated logic for marking decls as
alive was needed to prevent Decls incorrectly being garbage collected
that were indirectly referenced in such manner.
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 191be36494..922e1d9c3e 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -195,7 +195,7 @@ pub const DeclGen = struct { val: Value, decl: *Decl, ) error{ OutOfMemory, AnalysisFail }!void { - decl.alive = true; + markDeclAlive(decl); if (ty.isSlice()) { try writer.writeByte('('); @@ -227,6 +227,19 @@ pub const DeclGen = struct { try dg.renderDeclName(decl, writer); } + fn markDeclAlive(decl: *Decl) void { + if (decl.alive) return; + decl.alive = true; + + // This is the first time we are marking this Decl alive. We must + // therefore recurse into its value and mark any Decl it references + // as also alive, so that any Decl referenced does not get garbage collected. + + if (decl.val.pointerDecl()) |pointee| { + return markDeclAlive(pointee); + } + } + fn renderInt128( writer: anytype, int_val: anytype, |
