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:
Laura Hermanns 2023-02-03 10:03:15 -05:00 committed by GitHub
parent fd1e650cfe
commit cac9a5a3ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -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) {

View File

@ -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,