diff options
author | Diego Novillo <dnovillo@google.com> | 2019-07-29 13:27:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-29 13:27:40 -0700 |
commit | 49797609b7038e4e002415b287a6ed17ae273444 (patch) | |
tree | f9ffa1b3f813e8853b28200600713feb2d0c48a9 /test/opt/fold_test.cpp | |
parent | 7fd2365b06915dea766b9321b7920d5c3a5265d7 (diff) | |
download | spirv-tools-49797609b7038e4e002415b287a6ed17ae273444.tar.gz |
Protect against out-of-bounds references when folding OpCompositeExtract (#2774)
This fixes #2608.
The original test case had an out-of-bounds reference that ended up
folding into OpCompositeExtract that was indexing right outside the
constant composite.
The returned constant would then cause a segfault during constant
propagation.
Diffstat (limited to 'test/opt/fold_test.cpp')
-rw-r--r-- | test/opt/fold_test.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/test/opt/fold_test.cpp b/test/opt/fold_test.cpp index 3ea32046..a9f30890 100644 --- a/test/opt/fold_test.cpp +++ b/test/opt/fold_test.cpp @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "source/opt/fold.h" + #include <limits> #include <memory> #include <string> @@ -22,7 +24,6 @@ #include "gtest/gtest.h" #include "source/opt/build_module.h" #include "source/opt/def_use_manager.h" -#include "source/opt/fold.h" #include "source/opt/ir_context.h" #include "source/opt/module.h" #include "spirv-tools/libspirv.hpp" @@ -2980,7 +2981,17 @@ INSTANTIATE_TEST_SUITE_P(CompositeExtractFoldingTest, GeneralInstructionFoldingT "%4 = OpCompositeExtract %int %3 0\n" + "OpReturn\n" + "OpFunctionEnd", - 4, INT_7_ID) + 4, INT_7_ID), + // Test case 13: https://github.com/KhronosGroup/SPIRV-Tools/issues/2608 + // Out of bounds access. Do not fold. + InstructionFoldingCase<uint32_t>( + Header() + "%main = OpFunction %void None %void_func\n" + + "%main_lab = OpLabel\n" + + "%2 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1\n" + + "%3 = OpCompositeExtract %float %2 4\n" + + "OpReturn\n" + + "OpFunctionEnd", + 3, 0) )); INSTANTIATE_TEST_SUITE_P(CompositeConstructFoldingTest, GeneralInstructionFoldingTest, |