Skip to content

Commit 2b90d41

Browse files
committed
Updates based on feedback from @rjmccall
1 parent f2c4024 commit 2b90d41

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2508,7 +2508,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
25082508
assert(DestTy->isVectorType() && "Expected dest type to be vector type");
25092509
Value *Vec = Visit(const_cast<Expr *>(E));
25102510
SmallVector<int, 16> Mask;
2511-
Mask.insert(Mask.begin(), DestTy->getAs<VectorType>()->getNumElements(), 0);
2511+
Mask.insert(Mask.begin(), DestTy->castAs<VectorType>()->getNumElements(),
2512+
0);
25122513
return Builder.CreateShuffleVector(Vec, Mask, "trunc");
25132514
}
25142515

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15609,8 +15609,8 @@ static void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
1560915609
return;
1561015610
return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_vector_scalar);
1561115611
} else if (S.getLangOpts().HLSL &&
15612-
Target->getAs<VectorType>()->getNumElements() <
15613-
Source->getAs<VectorType>()->getNumElements()) {
15612+
Target->castAs<VectorType>()->getNumElements() <
15613+
Source->castAs<VectorType>()->getNumElements()) {
1561415614
// Diagnose vector truncation but don't return. We may also want to
1561515615
// diagnose an element conversion.
1561615616
DiagnoseImpCast(S, E, T, CC, diag::warn_hlsl_impcast_vector_truncation);

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4764,11 +4764,13 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
47644764
From->getValueKind()).get();
47654765
break;
47664766
case ICK_HLSL_Vector_Truncation: {
4767-
// Note: HLSL vectors are ExtVectors. Since this truncates a vector to a
4768-
// smaller vector, this can only operate on arguments where the source and
4769-
// destination types are ExtVectors.
4770-
auto *FromVec = From->getType()->castAs<ExtVectorType>();
4771-
auto *ToVec = ToType->castAs<ExtVectorType>();
4767+
// Note: HLSL built-in vectors are ExtVectors. Since this truncates a vector
4768+
// to a smaller vector, this can only operate on arguments where the source
4769+
// and destination types are ExtVectors.
4770+
assert(From->getType()->isExtVectorType() && ToType->isExtVectorType() &&
4771+
"HLSL vector truncation should only apply to ExtVectors");
4772+
auto *FromVec = From->getType()->castAs<VectorType>();
4773+
auto *ToVec = ToType->castAs<VectorType>();
47724774
QualType ElType = FromVec->getElementType();
47734775
QualType TruncTy =
47744776
Context.getExtVectorType(ElType, ToVec->getNumElements());

0 commit comments

Comments
 (0)