microsoft / microsoft/DirectXShaderCompiler

Report warning when loop variable shadows one from outer scope in HLSL 2021

Open
#5,395 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug hlsl2021
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
Prior to HLSL2021, a loop variable that shadowed one from the outer scope generated a warning. With HLSL 2021, that warning does not appear.

Steps to Reproduce

// RUN: %dxc -T ps_6_6 -HV 2021 %s

float4 main(float f: F) : SV_Target {

       uint i = 7;
       for (uint i = 0; i < 3; i++) {
         f += i;
       }
       return f + i;
}

produces:

 warning: redefinition of 'i' shadows declaration in the outer scope; most recent declaration will be used [-Wfor-redefinition]
       for (uint i = 0; i < 3; i++) {

Actual Behavior

with HLSL2021 enabled, no warning is produced.

Environment

  • DXC version (dxcompiler.dll: 1.7 - 1.7.0.3942)
  • Host Operating System Win11

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 running the inline HLSL reproduction with DXC using -T ps_6_6 -HV 2021 and compare its behavior with the shown warning. Trace the compiler's handling of loop-variable shadowing for HLSL 2021; done means the reproduction emits the outer-scope shadowing warning again.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.