microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.12k stars 699 forks source link

Integer vector as enum type causes ICE rather than error #4384

Open Ipotrick opened 2 years ago

Ipotrick commented 2 years ago

Hi, I am using the DXC c++ interface to compile hlsl to spirv. I found an internal compiler crash inside the "Compile" function of DxcCompiler3. I am using the msvc clang toolchain version 13.0.0 to compile. I downloaded the latest version of dxc from the repository (dbd8db0e84420e063f6f7da974a32d58aa79b64b). I can compile other code just fine and i also get error messages for other mistakes in my hlsl. Here are my used arguments: -Zpc -spirv -fspv-target-env=vulkan1.1 _o3 -E -T cs_6_0 -HV 2021. Minimal example that causes the compiler crash (reading illegal memory address, address varies from run to run):

enum EE : uint3 {
    E = uint3(0,0,0),
};

I am new to dxc and hlsl and i dont even know if it is legal to use a uint3 as a "Supper" for an enum, but i am sure it should NOT crash when i give a missinput like that.

pow2clk commented 2 years ago

Thanks for the report @ipotrick! Welcome to DXC!

Using an integer vector as the type for an enum is not allowed. We should produce an error here just as we do if you try to use float.

Just a note for @jaebaek and @sudonatalie that this issue is not limited to SPIRV.

jaebaek commented 2 years ago

@pow2clk Thank you for letting us know :)

llvm-beanz commented 1 year ago

Some added context here. This crashes for DXIL and SPIR-V.

Enum type specifier must be an integral basic type. It cannot be a vector, floating-point type, struct or array.