From 9f569d45e0e42bcf60fe8f43b847a133a1a38c12 Mon Sep 17 00:00:00 2001 From: Bruno Ricci Date: Fri, 21 Dec 2018 15:20:32 +0000 Subject: [PATCH] [AST] Store the callee and argument expressions of CallExpr in a trailing array. Since CallExpr::setNumArgs has been removed, it is now possible to store the callee expression and the argument expressions of CallExpr in a trailing array. This saves one pointer per CallExpr, CXXOperatorCallExpr, CXXMemberCallExpr, CUDAKernelCallExpr and UserDefinedLiteral. Given that CallExpr is used as a base of the above classes we cannot use llvm::TrailingObjects. Instead we store the offset in bytes from the this pointer to the start of the trailing objects and manually do the casts + arithmetic. Some notes: 1.) I did not try to fit the number of arguments in the bit-fields of Stmt. This leaves some space for future additions and avoid the discussion about whether x bits are sufficient to hold the number of arguments. 2.) It would be perfectly possible to recompute the offset to the trailing objects before accessing the trailing objects. However the trailing objects are frequently accessed and benchmarks show that it is slightly faster to just load the offset from the bit-fields. Additionally, because of 1), we have plenty of space in the bit-fields of Stmt. Differential Revision: https://reviews.llvm.org/D55771 Reviewed By: rjmccall git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349910 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Expr.h | 208 ++++++++++++++------- include/clang/AST/ExprCXX.h | 123 +++++++----- include/clang/AST/Stmt.h | 9 + lib/AST/ASTImporter.cpp | 13 +- lib/AST/Expr.cpp | 130 ++++++++----- lib/AST/ExprCXX.cpp | 145 ++++++++++++++ lib/Analysis/BodyFarm.cpp | 22 +-- lib/CodeGen/CGObjC.cpp | 8 +- lib/Frontend/Rewrite/RewriteModernObjC.cpp | 67 +++---- lib/Frontend/Rewrite/RewriteObjC.cpp | 37 ++-- lib/Sema/SemaExpr.cpp | 31 +-- lib/Sema/SemaExprCXX.cpp | 4 +- lib/Sema/SemaOpenMP.cpp | 4 +- lib/Sema/SemaOverload.cpp | 114 ++++++----- lib/Sema/TreeTransform.h | 2 +- lib/Serialization/ASTReaderStmt.cpp | 19 +- 16 files changed, 598 insertions(+), 338 deletions(-) diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index ee4e0d57b4..156782b330 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -2395,59 +2395,126 @@ public: /// a subclass for overloaded operator calls that use operator syntax, e.g., /// "str1 + str2" to resolve to a function call. class CallExpr : public Expr { - enum { FN=0, PREARGS_START=1 }; - Stmt **SubExprs; + enum { FN = 0, PREARGS_START = 1 }; + + /// The number of arguments in the call expression. unsigned NumArgs; + + /// The location of the right parenthese. This has a different meaning for + /// the derived classes of CallExpr. SourceLocation RParenLoc; void updateDependenciesFromArg(Expr *Arg); + // CallExpr store some data in trailing objects. However since CallExpr + // is used a base of other expression classes we cannot use + // llvm::TrailingObjects. Instead we manually perform the pointer arithmetic + // and casts. + // + // The trailing objects are in order: + // + // * A single "Stmt *" for the callee expression. + // + // * An array of getNumPreArgs() "Stmt *" for the pre-argument expressions. + // + // * An array of getNumArgs() "Stmt *" for the argument expressions. + // + // Note that we store the offset in bytes from the this pointer to the start + // of the trailing objects. It would be perfectly possible to compute it + // based on the dynamic kind of the CallExpr. However 1.) we have plenty of + // space in the bit-fields of Stmt. 2.) It was benchmarked to be faster to + // compute this once and then load the offset from the bit-fields of Stmt, + // instead of re-computing the offset each time the trailing objects are + // accessed. + + /// Return a pointer to the start of the trailing array of "Stmt *". + Stmt **getTrailingStmts() { + return reinterpret_cast(reinterpret_cast(this) + + CallExprBits.OffsetToTrailingObjects); + } + Stmt *const *getTrailingStmts() const { + return const_cast(this)->getTrailingStmts(); + } + + /// Map a statement class to the appropriate offset in bytes from the + /// this pointer to the trailing objects. + static unsigned offsetToTrailingObjects(StmtClass SC); + public: enum class ADLCallKind : bool { NotADL, UsesADL }; static constexpr ADLCallKind NotADL = ADLCallKind::NotADL; static constexpr ADLCallKind UsesADL = ADLCallKind::UsesADL; protected: - // These versions of the constructor are for derived classes. - CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, - ArrayRef preargs, ArrayRef args, QualType t, - ExprValueKind VK, SourceLocation rparenloc, unsigned MinNumArgs = 0, - ADLCallKind UsesADL = NotADL); - CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, ArrayRef args, - QualType t, ExprValueKind VK, SourceLocation rparenloc, - unsigned MinNumArgs = 0, ADLCallKind UsesADL = NotADL); - CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs, - unsigned NumArgs, EmptyShell Empty); - - Stmt *getPreArg(unsigned i) { - assert(i < getNumPreArgs() && "Prearg access out of range!"); - return SubExprs[PREARGS_START+i]; - } - const Stmt *getPreArg(unsigned i) const { - assert(i < getNumPreArgs() && "Prearg access out of range!"); - return SubExprs[PREARGS_START+i]; - } - void setPreArg(unsigned i, Stmt *PreArg) { - assert(i < getNumPreArgs() && "Prearg access out of range!"); - SubExprs[PREARGS_START+i] = PreArg; + /// Build a call expression, assuming that appropriate storage has been + /// allocated for the trailing objects. + CallExpr(StmtClass SC, Expr *Fn, ArrayRef PreArgs, + ArrayRef Args, QualType Ty, ExprValueKind VK, + SourceLocation RParenLoc, unsigned MinNumArgs, ADLCallKind UsesADL); + + /// Build an empty call expression, for deserialization. + CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs, + EmptyShell Empty); + + /// Return the size in bytes needed for the trailing objects. + /// Used by the derived classes to allocate the right amount of storage. + static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs) { + return (1 + NumPreArgs + NumArgs) * sizeof(Stmt *); + } + + Stmt *getPreArg(unsigned I) { + assert(I < getNumPreArgs() && "Prearg access out of range!"); + return getTrailingStmts()[PREARGS_START + I]; + } + const Stmt *getPreArg(unsigned I) const { + assert(I < getNumPreArgs() && "Prearg access out of range!"); + return getTrailingStmts()[PREARGS_START + I]; + } + void setPreArg(unsigned I, Stmt *PreArg) { + assert(I < getNumPreArgs() && "Prearg access out of range!"); + getTrailingStmts()[PREARGS_START + I] = PreArg; } unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } public: - /// Build a call expression. MinNumArgs specifies the minimum number of - /// arguments. The actual number of arguments will be the greater of - /// args.size() and MinNumArgs. - CallExpr(const ASTContext &C, Expr *fn, ArrayRef args, QualType t, - ExprValueKind VK, SourceLocation rparenloc, unsigned MinNumArgs = 0, - ADLCallKind UsesADL = NotADL); + /// Create a call expression. Fn is the callee expression, Args is the + /// argument array, Ty is the type of the call expression (which is *not* + /// the return type in general), VK is the value kind of the call expression + /// (lvalue, rvalue, ...), and RParenLoc is the location of the right + /// parenthese in the call expression. MinNumArgs specifies the minimum + /// number of arguments. The actual number of arguments will be the greater + /// of Args.size() and MinNumArgs. This is used in a few places to allocate + /// enough storage for the default arguments. UsesADL specifies whether the + /// callee was found through argument-dependent lookup. + /// + /// Note that you can use CreateTemporary if you need a temporary call + /// expression on the stack. + static CallExpr *Create(const ASTContext &Ctx, Expr *Fn, + ArrayRef Args, QualType Ty, ExprValueKind VK, + SourceLocation RParenLoc, unsigned MinNumArgs = 0, + ADLCallKind UsesADL = NotADL); + + /// Create a temporary call expression with no arguments in the memory + /// pointed to by Mem. Mem must points to at least sizeof(CallExpr) + /// + sizeof(Stmt *) bytes of storage, aligned to alignof(CallExpr): + /// + /// \code{.cpp} + /// llvm::AlignedCharArray Buffer; + /// CallExpr *TheCall = CallExpr::CreateTemporary(Buffer.buffer, etc); + /// \endcode + static CallExpr *CreateTemporary(void *Mem, Expr *Fn, QualType Ty, + ExprValueKind VK, SourceLocation RParenLoc, + ADLCallKind UsesADL = NotADL); - /// Build an empty call expression. - CallExpr(const ASTContext &C, unsigned NumArgs, EmptyShell Empty); + /// Create an empty call expression, for deserialization. + static CallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, + EmptyShell Empty); - const Expr *getCallee() const { return cast(SubExprs[FN]); } - Expr *getCallee() { return cast(SubExprs[FN]); } - void setCallee(Expr *F) { SubExprs[FN] = F; } + Expr *getCallee() { return cast(getTrailingStmts()[FN]); } + const Expr *getCallee() const { return cast(getTrailingStmts()[FN]); } + void setCallee(Expr *F) { getTrailingStmts()[FN] = F; } ADLCallKind getADLCallKind() const { return static_cast(CallExprBits.UsesADL); @@ -2457,55 +2524,56 @@ public: } bool usesADL() const { return getADLCallKind() == UsesADL; } - Decl *getCalleeDecl(); + Decl *getCalleeDecl() { return getCallee()->getReferencedDeclOfCallee(); } const Decl *getCalleeDecl() const { - return const_cast(this)->getCalleeDecl(); + return getCallee()->getReferencedDeclOfCallee(); } - /// If the callee is a FunctionDecl, return it. Otherwise return 0. - FunctionDecl *getDirectCallee(); + /// If the callee is a FunctionDecl, return it. Otherwise return null. + FunctionDecl *getDirectCallee() { + return dyn_cast_or_null(getCalleeDecl()); + } const FunctionDecl *getDirectCallee() const { - return const_cast(this)->getDirectCallee(); + return dyn_cast_or_null(getCalleeDecl()); } /// getNumArgs - Return the number of actual arguments to this call. - /// unsigned getNumArgs() const { return NumArgs; } /// Retrieve the call arguments. Expr **getArgs() { - return reinterpret_cast(SubExprs+getNumPreArgs()+PREARGS_START); + return reinterpret_cast(getTrailingStmts() + PREARGS_START + + getNumPreArgs()); } const Expr *const *getArgs() const { - return reinterpret_cast(SubExprs + getNumPreArgs() + - PREARGS_START); + return reinterpret_cast( + getTrailingStmts() + PREARGS_START + getNumPreArgs()); } /// getArg - Return the specified argument. Expr *getArg(unsigned Arg) { - assert(Arg < NumArgs && "Arg access out of range!"); - return cast_or_null(SubExprs[Arg + getNumPreArgs() + PREARGS_START]); + assert(Arg < getNumArgs() && "Arg access out of range!"); + return getArgs()[Arg]; } const Expr *getArg(unsigned Arg) const { - assert(Arg < NumArgs && "Arg access out of range!"); - return cast_or_null(SubExprs[Arg + getNumPreArgs() + PREARGS_START]); + assert(Arg < getNumArgs() && "Arg access out of range!"); + return getArgs()[Arg]; } /// setArg - Set the specified argument. void setArg(unsigned Arg, Expr *ArgExpr) { - assert(Arg < NumArgs && "Arg access out of range!"); - SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; + assert(Arg < getNumArgs() && "Arg access out of range!"); + getArgs()[Arg] = ArgExpr; } /// Reduce the number of arguments in this call expression. This is used for /// example during error recovery to drop extra arguments. There is no way /// to perform the opposite because: 1.) We don't track how much storage /// we have for the argument array 2.) This would potentially require growing - /// the argument array, something we cannot support since the arguments will - /// be stored in a trailing array in the future. - /// (TODO: update this comment when this is done). + /// the argument array, something we cannot support since the arguments are + /// stored in a trailing array. void shrinkNumArgs(unsigned NewNumArgs) { - assert((NewNumArgs <= NumArgs) && + assert((NewNumArgs <= getNumArgs()) && "shrinkNumArgs cannot increase the number of arguments!"); NumArgs = NewNumArgs; } @@ -2520,29 +2588,28 @@ public: return const_arg_range(arg_begin(), arg_end()); } - arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } - arg_iterator arg_end() { - return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); + arg_iterator arg_begin() { + return getTrailingStmts() + PREARGS_START + getNumPreArgs(); } + arg_iterator arg_end() { return arg_begin() + getNumArgs(); } + const_arg_iterator arg_begin() const { - return SubExprs+PREARGS_START+getNumPreArgs(); - } - const_arg_iterator arg_end() const { - return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); + return getTrailingStmts() + PREARGS_START + getNumPreArgs(); } + const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); } /// This method provides fast access to all the subexpressions of /// a CallExpr without going through the slower virtual child_iterator /// interface. This provides efficient reverse iteration of the /// subexpressions. This is currently used for CFG construction. - ArrayRef getRawSubExprs() { - return llvm::makeArrayRef(SubExprs, - getNumPreArgs() + PREARGS_START + getNumArgs()); + ArrayRef getRawSubExprs() { + return llvm::makeArrayRef(getTrailingStmts(), + PREARGS_START + getNumPreArgs() + getNumArgs()); } /// getNumCommas - Return the number of commas that must have been present in /// this function call. - unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } + unsigned getNumCommas() const { return getNumArgs() ? getNumArgs() - 1 : 0; } /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID /// of the callee. If not, return 0. @@ -2568,7 +2635,7 @@ public: bool isBuiltinAssumeFalse(const ASTContext &Ctx) const; bool isCallToStdMove() const { - const FunctionDecl* FD = getDirectCallee(); + const FunctionDecl *FD = getDirectCallee(); return getNumArgs() == 1 && FD && FD->isInStdNamespace() && FD->getIdentifier() && FD->getIdentifier()->isStr("move"); } @@ -2580,13 +2647,14 @@ public: // Iterators child_range children() { - return child_range(&SubExprs[0], - &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); + return child_range(getTrailingStmts(), getTrailingStmts() + PREARGS_START + + getNumPreArgs() + getNumArgs()); } const_child_range children() const { - return const_child_range(&SubExprs[0], &SubExprs[0] + NumArgs + - getNumPreArgs() + PREARGS_START); + return const_child_range(getTrailingStmts(), + getTrailingStmts() + PREARGS_START + + getNumPreArgs() + getNumArgs()); } }; diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index f39bddb040..21692c82b4 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -75,7 +75,10 @@ class TemplateParameterList; /// function itself will be a (possibly empty) set of functions and /// function templates that were found by name lookup at template /// definition time. -class CXXOperatorCallExpr : public CallExpr { +class CXXOperatorCallExpr final : public CallExpr { + friend class ASTStmtReader; + friend class ASTStmtWriter; + /// The overloaded operator. OverloadedOperatorKind Operator; @@ -84,29 +87,29 @@ class CXXOperatorCallExpr : public CallExpr { // Only meaningful for floating point types. FPOptions FPFeatures; + // CXXOperatorCallExpr has some trailing objects belonging + // to CallExpr. See CallExpr for the details. + SourceRange getSourceRangeImpl() const LLVM_READONLY; -public: - friend class ASTStmtReader; - friend class ASTStmtWriter; + CXXOperatorCallExpr(OverloadedOperatorKind OpKind, Expr *Fn, + ArrayRef Args, QualType Ty, ExprValueKind VK, + SourceLocation OperatorLoc, FPOptions FPFeatures, + ADLCallKind UsesADL); - CXXOperatorCallExpr(ASTContext &C, OverloadedOperatorKind Op, Expr *fn, - ArrayRef args, QualType t, ExprValueKind VK, - SourceLocation operatorloc, FPOptions FPFeatures, - ADLCallKind UsesADL = NotADL) - : CallExpr(C, CXXOperatorCallExprClass, fn, args, t, VK, operatorloc, - /*MinNumArgs=*/0, UsesADL), - Operator(Op), FPFeatures(FPFeatures) { - Range = getSourceRangeImpl(); - } + CXXOperatorCallExpr(unsigned NumArgs, EmptyShell Empty); + +public: + static CXXOperatorCallExpr * + Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, + ArrayRef Args, QualType Ty, ExprValueKind VK, + SourceLocation OperatorLoc, FPOptions FPFeatures, + ADLCallKind UsesADL = NotADL); - explicit CXXOperatorCallExpr(ASTContext &C, unsigned NumArgs, - EmptyShell Empty) - : CallExpr(C, CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs, - Empty) {} + static CXXOperatorCallExpr *CreateEmpty(const ASTContext &Ctx, + unsigned NumArgs, EmptyShell Empty); - /// Returns the kind of overloaded operator that this - /// expression refers to. + /// Returns the kind of overloaded operator that this expression refers to. OverloadedOperatorKind getOperator() const { return Operator; } static bool isAssignmentOp(OverloadedOperatorKind Opc) { @@ -165,16 +168,23 @@ public: /// both the object argument and the member function, while the /// arguments are the arguments within the parentheses (not including /// the object argument). -class CXXMemberCallExpr : public CallExpr { +class CXXMemberCallExpr final : public CallExpr { + // CXXMemberCallExpr has some trailing objects belonging + // to CallExpr. See CallExpr for the details. + + CXXMemberCallExpr(Expr *Fn, ArrayRef Args, QualType Ty, + ExprValueKind VK, SourceLocation RP, unsigned MinNumArgs); + + CXXMemberCallExpr(unsigned NumArgs, EmptyShell Empty); + public: - CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef args, QualType t, - ExprValueKind VK, SourceLocation RP, - unsigned MinNumArgs = 0) - : CallExpr(C, CXXMemberCallExprClass, fn, args, t, VK, RP, MinNumArgs, - NotADL) {} + static CXXMemberCallExpr *Create(const ASTContext &Ctx, Expr *Fn, + ArrayRef Args, QualType Ty, + ExprValueKind VK, SourceLocation RP, + unsigned MinNumArgs = 0); - CXXMemberCallExpr(ASTContext &C, unsigned NumArgs, EmptyShell Empty) - : CallExpr(C, CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {} + static CXXMemberCallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, + EmptyShell Empty); /// Retrieves the implicit object argument for the member call. /// @@ -206,20 +216,26 @@ public: }; /// Represents a call to a CUDA kernel function. -class CUDAKernelCallExpr : public CallExpr { -private: +class CUDAKernelCallExpr final : public CallExpr { enum { CONFIG, END_PREARG }; + // CUDAKernelCallExpr has some trailing objects belonging + // to CallExpr. See CallExpr for the details. + + CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, ArrayRef Args, + QualType Ty, ExprValueKind VK, SourceLocation RP, + unsigned MinNumArgs); + + CUDAKernelCallExpr(unsigned NumArgs, EmptyShell Empty); + public: - CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config, - ArrayRef args, QualType t, ExprValueKind VK, - SourceLocation RP, unsigned MinNumArgs = 0) - : CallExpr(C, CUDAKernelCallExprClass, fn, Config, args, t, VK, RP, - MinNumArgs, NotADL) {} + static CUDAKernelCallExpr *Create(const ASTContext &Ctx, Expr *Fn, + CallExpr *Config, ArrayRef Args, + QualType Ty, ExprValueKind VK, + SourceLocation RP, unsigned MinNumArgs = 0); - CUDAKernelCallExpr(ASTContext &C, unsigned NumArgs, EmptyShell Empty) - : CallExpr(C, CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, NumArgs, - Empty) {} + static CUDAKernelCallExpr *CreateEmpty(const ASTContext &Ctx, + unsigned NumArgs, EmptyShell Empty); const CallExpr *getConfig() const { return cast_or_null(getPreArg(CONFIG)); @@ -482,25 +498,30 @@ public: /// /// Since literal operators are never found by ADL and can only be declared at /// namespace scope, a user-defined literal is never dependent. -class UserDefinedLiteral : public CallExpr { +class UserDefinedLiteral final : public CallExpr { + friend class ASTStmtReader; + friend class ASTStmtWriter; + /// The location of a ud-suffix within the literal. SourceLocation UDSuffixLoc; -public: - friend class ASTStmtReader; - friend class ASTStmtWriter; + // UserDefinedLiteral has some trailing objects belonging + // to CallExpr. See CallExpr for the details. - UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef Args, - QualType T, ExprValueKind VK, SourceLocation LitEndLoc, - SourceLocation SuffixLoc) - : CallExpr(C, UserDefinedLiteralClass, Fn, Args, T, VK, LitEndLoc, - /*MinNumArgs=*/0, NotADL), - UDSuffixLoc(SuffixLoc) {} + UserDefinedLiteral(Expr *Fn, ArrayRef Args, QualType Ty, + ExprValueKind VK, SourceLocation LitEndLoc, + SourceLocation SuffixLoc); - explicit UserDefinedLiteral(const ASTContext &C, unsigned NumArgs, - EmptyShell Empty) - : CallExpr(C, UserDefinedLiteralClass, /*NumPreArgs=*/0, NumArgs, Empty) { - } + UserDefinedLiteral(unsigned NumArgs, EmptyShell Empty); + +public: + static UserDefinedLiteral *Create(const ASTContext &Ctx, Expr *Fn, + ArrayRef Args, QualType Ty, + ExprValueKind VK, SourceLocation LitEndLoc, + SourceLocation SuffixLoc); + + static UserDefinedLiteral *CreateEmpty(const ASTContext &Ctx, + unsigned NumArgs, EmptyShell Empty); /// The kind of literal operator which is invoked. enum LiteralOperatorKind { diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 23ac5af7ae..66872464e0 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -433,7 +433,16 @@ protected: /// True if the callee of the call expression was found using ADL. unsigned UsesADL : 1; + + /// Padding used to align OffsetToTrailingObjects to a byte multiple. + unsigned : 24 - 2 - NumExprBits; + + /// The offset in bytes from the this pointer to the start of the + /// trailing objects belonging to CallExpr. Intentionally byte sized + /// for faster access. + unsigned OffsetToTrailingObjects : 8; }; + enum { NumCallExprBits = 32 }; class MemberExprBitfields { friend class MemberExpr; diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 6a893c5035..a6169ff652 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -6990,9 +6990,8 @@ ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) return std::move(Err); - return new (Importer.getToContext()) CXXMemberCallExpr( - Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), - ToRParenLoc); + return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, + ToType, E->getValueKind(), ToRParenLoc); } ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { @@ -7317,15 +7316,15 @@ ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { return std::move(Err); if (const auto *OCE = dyn_cast(E)) { - return new (Importer.getToContext()) CXXOperatorCallExpr( + return CXXOperatorCallExpr::Create( Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), OCE->getADLCallKind()); } - return new (Importer.getToContext()) CallExpr( - Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), - ToRParenLoc, /*MinNumArgs=*/0, E->getADLCallKind()); + return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, + E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, + E->getADLCallKind()); } ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 4f3c5b3344..11191c4682 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1234,57 +1234,99 @@ OverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { // Postfix Operators. //===----------------------------------------------------------------------===// -CallExpr::CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, - ArrayRef preargs, ArrayRef args, QualType t, - ExprValueKind VK, SourceLocation rparenloc, - unsigned MinNumArgs, ADLCallKind UsesADL) - : Expr(SC, t, VK, OK_Ordinary, fn->isTypeDependent(), - fn->isValueDependent(), fn->isInstantiationDependent(), - fn->containsUnexpandedParameterPack()), - RParenLoc(rparenloc) { - CallExprBits.UsesADL = static_cast(UsesADL); - - NumArgs = std::max(args.size(), MinNumArgs); - unsigned NumPreArgs = preargs.size(); +CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef PreArgs, + ArrayRef Args, QualType Ty, ExprValueKind VK, + SourceLocation RParenLoc, unsigned MinNumArgs, + ADLCallKind UsesADL) + : Expr(SC, Ty, VK, OK_Ordinary, Fn->isTypeDependent(), + Fn->isValueDependent(), Fn->isInstantiationDependent(), + Fn->containsUnexpandedParameterPack()), + RParenLoc(RParenLoc) { + NumArgs = std::max(Args.size(), MinNumArgs); + unsigned NumPreArgs = PreArgs.size(); CallExprBits.NumPreArgs = NumPreArgs; + assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!"); + + unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC); + CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects; + assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) && + "OffsetToTrailingObjects overflow!"); - SubExprs = new (C) Stmt *[NumArgs + PREARGS_START + NumPreArgs]; - SubExprs[FN] = fn; - for (unsigned i = 0; i != NumPreArgs; ++i) { - updateDependenciesFromArg(preargs[i]); - SubExprs[i+PREARGS_START] = preargs[i]; + CallExprBits.UsesADL = static_cast(UsesADL); + + setCallee(Fn); + for (unsigned I = 0; I != NumPreArgs; ++I) { + updateDependenciesFromArg(PreArgs[I]); + setPreArg(I, PreArgs[I]); } - for (unsigned i = 0; i != args.size(); ++i) { - updateDependenciesFromArg(args[i]); - SubExprs[i+PREARGS_START+NumPreArgs] = args[i]; + for (unsigned I = 0; I != Args.size(); ++I) { + updateDependenciesFromArg(Args[I]); + setArg(I, Args[I]); } - for (unsigned i = args.size(); i != NumArgs; ++i) { - SubExprs[i + PREARGS_START + NumPreArgs] = nullptr; + for (unsigned I = Args.size(); I != NumArgs; ++I) { + setArg(I, nullptr); } } -CallExpr::CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, - ArrayRef args, QualType t, ExprValueKind VK, - SourceLocation rparenloc, unsigned MinNumArgs, - ADLCallKind UsesADL) - : CallExpr(C, SC, fn, ArrayRef(), args, t, VK, rparenloc, - MinNumArgs, UsesADL) {} - -CallExpr::CallExpr(const ASTContext &C, Expr *fn, ArrayRef args, - QualType t, ExprValueKind VK, SourceLocation rparenloc, - unsigned MinNumArgs, ADLCallKind UsesADL) - : CallExpr(C, CallExprClass, fn, ArrayRef(), args, t, VK, rparenloc, - MinNumArgs, UsesADL) {} - -CallExpr::CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs, - unsigned NumArgs, EmptyShell Empty) +CallExpr::CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs, + EmptyShell Empty) : Expr(SC, Empty), NumArgs(NumArgs) { CallExprBits.NumPreArgs = NumPreArgs; - SubExprs = new (C) Stmt *[NumArgs + PREARGS_START + NumPreArgs]; + assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!"); + + unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC); + CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects; + assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) && + "OffsetToTrailingObjects overflow!"); } -CallExpr::CallExpr(const ASTContext &C, unsigned NumArgs, EmptyShell Empty) - : CallExpr(C, CallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {} +CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr *Fn, + ArrayRef Args, QualType Ty, ExprValueKind VK, + SourceLocation RParenLoc, unsigned MinNumArgs, + ADLCallKind UsesADL) { + unsigned NumArgs = std::max(Args.size(), MinNumArgs); + unsigned SizeOfTrailingObjects = + CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); + void *Mem = + Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, alignof(CallExpr)); + return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, + RParenLoc, MinNumArgs, UsesADL); +} + +CallExpr *CallExpr::CreateTemporary(void *Mem, Expr *Fn, QualType Ty, + ExprValueKind VK, SourceLocation RParenLoc, + ADLCallKind UsesADL) { + assert(!(reinterpret_cast(Mem) % alignof(CallExpr)) && + "Misaligned memory in CallExpr::CreateTemporary!"); + return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, /*Args=*/{}, Ty, + VK, RParenLoc, /*MinNumArgs=*/0, UsesADL); +} + +CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, + EmptyShell Empty) { + unsigned SizeOfTrailingObjects = + CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); + void *Mem = + Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, alignof(CallExpr)); + return new (Mem) CallExpr(CallExprClass, /*NumPreArgs=*/0, NumArgs, Empty); +} + +unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) { + switch (SC) { + case CallExprClass: + return sizeof(CallExpr); + case CXXOperatorCallExprClass: + return sizeof(CXXOperatorCallExpr); + case CXXMemberCallExprClass: + return sizeof(CXXMemberCallExpr); + case UserDefinedLiteralClass: + return sizeof(UserDefinedLiteral); + case CUDAKernelCallExprClass: + return sizeof(CUDAKernelCallExpr); + default: + llvm_unreachable("unexpected class deriving from CallExpr!"); + } +} void CallExpr::updateDependenciesFromArg(Expr *Arg) { if (Arg->isTypeDependent()) @@ -1297,14 +1339,6 @@ void CallExpr::updateDependenciesFromArg(Expr *Arg) { ExprBits.ContainsUnexpandedParameterPack = true; } -FunctionDecl *CallExpr::getDirectCallee() { - return dyn_cast_or_null(getCalleeDecl()); -} - -Decl *CallExpr::getCalleeDecl() { - return getCallee()->getReferencedDeclOfCallee(); -} - Decl *Expr::getReferencedDeclOfCallee() { Expr *CEE = IgnoreParenImpCasts(); diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 5ed4ea2ab7..3ddfbf1d19 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -478,6 +478,46 @@ SourceLocation CXXConstructExpr::getEndLoc() const { return End; } +CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind, + Expr *Fn, ArrayRef Args, + QualType Ty, ExprValueKind VK, + SourceLocation OperatorLoc, + FPOptions FPFeatures, + ADLCallKind UsesADL) + : CallExpr(CXXOperatorCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, + OperatorLoc, /*MinNumArgs=*/0, UsesADL), + Operator(OpKind), FPFeatures(FPFeatures) { + Range = getSourceRangeImpl(); +} + +CXXOperatorCallExpr::CXXOperatorCallExpr(unsigned NumArgs, EmptyShell Empty) + : CallExpr(CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {} + +CXXOperatorCallExpr *CXXOperatorCallExpr::Create( + const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, + ArrayRef Args, QualType Ty, ExprValueKind VK, + SourceLocation OperatorLoc, FPOptions FPFeatures, ADLCallKind UsesADL) { + // Allocate storage for the trailing objects of CallExpr. + unsigned NumArgs = Args.size(); + unsigned SizeOfTrailingObjects = + CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); + void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects, + alignof(CXXOperatorCallExpr)); + return new (Mem) CXXOperatorCallExpr(OpKind, Fn, Args, Ty, VK, OperatorLoc, + FPFeatures, UsesADL); +} + +CXXOperatorCallExpr *CXXOperatorCallExpr::CreateEmpty(const ASTContext &Ctx, + unsigned NumArgs, + EmptyShell Empty) { + // Allocate storage for the trailing objects of CallExpr. + unsigned SizeOfTrailingObjects = + CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); + void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects, + alignof(CXXOperatorCallExpr)); + return new (Mem) CXXOperatorCallExpr(NumArgs, Empty); +} + SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const { OverloadedOperatorKind Kind = getOperator(); if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { @@ -502,6 +542,40 @@ SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const { } } +CXXMemberCallExpr::CXXMemberCallExpr(Expr *Fn, ArrayRef Args, + QualType Ty, ExprValueKind VK, + SourceLocation RP, unsigned MinNumArgs) + : CallExpr(CXXMemberCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, RP, + MinNumArgs, NotADL) {} + +CXXMemberCallExpr::CXXMemberCallExpr(unsigned NumArgs, EmptyShell Empty) + : CallExpr(CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {} + +CXXMemberCallExpr *CXXMemberCallExpr::Create(const ASTContext &Ctx, Expr *Fn, + ArrayRef Args, QualType Ty, + ExprValueKind VK, + SourceLocation RP, + unsigned MinNumArgs) { + // Allocate storage for the trailing objects of CallExpr. + unsigned NumArgs = std::max(Args.size(), MinNumArgs); + unsigned SizeOfTrailingObjects = + CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); + void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects, + alignof(CXXMemberCallExpr)); + return new (Mem) CXXMemberCallExpr(Fn, Args, Ty, VK, RP, MinNumArgs); +} + +CXXMemberCallExpr *CXXMemberCallExpr::CreateEmpty(const ASTContext &Ctx, + unsigned NumArgs, + EmptyShell Empty) { + // Allocate storage for the trailing objects of CallExpr. + unsigned SizeOfTrailingObjects = + CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); + void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects, + alignof(CXXMemberCallExpr)); + return new (Mem) CXXMemberCallExpr(NumArgs, Empty); +} + Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { const Expr *Callee = getCallee()->IgnoreParens(); if (const auto *MemExpr = dyn_cast(Callee)) @@ -715,6 +789,42 @@ SourceLocation CXXFunctionalCastExpr::getEndLoc() const { return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getEndLoc(); } +UserDefinedLiteral::UserDefinedLiteral(Expr *Fn, ArrayRef Args, + QualType Ty, ExprValueKind VK, + SourceLocation LitEndLoc, + SourceLocation SuffixLoc) + : CallExpr(UserDefinedLiteralClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, + LitEndLoc, /*MinNumArgs=*/0, NotADL), + UDSuffixLoc(SuffixLoc) {} + +UserDefinedLiteral::UserDefinedLiteral(unsigned NumArgs, EmptyShell Empty) + : CallExpr(UserDefinedLiteralClass, /*NumPreArgs=*/0, NumArgs, Empty) {} + +UserDefinedLiteral *UserDefinedLiteral::Create(const ASTContext &Ctx, Expr *Fn, + ArrayRef Args, + QualType Ty, ExprValueKind VK, + SourceLocation LitEndLoc, + SourceLocation SuffixLoc) { + // Allocate storage for the trailing objects of CallExpr. + unsigned NumArgs = Args.size(); + unsigned SizeOfTrailingObjects = + CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); + void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects, + alignof(UserDefinedLiteral)); + return new (Mem) UserDefinedLiteral(Fn, Args, Ty, VK, LitEndLoc, SuffixLoc); +} + +UserDefinedLiteral *UserDefinedLiteral::CreateEmpty(const ASTContext &Ctx, + unsigned NumArgs, + EmptyShell Empty) { + // Allocate storage for the trailing objects of CallExpr. + unsigned SizeOfTrailingObjects = + CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); + void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects, + alignof(UserDefinedLiteral)); + return new (Mem) UserDefinedLiteral(NumArgs, Empty); +} + UserDefinedLiteral::LiteralOperatorKind UserDefinedLiteral::getLiteralOperatorKind() const { if (getNumArgs() == 0) @@ -1443,3 +1553,38 @@ TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C, void *Mem = C.Allocate(totalSizeToAlloc(NumArgs)); return new (Mem) TypeTraitExpr(EmptyShell()); } + +CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, + ArrayRef Args, QualType Ty, + ExprValueKind VK, SourceLocation RP, + unsigned MinNumArgs) + : CallExpr(CUDAKernelCallExprClass, Fn, /*PreArgs=*/Config, Args, Ty, VK, + RP, MinNumArgs, NotADL) {} + +CUDAKernelCallExpr::CUDAKernelCallExpr(unsigned NumArgs, EmptyShell Empty) + : CallExpr(CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, NumArgs, + Empty) {} + +CUDAKernelCallExpr * +CUDAKernelCallExpr::Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config, + ArrayRef Args, QualType Ty, ExprValueKind VK, + SourceLocation RP, unsigned MinNumArgs) { + // Allocate storage for the trailing objects of CallExpr. + unsigned NumArgs = std::max(Args.size(), MinNumArgs); + unsigned SizeOfTrailingObjects = + CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs); + void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects, + alignof(CUDAKernelCallExpr)); + return new (Mem) CUDAKernelCallExpr(Fn, Config, Args, Ty, VK, RP, MinNumArgs); +} + +CUDAKernelCallExpr *CUDAKernelCallExpr::CreateEmpty(const ASTContext &Ctx, + unsigned NumArgs, + EmptyShell Empty) { + // Allocate storage for the trailing objects of CallExpr. + unsigned SizeOfTrailingObjects = + CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs); + void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects, + alignof(CUDAKernelCallExpr)); + return new (Mem) CUDAKernelCallExpr(NumArgs, Empty); +} diff --git a/lib/Analysis/BodyFarm.cpp b/lib/Analysis/BodyFarm.cpp index 9c1d529a68..35f0464067 100644 --- a/lib/Analysis/BodyFarm.cpp +++ b/lib/Analysis/BodyFarm.cpp @@ -269,8 +269,8 @@ static CallExpr *create_call_once_funcptr_call(ASTContext &C, ASTMaker M, llvm_unreachable("Unexpected state"); } - return new (C) - CallExpr(C, SubExpr, CallArgs, C.VoidTy, VK_RValue, SourceLocation()); + return CallExpr::Create(C, SubExpr, CallArgs, C.VoidTy, VK_RValue, + SourceLocation()); } static CallExpr *create_call_once_lambda_call(ASTContext &C, ASTMaker M, @@ -292,12 +292,12 @@ static CallExpr *create_call_once_lambda_call(ASTContext &C, ASTMaker M, /* T =*/ callOperatorDecl->getType(), /* VK =*/ VK_LValue); - return new (C) - CXXOperatorCallExpr(/*AstContext=*/C, OO_Call, callOperatorDeclRef, - /*args=*/CallArgs, - /*QualType=*/C.VoidTy, - /*ExprValueType=*/VK_RValue, - /*SourceLocation=*/SourceLocation(), FPOptions()); + return CXXOperatorCallExpr::Create( + /*AstContext=*/C, OO_Call, callOperatorDeclRef, + /*args=*/CallArgs, + /*QualType=*/C.VoidTy, + /*ExprValueType=*/VK_RValue, + /*SourceLocation=*/SourceLocation(), FPOptions()); } /// Create a fake body for std::call_once. @@ -509,7 +509,7 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) { ASTMaker M(C); // (1) Create the call. - CallExpr *CE = new (C) CallExpr( + CallExpr *CE = CallExpr::Create( /*ASTContext=*/C, /*StmtClass=*/M.makeLvalueToRvalue(/*Expr=*/Block), /*args=*/None, @@ -579,8 +579,8 @@ static Stmt *create_dispatch_sync(ASTContext &C, const FunctionDecl *D) { ASTMaker M(C); DeclRefExpr *DR = M.makeDeclRefExpr(PV); ImplicitCastExpr *ICE = M.makeLvalueToRvalue(DR, Ty); - CallExpr *CE = new (C) CallExpr(C, ICE, None, C.VoidTy, VK_RValue, - SourceLocation()); + CallExpr *CE = + CallExpr::Create(C, ICE, None, C.VoidTy, VK_RValue, SourceLocation()); return CE; } diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index d497179a53..4cc86ad094 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -3390,11 +3390,11 @@ CodeGenFunction::GenerateObjCAtomicSetterCopyHelperFunction( Expr *Args[2] = { &DST, &SRC }; CallExpr *CalleeExp = cast(PID->getSetterCXXAssignment()); - CXXOperatorCallExpr TheCall(C, OO_Equal, CalleeExp->getCallee(), - Args, DestTy->getPointeeType(), - VK_LValue, SourceLocation(), FPOptions()); + CXXOperatorCallExpr *TheCall = CXXOperatorCallExpr::Create( + C, OO_Equal, CalleeExp->getCallee(), Args, DestTy->getPointeeType(), + VK_LValue, SourceLocation(), FPOptions()); - EmitStmt(&TheCall); + EmitStmt(TheCall); FinishFunction(); HelperFn = llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy); diff --git a/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 9ed8b1568b..10ca9a7856 100644 --- a/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -2107,9 +2107,8 @@ RewriteModernObjC::SynthesizeCallToFunctionDecl(FunctionDecl *FD, const FunctionType *FT = msgSendType->getAs(); - CallExpr *Exp = new (Context) CallExpr(*Context, ICE, Args, - FT->getCallResultType(*Context), - VK_RValue, EndLoc); + CallExpr *Exp = CallExpr::Create( + *Context, ICE, Args, FT->getCallResultType(*Context), VK_RValue, EndLoc); return Exp; } @@ -2689,8 +2688,8 @@ Stmt *RewriteModernObjC::RewriteObjCBoxedExpr(ObjCBoxedExpr *Exp) { ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *CE = new (Context) - CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); + CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, EndLoc); ReplaceStmt(Exp, CE); return CE; } @@ -2729,8 +2728,8 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { for (unsigned i = 0; i < NumElements; i++) InitExprs.push_back(Exp->getElement(i)); Expr *NSArrayCallExpr = - new (Context) CallExpr(*Context, NSArrayDRE, InitExprs, - NSArrayFType, VK_LValue, SourceLocation()); + CallExpr::Create(*Context, NSArrayDRE, InitExprs, NSArrayFType, VK_LValue, + SourceLocation()); FieldDecl *ARRFD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), @@ -2810,8 +2809,8 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *CE = new (Context) - CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); + CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, EndLoc); ReplaceStmt(Exp, CE); return CE; } @@ -2858,8 +2857,8 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral // (const id [])objects Expr *NSValueCallExpr = - new (Context) CallExpr(*Context, NSDictDRE, ValueExprs, - NSDictFType, VK_LValue, SourceLocation()); + CallExpr::Create(*Context, NSDictDRE, ValueExprs, NSDictFType, VK_LValue, + SourceLocation()); FieldDecl *ARRFD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), @@ -2877,9 +2876,8 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral CK_BitCast, DictLiteralValueME); // (const id [])keys - Expr *NSKeyCallExpr = - new (Context) CallExpr(*Context, NSDictDRE, KeyExprs, - NSDictFType, VK_LValue, SourceLocation()); + Expr *NSKeyCallExpr = CallExpr::Create( + *Context, NSDictDRE, KeyExprs, NSDictFType, VK_LValue, SourceLocation()); MemberExpr *DictLiteralKeyME = new (Context) MemberExpr(NSKeyCallExpr, false, SourceLocation(), ARRFD, @@ -2962,8 +2960,8 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *CE = new (Context) - CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); + CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, EndLoc); ReplaceStmt(Exp, CE); return CE; } @@ -3172,10 +3170,10 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla FunctionDecl *FD = FunctionDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), ID, FuncType, nullptr, SC_Extern, false, false); - DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, FD, false, castType, - VK_RValue, SourceLocation()); - CallExpr *STCE = new (Context) CallExpr(*Context, DRE, MsgExprs, - castType, VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) + DeclRefExpr(*Context, FD, false, castType, VK_RValue, SourceLocation()); + CallExpr *STCE = CallExpr::Create(*Context, DRE, MsgExprs, castType, + VK_LValue, SourceLocation()); FieldDecl *FieldD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), @@ -3276,9 +3274,8 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, - superType, VK_LValue, - SourceLocation()); + SuperRep = CallExpr::Create(*Context, DRE, InitExprs, superType, + VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with // the structure definition in the header. The rewriter has it's own // internal definition (__rw_objc_super) that is uses. This is why @@ -3369,12 +3366,11 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, if (LangOpts.MicrosoftExt) { SynthSuperConstructorFunctionDecl(); // Simulate a constructor call... - DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, - SuperConstructorFunctionDecl, - false, superType, VK_LValue, - SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, - superType, VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) + DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, + VK_LValue, SourceLocation()); + SuperRep = CallExpr::Create(*Context, DRE, InitExprs, superType, + VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with // the structure definition in the header. The rewriter has it's own // internal definition (__rw_objc_super) that is uses. This is why @@ -3538,8 +3534,8 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *CE = new (Context) - CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); + CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, EndLoc); Stmt *ReplacingStmt = CE; if (MsgSendStretFlavor) { // We have the method which returns a struct/union. Must also generate @@ -4650,9 +4646,8 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp E = Exp->arg_end(); I != E; ++I) { BlkExprs.push_back(*I); } - CallExpr *CE = new (Context) CallExpr(*Context, PE, BlkExprs, - Exp->getType(), VK_RValue, - SourceLocation()); + CallExpr *CE = CallExpr::Create(*Context, PE, BlkExprs, Exp->getType(), + VK_RValue, SourceLocation()); return CE; } @@ -5395,8 +5390,8 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, Context->IntTy, SourceLocation()); InitExprs.push_back(FlagExp); } - NewRep = new (Context) CallExpr(*Context, DRE, InitExprs, - FType, VK_LValue, SourceLocation()); + NewRep = CallExpr::Create(*Context, DRE, InitExprs, FType, VK_LValue, + SourceLocation()); if (GlobalBlockExpr) { assert (!GlobalConstructionExp && diff --git a/lib/Frontend/Rewrite/RewriteObjC.cpp b/lib/Frontend/Rewrite/RewriteObjC.cpp index 0bbf4266fd..3e018800b9 100644 --- a/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -2020,9 +2020,8 @@ RewriteObjC::SynthesizeCallToFunctionDecl(FunctionDecl *FD, const FunctionType *FT = msgSendType->getAs(); - CallExpr *Exp = new (Context) CallExpr(*Context, ICE, Args, - FT->getCallResultType(*Context), - VK_RValue, EndLoc); + CallExpr *Exp = CallExpr::Create( + *Context, ICE, Args, FT->getCallResultType(*Context), VK_RValue, EndLoc); return Exp; } @@ -2607,8 +2606,8 @@ CallExpr *RewriteObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavo ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *STCE = new (Context) CallExpr( - *Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, SourceLocation()); + CallExpr *STCE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, SourceLocation()); return STCE; } @@ -2700,9 +2699,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, - superType, VK_LValue, - SourceLocation()); + SuperRep = CallExpr::Create(*Context, DRE, InitExprs, superType, + VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with // the structure definition in the header. The rewriter has it's own // internal definition (__rw_objc_super) that is uses. This is why @@ -2796,8 +2794,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, - superType, VK_LValue, SourceLocation()); + SuperRep = CallExpr::Create(*Context, DRE, InitExprs, superType, + VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with // the structure definition in the header. The rewriter has it's own // internal definition (__rw_objc_super) that is uses. This is why @@ -2961,8 +2959,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *CE = new (Context) - CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); + CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, EndLoc); Stmt *ReplacingStmt = CE; if (MsgSendStretFlavor) { // We have the method which returns a struct/union. Must also generate @@ -3812,9 +3810,8 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) { E = Exp->arg_end(); I != E; ++I) { BlkExprs.push_back(*I); } - CallExpr *CE = new (Context) CallExpr(*Context, PE, BlkExprs, - Exp->getType(), VK_RValue, - SourceLocation()); + CallExpr *CE = CallExpr::Create(*Context, PE, BlkExprs, Exp->getType(), + VK_RValue, SourceLocation()); return CE; } @@ -4524,11 +4521,11 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, Context->IntTy, SourceLocation()); InitExprs.push_back(FlagExp); } - NewRep = new (Context) CallExpr(*Context, DRE, InitExprs, - FType, VK_LValue, SourceLocation()); - NewRep = new (Context) UnaryOperator(NewRep, UO_AddrOf, - Context->getPointerType(NewRep->getType()), - VK_RValue, OK_Ordinary, SourceLocation(), false); + NewRep = CallExpr::Create(*Context, DRE, InitExprs, FType, VK_LValue, + SourceLocation()); + NewRep = new (Context) UnaryOperator( + NewRep, UO_AddrOf, Context->getPointerType(NewRep->getType()), VK_RValue, + OK_Ordinary, SourceLocation(), false); NewRep = NoTypeInfoCStyleCastExpr(Context, FType, CK_BitCast, NewRep); BlockDeclRefs.clear(); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 78dbf4365c..d38ae0fdc8 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -5439,8 +5439,8 @@ ExprResult Sema::ActOnCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc, ArgExprs.back()->getEndLoc())); } - return new (Context) - CallExpr(Context, Fn, None, Context.VoidTy, VK_RValue, RParenLoc); + return CallExpr::Create(Context, Fn, /*Args=*/{}, Context.VoidTy, + VK_RValue, RParenLoc); } if (Fn->getType() == Context.PseudoObjectTy) { ExprResult result = CheckPlaceholderExpr(Fn); @@ -5452,7 +5452,7 @@ ExprResult Sema::ActOnCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc, // in which case we won't do any semantic analysis now. if (Fn->isTypeDependent() || Expr::hasAnyTypeDependentArguments(ArgExprs)) { if (ExecConfig) { - return new (Context) CUDAKernelCallExpr( + return CUDAKernelCallExpr::Create( Context, Fn, cast(ExecConfig), ArgExprs, Context.DependentTy, VK_RValue, RParenLoc); } else { @@ -5461,8 +5461,8 @@ ExprResult Sema::ActOnCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc, *this, dyn_cast(Fn->IgnoreParens()), Fn->getBeginLoc()); - return new (Context) CallExpr( - Context, Fn, ArgExprs, Context.DependentTy, VK_RValue, RParenLoc); + return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy, + VK_RValue, RParenLoc); } } @@ -5490,8 +5490,8 @@ ExprResult Sema::ActOnCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc, // We aren't supposed to apply this logic if there's an '&' involved. if (!find.HasFormOfMemberPointer) { if (Expr::hasAnyTypeDependentArguments(ArgExprs)) - return new (Context) CallExpr( - Context, Fn, ArgExprs, Context.DependentTy, VK_RValue, RParenLoc); + return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy, + VK_RValue, RParenLoc); OverloadExpr *ovl = find.Expression; if (UnresolvedLookupExpr *ULE = dyn_cast(ovl)) return BuildOverloadedCallExpr( @@ -5680,12 +5680,12 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, if (Config) { assert(UsesADL == ADLCallKind::NotADL && "CUDAKernelCallExpr should not use ADL"); - TheCall = new (Context) - CUDAKernelCallExpr(Context, Fn, cast(Config), Args, ResultTy, - VK_RValue, RParenLoc, NumParams); + TheCall = + CUDAKernelCallExpr::Create(Context, Fn, cast(Config), Args, + ResultTy, VK_RValue, RParenLoc, NumParams); } else { - TheCall = new (Context) CallExpr(Context, Fn, Args, ResultTy, VK_RValue, - RParenLoc, NumParams, UsesADL); + TheCall = CallExpr::Create(Context, Fn, Args, ResultTy, VK_RValue, + RParenLoc, NumParams, UsesADL); } if (!getLangOpts().CPlusPlus) { @@ -16775,9 +16775,10 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) { auto *FD = cast(DRE->getDecl()); if (FD->getBuiltinID() == Builtin::BI__noop) { E = ImpCastExprToType(E, Context.getPointerType(FD->getType()), - CK_BuiltinFnToFnPtr).get(); - return new (Context) CallExpr(Context, E, None, Context.IntTy, - VK_RValue, SourceLocation()); + CK_BuiltinFnToFnPtr) + .get(); + return CallExpr::Create(Context, E, /*Args=*/{}, Context.IntTy, + VK_RValue, SourceLocation()); } } diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 18d0e78a4f..730c426076 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -7189,8 +7189,8 @@ ExprResult Sema::BuildCXXMemberCallExpr(Expr *E, NamedDecl *FoundDecl, ExprValueKind VK = Expr::getValueKindForType(ResultType); ResultType = ResultType.getNonLValueExprType(Context); - CXXMemberCallExpr *CE = new (Context) CXXMemberCallExpr( - Context, ME, None, ResultType, VK, Exp.get()->getEndLoc()); + CXXMemberCallExpr *CE = CXXMemberCallExpr::Create( + Context, ME, /*Args=*/{}, ResultType, VK, Exp.get()->getEndLoc()); if (CheckFunctionCall(Method, CE, Method->getType()->castAs())) diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 4fe8d3dd59..24e9ef4aaa 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -11231,8 +11231,8 @@ static bool actOnOMPReductionKindClause( ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, S.DefaultLvalueConversion(DeclareReductionRef.get()).get()); Expr *Args[] = {LHS.get(), RHS.get()}; - ReductionOp = new (Context) - CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); + ReductionOp = + CallExpr::Create(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); } else { ReductionOp = S.BuildBinOp( Stack->getCurScope(), ReductionId.getBeginLoc(), BOK, LHSDRE, RHSDRE); diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index d829194364..94f7979f66 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -7003,13 +7003,17 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion, // there are 0 arguments (i.e., nothing is allocated using ASTContext's // allocator). QualType CallResultType = ConversionType.getNonLValueExprType(Context); - CallExpr Call(Context, &ConversionFn, None, CallResultType, VK, - From->getBeginLoc()); + + llvm::AlignedCharArray + Buffer; + CallExpr *TheTemporaryCall = CallExpr::CreateTemporary( + Buffer.buffer, &ConversionFn, CallResultType, VK, From->getBeginLoc()); + ImplicitConversionSequence ICS = - TryCopyInitialization(*this, &Call, ToType, - /*SuppressUserConversions=*/true, - /*InOverloadResolution=*/false, - /*AllowObjCWritebackConversion=*/false); + TryCopyInitialization(*this, TheTemporaryCall, ToType, + /*SuppressUserConversions=*/true, + /*InOverloadResolution=*/false, + /*AllowObjCWritebackConversion=*/false); switch (ICS.getKind()) { case ImplicitConversionSequence::StandardConversion: @@ -11988,12 +11992,12 @@ bool Sema::buildOverloadedCallSet(Scope *S, Expr *Fn, if (CandidateSet->empty() || CandidateSet->BestViableFunction(*this, Fn->getBeginLoc(), Best) == OR_No_Viable_Function) { - // In Microsoft mode, if we are inside a template class member function then - // create a type dependent CallExpr. The goal is to postpone name lookup - // to instantiation time to be able to search into type dependent base - // classes. - CallExpr *CE = new (Context) CallExpr( - Context, Fn, Args, Context.DependentTy, VK_RValue, RParenLoc); + // In Microsoft mode, if we are inside a template class member function + // then create a type dependent CallExpr. The goal is to postpone name + // lookup to instantiation time to be able to search into type dependent + // base classes. + CallExpr *CE = CallExpr::Create(Context, Fn, Args, Context.DependentTy, + VK_RValue, RParenLoc); CE->setTypeDependent(true); CE->setValueDependent(true); CE->setInstantiationDependent(true); @@ -12199,14 +12203,12 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, VK_RValue, OK_Ordinary, OpLoc, false); CXXRecordDecl *NamingClass = nullptr; // lookup ignores member operators - UnresolvedLookupExpr *Fn - = UnresolvedLookupExpr::Create(Context, NamingClass, - NestedNameSpecifierLoc(), OpNameInfo, - /*ADL*/ true, IsOverloaded(Fns), - Fns.begin(), Fns.end()); - return new (Context) - CXXOperatorCallExpr(Context, Op, Fn, ArgsArray, Context.DependentTy, - VK_RValue, OpLoc, FPOptions()); + UnresolvedLookupExpr *Fn = UnresolvedLookupExpr::Create( + Context, NamingClass, NestedNameSpecifierLoc(), OpNameInfo, + /*ADL*/ true, IsOverloaded(Fns), Fns.begin(), Fns.end()); + return CXXOperatorCallExpr::Create(Context, Op, Fn, ArgsArray, + Context.DependentTy, VK_RValue, OpLoc, + FPOptions()); } // Build an empty overload set. @@ -12278,9 +12280,9 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, ResultTy = ResultTy.getNonLValueExprType(Context); Args[0] = Input; - CallExpr *TheCall = new (Context) - CXXOperatorCallExpr(Context, Op, FnExpr.get(), ArgsArray, ResultTy, - VK, OpLoc, FPOptions(), Best->IsADLCandidate); + CallExpr *TheCall = CXXOperatorCallExpr::Create( + Context, Op, FnExpr.get(), ArgsArray, ResultTy, VK, OpLoc, + FPOptions(), Best->IsADLCandidate); if (CheckCallReturnType(FnDecl->getReturnType(), OpLoc, TheCall, FnDecl)) return ExprError(); @@ -12390,14 +12392,12 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc, CXXRecordDecl *NamingClass = nullptr; // lookup ignores member operators // TODO: provide better source location info in DNLoc component. DeclarationNameInfo OpNameInfo(OpName, OpLoc); - UnresolvedLookupExpr *Fn - = UnresolvedLookupExpr::Create(Context, NamingClass, - NestedNameSpecifierLoc(), OpNameInfo, - /*ADL*/PerformADL, IsOverloaded(Fns), - Fns.begin(), Fns.end()); - return new (Context) - CXXOperatorCallExpr(Context, Op, Fn, Args, Context.DependentTy, - VK_RValue, OpLoc, FPFeatures); + UnresolvedLookupExpr *Fn = UnresolvedLookupExpr::Create( + Context, NamingClass, NestedNameSpecifierLoc(), OpNameInfo, + /*ADL*/ PerformADL, IsOverloaded(Fns), Fns.begin(), Fns.end()); + return CXXOperatorCallExpr::Create(Context, Op, Fn, Args, + Context.DependentTy, VK_RValue, OpLoc, + FPFeatures); } // Always do placeholder-like conversions on the RHS. @@ -12510,9 +12510,9 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc, ExprValueKind VK = Expr::getValueKindForType(ResultTy); ResultTy = ResultTy.getNonLValueExprType(Context); - CXXOperatorCallExpr *TheCall = new (Context) - CXXOperatorCallExpr(Context, Op, FnExpr.get(), Args, ResultTy, VK, - OpLoc, FPFeatures, Best->IsADLCandidate); + CXXOperatorCallExpr *TheCall = CXXOperatorCallExpr::Create( + Context, Op, FnExpr.get(), Args, ResultTy, VK, OpLoc, FPFeatures, + Best->IsADLCandidate); if (CheckCallReturnType(FnDecl->getReturnType(), OpLoc, TheCall, FnDecl)) @@ -12658,9 +12658,9 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, UnresolvedSetIterator()); // Can't add any actual overloads yet - return new (Context) - CXXOperatorCallExpr(Context, OO_Subscript, Fn, Args, - Context.DependentTy, VK_RValue, RLoc, FPOptions()); + return CXXOperatorCallExpr::Create(Context, OO_Subscript, Fn, Args, + Context.DependentTy, VK_RValue, RLoc, + FPOptions()); } // Handle placeholders on both operands. @@ -12734,10 +12734,8 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, ResultTy = ResultTy.getNonLValueExprType(Context); CXXOperatorCallExpr *TheCall = - new (Context) CXXOperatorCallExpr(Context, OO_Subscript, - FnExpr.get(), Args, - ResultTy, VK, RLoc, - FPOptions()); + CXXOperatorCallExpr::Create(Context, OO_Subscript, FnExpr.get(), + Args, ResultTy, VK, RLoc, FPOptions()); if (CheckCallReturnType(FnDecl->getReturnType(), LLoc, TheCall, FnDecl)) return ExprError(); @@ -12857,10 +12855,9 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, << (qualsString.find(' ') == std::string::npos ? 1 : 2); } - CXXMemberCallExpr *call - = new (Context) CXXMemberCallExpr(Context, MemExprE, Args, - resultType, valueKind, RParenLoc, - proto->getNumParams()); + CXXMemberCallExpr *call = + CXXMemberCallExpr::Create(Context, MemExprE, Args, resultType, + valueKind, RParenLoc, proto->getNumParams()); if (CheckCallReturnType(proto->getReturnType(), op->getRHS()->getBeginLoc(), call, nullptr)) @@ -12876,8 +12873,8 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, } if (isa(NakedMemExpr)) - return new (Context) - CallExpr(Context, MemExprE, Args, Context.VoidTy, VK_RValue, RParenLoc); + return CallExpr::Create(Context, MemExprE, Args, Context.VoidTy, VK_RValue, + RParenLoc); UnbridgedCastsSet UnbridgedCasts; if (checkArgPlaceholdersForOverload(*this, Args, UnbridgedCasts)) @@ -13012,9 +13009,8 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, assert(Method && "Member call to something that isn't a method?"); const auto *Proto = Method->getType()->getAs(); CXXMemberCallExpr *TheCall = - new (Context) CXXMemberCallExpr(Context, MemExprE, Args, - ResultType, VK, RParenLoc, - Proto->getNumParams()); + CXXMemberCallExpr::Create(Context, MemExprE, Args, ResultType, VK, + RParenLoc, Proto->getNumParams()); // Check for a valid return type. if (CheckCallReturnType(Method->getReturnType(), MemExpr->getMemberLoc(), @@ -13353,9 +13349,9 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj, ExprValueKind VK = Expr::getValueKindForType(ResultTy); ResultTy = ResultTy.getNonLValueExprType(Context); - CXXOperatorCallExpr *TheCall = new (Context) - CXXOperatorCallExpr(Context, OO_Call, NewFn.get(), MethodArgs, ResultTy, - VK, RParenLoc, FPOptions()); + CXXOperatorCallExpr *TheCall = + CXXOperatorCallExpr::Create(Context, OO_Call, NewFn.get(), MethodArgs, + ResultTy, VK, RParenLoc, FPOptions()); if (CheckCallReturnType(Method->getReturnType(), LParenLoc, TheCall, Method)) return true; @@ -13471,9 +13467,8 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc, QualType ResultTy = Method->getReturnType(); ExprValueKind VK = Expr::getValueKindForType(ResultTy); ResultTy = ResultTy.getNonLValueExprType(Context); - CXXOperatorCallExpr *TheCall = - new (Context) CXXOperatorCallExpr(Context, OO_Arrow, FnExpr.get(), - Base, ResultTy, VK, OpLoc, FPOptions()); + CXXOperatorCallExpr *TheCall = CXXOperatorCallExpr::Create( + Context, OO_Arrow, FnExpr.get(), Base, ResultTy, VK, OpLoc, FPOptions()); if (CheckCallReturnType(Method->getReturnType(), OpLoc, TheCall, Method)) return ExprError(); @@ -13545,10 +13540,9 @@ ExprResult Sema::BuildLiteralOperatorCall(LookupResult &R, ExprValueKind VK = Expr::getValueKindForType(ResultTy); ResultTy = ResultTy.getNonLValueExprType(Context); - UserDefinedLiteral *UDL = - new (Context) UserDefinedLiteral(Context, Fn.get(), - llvm::makeArrayRef(ConvArgs, Args.size()), - ResultTy, VK, LitEndLoc, UDSuffixLoc); + UserDefinedLiteral *UDL = UserDefinedLiteral::Create( + Context, Fn.get(), llvm::makeArrayRef(ConvArgs, Args.size()), ResultTy, + VK, LitEndLoc, UDSuffixLoc); if (CheckCallReturnType(FD->getReturnType(), UDSuffixLoc, UDL, FD)) return ExprError(); diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index cffc22e1b4..9de4e8d654 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -3138,7 +3138,7 @@ public: CK_BuiltinFnToFnPtr).get(); // Build the CallExpr - ExprResult TheCall = new (SemaRef.Context) CallExpr( + ExprResult TheCall = CallExpr::Create( SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 88e7bb6471..1b7389e71c 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -2481,9 +2481,8 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { break; case EXPR_CALL: - S = new (Context) CallExpr( - Context, /* NumArgs=*/Record[ASTStmtReader::NumExprFields], - Empty); + S = CallExpr::CreateEmpty( + Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], Empty); break; case EXPR_MEMBER: { @@ -3073,15 +3072,13 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { } case EXPR_CXX_OPERATOR_CALL: - S = new (Context) CXXOperatorCallExpr( - Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], - Empty); + S = CXXOperatorCallExpr::CreateEmpty( + Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], Empty); break; case EXPR_CXX_MEMBER_CALL: - S = new (Context) CXXMemberCallExpr( - Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], - Empty); + S = CXXMemberCallExpr::CreateEmpty( + Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], Empty); break; case EXPR_CXX_CONSTRUCT: @@ -3121,7 +3118,7 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { break; case EXPR_USER_DEFINED_LITERAL: - S = new (Context) UserDefinedLiteral( + S = UserDefinedLiteral::CreateEmpty( Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], Empty); break; @@ -3292,7 +3289,7 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { break; case EXPR_CUDA_KERNEL_CALL: - S = new (Context) CUDAKernelCallExpr( + S = CUDAKernelCallExpr::CreateEmpty( Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], Empty); break; -- 2.40.0