Skip to content

Commit f160e14

Browse files
committed
Updating based on PR feedback
Also fixed a bug thanks to @spall pointing out the missing test coverage! Thank you! ../clang/test/SemaHLSL/Language/InitIncompleteArrays.hlsl
1 parent 46cb70b commit f160e14

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,8 +3446,11 @@ class InitListTransformer {
34463446
// When we're generating initializer lists for incomplete array types we
34473447
// need to wrap around both when building the initializers and when
34483448
// generating the final initializer lists.
3449-
if (Wrap)
3450-
InitTy = QualType(InitTy->getBaseElementTypeUnsafe(), 0);
3449+
if (Wrap) {
3450+
assert(InitTy->isIncompleteArrayType());
3451+
const IncompleteArrayType *IAT = Ctx.getAsIncompleteArrayType(InitTy);
3452+
InitTy = IAT->getElementType();
3453+
}
34513454
BuildFlattenedTypeList(InitTy, DestTypes);
34523455
DstIt = DestTypes.begin();
34533456
}
@@ -3509,6 +3512,8 @@ bool SemaHLSL::transformInitList(const InitializedEntity &Entity,
35093512
// rvalue-reference. When checking the initializer we should look through
35103513
// the reference.
35113514
QualType InitTy = Entity.getType().getNonReferenceType();
3515+
if (InitTy.hasAddressSpace())
3516+
InitTy = SemaRef.getASTContext().removeAddrSpaceQualType(InitTy);
35123517
if (ExpectedSize != ActualSize) {
35133518
int TooManyOrFew = ActualSize > ExpectedSize ? 1 : 0;
35143519
SemaRef.Diag(Init->getBeginLoc(), diag::err_hlsl_incorrect_num_initializers)

clang/test/SemaHLSL/Language/InitIncompleteArrays.hlsl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ struct is_same<T, T> {
1111
static const bool value = true;
1212
};
1313

14+
template<typename T>
15+
struct remove_addrspace {
16+
using type = __decltype((T)0);
17+
};
18+
19+
template <typename T, typename V>
20+
using is_same_ignore_addrspace = is_same<typename remove_addrspace<T>::type, typename remove_addrspace<V>::type>;
21+
1422
struct SomeVals {
1523
int2 X;
1624
float2 Y;
@@ -23,22 +31,26 @@ static int2 SomeArr[] = {V}; // #SomeArr
2331
// expected-warning@#SomeArr 2 {{implicit conversion turns floating-point number into integer: 'double' to 'int'}}
2432
// expected-warning@#SomeArr 2 {{implicit conversion turns floating-point number into integer: 'float' to 'int'}}
2533

26-
_Static_assert(is_same<__decltype(SomeArr), int2[3]>::value, "What is this even?");
34+
_Static_assert(is_same_ignore_addrspace<__decltype(SomeArr), int2[3]>::value, "What is this even?");
2735

2836
static int2 VecArr[] = {
2937
int2(0,1),
3038
int2(2,3),
3139
int4(4,5,6,7),
3240
};
3341

34-
_Static_assert(is_same<__decltype(VecArr), int2[4]>::value, "One vec, two vec, three vecs, FOUR!");
42+
_Static_assert(is_same_ignore_addrspace<__decltype(VecArr), int2[4]>::value, "One vec, two vec, three vecs, FOUR!");
3543

3644
static int4 V4Arr[] = {
3745
int2(0,1),
3846
int2(2,3),
3947
};
4048

41-
_Static_assert(is_same<__decltype(V4Arr), int4[1]>::value, "One!");
49+
_Static_assert(is_same_ignore_addrspace<__decltype(V4Arr), int4[1]>::value, "One!");
50+
51+
static int ArrOfArr[][4] = { 1, 2, 3, 4, 5, 6, 7, 8 };
52+
53+
_Static_assert(is_same_ignore_addrspace<__decltype(ArrOfArr), int[2][4]>::value, "Two arrays of four!");
4254

4355
// expected-error@+1{{too few initializers in list for type 'int4[]' (aka 'vector<int, 4>[]') (expected 4 but found 2)}}
4456
static int4 V4ArrTooSmall[] = {
@@ -51,3 +63,6 @@ static int4 V4ArrAlsoTooSmall[] = {
5163
int2(2,3),
5264
int3(4,5,6),
5365
};
66+
67+
// expected-error@+1{{too few initializers in list for type 'int[][2]' (expected 6 but found 5)}}
68+
static int ArrOfArrTooSmall[][2] = { 1, 2, 3, 4, 5 };

0 commit comments

Comments
 (0)