mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
stage2: add compile error for shlExact overflow
- moves a stage1 test case and makes it target `llvm` backend instead of `stage1` backend
This commit is contained in:
parent
8fd20a5eb0
commit
0e118ed0ac
12
src/Sema.zig
12
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)
|
||||
|
||||
@ -4,7 +4,7 @@ comptime {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=llvm
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:15: error: operation caused overflow
|
||||
// :2:15: error: operation caused overflow
|
||||
Loading…
x
Reference in New Issue
Block a user