summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/AST/Decl.h11
-rw-r--r--clang/lib/Sema/SemaDecl.cpp7
-rw-r--r--clang/lib/Sema/SemaLookup.cpp4
3 files changed, 15 insertions, 7 deletions
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 97081ee6b9a..db13e259790 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1780,6 +1780,17 @@ public:
return isDefined(Definition);
}
+ /// \brief Get the definition for this declaration.
+ FunctionDecl *getDefinition() {
+ const FunctionDecl *Definition;
+ if (isDefined(Definition))
+ return const_cast<FunctionDecl *>(Definition);
+ return nullptr;
+ }
+ const FunctionDecl *getDefinition() const {
+ return const_cast<FunctionDecl *>(this)->getDefinition();
+ }
+
/// getBody - Retrieve the body (definition) of the function. The
/// function body might be in any of the (re-)declarations of this
/// function. The variant that accepts a FunctionDecl pointer will
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6f7a13d6322..c0ccbbf6241 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2327,11 +2327,8 @@ static const Decl *getDefinition(const Decl *D) {
return Def;
return VD->getActingDefinition();
}
- if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
- const FunctionDecl* Def;
- if (FD->isDefined(Def))
- return Def;
- }
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+ return FD->getDefinition();
return nullptr;
}
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 9160a3f6741..e2550824fb6 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -4936,8 +4936,8 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction,
static NamedDecl *getDefinitionToImport(NamedDecl *D) {
if (VarDecl *VD = dyn_cast<VarDecl>(D))
return VD->getDefinition();
- if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
- return FD->isDefined(FD) ? const_cast<FunctionDecl*>(FD) : nullptr;
+ if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+ return FD->getDefinition();
if (TagDecl *TD = dyn_cast<TagDecl>(D))
return TD->getDefinition();
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
OpenPOWER on IntegriCloud