Skip to content

Commit 8e16e5c

Browse files
authored
[HLSL] Bug fix crash using Array Parameters when De-sugaring is the same as canonicalizing (#127670)
Fixes this crash: https://hlsl.godbolt.org/z/9aP74s4bP Which happens because the de-sugared type is the same as the canonicalized type. Check if the de-sugared type is canonical before getting the ArrayParameterType of the canonical type. Add AST test to ensure crash doesn't happen.
1 parent 4efab09 commit 8e16e5c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,7 +3898,8 @@ QualType ASTContext::getArrayParameterType(QualType Ty) const {
38983898
if (Ty->isArrayParameterType())
38993899
return Ty;
39003900
assert(Ty->isConstantArrayType() && "Ty must be an array type.");
3901-
const auto *ATy = cast<ConstantArrayType>(Ty.getDesugaredType(*this));
3901+
QualType DTy = Ty.getDesugaredType(*this);
3902+
const auto *ATy = cast<ConstantArrayType>(DTy);
39023903
llvm::FoldingSetNodeID ID;
39033904
ATy->Profile(ID, *this, ATy->getElementType(), ATy->getZExtSize(),
39043905
ATy->getSizeExpr(), ATy->getSizeModifier(),
@@ -3910,7 +3911,7 @@ QualType ASTContext::getArrayParameterType(QualType Ty) const {
39103911
return QualType(AT, 0);
39113912

39123913
QualType Canonical;
3913-
if (!Ty.isCanonical()) {
3914+
if (!DTy.isCanonical()) {
39143915
Canonical = getArrayParameterType(getCanonicalType(Ty));
39153916

39163917
// Get the new insert position for the node we care about.

clang/test/AST/HLSL/TypdefArrayParam.hlsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,14 @@ void call2() {
5555
uint4 C[2] = {A,A};
5656
uint32_t D = Accumulate(C);
5757
}
58+
59+
typedef int Foo[2];
60+
61+
// CHECK-LABEL: call3
62+
// CHECK: ArraySubscriptExpr {{.*}} 'int' lvalue
63+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' <ArrayToPointerDecay>
64+
// CHECK-NEXT: DeclRefExpr {{.*}} 'int[2]' lvalue ParmVar {{.*}} 'F' 'int[2]'
65+
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0
66+
int call3(Foo F) {
67+
return F[0];
68+
}

0 commit comments

Comments
 (0)