Skip to content

Commit d54fbb4

Browse files
committed
address comments
1 parent 1faa1e6 commit d54fbb4

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

src/Sema.zig

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14029,8 +14029,8 @@ fn zirShl(
1402914029
const maybe_rhs_val = try sema.resolveValueResolveLazy(rhs);
1403014030

1403114031
if (maybe_rhs_val) |rhs_val| {
14032-
if (rhs_val.isUndef(zcu)) {
14033-
return pt.undefRef(lhs_ty);
14032+
if (rhs_val.anyScalarIsUndef(zcu)) {
14033+
return sema.failWithUseOfUndef(block, rhs_src);
1403414034
}
1403514035
// If rhs is 0, return lhs without doing any calculations.
1403614036
if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
@@ -14042,7 +14042,6 @@ fn zirShl(
1404214042
var i: usize = 0;
1404314043
while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
1404414044
const rhs_elem = try rhs_val.elemValue(pt, i);
14045-
if (rhs_elem.isUndef(zcu)) continue;
1404614045
if (rhs_elem.compareHetero(.gte, bit_value, zcu)) {
1404714046
return sema.fail(block, rhs_src, "shift amount '{f}' at index '{d}' is too large for operand type '{f}'", .{
1404814047
rhs_elem.fmtValueSema(pt, sema),
@@ -14060,23 +14059,15 @@ fn zirShl(
1406014059
}
1406114060
if (rhs_ty.zigTypeTag(zcu) == .vector) {
1406214061
var i: usize = 0;
14063-
var undef_count: usize = 0;
1406414062
while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
1406514063
const rhs_elem = try rhs_val.elemValue(pt, i);
14066-
if (rhs_elem.isUndef(zcu)) {
14067-
undef_count += 1;
14068-
continue;
14069-
}
1407014064
if (rhs_elem.compareHetero(.lt, try pt.intValue(scalar_rhs_ty, 0), zcu)) {
1407114065
return sema.fail(block, rhs_src, "shift by negative amount '{f}' at index '{d}'", .{
1407214066
rhs_elem.fmtValueSema(pt, sema),
1407314067
i,
1407414068
});
1407514069
}
1407614070
}
14077-
if (undef_count == rhs_ty.vectorLen(zcu)) {
14078-
return pt.undefRef(lhs_ty);
14079-
}
1408014071
} else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), zcu)) {
1408114072
return sema.fail(block, rhs_src, "shift by negative amount '{f}'", .{
1408214073
rhs_val.fmtValueSema(pt, sema),
@@ -14087,7 +14078,9 @@ fn zirShl(
1408714078
}
1408814079

1408914080
const runtime_src = if (maybe_lhs_val) |lhs_val| rs: {
14090-
if (lhs_val.isUndef(zcu)) return pt.undefRef(lhs_ty);
14081+
if (lhs_val.anyScalarIsUndef(zcu)) {
14082+
return sema.failWithUseOfUndef(block, lhs_src);
14083+
}
1409114084
const rhs_val = maybe_rhs_val orelse {
1409214085
if (scalar_ty.zigTypeTag(zcu) == .comptime_int) {
1409314086
return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});
@@ -14126,16 +14119,10 @@ fn zirShl(
1412614119
)).toIntern();
1412714120
const rhs_len = rhs_ty.vectorLen(zcu);
1412814121
const rhs_elems = try sema.arena.alloc(InternPool.Index, rhs_len);
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-
}
14122+
for (rhs_elems, 0..) |*rhs_elem, i| rhs_elem.* = (try pt.intValue(
14123+
rt_rhs_scalar_ty,
14124+
@min(try (try rhs_val.elemValue(pt, i)).getUnsignedIntSema(pt) orelse bit_count, bit_count),
14125+
)).toIntern();
1413914126
break :rt_rhs try pt.intern(.{ .aggregate = .{
1414014127
.ty = (try pt.vectorType(.{
1414114128
.len = rhs_len,

0 commit comments

Comments
 (0)