microsoft / microsoft/DirectXShaderCompiler

Infinite loop related to struct inheritance and empty struct

Open
#3,873 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I'm hitting an infinite loop when compiling a shader with a particular pattern of inheritance and function calls to a helper struct. From reducing the repro case the problem appears to occur when a parent struct declares a member of an empty helper struct, then a child struct derives from that and also declares its own member var (not zero-sized). Then calling a method on that helper struct from a function on the child will trigger the infinite loop.

The hang looks to be in the SROA pass, which suggestions a connection to #3770 (which also dealt with empty structs). However the fix for that does not seem to have fixed this issue, sadly.

Here's the minimal repro I came up with. Confirmed still occurs with the current-head e65a981. Compile with -T ps_6_7 -E main

struct Helper
{
	float getColor() { return 0; }
};

struct Parent
{
	Helper helper;
};

struct Child : Parent
{
	float memberVar;

	float color()
	{
		return helper.getColor();
	}
};

float main() : SV_Target
{
	Child instance;
	return instance.color();
}

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 minimal HLSL repro in the issue and compile it using -T ps_6_7 -E main against the current compiler. Investigate the SROA pass and the related empty-struct issue #3770 to identify where compilation loops. Done means this inheritance, empty-helper-struct, and method-call pattern compiles without hanging.

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.