Skip to content

Commit

Permalink
LLVM: fix canElideLoad behavior with loops
Browse files Browse the repository at this point in the history
closes #13546
  • Loading branch information
andrewrk committed Nov 30, 2022
1 parent b8473ae commit deda6b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
10 changes: 3 additions & 7 deletions ci/linux/build-x86_64-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,16 @@ stage3-debug/bin/zig fmt --check .. \
# simultaneously test building self-hosted without LLVM and with 32-bit arm
stage3-debug/bin/zig build -Dtarget=arm-linux-musleabihf

# building docs disabled due to:
# https://github.com/ziglang/zig/issues/13546
stage3-debug/bin/zig build test \
stage3-debug/bin/zig build test docs \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$(pwd)/../lib"

# langref disabled due to:
# https://github.com/ziglang/zig/issues/13546
## Look for HTML errors.
#tidy --drop-empty-elements no -qe ../zig-cache/langref.html
# Look for HTML errors.
tidy --drop-empty-elements no -qe ../zig-cache/langref.html

# Produce the experimental std lib documentation.
stage3-debug/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
5 changes: 4 additions & 1 deletion src/codegen/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8136,7 +8136,10 @@ pub const FuncGen = struct {
.write, .noret, .complex => return false,
.tomb => return true,
}
} else unreachable;
}
// The only way to get here is to hit the end of a loop instruction
// (implicit repeat).
return false;
}

fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !?*llvm.Value {
Expand Down
21 changes: 21 additions & 0 deletions test/behavior/while.zig
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,24 @@ test "else continue outer while" {
} else continue;
}
}

test "try terminating an infinite loop" {
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO

// Test coverage for https://github.com/ziglang/zig/issues/13546
const Foo = struct {
trash: i32,

fn bar() anyerror!@This() {
return .{ .trash = 1234 };
}
};
var t = true;
errdefer t = false;
try expect(while (true) {
if (t) break t;
_ = try Foo.bar();
} else unreachable);
}

0 comments on commit deda6b5

Please sign in to comment.