authorgravatar for jmc-88@users.noreply.github.comDaniele Cocca <jmc-88@users.noreply.github.com> 2022-03-13 20:36:15+00:00
committergravatar for daniele.cocca@gmail.comDaniele Cocca <daniele.cocca@gmail.com> 2022-03-14 00:52:20+00:00
log5a971bbeeaa58e66e5a10243a9716aabac72bdd0
tree0cb5530a32c86caf525855c842275c83f2c52b33
parentd0277a3d17f738036a951a44f367839597dcaee4

Review suggestion: use hasRuntimeBitsIgnoreComptime()

This should cover not only integers, as done in 87744a7ea9a2449764a110da4210d7750e3938ee, but also void, enums with a single field, etc... Co-authored-by: Andrew Kelley <andrew@ziglang.org>

1 files changed, 8 insertions(+), 6 deletions(-)

src/codegen/c.zig+8-6
......@@ -839,13 +839,11 @@ pub const DeclGen = struct {
839839 try w.writeAll("(");
840840 const param_len = dg.decl.ty.fnParamLen();
841841
842 const target = dg.module.getTarget();
843842 var index: usize = 0;
844843 var params_written: usize = 0;
845844 while (index < param_len) : (index += 1) {
846845 const param_type = dg.decl.ty.fnParamType(index);
847 if (param_type.zigTypeTag() == .Void) continue;
848 if (param_type.isInt() and param_type.intInfo(target).bits == 0) continue;
846 if (!param_type.hasRuntimeBitsIgnoreComptime()) continue;
849847 if (params_written > 0) {
850848 try w.writeAll(", ");
851849 }
......@@ -885,7 +883,7 @@ pub const DeclGen = struct {
885883 var params_written: usize = 0;
886884 var index: usize = 0;
887885 while (index < param_len) : (index += 1) {
888 if (fn_info.param_types[index].zigTypeTag() == .Void) continue;
886 if (!fn_info.param_types[index].hasRuntimeBitsIgnoreComptime()) continue;
889887 if (params_written > 0) {
890888 try bw.writeAll(", ");
891889 }
......@@ -2628,8 +2626,11 @@ fn airCall(
26282626 }
26292627
26302628 try writer.writeAll("(");
2631 for (args) |arg, i| {
2632 if (i != 0) {
2629 var args_written: usize = 0;
2630 for (args) |arg| {
2631 const ty = f.air.typeOf(arg);
2632 if (!ty.hasRuntimeBitsIgnoreComptime()) continue;
2633 if (args_written != 0) {
26332634 try writer.writeAll(", ");
26342635 }
26352636 if (f.air.value(arg)) |val| {
......@@ -2638,6 +2639,7 @@ fn airCall(
26382639 const val = try f.resolveInst(arg);
26392640 try f.writeCValue(writer, val);
26402641 }
2642 args_written += 1;
26412643 }
26422644 try writer.writeAll(");\n");
26432645 return result_local;