From 975e1e3fa8dbf68fdc57af1353aea5aff32f5d62 Mon Sep 17 00:00:00 2001 From: Sarah Spall Date: Tue, 18 Feb 2025 08:29:25 -0800 Subject: [PATCH] fix bug + test --- clang/lib/AST/ASTContext.cpp | 5 +++-- clang/test/AST/HLSL/TypdefArrayParam.hlsl | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b1b9d56ccca9f..5aaf4ce5c9155 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3902,7 +3902,8 @@ QualType ASTContext::getArrayParameterType(QualType Ty) const { if (Ty->isArrayParameterType()) return Ty; assert(Ty->isConstantArrayType() && "Ty must be an array type."); - const auto *ATy = cast(Ty.getDesugaredType(*this)); + QualType DTy = Ty.getDesugaredType(*this); + const auto *ATy = cast(DTy); llvm::FoldingSetNodeID ID; ATy->Profile(ID, *this, ATy->getElementType(), ATy->getZExtSize(), ATy->getSizeExpr(), ATy->getSizeModifier(), @@ -3914,7 +3915,7 @@ QualType ASTContext::getArrayParameterType(QualType Ty) const { return QualType(AT, 0); QualType Canonical; - if (!Ty.isCanonical()) { + if (!DTy.isCanonical()) { Canonical = getArrayParameterType(getCanonicalType(Ty)); // Get the new insert position for the node we care about. diff --git a/clang/test/AST/HLSL/TypdefArrayParam.hlsl b/clang/test/AST/HLSL/TypdefArrayParam.hlsl index c6ae168f84064..37f7a66de23a1 100644 --- a/clang/test/AST/HLSL/TypdefArrayParam.hlsl +++ b/clang/test/AST/HLSL/TypdefArrayParam.hlsl @@ -55,3 +55,14 @@ void call2() { uint4 C[2] = {A,A}; uint32_t D = Accumulate(C); } + +typedef int Foo[2]; + +// CHECK-LABEL: call3 +// CHECK: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: DeclRefExpr {{.*}} 'int[2]' lvalue ParmVar {{.*}} 'F' 'int[2]' +// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0 +int call3(Foo F) { + return F[0]; +}