diff options
| author | Emily Bellows <emily.a.bellows@hey.com> | 2021-11-02 21:23:41 -0400 |
|---|---|---|
| committer | Emily Bellows <emily.a.bellows@hey.com> | 2021-11-08 14:23:55 -0500 |
| commit | e3d638a49e09340bc1f779185cab3ad85d7045af (patch) | |
| tree | 359853c070abc6130f9cb79900573f6add9d74bb /src/codegen/c.zig | |
| parent | a7d215759e93be971ba5e560578e7473655cdd82 (diff) | |
| download | zig-e3d638a49e09340bc1f779185cab3ad85d7045af.tar.gz zig-e3d638a49e09340bc1f779185cab3ad85d7045af.zip | |
C backend: while, struct tests, better undefined global handling
1. Function signatures that return a no member struct return void
2. Undefined var decls don't get a value generated for them
3. Don't generate bitcast code if the result isn't used, since
bitcast is a pure function. Right now struct handling code
generates some weird unused bitcast AIR, and this optimization
side steps that issue.
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 5935985961..29e0f1e50e 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -448,7 +448,12 @@ pub const DeclGen = struct { try w.writeAll("ZIG_COLD "); } } - try dg.renderType(w, dg.decl.ty.fnReturnType()); + const return_ty = dg.decl.ty.fnReturnType(); + if (return_ty.hasCodeGenBits()) { + try dg.renderType(w, return_ty); + } else { + try w.writeAll("void"); + } try w.writeAll(" "); try dg.renderDeclName(dg.decl, w); try w.writeAll("("); @@ -947,6 +952,10 @@ pub fn genDecl(o: *Object) !void { } try fwd_decl_writer.writeAll(";\n"); + if (variable.init.isUndef()) { + return; + } + try o.indent_writer.insertNewline(); const w = o.writer(); try o.dg.renderType(w, o.dg.decl.ty); @@ -1886,6 +1895,9 @@ fn airBr(f: *Function, inst: Air.Inst.Index) !CValue { } fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue { + if (f.liveness.isUnused(inst)) + return CValue.none; + const ty_op = f.air.instructions.items(.data)[inst].ty_op; const operand = try f.resolveInst(ty_op.operand); |
