/// 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<Stmt **>(reinterpret_cast<char *>(this) +
+ CallExprBits.OffsetToTrailingObjects);
+ }
+ Stmt *const *getTrailingStmts() const {
+ return const_cast<CallExpr *>(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<Expr *> preargs, ArrayRef<Expr *> args, QualType t,
- ExprValueKind VK, SourceLocation rparenloc, unsigned MinNumArgs = 0,
- ADLCallKind UsesADL = NotADL);
- CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, ArrayRef<Expr *> 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<Expr *> PreArgs,
+ ArrayRef<Expr *> 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<Expr *> 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<Expr *> 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<alignof(CallExpr),
+ /// sizeof(CallExpr) + sizeof(Stmt *)> 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<Expr>(SubExprs[FN]); }
- Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
- void setCallee(Expr *F) { SubExprs[FN] = F; }
+ Expr *getCallee() { return cast<Expr>(getTrailingStmts()[FN]); }
+ const Expr *getCallee() const { return cast<Expr>(getTrailingStmts()[FN]); }
+ void setCallee(Expr *F) { getTrailingStmts()[FN] = F; }
ADLCallKind getADLCallKind() const {
return static_cast<ADLCallKind>(CallExprBits.UsesADL);
}
bool usesADL() const { return getADLCallKind() == UsesADL; }
- Decl *getCalleeDecl();
+ Decl *getCalleeDecl() { return getCallee()->getReferencedDeclOfCallee(); }
const Decl *getCalleeDecl() const {
- return const_cast<CallExpr*>(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<FunctionDecl>(getCalleeDecl());
+ }
const FunctionDecl *getDirectCallee() const {
- return const_cast<CallExpr*>(this)->getDirectCallee();
+ return dyn_cast_or_null<FunctionDecl>(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<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START);
+ return reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START +
+ getNumPreArgs());
}
const Expr *const *getArgs() const {
- return reinterpret_cast<Expr **>(SubExprs + getNumPreArgs() +
- PREARGS_START);
+ return reinterpret_cast<const Expr *const *>(
+ 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<Expr>(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<Expr>(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;
}
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<Stmt*> getRawSubExprs() {
- return llvm::makeArrayRef(SubExprs,
- getNumPreArgs() + PREARGS_START + getNumArgs());
+ ArrayRef<Stmt *> 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.
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");
}
// 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());
}
};
/// 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;
// 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<Expr *> Args, QualType Ty, ExprValueKind VK,
+ SourceLocation OperatorLoc, FPOptions FPFeatures,
+ ADLCallKind UsesADL);
- CXXOperatorCallExpr(ASTContext &C, OverloadedOperatorKind Op, Expr *fn,
- ArrayRef<Expr *> 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<Expr *> 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) {
/// 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<Expr *> Args, QualType Ty,
+ ExprValueKind VK, SourceLocation RP, unsigned MinNumArgs);
+
+ CXXMemberCallExpr(unsigned NumArgs, EmptyShell Empty);
+
public:
- CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr *> 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<Expr *> 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.
///
};
/// 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<Expr *> Args,
+ QualType Ty, ExprValueKind VK, SourceLocation RP,
+ unsigned MinNumArgs);
+
+ CUDAKernelCallExpr(unsigned NumArgs, EmptyShell Empty);
+
public:
- CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
- ArrayRef<Expr *> 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<Expr *> 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<CallExpr>(getPreArg(CONFIG));
///
/// 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<Expr *> 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<Expr *> 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<Expr *> 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 {
/// 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;
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) {
return std::move(Err);
if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(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) {
// Postfix Operators.
//===----------------------------------------------------------------------===//
-CallExpr::CallExpr(const ASTContext &C, StmtClass SC, Expr *fn,
- ArrayRef<Expr *> preargs, ArrayRef<Expr *> 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<bool>(UsesADL);
-
- NumArgs = std::max<unsigned>(args.size(), MinNumArgs);
- unsigned NumPreArgs = preargs.size();
+CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
+ ArrayRef<Expr *> 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<unsigned>(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<bool>(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<Expr *> args, QualType t, ExprValueKind VK,
- SourceLocation rparenloc, unsigned MinNumArgs,
- ADLCallKind UsesADL)
- : CallExpr(C, SC, fn, ArrayRef<Expr *>(), args, t, VK, rparenloc,
- MinNumArgs, UsesADL) {}
-
-CallExpr::CallExpr(const ASTContext &C, Expr *fn, ArrayRef<Expr *> args,
- QualType t, ExprValueKind VK, SourceLocation rparenloc,
- unsigned MinNumArgs, ADLCallKind UsesADL)
- : CallExpr(C, CallExprClass, fn, ArrayRef<Expr *>(), 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<Expr *> Args, QualType Ty, ExprValueKind VK,
+ SourceLocation RParenLoc, unsigned MinNumArgs,
+ ADLCallKind UsesADL) {
+ unsigned NumArgs = std::max<unsigned>(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<uintptr_t>(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())
ExprBits.ContainsUnexpandedParameterPack = true;
}
-FunctionDecl *CallExpr::getDirectCallee() {
- return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
-}
-
-Decl *CallExpr::getCalleeDecl() {
- return getCallee()->getReferencedDeclOfCallee();
-}
-
Decl *Expr::getReferencedDeclOfCallee() {
Expr *CEE = IgnoreParenImpCasts();
return End;
}
+CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind,
+ Expr *Fn, ArrayRef<Expr *> 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<Expr *> 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) {
}
}
+CXXMemberCallExpr::CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> 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<Expr *> Args, QualType Ty,
+ ExprValueKind VK,
+ SourceLocation RP,
+ unsigned MinNumArgs) {
+ // Allocate storage for the trailing objects of CallExpr.
+ unsigned NumArgs = std::max<unsigned>(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<MemberExpr>(Callee))
return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getEndLoc();
}
+UserDefinedLiteral::UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> 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<Expr *> 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)
void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs));
return new (Mem) TypeTraitExpr(EmptyShell());
}
+
+CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config,
+ ArrayRef<Expr *> 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<Expr *> Args, QualType Ty, ExprValueKind VK,
+ SourceLocation RP, unsigned MinNumArgs) {
+ // Allocate storage for the trailing objects of CallExpr.
+ unsigned NumArgs = std::max<unsigned>(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);
+}
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,
/* 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.
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,
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;
}
Expr *Args[2] = { &DST, &SRC };
CallExpr *CalleeExp = cast<CallExpr>(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);
const FunctionType *FT = msgSendType->getAs<FunctionType>();
- 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;
}
ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast);
const FunctionType *FT = msgSendType->getAs<FunctionType>();
- 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;
}
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(),
ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast);
const FunctionType *FT = msgSendType->getAs<FunctionType>();
- 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;
}
// (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(),
CK_BitCast,
DictLiteralValueME);
// (const id <NSCopying> [])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,
ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast);
const FunctionType *FT = msgSendType->getAs<FunctionType>();
- 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;
}
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(),
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
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
ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast);
const FunctionType *FT = msgSendType->getAs<FunctionType>();
- 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
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;
}
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 &&
const FunctionType *FT = msgSendType->getAs<FunctionType>();
- 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;
}
ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), cast);
const FunctionType *FT = msgSendType->getAs<FunctionType>();
- 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;
}
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
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
ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast);
const FunctionType *FT = msgSendType->getAs<FunctionType>();
- 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
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;
}
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();
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);
// 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<CallExpr>(ExecConfig), ArgExprs,
Context.DependentTy, VK_RValue, RParenLoc);
} else {
*this, dyn_cast<UnresolvedMemberExpr>(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);
}
}
// 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<UnresolvedLookupExpr>(ovl))
return BuildOverloadedCallExpr(
if (Config) {
assert(UsesADL == ADLCallKind::NotADL &&
"CUDAKernelCallExpr should not use ADL");
- TheCall = new (Context)
- CUDAKernelCallExpr(Context, Fn, cast<CallExpr>(Config), Args, ResultTy,
- VK_RValue, RParenLoc, NumParams);
+ TheCall =
+ CUDAKernelCallExpr::Create(Context, Fn, cast<CallExpr>(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) {
auto *FD = cast<FunctionDecl>(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());
}
}
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<FunctionProtoType>()))
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);
// 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<alignof(CallExpr), sizeof(CallExpr) + sizeof(Stmt *)>
+ 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:
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);
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.
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();
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.
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))
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.
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();
<< (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))
}
if (isa<CXXPseudoDestructorExpr>(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))
assert(Method && "Member call to something that isn't a method?");
const auto *Proto = Method->getType()->getAs<FunctionProtoType>();
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(),
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;
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();
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();
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);
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: {
}
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:
break;
case EXPR_USER_DEFINED_LITERAL:
- S = new (Context) UserDefinedLiteral(
+ S = UserDefinedLiteral::CreateEmpty(
Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], Empty);
break;
break;
case EXPR_CUDA_KERNEL_CALL:
- S = new (Context) CUDAKernelCallExpr(
+ S = CUDAKernelCallExpr::CreateEmpty(
Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], Empty);
break;