authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-11-29 17:17:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-11-30 00:20:49-05:00
logdeda6b514691c3a7ffc7931469886d0e7be2f67e
treec71ae6f91304fc3d7e68da2fc04fc1fe4154e61f
parentb8473ae7d333ea2750e55e712722d446076e99d9

LLVM: fix canElideLoad behavior with loops

closes #13546

3 files changed, 28 insertions(+), 8 deletions(-)

ci/linux/build-x86_64-debug.sh+3-7
...@@ -51,9 +51,7 @@ stage3-debug/bin/zig fmt --check .. \...@@ -51,9 +51,7 @@ stage3-debug/bin/zig fmt --check .. \
51# simultaneously test building self-hosted without LLVM and with 32-bit arm51# simultaneously test building self-hosted without LLVM and with 32-bit arm
52stage3-debug/bin/zig build -Dtarget=arm-linux-musleabihf52stage3-debug/bin/zig build -Dtarget=arm-linux-musleabihf
5353
54# building docs disabled due to:54stage3-debug/bin/zig build test docs \
55# https://github.com/ziglang/zig/issues/13546
56stage3-debug/bin/zig build test \
57 -fqemu \55 -fqemu \
58 -fwasmtime \56 -fwasmtime \
59 -Dstatic-llvm \57 -Dstatic-llvm \
...@@ -61,10 +59,8 @@ stage3-debug/bin/zig build test \...@@ -61,10 +59,8 @@ stage3-debug/bin/zig build test \
61 --search-prefix "$PREFIX" \59 --search-prefix "$PREFIX" \
62 --zig-lib-dir "$(pwd)/../lib"60 --zig-lib-dir "$(pwd)/../lib"
6361
64# langref disabled due to:62# Look for HTML errors.
65# https://github.com/ziglang/zig/issues/1354663tidy --drop-empty-elements no -qe ../zig-cache/langref.html
66## Look for HTML errors.
67#tidy --drop-empty-elements no -qe ../zig-cache/langref.html
6864
69# Produce the experimental std lib documentation.65# Produce the experimental std lib documentation.
70stage3-debug/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib66stage3-debug/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
src/codegen/llvm.zig+4-1
...@@ -8136,7 +8136,10 @@ pub const FuncGen = struct {...@@ -8136,7 +8136,10 @@ pub const FuncGen = struct {
8136 .write, .noret, .complex => return false,8136 .write, .noret, .complex => return false,
8137 .tomb => return true,8137 .tomb => return true,
8138 }8138 }
8139 } else unreachable;8139 }
8140 // The only way to get here is to hit the end of a loop instruction
8141 // (implicit repeat).
8142 return false;
8140 }8143 }
81418144
8142 fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !?*llvm.Value {8145 fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !?*llvm.Value {
test/behavior/while.zig+21
...@@ -343,3 +343,24 @@ test "else continue outer while" {...@@ -343,3 +343,24 @@ test "else continue outer while" {
343 } else continue;343 } else continue;
344 }344 }
345}345}
346
347test "try terminating an infinite loop" {
348 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
349 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
350 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
351
352 // Test coverage for https://github.com/ziglang/zig/issues/13546
353 const Foo = struct {
354 trash: i32,
355
356 fn bar() anyerror!@This() {
357 return .{ .trash = 1234 };
358 }
359 };
360 var t = true;
361 errdefer t = false;
362 try expect(while (true) {
363 if (t) break t;
364 _ = try Foo.bar();
365 } else unreachable);
366}