microsoft / microsoft/DirectXShaderCompiler

Error in implicit conversions when enums are involved

Open
#5,807 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug hlsl-next
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.