Merge pull request #24674 from Justus2308/undef-shift-bitwise

Sema: Improve comptime arithmetic undef handling
This commit is contained in:
Matthew Lugg
2025-08-13 14:04:59 +01:00
committed by GitHub
34 changed files with 13303 additions and 9303 deletions

View File

@@ -154,12 +154,6 @@ test "Saturating Shift Left where lhs is of a computed type" {
try expect(value.exponent == 0);
}
comptime {
var image: [1]u8 = undefined;
_ = ℑ
_ = @shlExact(@as(u16, image[0]), 8);
}
test "Saturating Shift Left" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;

View File

@@ -30,7 +30,9 @@ export fn d(rhs: @Vector(3, i32)) void {
//
// :2:25: error: shift by negative amount '-1'
// :7:12: error: shift by negative amount '-2'
// :11:47: error: shift by negative amount '-3' at index '0'
// :16:27: error: shift by negative amount '-4' at index '1'
// :11:47: error: shift by negative amount '-3'
// :11:47: note: when computing vector element at index '0'
// :16:27: error: shift by negative amount '-4'
// :16:27: note: when computing vector element at index '1'
// :20:25: error: shift by signed type 'i32'
// :24:40: error: shift by signed type '@Vector(3, i32)'

View File

@@ -0,0 +1,9 @@
export fn f() usize {
const a = comptime 0 <<| (1 << @bitSizeOf(usize));
return a;
}
// error
// target=x86_64-linux
//
// :2:30: error: this implementation only supports comptime shift amounts of up to 2^64 - 1 bits

View File

@@ -7,4 +7,4 @@ comptime {
// backend=stage2
// target=native
//
// :2:15: error: operation caused overflow
// :2:15: error: overflow of integer type 'u8' with value '340'

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff