microsoft / microsoft/DirectXShaderCompiler

DXC should warn on statically checkable out-of-bounds

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

Nobody has claimed this yet.

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

Description

Description
I made a struct T with a member of type uint[1], then I index it with a literal cosntant 2000.

I'm fairly sure that even though the StructuredBuffer is indeed an OpTypeRuntimeArray, its only for the struct T (see comments in the repro).

Steps to Reproduce
https://godbolt.org/z/frv3neY5x

Actual Behavior
Obviously if I were to index using some runtime variable instead of a constant literal, its impossible to bounds-check my indexing.

However a constant literal should be easy to check, but I don't know is its invalid SPIR-V and UB to index past the end or its fine?

In either case compiler should emit warning or error.

Environment

  • DXC version Latest on Godbolt
  • 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 with the Godbolt reproduction linked in the issue and confirm how DXC handles a literal index of 2000 into the uint[1] member of struct T. Determine whether the generated SPIR-V makes this invalid or undefined, then add the appropriate warning or error and tests demonstrating the diagnostic for statically out-of-bounds indexing.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.