Refactor code into a new CallExpr::getDirectCallee() method. Simplify some
code with the new method.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76164 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 63a6d31..320a4f1 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -224,6 +224,16 @@
C.Deallocate(this);
}
+FunctionDecl *CallExpr::getDirectCallee() {
+ Expr *CEE = getCallee()->IgnoreParenCasts();
+ if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) {
+ // FIXME: We can follow objective-c methods and C++ member functions...
+ return dyn_cast<FunctionDecl>(DRE->getDecl());
+ }
+
+ return 0;
+}
+
/// setNumArgs - This changes the number of arguments present in this call.
/// Any orphaned expressions are deleted by this, and any new operands are set
/// to null.
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp
index 884bc17..02fe22c 100644
--- a/lib/Analysis/CFG.cpp
+++ b/lib/Analysis/CFG.cpp
@@ -475,14 +475,9 @@
case Stmt::CallExprClass: {
bool NoReturn = false;
CallExpr *C = cast<CallExpr>(Terminator);
- Expr *CEE = C->getCallee()->IgnoreParenCasts();
- if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) {
- // FIXME: We can follow objective-c methods and C++ member functions...
- if (FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
- if (FD->hasAttr<NoReturnAttr>())
- NoReturn = true;
- }
- }
+ if (FunctionDecl *FD = C->getDirectCallee())
+ if (FD->hasAttr<NoReturnAttr>())
+ NoReturn = true;
if (!NoReturn)
break;
diff --git a/lib/Analysis/CallGraph.cpp b/lib/Analysis/CallGraph.cpp
index 16f14d7..d49e8ec 100644
--- a/lib/Analysis/CallGraph.cpp
+++ b/lib/Analysis/CallGraph.cpp
@@ -66,21 +66,10 @@
}
void CGBuilder::VisitCallExpr(CallExpr *CE) {
- Expr *Callee = CE->getCallee();
-
- if (CastExpr *CE = dyn_cast<CastExpr>(Callee))
- Callee = CE->getSubExpr();
-
- if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
- Decl *D = DRE->getDecl();
- if (FunctionDecl *CalleeDecl = dyn_cast<FunctionDecl>(D)) {
-
- Entity *Ent = Entity::get(CalleeDecl, G.getProgram());
-
- CallGraphNode *CalleeNode = G.getOrInsertFunction(Ent);
-
- CallerNode->addCallee(ASTLocation(FD, CE), CalleeNode);
- }
+ if (FunctionDecl *CalleeDecl = CE->getDirectCallee()) {
+ Entity *Ent = Entity::get(CalleeDecl, G.getProgram());
+ CallGraphNode *CalleeNode = G.getOrInsertFunction(Ent);
+ CallerNode->addCallee(ASTLocation(FD, CE), CalleeNode);
}
}