mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-22 19:50:05 +00:00
Fix null pointer in FoldInsertWithConstants. (#5093)
* Fix null pointer in FoldInsertWithConstants. Struct types are not supported in constant folding yet. * Added 'Test case 16' to fold_test. Tests OpCompositeInsert not to be folded on a struct type.
This commit is contained in:
parent
fd1e650cfe
commit
cac9a5a3ee
@ -145,12 +145,17 @@ ConstantFoldingRule FoldInsertWithConstants() {
|
||||
if (composite->AsNullConstant()) {
|
||||
// Make new composite so it can be inserted in the index with the
|
||||
// non-null value
|
||||
const auto new_composite = const_mgr->GetNullCompositeConstant(type);
|
||||
// Keep track of any indexes along the way to last index
|
||||
if (i != final_index) {
|
||||
chain.push_back(new_composite);
|
||||
if (const auto new_composite =
|
||||
const_mgr->GetNullCompositeConstant(type)) {
|
||||
// Keep track of any indexes along the way to last index
|
||||
if (i != final_index) {
|
||||
chain.push_back(new_composite);
|
||||
}
|
||||
components = new_composite->AsCompositeConstant()->GetComponents();
|
||||
} else {
|
||||
// Unsupported input type (such as structs)
|
||||
return nullptr;
|
||||
}
|
||||
components = new_composite->AsCompositeConstant()->GetComponents();
|
||||
} else {
|
||||
// Keep track of any indexes along the way to last index
|
||||
if (i != final_index) {
|
||||
|
@ -7363,7 +7363,16 @@ INSTANTIATE_TEST_SUITE_P(CompositeExtractOrInsertMatchingTest, MatchingInstructi
|
||||
"%5 = OpCompositeConstruct %v2int %3 %4\n" +
|
||||
"OpReturn\n" +
|
||||
"OpFunctionEnd",
|
||||
5, true)
|
||||
5, true),
|
||||
// Test case 16: Don't fold when type cannot be deduced to a constant.
|
||||
InstructionFoldingCase<bool>(
|
||||
Header() +
|
||||
"%main = OpFunction %void None %void_func\n" +
|
||||
"%main_lab = OpLabel\n" +
|
||||
"%4 = OpCompositeInsert %struct_v2int_int_int %int_1 %struct_v2int_int_int_null 2\n" +
|
||||
"OpReturn\n" +
|
||||
"OpFunctionEnd",
|
||||
4, false)
|
||||
));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(DotProductMatchingTest, MatchingInstructionFoldingTest,
|
||||
|
Loading…
Reference in New Issue
Block a user