microsoft / DirectXShaderCompiler

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

Non-const static data members of templated structs fail to compile #6073

Open KStocky opened 1 year ago

KStocky commented 1 year ago

Description As the title describes. A non-const static data member in a templated struct will fail to compile. Having a non-const static data member in a non-templated struct works just fine as demonstrated here https://shader-playground.timjones.io/86034155d4699032dcecce2b676f2f4d. And having a const static data member in a templated struct works just fine as demonstrated here https://shader-playground.timjones.io/a65880bc84396a5f9420e41956817761

Steps to Reproduce The following is a minimal example https://shader-playground.timjones.io/9cb247ff54bf1ee0c6bdaa960cb83f9d.

Actual Behavior Compiler outputs "Declaration may not be in a Comdat! i32* @"\01?Num@?$Test@$0CK@@@2HA"

Expected Behaviour I would expect this to compile

Environment

llvm-beanz commented 1 year ago

This code pattern is correct C++, but we're crashing in. A compiler explorer repro is here: https://cpp.godbolt.org/z/E5Yxj5qYv

The issue is likely caused by the way HLSL overrides the code generation for static and global variables. We can probably fix this instance, but I think we're going to need to think about changing the language in the future to avoid these kinds of collisions.