[PATCH] D54488: [AST] [analyzer] NFC: Reuse code in stable ID dumping methods.

2018-12-03 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348199: [AST] [analyzer] NFC: Reuse code in stable ID 
dumping methods. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D54488?vs=173900=176479#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54488/new/

https://reviews.llvm.org/D54488

Files:
  cfe/trunk/lib/AST/DeclBase.cpp
  cfe/trunk/lib/AST/DeclCXX.cpp
  cfe/trunk/lib/AST/Stmt.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -70,10 +70,7 @@
 }
 
 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 ,
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
@@ -284,10 +284,7 @@
 }
 
 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 {
Index: cfe/trunk/lib/AST/DeclCXX.cpp
===
--- cfe/trunk/lib/AST/DeclCXX.cpp
+++ cfe/trunk/lib/AST/DeclCXX.cpp
@@ -2247,11 +2247,8 @@
   IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {}
 
 int64_t CXXCtorInitializer::getID(const ASTContext ) 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 {
Index: cfe/trunk/lib/AST/DeclBase.cpp
===
--- cfe/trunk/lib/AST/DeclBase.cpp
+++ cfe/trunk/lib/AST/DeclBase.cpp
@@ -955,10 +955,7 @@
 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 {
Index: cfe/trunk/lib/AST/Stmt.cpp
===
--- cfe/trunk/lib/AST/Stmt.cpp
+++ cfe/trunk/lib/AST/Stmt.cpp
@@ -303,10 +303,7 @@
 }
 
 int64_t Stmt::getID(const ASTContext ) 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,


Index: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -70,10 +70,7 @@
 }
 
 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 ,
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
@@ -284,10 +284,7 @@
 }
 
 int64_t ExplodedNode::getID(ExplodedGraph *G) const {
-  Optional Out = G->getAllocator().identifyObject(this);
-  assert(Out && 

[PATCH] D54488: [AST] [analyzer] NFC: Reuse code in stable ID dumping methods.

2018-11-13 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: george.karpenkov, rsmith.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.

Use the new fancy method introduced in https://reviews.llvm.org/D54486 to 
simplify some code.


Repository:
  rC Clang

https://reviews.llvm.org/D54488

Files:
  lib/AST/DeclBase.cpp
  lib/AST/DeclCXX.cpp
  lib/AST/Stmt.cpp
  lib/StaticAnalyzer/Core/ExplodedGraph.cpp
  lib/StaticAnalyzer/Core/ProgramState.cpp


Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -70,10 +70,7 @@
 }
 
 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 ,
Index: lib/StaticAnalyzer/Core/ExplodedGraph.cpp
===
--- lib/StaticAnalyzer/Core/ExplodedGraph.cpp
+++ lib/StaticAnalyzer/Core/ExplodedGraph.cpp
@@ -284,10 +284,7 @@
 }
 
 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 {
Index: lib/AST/Stmt.cpp
===
--- lib/AST/Stmt.cpp
+++ lib/AST/Stmt.cpp
@@ -303,10 +303,7 @@
 }
 
 int64_t Stmt::getID(const ASTContext ) 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,
Index: lib/AST/DeclCXX.cpp
===
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -2247,11 +2247,8 @@
   IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {}
 
 int64_t CXXCtorInitializer::getID(const ASTContext ) 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 {
Index: lib/AST/DeclBase.cpp
===
--- lib/AST/DeclBase.cpp
+++ lib/AST/DeclBase.cpp
@@ -955,10 +955,7 @@
 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 {


Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -70,10 +70,7 @@
 }
 
 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 ,
Index: lib/StaticAnalyzer/Core/ExplodedGraph.cpp
===
--- lib/StaticAnalyzer/Core/ExplodedGraph.cpp
+++ lib/StaticAnalyzer/Core/ExplodedGraph.cpp
@@ -284,10 +284,7 @@
 }
 
 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 {
Index: lib/AST/Stmt.cpp
===
---