diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-02 20:15:03 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-02 20:15:03 -0700 |
| commit | c4df9bf56f204f63f4e87255933ba453d69d0182 (patch) | |
| tree | 647cec61769d5723385f8ac9b1392b3c935a219b /src/codegen | |
| parent | 61a53a587558ff1fe1b0ec98bb424022885edccf (diff) | |
| download | zig-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')
| -rw-r--r-- | src/codegen/llvm.zig | 10 |
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; } |
