Skip to content

Commit 41ea1e8

Browse files
committed
Updates based on PR feedback
I beleive this captures all of the feedback from @efriedma-quic. Thank you for your patience and great feedback!
1 parent 71e007f commit 41ea1e8

File tree

9 files changed

+16
-19
lines changed

9 files changed

+16
-19
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10966,8 +10966,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, bool OfBlockPointer,
1096610966
"Equivalent pipe types should have already been handled!");
1096710967
return {};
1096810968
case Type::ArrayParameter:
10969-
if (RHS != LHS)
10970-
return {}; // If these aren't equivalent we should fail.
10969+
assert(LHS != RHS &&
10970+
"Equivalent pipe types should have already been handled!");
1097110971
return LHS;
1097210972
case Type::BitInt: {
1097310973
// Merge two bit-precise int types, while trying to preserve typedef info.

clang/lib/CodeGen/CGCall.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4655,13 +4655,6 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
46554655
return emitWritebackArg(*this, args, CRE);
46564656
}
46574657

4658-
// If an argument is an array paramter expression being passed through. Emit
4659-
// the argument to a temporary and pass the temporary as the call arg.
4660-
if (auto AT = dyn_cast<ArrayParameterType>(type)) {
4661-
args.add(EmitAnyExprToTemp(E), type);
4662-
return;
4663-
}
4664-
46654658
assert(type->isReferenceType() == E->isGLValue() &&
46664659
"reference binding to unmaterialized r-value!");
46674660

@@ -4709,7 +4702,8 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
47094702
}
47104703

47114704
if (HasAggregateEvalKind && isa<ImplicitCastExpr>(E) &&
4712-
cast<CastExpr>(E)->getCastKind() == CK_LValueToRValue) {
4705+
cast<CastExpr>(E)->getCastKind() == CK_LValueToRValue &&
4706+
!type->isArrayParameterType()) {
47134707
LValue L = EmitLValue(cast<CastExpr>(E)->getSubExpr());
47144708
assert(L.isSimple());
47154709
args.addUncopiedAggregate(L, type);

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,6 @@ static bool castPreservesZero(const CastExpr *CE) {
14451445
case CK_BitCast:
14461446
case CK_ToUnion:
14471447
case CK_ToVoid:
1448-
case CK_HLSLArrayRValue:
14491448
// Conversions between (possibly-complex) integral, (possibly-complex)
14501449
// floating-point, and bool.
14511450
case CK_BooleanToSignedIntegral:
@@ -1525,6 +1524,7 @@ static bool castPreservesZero(const CastExpr *CE) {
15251524
case CK_LValueToRValue:
15261525
case CK_LValueToRValueBitCast:
15271526
case CK_UncheckedDerivedToBase:
1527+
case CK_HLSLArrayRValue:
15281528
return false;
15291529
}
15301530
llvm_unreachable("Unhandled clang::CastKind enum");

clang/lib/CodeGen/CGExprComplex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@ ComplexPairTy ComplexExprEmitter::EmitCast(CastKind CK, Expr *Op,
547547
case CK_NoOp:
548548
case CK_LValueToRValue:
549549
case CK_UserDefinedConversion:
550-
case CK_HLSLArrayRValue:
551550
return Visit(Op);
552551

553552
case CK_LValueBitCast: {
@@ -617,6 +616,7 @@ ComplexPairTy ComplexExprEmitter::EmitCast(CastKind CK, Expr *Op,
617616
case CK_IntegralToFixedPoint:
618617
case CK_MatrixCast:
619618
case CK_HLSLVectorTruncation:
619+
case CK_HLSLArrayRValue:
620620
llvm_unreachable("invalid cast kind for complex value");
621621

622622
case CK_FloatingRealToComplex:

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,6 @@ class ConstExprEmitter :
11261126
case CK_NonAtomicToAtomic:
11271127
case CK_NoOp:
11281128
case CK_ConstructorConversion:
1129-
case CK_HLSLArrayRValue:
11301129
return Visit(subExpr, destType);
11311130

11321131
case CK_ArrayToPointerDecay:
@@ -1227,6 +1226,7 @@ class ConstExprEmitter :
12271226
case CK_ZeroToOCLOpaqueType:
12281227
case CK_MatrixCast:
12291228
case CK_HLSLVectorTruncation:
1229+
case CK_HLSLArrayRValue:
12301230
return nullptr;
12311231
}
12321232
llvm_unreachable("Invalid CastKind");

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,8 +2231,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
22312231
case CK_UserDefinedConversion:
22322232
return Visit(const_cast<Expr*>(E));
22332233

2234-
case CK_NoOp:
2235-
case CK_HLSLArrayRValue: {
2234+
case CK_NoOp: {
22362235
return CE->changesVolatileQualification() ? EmitLoadOfLValue(CE)
22372236
: Visit(const_cast<Expr *>(E));
22382237
}
@@ -2328,6 +2327,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
23282327
case CK_FloatingComplexToIntegralComplex:
23292328
case CK_ConstructorConversion:
23302329
case CK_ToUnion:
2330+
case CK_HLSLArrayRValue:
23312331
llvm_unreachable("scalar cast to non-scalar value");
23322332

23332333
case CK_LValueToRValue:

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,9 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) {
658658
QualType T = E->getType();
659659
assert(!T.isNull() && "r-value conversion on typeless expression?");
660660

661-
// lvalue-to-rvalue conversion cannot be applied to function or array types.
662-
if (T->isFunctionType() || T->isArrayType())
661+
// lvalue-to-rvalue conversion cannot be applied to types that decay to
662+
// pointers (i.e. function or array types).
663+
if (T->canDecayToPointerType())
663664
return E;
664665

665666
// We don't want to throw lvalue-to-rvalue casts on top of

clang/lib/Sema/SemaOverload.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,8 +2133,7 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType,
21332133
// A glvalue (3.10) of a non-function, non-array type T can
21342134
// be converted to a prvalue.
21352135
bool argIsLValue = From->isGLValue();
2136-
if (argIsLValue &&
2137-
!FromType->isFunctionType() && !FromType->isArrayType() &&
2136+
if (argIsLValue && !FromType->canDecayToPointerType() &&
21382137
S.Context.getCanonicalType(FromType) != S.Context.OverloadTy) {
21392138
SCS.First = ICK_Lvalue_To_Rvalue;
21402139

clang/test/SemaHLSL/ArrayTemporary.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ void template_fn(T Val) {}
7575
// CHECK: CallExpr {{.*}} 'void'
7676
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(float[2])' <FunctionToPointerDecay>
7777
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (float[2])' lvalue Function {{.*}} 'template_fn' 'void (float[2])' (FunctionTemplate {{.*}} 'template_fn')
78+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float[2]' <LValueToRValue>
7879
// CHECK-NEXT: DeclRefExpr {{.*}} 'float[2]' lvalue ParmVar {{.*}} 'FA2' 'float[2]'
7980
// CHECK-NEXT: CallExpr {{.*}} 'void'
8081
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(float[4])' <FunctionToPointerDecay>
8182
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (float[4])' lvalue Function {{.*}} 'template_fn' 'void (float[4])' (FunctionTemplate {{.*}} 'template_fn')
83+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float[4]' <LValueToRValue>
8284
// CHECK-NEXT: DeclRefExpr {{.*}} 'float[4]' lvalue ParmVar {{.*}} 'FA4' 'float[4]'
8385
// CHECK-NEXT: CallExpr {{.*}} 'void'
8486
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(int[3])' <FunctionToPointerDecay>
8587
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (int[3])' lvalue Function {{.*}} 'template_fn' 'void (int[3])' (FunctionTemplate {{.*}} 'template_fn')
88+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int[3]' <LValueToRValue>
8689
// CHECK-NEXT: DeclRefExpr {{.*}} 'int[3]' lvalue ParmVar {{.*}} 'IA3' 'int[3]'
8790

8891
void call(float FA2[2], float FA4[4], int IA3[3]) {

0 commit comments

Comments
 (0)