mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-10-18 11:10:05 +00:00
spirv-opt: fix crash in function declarations (#5796)
* spirv-opt: fix crash in function declarations Function declarations contain no blocks, so bail before segfaulting in function optimization passes that operate on blocks. Fixes #5795 * spirv-opt: add test for optimizing declarations
This commit is contained in:
parent
380275eacd
commit
37d2fcb485
@ -267,6 +267,7 @@ void AggressiveDCEPass::AddBreaksAndContinuesToWorklist(
|
||||
}
|
||||
|
||||
bool AggressiveDCEPass::AggressiveDCE(Function* func) {
|
||||
if (func->IsDeclaration()) return false;
|
||||
std::list<BasicBlock*> structured_order;
|
||||
cfg()->ComputeStructuredOrder(func, &*func->begin(), &structured_order);
|
||||
live_local_vars_.clear();
|
||||
|
@ -415,6 +415,7 @@ void MemPass::RemoveBlock(Function::iterator* bi) {
|
||||
}
|
||||
|
||||
bool MemPass::RemoveUnreachableBlocks(Function* func) {
|
||||
if (func->IsDeclaration()) return false;
|
||||
bool modified = false;
|
||||
|
||||
// Mark reachable all blocks reachable from the function's entry block.
|
||||
|
@ -8070,6 +8070,42 @@ TEST_F(AggressiveDCETest, StoringAPointer) {
|
||||
SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
|
||||
}
|
||||
|
||||
TEST_F(AggressiveDCETest, FunctionDeclaration) {
|
||||
// Ensure the optimizer can handle traversing over a function declaration
|
||||
// 'myfunc' which has no blocks
|
||||
|
||||
const std::string text = R"(OpCapability Linkage
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %PSMain "main" %entryPointParam_PSMain
|
||||
OpExecutionMode %PSMain OriginUpperLeft
|
||||
OpSource Slang 1
|
||||
OpName %myfunc "myfunc"
|
||||
OpName %entryPointParam_PSMain "entryPointParam_PSMain"
|
||||
OpName %PSMain "PSMain"
|
||||
OpDecorate %myfunc LinkageAttributes "_S6myfuncp0pv4f" Import
|
||||
OpDecorate %entryPointParam_PSMain Location 0
|
||||
%void = OpTypeVoid
|
||||
%5 = OpTypeFunction %void
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%8 = OpTypeFunction %v4float
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
%entryPointParam_PSMain = OpVariable %_ptr_Output_v4float Output
|
||||
%myfunc = OpFunction %v4float None %8
|
||||
OpFunctionEnd
|
||||
%PSMain = OpFunction %void None %5
|
||||
%10 = OpLabel
|
||||
%11 = OpFunctionCall %v4float %myfunc
|
||||
OpStore %entryPointParam_PSMain %11
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
|
||||
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
|
||||
SinglePassRunAndCheck<AggressiveDCEPass>(text, text, true, true);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace opt
|
||||
} // namespace spvtools
|
||||
|
Loading…
Reference in New Issue
Block a user