[PATCH] D34468: Make IPDBSession::getGlobalScope a non-const method

Adrian McCarthy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 21 11:46:21 PDT 2017


amccarth created this revision.
Herald added a subscriber: hiraditya.

There doesn't seem to be a compelling reason why this method should be const other than it was possible with the DIA implementation.  The native session is going to act as a symbol factory and cache.  This could be acheived with mutable (and the existing const_cast), but it seems cleaner to accept that this method affects the state of the session.

This change eliminates an existing const_cast.


https://reviews.llvm.org/D34468

Files:
  llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h
  llvm/include/llvm/DebugInfo/PDB/IPDBSession.h
  llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h
  llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
  llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp


Index: llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp
===================================================================
--- llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp
+++ llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp
@@ -63,9 +63,7 @@
 class MockSession : public IPDBSession {
   uint64_t getLoadAddress() const override { return 0; }
   void setLoadAddress(uint64_t Address) override {}
-  std::unique_ptr<PDBSymbolExe> getGlobalScope() const override {
-    return nullptr;
-  }
+  std::unique_ptr<PDBSymbolExe> getGlobalScope() override { return nullptr; }
   std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override {
     return nullptr;
   }
Index: llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
===================================================================
--- llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
+++ llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
@@ -70,12 +70,11 @@
 
 void NativeSession::setLoadAddress(uint64_t Address) {}
 
-std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() const {
-  auto RawSymbol =
-      llvm::make_unique<NativeExeSymbol>(const_cast<NativeSession &>(*this));
+std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() {
+  auto RawSymbol = llvm::make_unique<NativeExeSymbol>(*this);
   auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol)));
   std::unique_ptr<PDBSymbolExe> ExeSymbol(
-    static_cast<PDBSymbolExe *>(PdbSymbol.release()));
+      static_cast<PDBSymbolExe *>(PdbSymbol.release()));
   return ExeSymbol;
 }
 
Index: llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp
===================================================================
--- llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp
+++ llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp
@@ -151,7 +151,7 @@
   Session->put_loadAddress(Address);
 }
 
-std::unique_ptr<PDBSymbolExe> DIASession::getGlobalScope() const {
+std::unique_ptr<PDBSymbolExe> DIASession::getGlobalScope() {
   CComPtr<IDiaSymbol> GlobalScope;
   if (S_OK != Session->get_globalScope(&GlobalScope))
     return nullptr;
Index: llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h
===================================================================
--- llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h
+++ llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h
@@ -32,7 +32,7 @@
 
   uint64_t getLoadAddress() const override;
   void setLoadAddress(uint64_t Address) override;
-  std::unique_ptr<PDBSymbolExe> getGlobalScope() const override;
+  std::unique_ptr<PDBSymbolExe> getGlobalScope() override;
   std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override;
 
   std::unique_ptr<PDBSymbol>
Index: llvm/include/llvm/DebugInfo/PDB/IPDBSession.h
===================================================================
--- llvm/include/llvm/DebugInfo/PDB/IPDBSession.h
+++ llvm/include/llvm/DebugInfo/PDB/IPDBSession.h
@@ -29,7 +29,7 @@
 
   virtual uint64_t getLoadAddress() const = 0;
   virtual void setLoadAddress(uint64_t Address) = 0;
-  virtual std::unique_ptr<PDBSymbolExe> getGlobalScope() const = 0;
+  virtual std::unique_ptr<PDBSymbolExe> getGlobalScope() = 0;
   virtual std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const = 0;
 
   template <typename T>
Index: llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h
===================================================================
--- llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h
+++ llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h
@@ -31,7 +31,7 @@
 
   uint64_t getLoadAddress() const override;
   void setLoadAddress(uint64_t Address) override;
-  std::unique_ptr<PDBSymbolExe> getGlobalScope() const override;
+  std::unique_ptr<PDBSymbolExe> getGlobalScope() override;
   std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override;
 
   std::unique_ptr<PDBSymbol>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34468.103431.patch
Type: text/x-patch
Size: 3803 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170621/aedfef37/attachment.bin>


More information about the llvm-commits mailing list