microsoft / microsoft/DirectXShaderCompiler

-Wcomma-in-init should maybe be more aggressive?

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

Nobody has claimed this yet.

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

Description

Description

Had a bug on a compute shader. Spent quite some time to figure out what's the issue (concurrent read/write to some buffers from multiple threads, etc, so LOTS of places things could go wrong).
Turns out the issue is simple:

uint thread_count = 32;
uint width = 4096
uint height = 2048
uint2 size = (width, height) / thread_count

I had forgotten the uint2 in the initializer:

uint2 size = uint2(width, height) / thread_count

Steps to Reproduce

[numthreads(1, 1, 1)]
void main()
{
  uint2 a = (1, 2) / 2;
}

dxc -T cs_6_6 repro.hlsl -Od

Dxc builds with no complaints.

Actual Behavior

Maybe DXC should complain that a constructor list may have been intended?
This code does generates the warning:

[numthreads(1, 1, 1)]
void main()
{
  uint2 a = (1, 2);
}

Environment

  • DXC version: libdxcompiler.so: 1.7(dev;4028-56db6cef)
  • DXC hash: 1d6b5627ac46a8b433f21fae50b9192689336c15
  • 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 running the reported dxc command on repro.hlsl and compare the existing -Wcomma-in-init behavior for the two examples. Trace the compiler warning implementation and its diagnostic tests to determine where parenthesized comma expressions in arithmetic should be checked. Done means the intended case produces a warning without introducing false positives, with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.