Skip to content

Commit b23c015

Browse files
Greg Rothtex3d
authored andcommitted
Fix unbound arrays flattened type compare (#3544)
Comparing two unbound arrays where one was initilizing the other resulted in infinitely incrementing both and never reaching a conclusion. This adds detection to FlattenedTypeIterator for the situation whereupon the comparison is terminated and the result returned. A simple test of the assignment is added expecting the correct error.
1 parent 55f39f5 commit b23c015

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,6 +5262,8 @@ class FlattenedTypeIterator
52625262
QualType getCurrentElement() const;
52635263
/// <summary>Get the number of repeated current elements.</summary>
52645264
unsigned int getCurrentElementSize() const;
5265+
/// <summary>Gets the current element's Iterkind.</summary>
5266+
FlattenedIterKind getCurrentElementKind() const { return m_typeTrackers.back().IterKind; }
52655267
/// <summary>Checks whether the iterator has a current element type to report.</summary>
52665268
bool hasCurrentElement() const;
52675269
/// <summary>Consumes count elements on this iterator.</summary>
@@ -10997,6 +10999,11 @@ FlattenedTypeIterator::CompareIterators(
1099710999
advance = 1;
1099811000
}
1099911001

11002+
// If both elements are unbound arrays, break out or we'll never finish
11003+
if (leftIter.getCurrentElementKind() == FK_IncompleteArray &&
11004+
rightIter.getCurrentElementKind() == FK_IncompleteArray)
11005+
break;
11006+
1100011007
leftIter.advanceCurrentElement(advance);
1100111008
rightIter.advanceCurrentElement(advance);
1100211009
result.LeftCount += advance;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %dxc -T ps_6_0 %s | FileCheck %s
2+
3+
// Verify that error for unbounded array struct member is produced
4+
// even if the struct is initialized with a resource that is an unbounded array
5+
// Previously, this would hang the compiler
6+
7+
Texture2D unboundResource[] : register(t0);
8+
9+
// CHECK: error: array dimensions of struct/class members must be explicit
10+
static const struct {
11+
Texture2D unboundField[];
12+
} unboundStruct = { unboundResource };
13+
14+
float4 main() {
15+
return 0.0;
16+
}

0 commit comments

Comments
 (0)