From b841963b254e38f199316604e9afbf74094c65c3 Mon Sep 17 00:00:00 2001 From: Adrian McCarthy Date: Thu, 22 Jun 2017 18:42:23 +0000 Subject: [PATCH] Make IPDBSession::getGlobalScope a non-const method 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306041 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/PDB/DIA/DIASession.h | 2 +- include/llvm/DebugInfo/PDB/IPDBSession.h | 2 +- include/llvm/DebugInfo/PDB/Native/NativeSession.h | 2 +- lib/DebugInfo/PDB/DIA/DIASession.cpp | 2 +- lib/DebugInfo/PDB/Native/NativeSession.cpp | 7 +++---- unittests/DebugInfo/PDB/PDBApiTest.cpp | 4 +--- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/llvm/DebugInfo/PDB/DIA/DIASession.h b/include/llvm/DebugInfo/PDB/DIA/DIASession.h index 3f5818631e7..350442556be 100644 --- a/include/llvm/DebugInfo/PDB/DIA/DIASession.h +++ b/include/llvm/DebugInfo/PDB/DIA/DIASession.h @@ -31,7 +31,7 @@ public: uint64_t getLoadAddress() const override; void setLoadAddress(uint64_t Address) override; - std::unique_ptr getGlobalScope() const override; + std::unique_ptr getGlobalScope() override; std::unique_ptr getSymbolById(uint32_t SymbolId) const override; std::unique_ptr diff --git a/include/llvm/DebugInfo/PDB/IPDBSession.h b/include/llvm/DebugInfo/PDB/IPDBSession.h index 85d9fe12485..cf195095c8d 100644 --- a/include/llvm/DebugInfo/PDB/IPDBSession.h +++ b/include/llvm/DebugInfo/PDB/IPDBSession.h @@ -29,7 +29,7 @@ public: virtual uint64_t getLoadAddress() const = 0; virtual void setLoadAddress(uint64_t Address) = 0; - virtual std::unique_ptr getGlobalScope() const = 0; + virtual std::unique_ptr getGlobalScope() = 0; virtual std::unique_ptr getSymbolById(uint32_t SymbolId) const = 0; template diff --git a/include/llvm/DebugInfo/PDB/Native/NativeSession.h b/include/llvm/DebugInfo/PDB/Native/NativeSession.h index e6da266f796..bbe207738e0 100644 --- a/include/llvm/DebugInfo/PDB/Native/NativeSession.h +++ b/include/llvm/DebugInfo/PDB/Native/NativeSession.h @@ -32,7 +32,7 @@ public: uint64_t getLoadAddress() const override; void setLoadAddress(uint64_t Address) override; - std::unique_ptr getGlobalScope() const override; + std::unique_ptr getGlobalScope() override; std::unique_ptr getSymbolById(uint32_t SymbolId) const override; std::unique_ptr diff --git a/lib/DebugInfo/PDB/DIA/DIASession.cpp b/lib/DebugInfo/PDB/DIA/DIASession.cpp index ef47b92b4f2..ef9390cda31 100644 --- a/lib/DebugInfo/PDB/DIA/DIASession.cpp +++ b/lib/DebugInfo/PDB/DIA/DIASession.cpp @@ -151,7 +151,7 @@ void DIASession::setLoadAddress(uint64_t Address) { Session->put_loadAddress(Address); } -std::unique_ptr DIASession::getGlobalScope() const { +std::unique_ptr DIASession::getGlobalScope() { CComPtr GlobalScope; if (S_OK != Session->get_globalScope(&GlobalScope)) return nullptr; diff --git a/lib/DebugInfo/PDB/Native/NativeSession.cpp b/lib/DebugInfo/PDB/Native/NativeSession.cpp index 7e6843bceb7..c59cf866d1c 100644 --- a/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -70,12 +70,11 @@ uint64_t NativeSession::getLoadAddress() const { return 0; } void NativeSession::setLoadAddress(uint64_t Address) {} -std::unique_ptr NativeSession::getGlobalScope() const { - auto RawSymbol = - llvm::make_unique(const_cast(*this)); +std::unique_ptr NativeSession::getGlobalScope() { + auto RawSymbol = llvm::make_unique(*this); auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol))); std::unique_ptr ExeSymbol( - static_cast(PdbSymbol.release())); + static_cast(PdbSymbol.release())); return ExeSymbol; } diff --git a/unittests/DebugInfo/PDB/PDBApiTest.cpp b/unittests/DebugInfo/PDB/PDBApiTest.cpp index 6afe83cd90d..257a8879e43 100644 --- a/unittests/DebugInfo/PDB/PDBApiTest.cpp +++ b/unittests/DebugInfo/PDB/PDBApiTest.cpp @@ -63,9 +63,7 @@ namespace { class MockSession : public IPDBSession { uint64_t getLoadAddress() const override { return 0; } void setLoadAddress(uint64_t Address) override {} - std::unique_ptr getGlobalScope() const override { - return nullptr; - } + std::unique_ptr getGlobalScope() override { return nullptr; } std::unique_ptr getSymbolById(uint32_t SymbolId) const override { return nullptr; } -- 2.11.0