Author: george.karpenkov Date: Fri Sep 14 19:03:58 2018 New Revision: 342315
URL: http://llvm.org/viewvc/llvm-project?rev=342315&view=rev Log: Generate unique identifiers for Decl objects The generated identifier is stable across multiple runs, and can be a great visualization or debugging aide. Differential Revision: https://reviews.llvm.org/D52113 Modified: cfe/trunk/include/clang/AST/DeclBase.h cfe/trunk/lib/AST/DeclBase.cpp Modified: cfe/trunk/include/clang/AST/DeclBase.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=342315&r1=342314&r2=342315&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/DeclBase.h (original) +++ cfe/trunk/include/clang/AST/DeclBase.h Fri Sep 14 19:03:58 2018 @@ -1141,6 +1141,9 @@ public: void dump(raw_ostream &Out, bool Deserialize = false) const; + /// \return Unique reproducible object identifier + int64_t getID() const; + /// Looks through the Decl's underlying type to extract a FunctionType /// when possible. Will return null if the type underlying the Decl does not /// have a FunctionType. Modified: cfe/trunk/lib/AST/DeclBase.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=342315&r1=342314&r2=342315&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclBase.cpp (original) +++ cfe/trunk/lib/AST/DeclBase.cpp Fri Sep 14 19:03:58 2018 @@ -930,6 +930,13 @@ bool Decl::AccessDeclContextSanity() con 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<int64_t> Out = getASTContext().getAllocator().identifyObject(this); + assert(Out && "Wrong allocator used"); + assert(*Out % alignof(Decl) == 0 && "Wrong alignment information"); + return *Out / alignof(Decl); +} + const FunctionType *Decl::getFunctionType(bool BlocksToo) const { QualType Ty; if (const auto *D = dyn_cast<ValueDecl>(this)) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits