Set wrapped kill basic block's parent (#3269)

Fixes #3268

* Set the parent of the basic block for the wrapper function
* Add a test
This commit is contained in:
alan-baker 2020-04-01 12:31:57 -04:00 committed by GitHub
parent c37c94929b
commit f20c0d7971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -147,6 +147,7 @@ uint32_t WrapOpKill::GetOpKillFuncId() {
bb->AddInstruction(std::move(kill_inst)); bb->AddInstruction(std::move(kill_inst));
// Add the bb to the function // Add the bb to the function
bb->SetParent(opkill_function_.get());
opkill_function_->AddBasicBlock(std::move(bb)); opkill_function_->AddBasicBlock(std::move(bb));
// Add the function to the module. // Add the function to the module.

View File

@ -513,6 +513,40 @@ OpFunctionEnd
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); 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<WrapOpKill>(text, true);
EXPECT_EQ(Pass::Status::SuccessWithChange, std::get<1>(result));
result = SinglePassRunToBinary<WrapOpKill>(text, true);
EXPECT_EQ(Pass::Status::SuccessWithChange, std::get<1>(result));
}
} // namespace } // namespace
} // namespace opt } // namespace opt
} // namespace spvtools } // namespace spvtools