microsoft / microsoft/DirectXShaderCompiler

Nonsensical error message when using undef offset in structured buffer

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

Nobody has claimed this yet.

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

Description

This shader

// dxc /Tps_6_0 .\rawbuf.hlsl
// error: llvm::cast<X>() argument of incompatible type!

struct S {float A[3];};
RWStructuredBuffer<S> buf;

[RootSignature("UAV(u0)")]
float main() : SV_Target
{
    uint X;
    return buf[0].A[X];
}

Gives an error like

error: llvm::cast() argument of incompatible type!

But it should say something like "error: using uninitialized value to access structured buffer"

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 compiling the provided rawbuf.hlsl example with the dxc /Tps_6_0 command and inspect the diagnostic produced for main. Trace the handling of the uninitialized X used in buf[0].A[X]. Done means the compiler reports an informative uninitialized-value error instead of the llvm::cast() failure.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.