microsoft / DirectXShaderCompiler

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

Can construct-cast an array type to non-array without compiler complaining (DXIL Crash) #5632

Open devshgraphicsprogramming opened 1 year ago

devshgraphicsprogramming commented 1 year ago

Description

I have a member in a struct of type uint _pad[1]

if turns out its possible for me to do

float(obj._pad)

without the compiler warning or complaining, and it will even emit on the OpLoad-ed access chain

         %25 = OpCompositeExtract %uint %24 0

so this behaves as-if I did float(obj._pad[0]) ?

Is this intended behaviour?

Steps to Reproduce https://godbolt.org/z/dqa1jG41b

Actual Behavior

No warnings or errors about what I'm doing.

Environment

llvm-beanz commented 1 year ago

The SPIR-V behavior here matches FXC: https://shader-playground.timjones.io/36dfb3e4879857ee6023e3216148ae76

DXC crashes when generating DXIL for this code: https://godbolt.org/z/97GMh3zjd

So I think the only bug here is that DXC is crashing in DXIL, and we should probably issue a diagnostic on array->scalar truncation.