[clang] [HLSL] add support for HLSLAggregateSplatCast and HLSLElementwiseCast to constant expression evaluator (PR #164700)
Joshua Batista via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 29 13:08:14 PDT 2025
================
@@ -10851,6 +11194,67 @@ bool RecordExprEvaluator::VisitCastExpr(const CastExpr *E) {
Result = *Value;
return true;
}
+ case CK_HLSLAggregateSplatCast: {
+ APValue Val;
+ const Expr *SE = E->getSubExpr();
+
+ if (!Evaluate(Val, Info, SE))
+ return Error(E);
+
+ unsigned NEls = elementwiseSize(Info, E->getType());
+ // flatten the source
+ SmallVector<APValue, 1> SrcEls;
+ SmallVector<QualType, 1> SrcTypes;
+ if (!flattenAPValue(Info.Ctx, Val, SE->getType(), SrcEls, SrcTypes, NEls))
+ return Error(E);
+
+ // check there is only one and splat it
+ assert(SrcEls.size() == 1);
+ SmallVector<APValue> SplatEls(NEls, SrcEls[0]);
+ SmallVector<QualType> SplatType(NEls, SrcTypes[0]);
+
+ APValue Tmp;
+ handleDefaultInitValue(E->getType(), Tmp);
+
+ // cast the elements and construct our struct result
+ const FPOptions FPO = E->getFPFeaturesInEffect(Info.Ctx.getLangOpts());
+ if (!constructAggregate(Info, FPO, E, Result, E->getType(), SplatEls,
+ SplatType))
+ return Error(E);
+
+ return true;
+ }
+ case CK_HLSLElementwiseCast: {
+ APValue Val;
+ const Expr *SE = E->getSubExpr();
+
+ if (!Evaluate(Val, Info, SE))
+ return Error(E);
+
+ // must be dealing with a record;
+ if (Val.isLValue()) {
+ LValue LVal;
+ LVal.setFrom(Info.Ctx, Val);
+ if (!handleLValueToRValueConversion(Info, SE, SE->getType(), LVal, Val))
+ return false;
+ }
+
+ // flatten the source
+ SmallVector<APValue> SrcEls;
+ SmallVector<QualType> SrcTypes;
+ if (!flattenAPValue(Info.Ctx, Val, SE->getType(), SrcEls, SrcTypes,
----------------
bob80905 wrote:
Why not get NEls from elementwiseSize here again, instead of using UINT_MAX?
https://github.com/llvm/llvm-project/pull/164700
More information about the cfe-commits
mailing list