Commit 0ef26d113a
Changed files (8)
src/Sema/arith.zig
@@ -1221,16 +1221,9 @@ fn shrScalar(
const pt = sema.pt;
const zcu = pt.zcu;
- switch (op) {
- .shr => {
- if (lhs_val.isUndef(zcu)) return lhs_val;
- if (rhs_val.isUndef(zcu)) return pt.undefValue(lhs_ty);
- },
- .shr_exact => {
- if (lhs_val.isUndef(zcu)) return sema.failWithUseOfUndef(block, lhs_src, vec_idx);
- if (rhs_val.isUndef(zcu)) return sema.failWithUseOfUndef(block, rhs_src, vec_idx);
- },
- }
+ if (lhs_val.isUndef(zcu)) return sema.failWithUseOfUndef(block, lhs_src, vec_idx);
+ if (rhs_val.isUndef(zcu)) return sema.failWithUseOfUndef(block, rhs_src, vec_idx);
+
switch (try rhs_val.orderAgainstZeroSema(pt)) {
.gt => {},
.eq => return lhs_val,
src/Sema.zig
@@ -13826,11 +13826,9 @@ fn zirShr(
else => unreachable,
})).toIntern());
}
- if (rhs_val.isUndef(zcu)) switch (air_tag) {
- .shr => return pt.undefRef(lhs_ty),
- .shr_exact => return sema.failWithUseOfUndef(block, rhs_src, null),
- else => unreachable,
- };
+ if (rhs_val.isUndef(zcu)) {
+ return sema.failWithUseOfUndef(block, rhs_src, null);
+ }
const bits_val = try pt.intValue(.comptime_int, scalar_ty.intInfo(zcu).bits);
switch (rhs_ty.zigTypeTag(zcu)) {
.int, .comptime_int => {
@@ -13849,11 +13847,9 @@ fn zirShr(
var elem_idx: usize = 0;
while (elem_idx < rhs_ty.vectorLen(zcu)) : (elem_idx += 1) {
const rhs_elem = try rhs_val.elemValue(pt, elem_idx);
- if (rhs_elem.isUndef(zcu)) switch (air_tag) {
- .shr => continue,
- .shr_exact => return sema.failWithUseOfUndef(block, rhs_src, elem_idx),
- else => unreachable,
- };
+ if (rhs_elem.isUndef(zcu)) {
+ return sema.failWithUseOfUndef(block, rhs_src, elem_idx);
+ }
switch (try rhs_elem.orderAgainstZeroSema(pt)) {
.gt => {
if (try rhs_elem.compareHeteroSema(.gte, bits_val, pt)) {
@@ -13875,11 +13871,7 @@ fn zirShr(
return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});
}
if (maybe_lhs_val) |lhs_val| {
- switch (air_tag) {
- .shr => if (lhs_val.isUndef(zcu)) return pt.undefRef(lhs_ty),
- .shr_exact => try sema.checkAllScalarsDefined(block, lhs_src, lhs_val),
- else => unreachable,
- }
+ try sema.checkAllScalarsDefined(block, lhs_src, lhs_val);
}
}
break :rs rhs_src;
test/behavior/bit_shifting.zig
@@ -196,10 +196,3 @@ test "Saturating Shift Left" {
try expectEqual(170141183460469231731687303715884105727, S.shlSat(@as(i128, 0x2fe6bc5448c55ce18252e2c9d4477750), 0x31));
try expectEqual(0, S.shlSat(@as(i128, 0), 127));
}
-
-test "shift by partially undef vector" {
- comptime {
- const a: @Vector(1, u8) = .{undefined};
- _ = a >> @splat(4);
- }
-}
test/cases/compile_errors/shl_exact_on_undefined_value.zig
@@ -0,0 +1,11 @@
+comptime {
+ var a: i64 = undefined;
+ var b: u6 = undefined;
+ _ = &a;
+ _ = &b;
+ _ = @shlExact(a, b);
+}
+
+// error
+//
+// :6:19: error: use of undefined value here causes illegal behavior
test/cases/compile_errors/shl_on_undefined_value.zig
@@ -0,0 +1,11 @@
+comptime {
+ var a: i64 = undefined;
+ var b: u6 = undefined;
+ _ = &a;
+ _ = &b;
+ _ = a << b;
+}
+
+// error
+//
+// :6:9: error: use of undefined value here causes illegal behavior
test/cases/compile_errors/shl_with_overflow_on_undefined_value.zig
@@ -0,0 +1,11 @@
+comptime {
+ var a: i64 = undefined;
+ var b: u6 = undefined;
+ _ = &a;
+ _ = &b;
+ _ = @shlWithOverflow(a, b);
+}
+
+// error
+//
+// :6:26: error: use of undefined value here causes illegal behavior
test/cases/compile_errors/shr_exact_on_undefined_value.zig
@@ -0,0 +1,11 @@
+comptime {
+ var a: i64 = undefined;
+ var b: u6 = undefined;
+ _ = &a;
+ _ = &b;
+ _ = @shrExact(a, b);
+}
+
+// error
+//
+// :6:19: error: use of undefined value here causes illegal behavior
test/cases/compile_errors/shr_on_undefined_value.zig
@@ -0,0 +1,11 @@
+comptime {
+ var a: i64 = undefined;
+ var b: u6 = undefined;
+ _ = &a;
+ _ = &b;
+ _ = a >> b;
+}
+
+// error
+//
+// :6:9: error: use of undefined value here causes illegal behavior