KhronosGroup / SPIRV-Tools

Apache License 2.0
1.05k stars 549 forks source link

opt: segfault in std::unique_ptr<spvtools::opt::Instruction, std::default_delete<spvtools::opt::Instruction> >::get() a.k.a _ZNKSt10unique_ptrIN8spvtools3opt11InstructionESt14default_deleteIS2_EE3getEv within spvtools::opt::BasicBlock::id() const within spvtools::opt::InlinePass::IsInlinableFunctionCall(spvtools::opt::Instruction*) #2748

Closed paulthomson closed 4 years ago

paulthomson commented 5 years ago

bug_report.zip

Issue found using GraphicsFuzz.

Tool versions:

To reproduce:

glslangValidator -V shader.frag -o shader.frag.spv

spirv-opt shader.frag.spv -o temp.spv --validate-after-all -O

The following shader files are included in the attached archive, some of which are also shown inline below:

0_glsl/shader.frag:

#version 310 es
precision highp float;

vec3 drawShape()
{
 bool c1;
 if(c1)
  {
   return vec3(1.0);
  }
 bool c2;
 if(c2)
  {
   return vec3(1.0);
  }
 bool c3;
 if(c3)
  {
   return vec3(1.0);
  }
 bool c4;
 if(c4)
  {
   return vec3(1.0);
  }
 bool c5;
 if(c5)
  {
   return vec3(1.0);
  }
 bool c6;
 if(c6)
  {
   return vec3(1.0);
  }
 bool c7;
 if(c7)
  {
   return vec3(1.0);
  }
 bool c8;
 if(c8)
  {
   return vec3(1.0);
  }
 discard;
 return vec3(1.0);
}
vec3 computePoint()
{
 drawShape();
 return vec3(1.0);
}
void main()
{
 drawShape();
 computePoint();
}

1_spirv_asm/shader.frag.asm:

; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 65
; Schema: 0
               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %4 "main"
               OpExecutionMode %4 OriginUpperLeft
               OpSource ESSL 310
               OpName %4 "main"
               OpName %9 "drawShape("
               OpName %11 "computePoint("
               OpName %15 "c1"
               OpName %22 "c2"
               OpName %27 "c3"
               OpName %32 "c4"
               OpName %37 "c5"
               OpName %42 "c6"
               OpName %47 "c7"
               OpName %52 "c8"
          %2 = OpTypeVoid
          %3 = OpTypeFunction %2
          %6 = OpTypeFloat 32
          %7 = OpTypeVector %6 3
          %8 = OpTypeFunction %7
         %13 = OpTypeBool
         %14 = OpTypePointer Function %13
         %19 = OpConstant %6 1
         %20 = OpConstantComposite %7 %19 %19 %19
          %4 = OpFunction %2 None %3
          %5 = OpLabel
         %63 = OpFunctionCall %7 %9
         %64 = OpFunctionCall %7 %11
               OpReturn
               OpFunctionEnd
          %9 = OpFunction %7 None %8
         %10 = OpLabel
         %15 = OpVariable %14 Function
         %22 = OpVariable %14 Function
         %27 = OpVariable %14 Function
         %32 = OpVariable %14 Function
         %37 = OpVariable %14 Function
         %42 = OpVariable %14 Function
         %47 = OpVariable %14 Function
         %52 = OpVariable %14 Function
         %16 = OpLoad %13 %15
               OpSelectionMerge %18 None
               OpBranchConditional %16 %17 %18
         %17 = OpLabel
               OpReturnValue %20
         %18 = OpLabel
         %23 = OpLoad %13 %22
               OpSelectionMerge %25 None
               OpBranchConditional %23 %24 %25
         %24 = OpLabel
               OpReturnValue %20
         %25 = OpLabel
         %28 = OpLoad %13 %27
               OpSelectionMerge %30 None
               OpBranchConditional %28 %29 %30
         %29 = OpLabel
               OpReturnValue %20
         %30 = OpLabel
         %33 = OpLoad %13 %32
               OpSelectionMerge %35 None
               OpBranchConditional %33 %34 %35
         %34 = OpLabel
               OpReturnValue %20
         %35 = OpLabel
         %38 = OpLoad %13 %37
               OpSelectionMerge %40 None
               OpBranchConditional %38 %39 %40
         %39 = OpLabel
               OpReturnValue %20
         %40 = OpLabel
         %43 = OpLoad %13 %42
               OpSelectionMerge %45 None
               OpBranchConditional %43 %44 %45
         %44 = OpLabel
               OpReturnValue %20
         %45 = OpLabel
         %48 = OpLoad %13 %47
               OpSelectionMerge %50 None
               OpBranchConditional %48 %49 %50
         %49 = OpLabel
               OpReturnValue %20
         %50 = OpLabel
         %53 = OpLoad %13 %52
               OpSelectionMerge %55 None
               OpBranchConditional %53 %54 %55
         %54 = OpLabel
               OpReturnValue %20
         %55 = OpLabel
               OpKill
               OpFunctionEnd
         %11 = OpFunction %7 None %8
         %12 = OpLabel
         %60 = OpFunctionCall %7 %9
               OpReturnValue %20
               OpFunctionEnd
s-perron commented 4 years ago

Fixed by #2842 I believe.