diff options
| author | amp-59 <114923809+amp-59@users.noreply.github.com> | 2023-12-26 23:14:48 +0000 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-01-04 00:10:41 -0700 |
| commit | 10016e0368c382363e168e45fac2cca4bc64e38f (patch) | |
| tree | ca3e36c7c8e26b5c9353a40602d07293933a3a9c /src | |
| parent | ecd520f6619c08cac17f8f662facc90595444ac5 (diff) | |
| download | zig-10016e0368c382363e168e45fac2cca4bc64e38f.tar.gz zig-10016e0368c382363e168e45fac2cca4bc64e38f.zip | |
Sema: fix crash compiling `@shlExact`
Updated `zirShl`, to compute `shl_exact` with `comptime_int` LHS operand
like `shl`, and added test case for `@shlExact` with `comptime_int` LHS
operand.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index a2ed81161b..c6cb1a8b2f 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -13247,32 +13247,20 @@ fn zirShl( } break :rs rhs_src; }; - - const val = switch (air_tag) { + const val = if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) + try lhs_val.shl(rhs_val, lhs_ty, sema.arena, mod) + else switch (air_tag) { .shl_exact => val: { const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, mod); - if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) { - break :val shifted.wrapped_result; - } if (shifted.overflow_bit.compareAllWithZero(.eq, mod)) { break :val shifted.wrapped_result; } return sema.fail(block, src, "operation caused overflow", .{}); }, - - .shl_sat => if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) - try lhs_val.shl(rhs_val, lhs_ty, sema.arena, mod) - else - try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, mod), - - .shl => if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) - try lhs_val.shl(rhs_val, lhs_ty, sema.arena, mod) - else - try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, mod), - + .shl_sat => try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, mod), + .shl => try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, mod), else => unreachable, }; - return Air.internedToRef(val.toIntern()); } else lhs_src; |
