aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-12-03 19:30:08 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-12-04 15:57:40 -0700
commit4aae0b09cfdc444a0b4e98d3ed7f83bfe421c06f (patch)
treeb39b9beb40acde354abd178a47f10a0f73d8af33 /src/codegen/c.zig
parentf2e59e41c1ea3884a50e45f54a74c29f52954b24 (diff)
downloadzig-4aae0b09cfdc444a0b4e98d3ed7f83bfe421c06f.tar.gz
zig-4aae0b09cfdc444a0b4e98d3ed7f83bfe421c06f.zip
CBE and LLVM: handle unused try instructions
In both backends they did not observe the Liveness information for try instructions. Now they do. For the C backend this is necessary for correctness; for the LLVM backend, it improves code generation.
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 372e89bac7..ac22ac3fa6 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -4092,9 +4092,14 @@ fn lowerTry(
}
}
+ try reap(f, inst, &.{operand});
+
+ if (f.liveness.isUnused(inst)) {
+ return CValue.none;
+ }
+
const target = f.object.dg.module.getTarget();
const is_array = lowersToArray(payload_ty, target);
- try reap(f, inst, &.{operand});
const local = try f.allocLocal(inst, result_ty);
if (is_array) {
try writer.writeAll("memcpy(");