authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-07-13 01:12:49-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-07-13 01:49:04-04:00
log4a462481982e96e1f94e2dd431aeaf8686c0c4b1
tree29dbca037ab74807260492bdd2f5b1c8530e8025
parenta124b027b45384e595c6967adabe8b5033b9c410
signaturelock-open Commit is signed but in an unrecognized format.

CBE: Only generate `(void)` for calls whose return values are ignored


1 files changed, 4 insertions(+), 4 deletions(-)

src-self-hosted/cgen.zig+4-4
......@@ -120,13 +120,13 @@ pub fn generate(file: *C, decl: *Decl) !void {
120120 try writer.writeAll(");");
121121 },
122122 .call => {
123 const call = inst.cast(ir.Inst.Call).?.args;
124 if (call.func.cast(ir.Inst.Constant)) |func_inst| {
123 const call = inst.cast(ir.Inst.Call).?;
124 if (call.args.func.cast(ir.Inst.Constant)) |func_inst| {
125125 if (func_inst.val.cast(Value.Payload.Function)) |func_val| {
126126 const target = func_val.func.owner_decl;
127127 const target_ty = target.typed_value.most_recent.typed_value.ty;
128128 const ret_ty = target_ty.fnReturnType().tag();
129 if (target_ty.fnReturnType().hasCodeGenBits()) {
129 if (target_ty.fnReturnType().hasCodeGenBits() and call.base.isUnused()) {
130130 try writer.print("(void)", .{});
131131 }
132132 const tname = mem.spanZ(target.name);
......@@ -139,7 +139,7 @@ pub fn generate(file: *C, decl: *Decl) !void {
139139 } else {
140140 return file.fail(decl.src(), "TODO non-function call target?", .{});
141141 }
142 if (call.args.len != 0) {
142 if (call.args.args.len != 0) {
143143 return file.fail(decl.src(), "TODO function arguments", .{});
144144 }
145145 } else {