diff options
author | Steven Perron <stevenperron@google.com> | 2018-12-04 10:04:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-04 10:04:02 -0500 |
commit | 17cba4695c5da4c7779bc228548adc0b13734d5f (patch) | |
tree | 69da4c36fc662fb743dbb445eb58e92bd5f01f70 /test/opt/fold_test.cpp | |
parent | d81a0c0ec4880cefd9f23da2c68a6d928f27baea (diff) | |
download | spirv-tools-17cba4695c5da4c7779bc228548adc0b13734d5f.tar.gz |
Remove undefined behaviour when folding shifts. (#2157)
We currently simulate all shift operations when the two operand are
constants. The problem is that if the shift amount is larger than
32, the result is undefined.
I'm changing the folder to return 0 if the shift value is too high.
That way, we will have defined behaviour.
https://crbug.com/910937.
Diffstat (limited to 'test/opt/fold_test.cpp')
-rw-r--r-- | test/opt/fold_test.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/opt/fold_test.cpp b/test/opt/fold_test.cpp index 9aae338b..1a544218 100644 --- a/test/opt/fold_test.cpp +++ b/test/opt/fold_test.cpp @@ -179,6 +179,7 @@ OpName %main "main" %uint_3 = OpConstant %uint 3 %uint_4 = OpConstant %uint 4 %uint_32 = OpConstant %uint 32 +%uint_42 = OpConstant %uint 42 %uint_max = OpConstant %uint 4294967295 %v2int_undef = OpUndef %v2int %v2int_0_0 = OpConstantComposite %v2int %int_0 %int_0 @@ -474,6 +475,36 @@ INSTANTIATE_TEST_CASE_P(TestCase, IntegerInstructionFoldingTest, "%2 = OpUMod %uint %uint_1 %uint_0\n" + "OpReturn\n" + "OpFunctionEnd", + 2, 0), + // Test case 22: fold unsigned n >> 42 (undefined, so set to zero). + InstructionFoldingCase<uint32_t>( + Header() + "%main = OpFunction %void None %void_func\n" + + "%main_lab = OpLabel\n" + + "%n = OpVariable %_ptr_uint Function\n" + + "%load = OpLoad %uint %n\n" + + "%2 = OpShiftRightLogical %uint %load %uint_42\n" + + "OpReturn\n" + + "OpFunctionEnd", + 2, 0), + // Test case 21: fold signed n >> 42 (undefined, so set to zero). + InstructionFoldingCase<uint32_t>( + Header() + "%main = OpFunction %void None %void_func\n" + + "%main_lab = OpLabel\n" + + "%n = OpVariable %_ptr_int Function\n" + + "%load = OpLoad %int %n\n" + + "%2 = OpShiftRightLogical %int %load %uint_42\n" + + "OpReturn\n" + + "OpFunctionEnd", + 2, 0), + // Test case 22: fold n << 42 (undefined, so set to zero). + InstructionFoldingCase<uint32_t>( + Header() + "%main = OpFunction %void None %void_func\n" + + "%main_lab = OpLabel\n" + + "%n = OpVariable %_ptr_int Function\n" + + "%load = OpLoad %int %n\n" + + "%2 = OpShiftLeftLogical %int %load %uint_42\n" + + "OpReturn\n" + + "OpFunctionEnd", 2, 0) )); // clang-format on |