llvm / llvm/llvm-project

[HLSL] Error forming initializer list with nested arrays in structs

Open
#197,840 0 comments 0 reactions 0 assignees View on GitHub
HLSL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I generated some really awful code that works in DXC but not Clang.

```hlsl
// ---- Leaf-level structs (pure composition of scalars / arrays) ----
struct LeafA {
int data[100]; // 100 scalars
}; // total: 100

struct LeafB {
float values[80]; // 80 scalars
int2 pair; // 2 scalars
}; // total: 82

// ---- Mid-level: inheritance + composition ----
struct MidBase {
float3 origin; // 3 scalars
int tag; // 1 scalar
}; // total: 4

struct MidA : MidBase {
LeafA chunks[50]; // 50 * 100 = 5000
LeafB extras[10]; // 10 * 82 = 820
}; // total: 4 + 5000 + 820 = 5824

struct MidB : MidBase {
LeafB blocks[60]; // 60 * 82 = 4920
LeafA scratch[5]; // 5 * 100 = 500
}; // total: 4 + 4920 + 500 = 5424

// ---- Top-level: inheritance + composition ----
struct TopBase {
int header[10]; // 10 scalars
float3 anchor; // 3 scalars
}; // total: 13

struct Big : TopBase {
MidA majors[10]; // 10 * 5824 = 58240
MidB minors[2]; // 2 * 5424 = 10848
LeafA tail[3]; // 3 * 100 = 300
}; // total: 13 + 58240 + 10848 + 300 = 69401 scalars

struct Alternate : TopBase {
LeafA tail[3];
MidA majors[10];
MidB minors[2];
};

export int fn(int X) {
Big b = (Big)0;
Alternate a = {b};
return a.tail[0].data[0];
}
```

[compiler explorer](https://godbolt.org/z/WboEG8n68)

This code is awful, but it should be valid.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.