Skip to content

Commit 0e118ed

Browse files
leroycepandrewrk
authored andcommitted
stage2: add compile error for shlExact overflow
- moves a stage1 test case and makes it target `llvm` backend instead of `stage1` backend
1 parent 8fd20a5 commit 0e118ed

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/Sema.zig

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10269,16 +10269,14 @@ fn zirShl(
1026910269

1027010270
const val = switch (air_tag) {
1027110271
.shl_exact => val: {
10272-
const shifted = try lhs_val.shl(rhs_val, lhs_ty, sema.arena, target);
10272+
const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, target);
1027310273
if (scalar_ty.zigTypeTag() == .ComptimeInt) {
10274-
break :val shifted;
10274+
break :val shifted.wrapped_result;
1027510275
}
10276-
const int_info = scalar_ty.intInfo(target);
10277-
const truncated = try shifted.intTrunc(lhs_ty, sema.arena, int_info.signedness, int_info.bits, target);
10278-
if (try sema.compare(block, src, truncated, .eq, shifted, lhs_ty)) {
10279-
break :val shifted;
10276+
if (shifted.overflowed.compareWithZero(.eq)) {
10277+
break :val shifted.wrapped_result;
1028010278
}
10281-
return sema.addConstUndef(lhs_ty);
10279+
return sema.fail(block, src, "operation caused overflow", .{});
1028210280
},
1028310281

1028410282
.shl_sat => if (scalar_ty.zigTypeTag() == .ComptimeInt)

test/cases/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig renamed to test/cases/compile_errors/shlExact_shifts_out_1_bits.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ comptime {
44
}
55

66
// error
7-
// backend=stage1
7+
// backend=llvm
88
// target=native
99
//
10-
// tmp.zig:2:15: error: operation caused overflow
10+
// :2:15: error: operation caused overflow

0 commit comments

Comments
 (0)