aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-02 20:15:03 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-02 20:15:03 -0700
commitc4df9bf56f204f63f4e87255933ba453d69d0182 (patch)
tree647cec61769d5723385f8ac9b1392b3c935a219b /src/codegen/llvm.zig
parent61a53a587558ff1fe1b0ec98bb424022885edccf (diff)
downloadzig-c4df9bf56f204f63f4e87255933ba453d69d0182.tar.gz
zig-c4df9bf56f204f63f4e87255933ba453d69d0182.zip
AstGen: fix `while` and `for` with unreachable bodies
Companion commit to 61a53a587558ff1fe1b0ec98bb424022885edccf. This commit also moves over a bunch of behavior test cases to the passing-for-stage2 section.
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 761dd2a8bc..500aa482fa 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -1605,7 +1605,15 @@ pub const FuncGen = struct {
self.builder.positionBuilderAtEnd(loop_block);
try self.genBody(body);
- _ = self.builder.buildBr(loop_block);
+ // TODO instead of this logic, change AIR to have the property that
+ // every block is guaranteed to end with a noreturn instruction.
+ // Then we can simply rely on the fact that a repeat or break instruction
+ // would have been emitted already. Also the main loop in genBody can
+ // be while(true) instead of for(body), which will eliminate 1 branch on
+ // a hot path.
+ if (body.len == 0 or !self.air.typeOfIndex(body[body.len - 1]).isNoReturn()) {
+ _ = self.builder.buildBr(loop_block);
+ }
return null;
}