aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2021-08-28 23:18:47 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2021-08-29 08:59:27 +0000
commit7b863aa8ac6d48092c8d5b3c8713d9f8a9cfbdf3 (patch)
tree31d86d703f717419c5224f129c4bfc2788ce96ec /src/AstGen.zig
parent4bb5d17edc85eac74626224810d6a44a3c73cca3 (diff)
downloadzig-7b863aa8ac6d48092c8d5b3c8713d9f8a9cfbdf3.tar.gz
zig-7b863aa8ac6d48092c8d5b3c8713d9f8a9cfbdf3.zip
AstGen: short-circuit rvalue() if code is unreachable
This avoids generating instructions which will never be reached.
Diffstat (limited to 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index b962f58ba1..59a2bc2de2 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -8389,7 +8389,7 @@ fn nodeImpliesRuntimeBits(tree: *const ast.Tree, start_node: ast.Node.Index) boo
}
}
-/// Applies `rl` semantics to `inst`. Expressions which do not do their own handling of
+/// Applies `rl` semantics to `result`. Expressions which do not do their own handling of
/// result locations must call this function on their result.
/// As an example, if the `ResultLoc` is `ptr`, it will write the result to the pointer.
/// If the `ResultLoc` is `ty`, it will coerce the result to the type.
@@ -8399,6 +8399,7 @@ fn rvalue(
result: Zir.Inst.Ref,
src_node: ast.Node.Index,
) InnerError!Zir.Inst.Ref {
+ if (gz.endsWithNoReturn()) return result;
switch (rl) {
.none, .none_or_ref, .coerced_ty => return result,
.discard => {