@@ -13572,8 +13572,8 @@ fn zirShl(
13572
13572
const maybe_rhs_val = try sema.resolveValueResolveLazy(rhs);
13573
13573
13574
13574
if (maybe_rhs_val) |rhs_val| {
13575
- if (rhs_val.isUndef (zcu)) {
13576
- return pt.undefRef( sema.typeOf(lhs) );
13575
+ if (rhs_val.anyScalarIsUndef (zcu)) {
13576
+ return sema.failWithUseOfUndef(block, rhs_src );
13577
13577
}
13578
13578
// If rhs is 0, return lhs without doing any calculations.
13579
13579
if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
@@ -13621,7 +13621,9 @@ fn zirShl(
13621
13621
}
13622
13622
13623
13623
const runtime_src = if (maybe_lhs_val) |lhs_val| rs: {
13624
- if (lhs_val.isUndef(zcu)) return pt.undefRef(lhs_ty);
13624
+ if (lhs_val.anyScalarIsUndef(zcu)) {
13625
+ return sema.failWithUseOfUndef(block, lhs_src);
13626
+ }
13625
13627
const rhs_val = maybe_rhs_val orelse {
13626
13628
if (scalar_ty.zigTypeTag(zcu) == .comptime_int) {
13627
13629
return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});
@@ -13753,8 +13755,10 @@ fn zirShr(
13753
13755
const maybe_rhs_val = try sema.resolveValueResolveLazy(rhs);
13754
13756
13755
13757
const runtime_src = if (maybe_rhs_val) |rhs_val| rs: {
13756
- if (rhs_val.isUndef(zcu)) {
13757
- return pt.undefRef(lhs_ty);
13758
+ switch (air_tag) {
13759
+ .shr => if (rhs_val.isUndefDeep(zcu)) return pt.undefRef(lhs_ty),
13760
+ .shr_exact => if (rhs_val.anyScalarIsUndef(zcu)) return sema.failWithUseOfUndef(block, rhs_src),
13761
+ else => unreachable,
13758
13762
}
13759
13763
// If rhs is 0, return lhs without doing any calculations.
13760
13764
if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
@@ -13766,6 +13770,7 @@ fn zirShr(
13766
13770
var i: usize = 0;
13767
13771
while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
13768
13772
const rhs_elem = try rhs_val.elemValue(pt, i);
13773
+ if (rhs_elem.isUndef(zcu)) continue;
13769
13774
if (rhs_elem.compareHetero(.gte, bit_value, zcu)) {
13770
13775
return sema.fail(block, rhs_src, "shift amount '{f}' at index '{d}' is too large for operand type '{f}'", .{
13771
13776
rhs_elem.fmtValueSema(pt, sema),
@@ -13785,6 +13790,7 @@ fn zirShr(
13785
13790
var i: usize = 0;
13786
13791
while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
13787
13792
const rhs_elem = try rhs_val.elemValue(pt, i);
13793
+ if (rhs_elem.isUndef(zcu)) continue;
13788
13794
if (rhs_elem.compareHetero(.lt, try pt.intValue(rhs_ty.childType(zcu), 0), zcu)) {
13789
13795
return sema.fail(block, rhs_src, "shift by negative amount '{f}' at index '{d}'", .{
13790
13796
rhs_elem.fmtValueSema(pt, sema),
@@ -13798,15 +13804,17 @@ fn zirShr(
13798
13804
});
13799
13805
}
13800
13806
if (maybe_lhs_val) |lhs_val| {
13801
- if (lhs_val.isUndef(zcu)) {
13802
- return pt.undefRef(lhs_ty);
13803
- }
13804
- if (air_tag == .shr_exact) {
13805
- // Detect if any ones would be shifted out.
13806
- const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, pt);
13807
- if (!(try truncated.compareAllWithZeroSema(.eq, pt))) {
13808
- return sema.fail(block, src, "exact shift shifted out 1 bits", .{});
13809
- }
13807
+ switch (air_tag) {
13808
+ .shr => if (lhs_val.isUndefDeep(zcu)) return pt.undefRef(lhs_ty),
13809
+ .shr_exact => {
13810
+ if (lhs_val.anyScalarIsUndef(zcu)) return sema.failWithUseOfUndef(block, lhs_src);
13811
+ // Detect if any ones would be shifted out.
13812
+ const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, pt);
13813
+ if (!(try truncated.compareAllWithZeroSema(.eq, pt))) {
13814
+ return sema.fail(block, src, "exact shift shifted out 1 bits", .{});
13815
+ }
13816
+ },
13817
+ else => unreachable,
13810
13818
}
13811
13819
const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, pt);
13812
13820
return Air.internedToRef(val.toIntern());
0 commit comments