Skip to content

Commit f5fbf54

Browse files
spallIcohedron
authored andcommitted
[HLSL] Desugar type when converting from a ConstantArrayType to an ArrayParameterType (llvm#126561)
Desugar type when converting from a ConstantArrayType to an ArrayParameterType in getArrayParameterType Closes llvm#125743
1 parent a7b9026 commit f5fbf54

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3902,7 +3902,7 @@ QualType ASTContext::getArrayParameterType(QualType Ty) const {
39023902
if (Ty->isArrayParameterType())
39033903
return Ty;
39043904
assert(Ty->isConstantArrayType() && "Ty must be an array type.");
3905-
const auto *ATy = cast<ConstantArrayType>(Ty);
3905+
const auto *ATy = cast<ConstantArrayType>(Ty.getDesugaredType(*this));
39063906
llvm::FoldingSetNodeID ID;
39073907
ATy->Profile(ID, *this, ATy->getElementType(), ATy->getZExtSize(),
39083908
ATy->getSizeExpr(), ATy->getSizeModifier(),
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -finclude-default-header -x hlsl -ast-dump %s | FileCheck %s
2+
3+
typedef uint4 uint32_t4;
4+
typedef uint32_t4 uint32_t8[2];
5+
6+
// CHECK-LABEL: FunctionDecl {{.*}} used Accumulate 'uint32_t (uint32_t4[2])'
7+
// CHECK-NEXT: ParmVarDecl {{.*}} used V 'uint32_t4[2]'
8+
uint32_t Accumulate(uint32_t8 V) {
9+
uint32_t4 SumVec = V[0] + V[1];
10+
return SumVec.x + SumVec.y + SumVec.z + SumVec.w;
11+
}
12+
13+
// CHECK-LABEL: FunctionDecl {{.*}} used InOutAccu 'void (inout uint32_t4[2])'
14+
// CHECK-NEXT: ParmVarDecl {{.*}} used V 'uint32_t4[2]'
15+
// CHECK-NEXT: HLSLParamModifierAttr {{.*}} inout
16+
void InOutAccu(inout uint32_t8 V) {
17+
uint32_t4 SumVec = V[0] + V[1];
18+
V[0] = SumVec;
19+
}
20+
21+
// CHECK-LABEL: call1
22+
// CHECK: CallExpr {{.*}} 'void'
23+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(inout uint32_t4[2])' <FunctionToPointerDecay>
24+
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (inout uint32_t4[2])' lvalue Function {{.*}} 'InOutAccu' 'void (inout uint32_t4[2])'
25+
// CHECK-NEXT: HLSLOutArgExpr {{.*}} 'uint32_t4[2]' lvalue inout
26+
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue
27+
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue Var {{.*}} 'B' 'uint32_t8':'uint32_t4[2]'
28+
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t4[2]' lvalue
29+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint32_t4[2]' <HLSLArrayRValue>
30+
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue
31+
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue Var {{.*}} 'B' 'uint32_t8':'uint32_t4[2]'
32+
// CHECK-NEXT: BinaryOperator {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue '='
33+
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue
34+
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue Var {{.*}} 'B' 'uint32_t8':'uint32_t4[2]'
35+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint32_t4[2]' <HLSLArrayRValue>
36+
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t4[2]' lvalue
37+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint32_t4[2]' <HLSLArrayRValue>
38+
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue
39+
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint32_t8':'uint32_t4[2]' lvalue Var {{.*}} 'B' 'uint32_t8':'uint32_t4[2]'
40+
void call1() {
41+
uint32_t4 A = {1,2,3,4};
42+
uint32_t8 B = {A,A};
43+
InOutAccu(B);
44+
}
45+
46+
// CHECK-LABEL: call2
47+
// CHECK: VarDecl {{.*}} D 'uint32_t':'unsigned int' cinit
48+
// CHECK-NEXT: CallExpr {{.*}} 'uint32_t':'unsigned int'
49+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint32_t (*)(uint32_t4[2])' <FunctionToPointerDecay>
50+
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint32_t (uint32_t4[2])' lvalue Function {{.*}} 'Accumulate' 'uint32_t (uint32_t4[2])'
51+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint4[2]' <HLSLArrayRValue>
52+
// CHECK-NEXT: DeclRefExpr {{.*}} 'uint4[2]' lvalue Var {{.*}} 'C' 'uint4[2]'
53+
void call2() {
54+
uint4 A = {1,2,3,4};
55+
uint4 C[2] = {A,A};
56+
uint32_t D = Accumulate(C);
57+
}

0 commit comments

Comments
 (0)