microsoft / microsoft/DirectXShaderCompiler

Infinite loop in SemaHLSL when compiling weird array

Open
#6,407 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

DXC loops indefinitely when building a simple HLSL shader with a weird array initializer.
Affects both DXIL and SPIR-V.

Seems like the loop is in SemaHLSL.cpp:

Process 3039522 stopped
* thread #1, name = 'dxc', stop reason = step over
    frame #0: 0x00007ffff57eb0c2 libdxcompiler.so`FlattenedTypeIterator::FlattenedTypeIterator(this=0x00007fffffff2fe0, loc=(ID = 46), type=QualType @ 0x00007fffffff2df0, source=0x0000555555a02310) at SemaHLSL.cpp:11857:7
   11854	      m_incompleteCount(0), m_typeDepth(0), m_loc(loc) {
   11855	  if (pushTrackerForType(type, nullptr)) {
   11856	    while (!m_typeTrackers.empty() && !considerLeaf())
-> 11857	      consumeLeaf();
   11858	  }
   11859	}
   11860

Steps to Reproduce

[numthreads(1, 1, 1)]
void main() {
  float array[1][0] = { {} };
}
./build/bin/dxc -T cs_6_0 -E main loop.hlsl

Environment

  • DXC version: HEAD (130877392c263888ef06bab768856d3dab1f1c9a)
  • 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

Reproduce the issue with the provided HLSL shader and dxc command, then inspect FlattenedTypeIterator in SemaHLSL.cpp around line 11857. Trace why the constructor's loop does not make progress for the zero-length array initializer. Done means compilation terminates for the reproducer, with behavior checked for both DXIL and SPIR-V.

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.