@@ -5558,17 +5558,18 @@ bool Sema::BuiltinComplex(CallExpr *TheCall) {
55585558/// BuiltinShuffleVector - Handle __builtin_shufflevector.
55595559// This is declared to take (...), so we have to check everything.
55605560ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) {
5561- if (TheCall->getNumArgs() < 2)
5561+ unsigned NumArgs = TheCall->getNumArgs();
5562+ if (NumArgs < 2)
55625563 return ExprError(Diag(TheCall->getEndLoc(),
55635564 diag::err_typecheck_call_too_few_args_at_least)
5564- << 0 /*function call*/ << 2 << TheCall->getNumArgs()
5565+ << 0 /*function call*/ << 2 << NumArgs
55655566 << /*is non object*/ 0 << TheCall->getSourceRange());
55665567
55675568 // Determine which of the following types of shufflevector we're checking:
55685569 // 1) unary, vector mask: (lhs, mask)
55695570 // 2) binary, scalar mask: (lhs, rhs, index, ..., index)
5570- QualType resType = TheCall->getArg(0)->getType();
5571- unsigned numElements = 0;
5571+ QualType ResType = TheCall->getArg(0)->getType();
5572+ unsigned NumElements = 0;
55725573
55735574 if (!TheCall->getArg(0)->isTypeDependent() &&
55745575 !TheCall->getArg(1)->isTypeDependent()) {
@@ -5578,43 +5579,43 @@ ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) {
55785579 if (!LHSType->isVectorType() || !RHSType->isVectorType())
55795580 return ExprError(
55805581 Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector)
5581- << TheCall->getDirectCallee() << /*isMorethantwoArgs */ false
5582+ << TheCall->getDirectCallee() << /*isMoreThanTwoArgs */ false
55825583 << SourceRange(TheCall->getArg(0)->getBeginLoc(),
55835584 TheCall->getArg(1)->getEndLoc()));
55845585
5585- numElements = LHSType->castAs<VectorType>()->getNumElements();
5586- unsigned numResElements = TheCall->getNumArgs() - 2;
5586+ NumElements = LHSType->castAs<VectorType>()->getNumElements();
5587+ unsigned NumResElements = NumArgs - 2;
55875588
55885589 // Check to see if we have a call with 2 vector arguments, the unary shuffle
55895590 // with mask. If so, verify that RHS is an integer vector type with the
55905591 // same number of elts as lhs.
5591- if (TheCall->getNumArgs() == 2) {
5592+ if (NumArgs == 2) {
55925593 if (!RHSType->hasIntegerRepresentation() ||
5593- RHSType->castAs<VectorType>()->getNumElements() != numElements )
5594+ RHSType->castAs<VectorType>()->getNumElements() != NumElements )
55945595 return ExprError(Diag(TheCall->getBeginLoc(),
55955596 diag::err_vec_builtin_incompatible_vector)
55965597 << TheCall->getDirectCallee()
5597- << /*isMorethantwoArgs */ false
5598+ << /*isMoreThanTwoArgs */ false
55985599 << SourceRange(TheCall->getArg(1)->getBeginLoc(),
55995600 TheCall->getArg(1)->getEndLoc()));
56005601 } else if (!Context.hasSameUnqualifiedType(LHSType, RHSType)) {
56015602 return ExprError(Diag(TheCall->getBeginLoc(),
56025603 diag::err_vec_builtin_incompatible_vector)
56035604 << TheCall->getDirectCallee()
5604- << /*isMorethantwoArgs */ false
5605+ << /*isMoreThanTwoArgs */ false
56055606 << SourceRange(TheCall->getArg(0)->getBeginLoc(),
56065607 TheCall->getArg(1)->getEndLoc()));
5607- } else if (numElements != numResElements ) {
5608- QualType eltType = LHSType->castAs<VectorType>()->getElementType();
5609- resType = resType ->isExtVectorType()
5610- ? Context.getExtVectorType(eltType, numResElements )
5611- : Context.getVectorType(eltType, numResElements ,
5608+ } else if (NumElements != NumResElements ) {
5609+ QualType EltType = LHSType->castAs<VectorType>()->getElementType();
5610+ ResType = ResType ->isExtVectorType()
5611+ ? Context.getExtVectorType(EltType, NumResElements )
5612+ : Context.getVectorType(EltType, NumResElements ,
56125613 VectorKind::Generic);
56135614 }
56145615 }
56155616
5616- for (unsigned i = 2; i < TheCall->getNumArgs(); i++ ) {
5617- Expr *Arg = TheCall->getArg(i );
5617+ for (unsigned I = 2; I != NumArgs; ++I ) {
5618+ Expr *Arg = TheCall->getArg(I );
56185619 if (Arg->isTypeDependent() || Arg->isValueDependent())
56195620 continue;
56205621
@@ -5628,23 +5629,21 @@ ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) {
56285629 if (Result->isSigned() && Result->isAllOnes())
56295630 ;
56305631 else if (Result->getActiveBits() > 64 ||
5631- Result->getZExtValue() >= numElements * 2)
5632+ Result->getZExtValue() >= NumElements * 2)
56325633 return ExprError(Diag(TheCall->getBeginLoc(),
56335634 diag::err_shufflevector_argument_too_large)
56345635 << Arg->getSourceRange());
56355636
5636- TheCall->setArg(i , ConstantExpr::Create(Context, Arg, APValue(*Result)));
5637+ TheCall->setArg(I , ConstantExpr::Create(Context, Arg, APValue(*Result)));
56375638 }
56385639
5639- SmallVector<Expr *> exprs;
5640- for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; i++) {
5641- exprs.push_back(TheCall->getArg(i));
5642- TheCall->setArg(i, nullptr);
5643- }
5640+ auto *Result = new (Context) ShuffleVectorExpr(
5641+ Context, ArrayRef(TheCall->getArgs(), NumArgs), ResType,
5642+ TheCall->getCallee()->getBeginLoc(), TheCall->getRParenLoc());
56445643
5645- return new (Context) ShuffleVectorExpr(Context, exprs, resType,
5646- TheCall->getCallee()->getBeginLoc(),
5647- TheCall->getRParenLoc()) ;
5644+ // All moved to Result.
5645+ TheCall->shrinkNumArgs(0);
5646+ return Result ;
56485647}
56495648
56505649ExprResult Sema::ConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
0 commit comments