@@ -14030,7 +14030,7 @@ fn zirShl(
14030
14030
14031
14031
if (maybe_rhs_val) |rhs_val| {
14032
14032
if (rhs_val.isUndef(zcu)) {
14033
- return pt.undefRef(sema.typeOf(lhs) );
14033
+ return pt.undefRef(lhs_ty );
14034
14034
}
14035
14035
// If rhs is 0, return lhs without doing any calculations.
14036
14036
if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
@@ -14042,6 +14042,7 @@ fn zirShl(
14042
14042
var i: usize = 0;
14043
14043
while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
14044
14044
const rhs_elem = try rhs_val.elemValue(pt, i);
14045
+ if (rhs_elem.isUndef(zcu)) continue;
14045
14046
if (rhs_elem.compareHetero(.gte, bit_value, zcu)) {
14046
14047
return sema.fail(block, rhs_src, "shift amount '{f}' at index '{d}' is too large for operand type '{f}'", .{
14047
14048
rhs_elem.fmtValueSema(pt, sema),
@@ -14059,15 +14060,23 @@ fn zirShl(
14059
14060
}
14060
14061
if (rhs_ty.zigTypeTag(zcu) == .vector) {
14061
14062
var i: usize = 0;
14063
+ var undef_count: usize = 0;
14062
14064
while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
14063
14065
const rhs_elem = try rhs_val.elemValue(pt, i);
14066
+ if (rhs_elem.isUndef(zcu)) {
14067
+ undef_count += 1;
14068
+ continue;
14069
+ }
14064
14070
if (rhs_elem.compareHetero(.lt, try pt.intValue(scalar_rhs_ty, 0), zcu)) {
14065
14071
return sema.fail(block, rhs_src, "shift by negative amount '{f}' at index '{d}'", .{
14066
14072
rhs_elem.fmtValueSema(pt, sema),
14067
14073
i,
14068
14074
});
14069
14075
}
14070
14076
}
14077
+ if (undef_count == rhs_ty.vectorLen(zcu)) {
14078
+ return pt.undefRef(lhs_ty);
14079
+ }
14071
14080
} else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), zcu)) {
14072
14081
return sema.fail(block, rhs_src, "shift by negative amount '{f}'", .{
14073
14082
rhs_val.fmtValueSema(pt, sema),
@@ -14117,10 +14126,16 @@ fn zirShl(
14117
14126
)).toIntern();
14118
14127
const rhs_len = rhs_ty.vectorLen(zcu);
14119
14128
const rhs_elems = try sema.arena.alloc(InternPool.Index, rhs_len);
14120
- for (rhs_elems, 0..) |*rhs_elem, i| rhs_elem.* = (try pt.intValue(
14121
- rt_rhs_scalar_ty,
14122
- @min(try (try rhs_val.elemValue(pt, i)).getUnsignedIntSema(pt) orelse bit_count, bit_count),
14123
- )).toIntern();
14129
+ for (rhs_elems, 0..) |*rhs_elem, i| {
14130
+ const elem_val = try rhs_val.elemValue(pt, i);
14131
+ const min_val = if (elem_val.isUndef(zcu))
14132
+ bit_count
14133
+ else if (try elem_val.getUnsignedIntSema(pt)) |uint|
14134
+ @min(uint, bit_count)
14135
+ else
14136
+ bit_count;
14137
+ rhs_elem.* = (try pt.intValue(rt_rhs_scalar_ty, min_val)).toIntern();
14138
+ }
14124
14139
break :rt_rhs try pt.intern(.{ .aggregate = .{
14125
14140
.ty = (try pt.vectorType(.{
14126
14141
.len = rhs_len,
@@ -14223,6 +14238,7 @@ fn zirShr(
14223
14238
var i: usize = 0;
14224
14239
while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
14225
14240
const rhs_elem = try rhs_val.elemValue(pt, i);
14241
+ if (rhs_elem.isUndef(zcu)) continue;
14226
14242
if (rhs_elem.compareHetero(.gte, bit_value, zcu)) {
14227
14243
return sema.fail(block, rhs_src, "shift amount '{f}' at index '{d}' is too large for operand type '{f}'", .{
14228
14244
rhs_elem.fmtValueSema(pt, sema),
@@ -14240,15 +14256,23 @@ fn zirShr(
14240
14256
}
14241
14257
if (rhs_ty.zigTypeTag(zcu) == .vector) {
14242
14258
var i: usize = 0;
14259
+ var undef_count: usize = 0;
14243
14260
while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
14244
14261
const rhs_elem = try rhs_val.elemValue(pt, i);
14262
+ if (rhs_elem.isUndef(zcu)) {
14263
+ undef_count += 1;
14264
+ continue;
14265
+ }
14245
14266
if (rhs_elem.compareHetero(.lt, try pt.intValue(rhs_ty.childType(zcu), 0), zcu)) {
14246
14267
return sema.fail(block, rhs_src, "shift by negative amount '{f}' at index '{d}'", .{
14247
14268
rhs_elem.fmtValueSema(pt, sema),
14248
14269
i,
14249
14270
});
14250
14271
}
14251
14272
}
14273
+ if (undef_count == rhs_ty.vectorLen(zcu)) {
14274
+ return pt.undefRef(lhs_ty);
14275
+ }
14252
14276
} else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), zcu)) {
14253
14277
return sema.fail(block, rhs_src, "shift by negative amount '{f}'", .{
14254
14278
rhs_val.fmtValueSema(pt, sema),
0 commit comments