Skip to content

Opt: segfault or assertion failure on merge blocks for unreachable loop #2374

@paulthomson

Description

@paulthomson

The following SPIRV causes an assertion failure in spirv-opt. The issue is that the merge blocks pass tries to merge blocks %15 and %11 via the back-edge. The loop is unreachable. I came across this issue using spirv-reduce, which uses the merge blocks code. I made a test using the text below, plus: SinglePassRunAndCheck<BlockMergePass>(text, text, true, true); In other words, I assume there should be no change once the issue is fixed.

spirv-opt --merge-blocks -o opt.spv in.spv

               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %main "main"
               OpExecutionMode %main OriginUpperLeft
               OpSource ESSL 310
               OpName %main "main"
       %void = OpTypeVoid
          %4 = OpTypeFunction %void
        %int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
       %bool = OpTypeBool
      %false = OpConstantFalse %bool
       %main = OpFunction %void None %4
          %9 = OpLabel
               OpBranch %10
         %11 = OpLabel
               OpLoopMerge %12 %13 None
               OpBranchConditional %false %13 %14
         %13 = OpLabel
               OpSelectionMerge %15 None
               OpBranchConditional %false %16 %17
         %16 = OpLabel
               OpBranch %15
         %17 = OpLabel
               OpBranch %15
         %15 = OpLabel
               OpBranch %11
         %14 = OpLabel
               OpReturn
         %12 = OpLabel
               OpBranch %10
         %10 = OpLabel
               OpReturn
               OpFunctionEnd

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions