From 9b6b31be5b38c588bde28d5f215d78cfc62620da Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:26:12 -0700 Subject: Print warning when operator<< shifting too much (#4255) * Print warning when operator<< shifting too much Closes #3944 For the given type of the left side operand to `operator<<` is not big enough for the right side operand, print a warning that the result will be always zero. --- .../warning_operator_left_shift_overflow.slang | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/diagnostics/warning_operator_left_shift_overflow.slang (limited to 'tests') diff --git a/tests/diagnostics/warning_operator_left_shift_overflow.slang b/tests/diagnostics/warning_operator_left_shift_overflow.slang new file mode 100644 index 000000000..5c156a9b9 --- /dev/null +++ b/tests/diagnostics/warning_operator_left_shift_overflow.slang @@ -0,0 +1,27 @@ +//TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target hlsl + +RWStructuredBuffer inputBuffer; +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + uint8_t u8 = uint8_t(inputBuffer[0]); + + uint result = (u8 << 0) + + (u8 << 1) + + (u8 << 2) + + (u8 << 3) + + (u8 << 4) + + (u8 << 5) + + (u8 << 6) + + (u8 << 7) + // CHECK-NOT: warning 41030: + // CHECK: ([[#@LINE+1]]): warning 41030: {{.*}}uint8{{.*}}8 + + (u8 << 8) + // CHECK: ([[#@LINE+1]]): warning 41030: {{.*}}uint8{{.*}}9 + + (u8 << 9) + ; + + outputBuffer[0] = int(result); +} -- cgit v1.2.3