Skip to content

Commit 11ecff9

Browse files
committed
compare unqualified canonical types and add an hlsl array rvalue cast
1 parent 97dcbde commit 11ecff9

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,19 +4418,12 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
44184418
case ICK_HLSL_Array_RValue:
44194419
if (ToType->isArrayParameterType()) {
44204420
FromType = Context.getArrayParameterType(FromType);
4421-
From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
4422-
/*BasePath=*/nullptr, CCK)
4423-
.get();
4424-
} else { // FromType must be ArrayParameterType
4425-
assert(FromType->isArrayParameterType() &&
4426-
"FromType must be ArrayParameterType in ICK_HLSL_Array_RValue \
4427-
if it is not ToType");
4421+
} else if (FromType->isArrayParameterType()) {
44284422
const ArrayParameterType *APT = cast<ArrayParameterType>(FromType);
44294423
FromType = APT->getConstantArrayType(Context);
4430-
From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
4431-
/*BasePath=*/nullptr, CCK)
4432-
.get();
44334424
}
4425+
From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
4426+
/*BasePath=*/nullptr, CCK).get();
44344427
break;
44354428

44364429
case ICK_Function_To_Pointer:

clang/lib/Sema/SemaOverload.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,17 +2268,15 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType,
22682268
// handling here.
22692269
if (ToType->isArrayParameterType()) {
22702270
FromType = S.Context.getArrayParameterType(FromType);
2271-
SCS.First = ICK_HLSL_Array_RValue;
22722271
} else if (FromType->isArrayParameterType()) {
22732272
const ArrayParameterType *APT = cast<ArrayParameterType>(FromType);
22742273
FromType = APT->getConstantArrayType(S.Context);
2275-
SCS.First = ICK_HLSL_Array_RValue;
2276-
} else {
2277-
SCS.First = ICK_Identity;
22782274
}
22792275

2280-
if (S.Context.getCanonicalType(FromType) !=
2281-
S.Context.getCanonicalType(ToType))
2276+
SCS.First = ICK_HLSL_Array_RValue;
2277+
2278+
if (FromType.getCanonicalType().getUnqualifiedType() !=
2279+
ToType.getCanonicalType().getUnqualifiedType())
22822280
return false;
22832281

22842282
SCS.setAllToTypes(ToType);

clang/test/CodeGenHLSL/ArrayAssignable.hlsl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --enable-var-scope
22

3+
4+
//CHECK-DAG: [[CBLayout:%.*]] = type <{ [2 x float] }>
5+
//CHECK-DAG: @CBArrays.cb = global target("dx.CBuffer", target("dx.Layout", [[CBLayout]], 20, 0)) poison
6+
//CHECK-DAG: @c1 = external addrspace(2) global [2 x float], align 4
7+
cbuffer CBArrays {
8+
float c1[2];
9+
}
10+
311
// CHECK-LABEL: define void {{.*}}arr_assign1
412
// CHECK: [[Arr:%.*]] = alloca [2 x i32], align 4
513
// CHECK-NEXT: [[Arr2:%.*]] = alloca [2 x i32], align 4
@@ -116,3 +124,15 @@ void arr_assign7() {
116124
int Arr2[2][2] = {{0, 0}, {1, 1}};
117125
(Arr = Arr2)[0] = {6, 6};
118126
}
127+
128+
// Verify you can assign from a cbuffer array
129+
130+
// CHECK-LABEL: define void {{.*}}arr_assign8
131+
// CHECK: [[C:%.*]] = alloca [2 x float], align 4
132+
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[C]], ptr align 4 {{.*}}, i32 8, i1 false)
133+
// CHECK-NEXT: call void @llvm.memcpy.p0.p2.i32(ptr align 4 [[C]], ptr addrspace(2) align 4 @c1, i32 8, i1 false)
134+
// CHECK-NEXT: ret void
135+
void arr_assign8() {
136+
float C[2] = {1.0, 2.0};
137+
C = c1;
138+
}

0 commit comments

Comments
 (0)