r314722 - [Analyzer] Avoid copy and modifying passed reference in BodyFarm::create_call_once
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 2 14:01:46 PDT 2017
Author: george.karpenkov
Date: Mon Oct 2 14:01:46 2017
New Revision: 314722
URL: http://llvm.org/viewvc/llvm-project?rev=314722&view=rev
Log:
[Analyzer] Avoid copy and modifying passed reference in BodyFarm::create_call_once
Differential Revision: https://reviews.llvm.org/D38475
Modified:
cfe/trunk/lib/Analysis/BodyFarm.cpp
Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BodyFarm.cpp?rev=314722&r1=314721&r2=314722&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp Mon Oct 2 14:01:46 2017
@@ -257,10 +257,9 @@ NamedDecl *ASTMaker::findMemberField(con
typedef Stmt *(*FunctionFarmer)(ASTContext &C, const FunctionDecl *D);
-static CallExpr *
-create_call_once_funcptr_call(ASTContext &C, ASTMaker M,
- const ParmVarDecl *Callback,
- SmallVectorImpl<Expr *> &CallArgs) {
+static CallExpr *create_call_once_funcptr_call(ASTContext &C, ASTMaker M,
+ const ParmVarDecl *Callback,
+ ArrayRef<Expr *> CallArgs) {
return new (C) CallExpr(
/*ASTContext=*/C,
@@ -271,10 +270,10 @@ create_call_once_funcptr_call(ASTContext
/*SourceLocation=*/SourceLocation());
}
-static CallExpr *
-create_call_once_lambda_call(ASTContext &C, ASTMaker M,
- const ParmVarDecl *Callback, QualType CallbackType,
- SmallVectorImpl<Expr *> &CallArgs) {
+static CallExpr *create_call_once_lambda_call(ASTContext &C, ASTMaker M,
+ const ParmVarDecl *Callback,
+ QualType CallbackType,
+ ArrayRef<Expr *> CallArgs) {
CXXRecordDecl *CallbackDecl = CallbackType->getAsCXXRecordDecl();
@@ -293,12 +292,6 @@ create_call_once_lambda_call(ASTContext
/* T = */ callOperatorDecl->getType(),
/* VK = */ VK_LValue);
- CallArgs.insert(
- CallArgs.begin(),
- M.makeDeclRefExpr(Callback,
- /* RefersToEnclosingVariableOrCapture= */ true,
- /* GetNonReferenceType= */ true));
-
return new (C)
CXXOperatorCallExpr(/*AstContext=*/C, OO_Call, callOperatorDeclRef,
/*args=*/CallArgs,
@@ -335,15 +328,24 @@ static Stmt *create_call_once(ASTContext
const ParmVarDecl *Callback = D->getParamDecl(1);
QualType CallbackType = Callback->getType().getNonReferenceType();
+ bool isLambdaCall = CallbackType->getAsCXXRecordDecl() &&
+ CallbackType->getAsCXXRecordDecl()->isLambda();
+
SmallVector<Expr *, 5> CallArgs;
+ if (isLambdaCall)
+ // Lambda requires callback itself inserted as a first parameter.
+ CallArgs.push_back(
+ M.makeDeclRefExpr(Callback,
+ /* RefersToEnclosingVariableOrCapture= */ true,
+ /* GetNonReferenceType= */ true));
+
// All arguments past first two ones are passed to the callback.
for (unsigned int i = 2; i < D->getNumParams(); i++)
CallArgs.push_back(M.makeLvalueToRvalue(D->getParamDecl(i)));
CallExpr *CallbackCall;
- if (CallbackType->getAsCXXRecordDecl() &&
- CallbackType->getAsCXXRecordDecl()->isLambda()) {
+ if (isLambdaCall) {
CallbackCall =
create_call_once_lambda_call(C, M, Callback, CallbackType, CallArgs);
More information about the cfe-commits
mailing list