DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

Whlsl-legacy-literal triggers for literals with explicit signedness

Open simondeschenes opened this issue 2 months ago • 0 comments

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.

simondeschenes avatar Oct 31 '25 21:10 simondeschenes