Skip to content

spirv-opt crashes when optimizing function declarations #5795

@cheneym2

Description

@cheneym2

When spv input to spirv-opt contains functions without blocks (declarations), some optimization passes crash. It seems that they assume functions will have blocks.

 %normalFunc = OpFunction %int None %26
          %a = OpFunctionParameter %int
               OpFunctionEnd
; SPIR-V
; Version: 1.5
; Generator: Khronos; 40
; Bound: 36
; Schema: 0
               OpCapability Linkage
               OpCapability RayTracingKHR
               OpCapability Shader
               OpExtension "SPV_KHR_ray_tracing"
               OpMemoryModel Logical GLSL450
               OpEntryPoint AnyHitKHR %anyhit "main" %Constants %8
               OpSource Slang 1
               OpName %Payload "Payload"
               OpMemberName %Payload 0 "val"
               OpName %SLANG_ParameterGroup_Constants_std140 "SLANG_ParameterGroup_Constants_std140"
               OpMemberName %SLANG_ParameterGroup_Constants_std140 0 "x"
               OpMemberName %SLANG_ParameterGroup_Constants_std140 1 "y"
               OpName %Constants "Constants"
               OpName %a "a"
               OpName %normalFunc "normalFunc"
               OpName %a_0 "a"
               OpName %normalFuncUsesGeneric "normalFuncUsesGeneric"
               OpName %anyhit "anyhit"
               OpMemberDecorate %Payload 0 Offset 0
               OpDecorate %SLANG_ParameterGroup_Constants_std140 Block
               OpMemberDecorate %SLANG_ParameterGroup_Constants_std140 0 Offset 0
               OpMemberDecorate %SLANG_ParameterGroup_Constants_std140 1 Offset 4
               OpDecorate %Constants Binding 0
               OpDecorate %Constants DescriptorSet 0
               OpDecorate %normalFunc LinkageAttributes "_SR29export_2Dxlibrary_2Dxgenerics10normalFuncp1pi_ii" Import
               OpDecorate %normalFuncUsesGeneric LinkageAttributes "_SR29export_2Dxlibrary_2Dxgenerics21normalFuncUsesGenericp1pi_ii" Import
       %void = OpTypeVoid
          %3 = OpTypeFunction %void
        %int = OpTypeInt 32 1
    %Payload = OpTypeStruct %int
%_ptr_IncomingRayPayloadKHR_Payload = OpTypePointer IncomingRayPayloadKHR %Payload
      %int_0 = OpConstant %int 0
%_ptr_IncomingRayPayloadKHR_int = OpTypePointer IncomingRayPayloadKHR %int
      %float = OpTypeFloat 32
%SLANG_ParameterGroup_Constants_std140 = OpTypeStruct %float %float
%_ptr_Uniform_SLANG_ParameterGroup_Constants_std140 = OpTypePointer Uniform %SLANG_ParameterGroup_Constants_std140
%_ptr_Uniform_float = OpTypePointer Uniform %float
      %int_1 = OpConstant %int 1
         %26 = OpTypeFunction %int %int
          %8 = OpVariable %_ptr_IncomingRayPayloadKHR_Payload IncomingRayPayloadKHR
  %Constants = OpVariable %_ptr_Uniform_SLANG_ParameterGroup_Constants_std140 Uniform
 %normalFunc = OpFunction %int None %26
          %a = OpFunctionParameter %int
               OpFunctionEnd
%normalFuncUsesGeneric = OpFunction %int None %26
        %a_0 = OpFunctionParameter %int
               OpFunctionEnd
     %anyhit = OpFunction %void None %3
          %4 = OpLabel
         %11 = OpAccessChain %_ptr_IncomingRayPayloadKHR_int %8 %int_0
         %17 = OpAccessChain %_ptr_Uniform_float %Constants %int_0
         %18 = OpLoad %float %17
         %20 = OpAccessChain %_ptr_Uniform_float %Constants %int_1
         %21 = OpLoad %float %20
         %22 = OpFMul %float %18 %21
         %23 = OpConvertFToS %int %22
         %24 = OpFunctionCall %int %normalFunc %23
         %28 = OpLoad %float %20
         %29 = OpConvertFToS %int %28
         %30 = OpFunctionCall %int %normalFuncUsesGeneric %29
         %33 = OpIAdd %int %24 %30
               OpStore %11 %33
               OpReturn
               OpFunctionEnd

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions