SpirvShaderDebugger: Add a virtual destructor to debug::Object. This used to be unnecessary as the debug objects used to contain POD, but we now also have std::string and std::vector fields in these objects, and we need them to destruct. Bug: b/148401179 Change-Id: I28637f645a96e3e895e7ae5f3028eb7872c92dd3 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/45608 Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Tested-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Pipeline/SpirvShaderDebugger.cpp b/src/Pipeline/SpirvShaderDebugger.cpp index a93a1a3..021c240 100644 --- a/src/Pipeline/SpirvShaderDebugger.cpp +++ b/src/Pipeline/SpirvShaderDebugger.cpp
@@ -150,6 +150,8 @@ // kindof() returns true iff kind is of this type, or any type deriving from // this type. static constexpr bool kindof(Object::Kind kind) { return true; } + + virtual ~Object() = default; }; // cstr() returns the c-string name of the given Object::Kind. @@ -704,8 +706,8 @@ private: // add() registers the debug object with the given id. - template<typename ID, typename T> - void add(ID id, T *); + template<typename ID> + void add(ID id, std::unique_ptr<debug::Object> &&); // addNone() registers given id as a None value or type. void addNone(debug::Object::ID id); @@ -1143,7 +1145,7 @@ switch(pass) { case Pass::Define: - add(id, new T()); + add(id, std::unique_ptr<debug::Object>(new T())); break; case Pass::Emit: emit(get<T>(id)); @@ -1437,11 +1439,11 @@ } } -template<typename ID, typename T> -void SpirvShader::Impl::Debugger::add(ID id, T *obj) +template<typename ID> +void SpirvShader::Impl::Debugger::add(ID id, std::unique_ptr<debug::Object> &&obj) { ASSERT_MSG(obj != nullptr, "add() called with nullptr obj"); - bool added = objects.emplace(debug::Object::ID(id.value()), obj).second; + bool added = objects.emplace(debug::Object::ID(id.value()), std::move(obj)).second; ASSERT_MSG(added, "Debug object with %d already exists", id.value()); }