microsoft / microsoft/DirectXShaderCompiler
Whlsl-legacy-literal triggers for literals with explicit signedness
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
When using HLSL 202x, a warning can be enabled to find every place where a signed literal is now unsigned.
This warning is enabled with -Whlsl-legacy-literal.
It allows going over all the potentially problematic cases in the code.
However, if the programmer explicitly handles the "signedness" of the literal by using the u suffix or by casting the literal to a specific type, the warning shouldn't trigger. Currently it does trigger in those cases and the warning can't be easily silenced.
Steps to Reproduce
All of the following will trigger the warning
static const uint A = 0xFFF00000u;
static const uint B = (uint)0xFFF00000;
static const int C = (int)0xFFF00000;
To reproduce, make sure to include the following arguments: -HV 202x -WX -Whlsl-legacy-literal
Actual Behavior
error: literal value is treated as signed in HLSL 2021 and earlier, and unsigned in later language versions [-Werror,-Whlsl-legacy-literal]
Environment
- DXC version: v1.8.2505.1
- Host Operating System: Windows 11 24H2
@llvm-beanz asked me to tag him on this bug report.
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 reproducing the warning with the three HLSL snippets and the listed -HV 202x -WX -Whlsl-legacy-literal arguments. Trace the compiler entry point for -Whlsl-legacy-literal and locate its existing diagnostic tests. Done means explicitly unsigned or cast literals no longer trigger the warning, while the warning still identifies unhandled legacy literals.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100