summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Karpenkov <ekarpenkov@apple.com>2017-11-01 01:36:01 +0000
committerGeorge Karpenkov <ekarpenkov@apple.com>2017-11-01 01:36:01 +0000
commiteb1c10e34de92b9ee0d0ccfbef13a231187eda3d (patch)
tree52e5ca61abab91653b7c1f611de547afbc7a9536
parent8ac52b01ceb1331c1642ac52b93229d038bf8df1 (diff)
[Analyzer] Use value storage for BodyFarm
Differential Revision: https://reviews.llvm.org/D39428 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317065 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Analysis/AnalysisDeclContext.h8
-rw-r--r--include/clang/Analysis/BodyFarm.h3
-rw-r--r--lib/Analysis/AnalysisDeclContext.cpp13
3 files changed, 12 insertions, 12 deletions
diff --git a/include/clang/Analysis/AnalysisDeclContext.h b/include/clang/Analysis/AnalysisDeclContext.h
index ecd99f8054..39f6a8df7b 100644
--- a/include/clang/Analysis/AnalysisDeclContext.h
+++ b/include/clang/Analysis/AnalysisDeclContext.h
@@ -419,9 +419,9 @@ class AnalysisDeclContextManager {
/// declarations from external source.
std::unique_ptr<CodeInjector> Injector;
- /// Pointer to a factory for creating and caching implementations for common
+ /// A factory for creating and caching implementations for common
/// methods during the analysis.
- std::unique_ptr<BodyFarm> FunctionBodyFarm;
+ BodyFarm FunctionBodyFarm;
/// Flag to indicate whether or not bodies should be synthesized
/// for well-known functions.
@@ -475,8 +475,8 @@ public:
return LocContexts.getStackFrame(getContext(D), Parent, S, Blk, Idx);
}
- /// Get and lazily create a {@code BodyFarm} instance.
- BodyFarm *getBodyFarm();
+ /// Get a reference to {@code BodyFarm} instance.
+ BodyFarm &getBodyFarm();
/// Discard all previously created AnalysisDeclContexts.
void clear();
diff --git a/include/clang/Analysis/BodyFarm.h b/include/clang/Analysis/BodyFarm.h
index 14cf2624b8..ff0859bc66 100644
--- a/include/clang/Analysis/BodyFarm.h
+++ b/include/clang/Analysis/BodyFarm.h
@@ -39,6 +39,9 @@ public:
/// Factory method for creating bodies for Objective-C properties.
Stmt *getBody(const ObjCMethodDecl *D);
+ /// Remove copy constructor to avoid accidental copying.
+ BodyFarm(const BodyFarm &other) = delete;
+
private:
typedef llvm::DenseMap<const Decl *, Optional<Stmt *>> BodyMap;
diff --git a/lib/Analysis/AnalysisDeclContext.cpp b/lib/Analysis/AnalysisDeclContext.cpp
index c7c720eb77..f54e7c1654 100644
--- a/lib/Analysis/AnalysisDeclContext.cpp
+++ b/lib/Analysis/AnalysisDeclContext.cpp
@@ -68,7 +68,8 @@ AnalysisDeclContextManager::AnalysisDeclContextManager(
bool addInitializers, bool addTemporaryDtors, bool addLifetime,
bool addLoopExit, bool synthesizeBodies, bool addStaticInitBranch,
bool addCXXNewAllocator, CodeInjector *injector)
- : ASTCtx(ASTCtx), Injector(injector), SynthesizeBodies(synthesizeBodies) {
+ : ASTCtx(ASTCtx), Injector(injector), FunctionBodyFarm(ASTCtx, injector),
+ SynthesizeBodies(synthesizeBodies) {
cfgBuildOptions.PruneTriviallyFalseEdges = !useUnoptimizedCFG;
cfgBuildOptions.AddImplicitDtors = addImplicitDtors;
cfgBuildOptions.AddInitializers = addInitializers;
@@ -88,7 +89,7 @@ Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const {
if (auto *CoroBody = dyn_cast_or_null<CoroutineBodyStmt>(Body))
Body = CoroBody->getBody();
if (Manager && Manager->synthesizeBodies()) {
- Stmt *SynthesizedBody = Manager->getBodyFarm()->getBody(FD);
+ Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(FD);
if (SynthesizedBody) {
Body = SynthesizedBody;
IsAutosynthesized = true;
@@ -99,7 +100,7 @@ Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const {
else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
Stmt *Body = MD->getBody();
if (Manager && Manager->synthesizeBodies()) {
- Stmt *SynthesizedBody = Manager->getBodyFarm()->getBody(MD);
+ Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(MD);
if (SynthesizedBody) {
Body = SynthesizedBody;
IsAutosynthesized = true;
@@ -304,11 +305,7 @@ AnalysisDeclContext *AnalysisDeclContextManager::getContext(const Decl *D) {
return AC.get();
}
-BodyFarm *AnalysisDeclContextManager::getBodyFarm() {
- if (!FunctionBodyFarm)
- FunctionBodyFarm = llvm::make_unique<BodyFarm>(ASTCtx, Injector.get());
- return FunctionBodyFarm.get();
-}
+BodyFarm &AnalysisDeclContextManager::getBodyFarm() { return FunctionBodyFarm; }
const StackFrameContext *
AnalysisDeclContext::getStackFrame(LocationContext const *Parent, const Stmt *S,