Skip to content

[HLSL] Desugar type when converting from a ConstantArrayType to an ArrayParameterType #126561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3902,7 +3902,7 @@ QualType ASTContext::getArrayParameterType(QualType Ty) const {
if (Ty->isArrayParameterType())
return Ty;
assert(Ty->isConstantArrayType() && "Ty must be an array type.");
const auto *ATy = cast<ConstantArrayType>(Ty);
const auto *ATy = cast<ConstantArrayType>(Ty.getDesugaredType(*this));
llvm::FoldingSetNodeID ID;
ATy->Profile(ID, *this, ATy->getElementType(), ATy->getZExtSize(),
ATy->getSizeExpr(), ATy->getSizeModifier(),
Expand Down
57 changes: 57 additions & 0 deletions clang/test/AST/HLSL/TypdefArrayParam.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -finclude-default-header -x hlsl -ast-dump %s | FileCheck %s

typedef uint4 uint32_t4;
typedef uint32_t4 uint32_t8[2];

// CHECK-LABEL: FunctionDecl {{.*}} used Accumulate 'uint32_t (uint32_t4[2])'
// CHECK-NEXT: ParmVarDecl {{.*}} used V 'uint32_t4[2]'
uint32_t Accumulate(uint32_t8 V) {
uint32_t4 SumVec = V[0] + V[1];
return SumVec.x + SumVec.y + SumVec.z + SumVec.w;
}

// CHECK-LABEL: FunctionDecl {{.*}} used InOutAccu 'void (inout uint32_t4[2])'
// CHECK-NEXT: ParmVarDecl {{.*}} used V 'uint32_t4[2]'
// CHECK-NEXT: HLSLParamModifierAttr {{.*}} inout
void InOutAccu(inout uint32_t8 V) {
uint32_t4 SumVec = V[0] + V[1];
V[0] = SumVec;
}

// CHECK-LABEL: call1
// CHECK: CallExpr {{.*}} 'void'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(inout uint32_t4[2])' <FunctionToPointerDecay>
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (inout uint32_t4[2])' lvalue Function {{.*}} 'InOutAccu' 'void (inout uint32_t4[2])'
// CHECK-NEXT: HLSLOutArgExpr {{.*}} 'uint32_t4[2]' lvalue inout
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue Var {{.*}} 'B' 'uint32_t8':'uint32_t4[2]'
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t4[2]' lvalue
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint32_t4[2]' <HLSLArrayRValue>
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue Var {{.*}} 'B' 'uint32_t8':'uint32_t4[2]'
// CHECK-NEXT: BinaryOperator {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue '='
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue Var {{.*}} 'B' 'uint32_t8':'uint32_t4[2]'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint32_t4[2]' <HLSLArrayRValue>
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t4[2]' lvalue
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint32_t4[2]' <HLSLArrayRValue>
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue Var {{.*}} 'B' 'uint32_t8':'uint32_t4[2]'
void call1() {
uint32_t4 A = {1,2,3,4};
uint32_t8 B = {A,A};
InOutAccu(B);
}

// CHECK-LABEL: call2
// CHECK: VarDecl {{.*}} D 'uint32_t':'unsigned int' cinit
// CHECK-NEXT: CallExpr {{.*}} 'uint32_t':'unsigned int'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint32_t (*)(uint32_t4[2])' <FunctionToPointerDecay>
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint32_t (uint32_t4[2])' lvalue Function {{.*}} 'Accumulate' 'uint32_t (uint32_t4[2])'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint4[2]' <HLSLArrayRValue>
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint4[2]' lvalue Var {{.*}} 'C' 'uint4[2]'
void call2() {
uint4 A = {1,2,3,4};
uint4 C[2] = {A,A};
uint32_t D = Accumulate(C);
}