-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-hlsl Author: Sarah Spall (spall) ChangesDesugar type when converting from a ConstantArrayType to an ArrayParameterType in getArrayParameterType Full diff: https://github.com/llvm/llvm-project/pull/126561.diff 2 Files Affected:
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index de617860b70040b..e3b44bdbe3dc52f 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -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(),
diff --git a/clang/test/AST/HLSL/TypdefArrayParam.hlsl b/clang/test/AST/HLSL/TypdefArrayParam.hlsl
new file mode 100644
index 000000000000000..c6ae168f8406456
--- /dev/null
+++ b/clang/test/AST/HLSL/TypdefArrayParam.hlsl
@@ -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);
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM from a code perspective. If you're confident that it's the right thing to do then yay!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…rayParameterType (llvm#126561) Desugar type when converting from a ConstantArrayType to an ArrayParameterType in getArrayParameterType Closes llvm#125743
…rayParameterType (llvm#126561) Desugar type when converting from a ConstantArrayType to an ArrayParameterType in getArrayParameterType Closes llvm#125743
…rayParameterType (llvm#126561) Desugar type when converting from a ConstantArrayType to an ArrayParameterType in getArrayParameterType Closes llvm#125743
Desugar type when converting from a ConstantArrayType to an ArrayParameterType in getArrayParameterType
Closes #125743