microsoft / microsoft/DirectXShaderCompiler

Whlsl-legacy-literal triggers for literals with explicit signedness

Open
#7,864 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.