diff --git a/src/Sema.zig b/src/Sema.zig index fc8a182508acde178b711e8eb338be64b41bd21d..4fefff7c26a17f2ad234d99a8f285ac5576b91ea 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) diff --git a/test/cases/compile_errors/shlExact_shifts_out_1_bits.zig b/test/cases/compile_errors/shlExact_shifts_out_1_bits.zig new file mode 100644 index 0000000000000000000000000000000000000000..b2ab45a8e9233958df13e7a60867ca77d0af1914 --- /dev/null +++ b/test/cases/compile_errors/shlExact_shifts_out_1_bits.zig @@ -0,0 +1,10 @@ +comptime { + const x = @shlExact(@as(u8, 0b01010101), 2); + _ = x; +} + +// error +// backend=llvm +// target=native +// +// :2:15: error: operation caused overflow diff --git a/test/cases/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig b/test/cases/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig deleted file mode 100644 index 953c5fec50199c59dd2669b4e8601d026f4d70f8..0000000000000000000000000000000000000000 --- a/test/cases/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig +++ /dev/null @@ -1,10 +0,0 @@ -comptime { - const x = @shlExact(@as(u8, 0b01010101), 2); - _ = x; -} - -// error -// backend=stage1 -// target=native -// -// tmp.zig:2:15: error: operation caused overflow