Merge pull request #24674 from Justus2308/undef-shift-bitwise
Sema: Improve comptime arithmetic undef handling
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)'
|
||||
|
||||
9
test/cases/compile_errors/shift_by_larger_than_usize.zig
Normal file
9
test/cases/compile_errors/shift_by_larger_than_usize.zig
Normal 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
|
||||
@@ -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'
|
||||
|
||||
11
test/cases/compile_errors/shl_exact_on_undefined_value.zig
Normal file
11
test/cases/compile_errors/shl_exact_on_undefined_value.zig
Normal 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
|
||||
11
test/cases/compile_errors/shl_on_undefined_value.zig
Normal file
11
test/cases/compile_errors/shl_on_undefined_value.zig
Normal 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
|
||||
@@ -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
|
||||
11
test/cases/compile_errors/shr_exact_on_undefined_value.zig
Normal file
11
test/cases/compile_errors/shr_exact_on_undefined_value.zig
Normal 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
|
||||
11
test/cases/compile_errors/shr_on_undefined_value.zig
Normal file
11
test/cases/compile_errors/shr_on_undefined_value.zig
Normal 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
3004
test/cases/compile_errors/undef_shifts_are_illegal.zig
Normal file
3004
test/cases/compile_errors/undef_shifts_are_illegal.zig
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user