microsoft / microsoft/DirectXShaderCompiler
Error in implicit conversions when enums are involved
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
DXC seems to be having some issues when there are bit shift operations with enums. Other bit operators seem to work fine but not bit shifts. While I haven't checked the C++ spec I believe HLSL mirrors C++'s behavior. Despite that this error is not something I've seen or was able to reproduce in any of the C++ compilers that I've tested. This leads me to believe that there might be an issue with DXC.
Steps to Reproduce
Pretty simple repro case:
enum E : uint {
A,
B
};
float4 PSMain() : SV_Target0 {
uint e = E::A << 1u;
return 0.0;
}
And the error is:
error: cannot convert from 'unsigned int' to 'E'
Replacing << with | for example works fine.
Godbolt link: https://godbolt.org/z/nKThYcs1z
Actual Behavior
Pretty sure that this type of operations shouldn't throw an error.
Environment
- DXC version: Trunk (6b4b0eb5)
- Host Operating System: Linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the provided HLSL repro with DXC trunk and compare the enum shift with the working bitwise-OR form. Trace the implicit-conversion handling for enum expressions; done means the shift expression compiles without the reported conversion error while preserving the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100