Commit 3011de5d by Ben Clayton

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: 's avatarAntonio Maiorano <amaiorano@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent 8cbee410
...@@ -150,6 +150,8 @@ struct Object ...@@ -150,6 +150,8 @@ struct Object
// kindof() returns true iff kind is of this type, or any type deriving from // kindof() returns true iff kind is of this type, or any type deriving from
// this type. // this type.
static constexpr bool kindof(Object::Kind kind) { return true; } static constexpr bool kindof(Object::Kind kind) { return true; }
virtual ~Object() = default;
}; };
// cstr() returns the c-string name of the given Object::Kind. // cstr() returns the c-string name of the given Object::Kind.
...@@ -704,8 +706,8 @@ struct SpirvShader::Impl::Debugger ...@@ -704,8 +706,8 @@ struct SpirvShader::Impl::Debugger
private: private:
// add() registers the debug object with the given id. // add() registers the debug object with the given id.
template<typename ID, typename T> template<typename ID>
void add(ID id, T *); void add(ID id, std::unique_ptr<debug::Object> &&);
// addNone() registers given id as a None value or type. // addNone() registers given id as a None value or type.
void addNone(debug::Object::ID id); void addNone(debug::Object::ID id);
...@@ -1143,7 +1145,7 @@ void SpirvShader::Impl::Debugger::defineOrEmit(InsnIterator insn, Pass pass, F & ...@@ -1143,7 +1145,7 @@ void SpirvShader::Impl::Debugger::defineOrEmit(InsnIterator insn, Pass pass, F &
switch(pass) switch(pass)
{ {
case Pass::Define: case Pass::Define:
add(id, new T()); add(id, std::unique_ptr<debug::Object>(new T()));
break; break;
case Pass::Emit: case Pass::Emit:
emit(get<T>(id)); emit(get<T>(id));
...@@ -1437,11 +1439,11 @@ void SpirvShader::Impl::Debugger::setLocation(EmitState *state, const std::strin ...@@ -1437,11 +1439,11 @@ void SpirvShader::Impl::Debugger::setLocation(EmitState *state, const std::strin
} }
} }
template<typename ID, typename T> template<typename ID>
void SpirvShader::Impl::Debugger::add(ID id, T *obj) void SpirvShader::Impl::Debugger::add(ID id, std::unique_ptr<debug::Object> &&obj)
{ {
ASSERT_MSG(obj != nullptr, "add() called with nullptr 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()); ASSERT_MSG(added, "Debug object with %d already exists", id.value());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment