[clang] [HLSL] Allow truncation to scalar (PR #104844)
Justin Bogner via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 6 15:05:26 PDT 2024
================
@@ -2692,14 +2692,19 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
return CGF.CGM.createOpenCLIntToSamplerConversion(E, CGF);
case CK_HLSLVectorTruncation: {
- assert(DestTy->isVectorType() && "Expected dest type to be vector type");
+ assert((DestTy->isVectorType() || DestTy->isBuiltinType()) &&
+ "Destination type must be a vector or builtin type.");
Value *Vec = Visit(const_cast<Expr *>(E));
- SmallVector<int, 16> Mask;
- unsigned NumElts = DestTy->castAs<VectorType>()->getNumElements();
- for (unsigned I = 0; I != NumElts; ++I)
- Mask.push_back(I);
+ if (auto *VecTy = DestTy->getAs<VectorType>()) {
+ SmallVector<int, 16> Mask;
----------------
bogner wrote:
It was already here, but while I see it: better to use `SmallVector<int>` and let it pick the size here
https://github.com/llvm/llvm-project/pull/104844
More information about the cfe-commits
mailing list