From a55b8668b2a69a7d1510aec244cb826eea7065e3 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Mon, 3 Dec 2018 22:19:05 +0000 Subject: [PATCH] [AST] [analyzer] NFC: Reuse code in stable ID dumping methods. Use the new fancy method introduced in r348197 to simplify some code. Differential Revision: https://reviews.llvm.org/D54488 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348199 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclBase.cpp | 5 +---- lib/AST/DeclCXX.cpp | 7 ++----- lib/AST/Stmt.cpp | 5 +---- lib/StaticAnalyzer/Core/ExplodedGraph.cpp | 5 +---- lib/StaticAnalyzer/Core/ProgramState.cpp | 5 +---- 5 files changed, 6 insertions(+), 21 deletions(-) diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index f65d3063e3..95babf7917 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -955,10 +955,7 @@ static Decl::Kind getKind(const Decl *D) { return D->getKind(); } static Decl::Kind getKind(const DeclContext *DC) { return DC->getDeclKind(); } int64_t Decl::getID() const { - Optional Out = getASTContext().getAllocator().identifyObject(this); - assert(Out && "Wrong allocator used"); - assert(*Out % alignof(Decl) == 0 && "Wrong alignment information"); - return *Out / alignof(Decl); + return getASTContext().getAllocator().identifyKnownAlignedObject(this); } const FunctionType *Decl::getFunctionType(bool BlocksToo) const { diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 81ee48c182..419326ae90 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -2247,11 +2247,8 @@ CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {} int64_t CXXCtorInitializer::getID(const ASTContext &Context) const { - Optional Out = Context.getAllocator().identifyObject(this); - assert(Out && "Wrong allocator used"); - assert(*Out % alignof(CXXCtorInitializer) == 0 && - "Wrong alignment information"); - return *Out / alignof(CXXCtorInitializer); + return Context.getAllocator() + .identifyKnownAlignedObject(this); } TypeLoc CXXCtorInitializer::getBaseClassLoc() const { diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 901df9ca75..32330ea3bf 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -303,10 +303,7 @@ SourceLocation Stmt::getEndLoc() const { } int64_t Stmt::getID(const ASTContext &Context) const { - Optional Out = Context.getAllocator().identifyObject(this); - assert(Out && "Wrong allocator used"); - assert(*Out % alignof(Stmt) == 0 && "Wrong alignment information"); - return *Out / alignof(Stmt); + return Context.getAllocator().identifyKnownAlignedObject(this); } CompoundStmt::CompoundStmt(ArrayRef Stmts, SourceLocation LB, diff --git a/lib/StaticAnalyzer/Core/ExplodedGraph.cpp b/lib/StaticAnalyzer/Core/ExplodedGraph.cpp index d76710004c..d6bcbb96b5 100644 --- a/lib/StaticAnalyzer/Core/ExplodedGraph.cpp +++ b/lib/StaticAnalyzer/Core/ExplodedGraph.cpp @@ -284,10 +284,7 @@ ExplodedNode * const *ExplodedNode::NodeGroup::end() const { } int64_t ExplodedNode::getID(ExplodedGraph *G) const { - Optional Out = G->getAllocator().identifyObject(this); - assert(Out && "Wrong allocator used"); - assert(*Out % alignof(ExplodedNode) == 0 && "Wrong alignment information"); - return *Out / alignof(ExplodedNode); + return G->getAllocator().identifyKnownAlignedObject(this); } bool ExplodedNode::isTrivial() const { diff --git a/lib/StaticAnalyzer/Core/ProgramState.cpp b/lib/StaticAnalyzer/Core/ProgramState.cpp index 399cf18302..ceb4fbdf78 100644 --- a/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -70,10 +70,7 @@ ProgramState::~ProgramState() { } int64_t ProgramState::getID() const { - Optional Out = getStateManager().Alloc.identifyObject(this); - assert(Out && "Wrong allocator used"); - assert(*Out % alignof(ProgramState) == 0 && "Wrong alignment information"); - return *Out / alignof(ProgramState); + return getStateManager().Alloc.identifyKnownAlignedObject(this); } ProgramStateManager::ProgramStateManager(ASTContext &Ctx, -- 2.40.0