aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLeRoyce Pearson <contact@leroycepearson.dev>2022-08-09 16:08:59 -0600
committerAndrew Kelley <andrew@ziglang.org>2022-08-10 16:14:30 -0400
commit0e118ed0aca3d852d2499fa37d04adef62b03ead (patch)
tree16192710018414ad7cfc46833e29f724d9abbd4b /src
parent8fd20a5eb015fda4b27cef14c9e3149575861994 (diff)
downloadzig-0e118ed0aca3d852d2499fa37d04adef62b03ead.tar.gz
zig-0e118ed0aca3d852d2499fa37d04adef62b03ead.zip
stage2: add compile error for shlExact overflow
- moves a stage1 test case and makes it target `llvm` backend instead of `stage1` backend
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index fc8a182508..4fefff7c26 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -10269,16 +10269,14 @@ fn zirShl(
const val = switch (air_tag) {
.shl_exact => val: {
- const shifted = try lhs_val.shl(rhs_val, lhs_ty, sema.arena, target);
+ const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, target);
if (scalar_ty.zigTypeTag() == .ComptimeInt) {
- break :val shifted;
+ break :val shifted.wrapped_result;
}
- const int_info = scalar_ty.intInfo(target);
- const truncated = try shifted.intTrunc(lhs_ty, sema.arena, int_info.signedness, int_info.bits, target);
- if (try sema.compare(block, src, truncated, .eq, shifted, lhs_ty)) {
- break :val shifted;
+ if (shifted.overflowed.compareWithZero(.eq)) {
+ break :val shifted.wrapped_result;
}
- return sema.addConstUndef(lhs_ty);
+ return sema.fail(block, src, "operation caused overflow", .{});
},
.shl_sat => if (scalar_ty.zigTypeTag() == .ComptimeInt)