diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-08-07 20:34:28 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-08-07 20:34:28 -0700 |
| commit | 799fedf612aa8742c446b015c12d21707a1dbec0 (patch) | |
| tree | 1d9efbc4cb3f6dda9631160784a074e58d6bd479 /src/codegen/c.zig | |
| parent | f81b2531cb4904064446f84a06f6e09e4120e28a (diff) | |
| download | zig-799fedf612aa8742c446b015c12d21707a1dbec0.tar.gz zig-799fedf612aa8742c446b015c12d21707a1dbec0.zip | |
stage2: pass some error union tests
* Value: rename `error_union` to `eu_payload` and clarify the intended
usage in the doc comments. The way error unions is represented with
Value is fixed to not have ambiguous values.
* Fix codegen for error union constants in all the backends.
* Implement the AIR instructions having to do with error unions in the
LLVM backend.
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 65ad4bac8e..a67e2438c2 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -350,32 +350,25 @@ pub const DeclGen = struct { .ErrorUnion => { const error_type = t.errorUnionSet(); const payload_type = t.errorUnionPayload(); - const sub_val = val.castTag(.error_union).?.data; if (!payload_type.hasCodeGenBits()) { // We use the error type directly as the type. - return dg.renderValue(writer, error_type, sub_val); + const err_val = if (val.errorUnionIsPayload()) Value.initTag(.zero) else val; + return dg.renderValue(writer, error_type, err_val); } try writer.writeByte('('); try dg.renderType(writer, t); try writer.writeAll("){"); - if (val.getError()) |_| { - try writer.writeAll(" .error = "); - try dg.renderValue( - writer, - error_type, - sub_val, - ); - try writer.writeAll(" }"); - } else { + if (val.castTag(.eu_payload)) |pl| { + const payload_val = pl.data; try writer.writeAll(" .payload = "); - try dg.renderValue( - writer, - payload_type, - sub_val, - ); + try dg.renderValue(writer, payload_type, payload_val); try writer.writeAll(", .error = 0 }"); + } else { + try writer.writeAll(" .error = "); + try dg.renderValue(writer, error_type, val); + try writer.writeAll(" }"); } }, .Enum => { |
