@@ -2609,6 +2609,18 @@ static ExprResult BuiltinInvoke(Sema &S, CallExpr *TheCall) {
26092609 Args.drop_front(), TheCall->getRParenLoc());
26102610}
26112611
2612+ // Performs a similar job to Sema::UsualUnaryConversions, but without any
2613+ // implicit promotion of integral/enumeration types.
2614+ static ExprResult BuiltinVectorMathConversions(Sema &S, Expr *E) {
2615+ // First, convert to an r-value.
2616+ ExprResult Res = S.DefaultFunctionArrayLvalueConversion(E);
2617+ if (Res.isInvalid())
2618+ return ExprError();
2619+
2620+ // Promote floating-point types.
2621+ return S.UsualUnaryFPConversions(Res.get());
2622+ }
2623+
26122624ExprResult
26132625Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
26142626 CallExpr *TheCall) {
@@ -3273,6 +3285,46 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
32733285 return ExprError();
32743286 break;
32753287
3288+ case Builtin::BI__builtin_elementwise_ldexp: {
3289+ if (checkArgCount(TheCall, 2))
3290+ return ExprError();
3291+
3292+ ExprResult A = BuiltinVectorMathConversions(*this, TheCall->getArg(0));
3293+ if (A.isInvalid())
3294+ return ExprError();
3295+ QualType TyA = A.get()->getType();
3296+ if (checkMathBuiltinElementType(*this, A.get()->getBeginLoc(), TyA,
3297+ EltwiseBuiltinArgTyRestriction::FloatTy, 1))
3298+ return ExprError();
3299+
3300+ ExprResult Exp = UsualUnaryConversions(TheCall->getArg(1));
3301+ if (Exp.isInvalid())
3302+ return ExprError();
3303+ QualType TyExp = Exp.get()->getType();
3304+ if (checkMathBuiltinElementType(*this, Exp.get()->getBeginLoc(), TyExp,
3305+ EltwiseBuiltinArgTyRestriction::IntegerTy,
3306+ 2))
3307+ return ExprError();
3308+
3309+ // Check the two arguments are either scalars or vectors of equal length.
3310+ const auto *Vec0 = TyA->getAs<VectorType>();
3311+ const auto *Vec1 = TyExp->getAs<VectorType>();
3312+ unsigned Arg0Length = Vec0 ? Vec0->getNumElements() : 0;
3313+ unsigned Arg1Length = Vec1 ? Vec1->getNumElements() : 0;
3314+ if (Arg0Length != Arg1Length) {
3315+ Diag(Exp.get()->getBeginLoc(),
3316+ diag::err_typecheck_vector_lengths_not_equal)
3317+ << TyA << TyExp << A.get()->getSourceRange()
3318+ << Exp.get()->getSourceRange();
3319+ return ExprError();
3320+ }
3321+
3322+ TheCall->setArg(0, A.get());
3323+ TheCall->setArg(1, Exp.get());
3324+ TheCall->setType(TyA);
3325+ break;
3326+ }
3327+
32763328 // These builtins restrict the element type to floating point
32773329 // types only, and take in two arguments.
32783330 case Builtin::BI__builtin_elementwise_minnum:
@@ -15992,18 +16044,6 @@ void Sema::CheckAddressOfPackedMember(Expr *rhs) {
1599216044 _2, _3, _4));
1599316045}
1599416046
15995- // Performs a similar job to Sema::UsualUnaryConversions, but without any
15996- // implicit promotion of integral/enumeration types.
15997- static ExprResult BuiltinVectorMathConversions(Sema &S, Expr *E) {
15998- // First, convert to an r-value.
15999- ExprResult Res = S.DefaultFunctionArrayLvalueConversion(E);
16000- if (Res.isInvalid())
16001- return ExprError();
16002-
16003- // Promote floating-point types.
16004- return S.UsualUnaryFPConversions(Res.get());
16005- }
16006-
1600716047bool Sema::PrepareBuiltinElementwiseMathOneArgCall(
1600816048 CallExpr *TheCall, EltwiseBuiltinArgTyRestriction ArgTyRestr) {
1600916049 if (checkArgCount(TheCall, 1))
0 commit comments