diff --git a/source/opt/wrap_opkill.cpp b/source/opt/wrap_opkill.cpp index ffd7a1050..05e1db034 100644 --- a/source/opt/wrap_opkill.cpp +++ b/source/opt/wrap_opkill.cpp @@ -147,6 +147,7 @@ uint32_t WrapOpKill::GetOpKillFuncId() { bb->AddInstruction(std::move(kill_inst)); // Add the bb to the function + bb->SetParent(opkill_function_.get()); opkill_function_->AddBasicBlock(std::move(bb)); // Add the function to the module. diff --git a/test/opt/wrap_opkill_test.cpp b/test/opt/wrap_opkill_test.cpp index d50af28a1..b6b6a2321 100644 --- a/test/opt/wrap_opkill_test.cpp +++ b/test/opt/wrap_opkill_test.cpp @@ -513,6 +513,40 @@ OpFunctionEnd EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); } +TEST_F(WrapOpKillTest, SetParentBlock) { + const std::string text = R"( +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %main "main" +OpExecutionMode %main OriginUpperLeft +%void = OpTypeVoid +%bool = OpTypeBool +%undef = OpUndef %bool +%void_fn = OpTypeFunction %void +%main = OpFunction %void None %void_fn +%entry = OpLabel +OpBranch %loop +%loop = OpLabel +OpLoopMerge %merge %continue None +OpBranchConditional %undef %merge %continue +%continue = OpLabel +%call = OpFunctionCall %void %kill_func +OpBranch %loop +%merge = OpLabel +OpReturn +OpFunctionEnd +%kill_func = OpFunction %void None %void_fn +%kill_entry = OpLabel +OpKill +OpFunctionEnd +)"; + + auto result = SinglePassRunToBinary(text, true); + EXPECT_EQ(Pass::Status::SuccessWithChange, std::get<1>(result)); + result = SinglePassRunToBinary(text, true); + EXPECT_EQ(Pass::Status::SuccessWithChange, std::get<1>(result)); +} + } // namespace } // namespace opt } // namespace spvtools