SpirvShader: Implement OpenCLDebugInfo100DebugInfoNone

Acts as a placeholder for no-debug-info. Implemented as nullptr.

Bug: b/148401179
Change-Id: I6cbfb227296d98befa6a7d2baa29128cb0c7bd29
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42193
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Pipeline/SpirvShaderDebugger.cpp b/src/Pipeline/SpirvShaderDebugger.cpp
index 0648922..08f4c05 100644
--- a/src/Pipeline/SpirvShaderDebugger.cpp
+++ b/src/Pipeline/SpirvShaderDebugger.cpp
@@ -153,12 +153,14 @@
 template<typename TO, typename FROM>
 TO *cast(FROM *obj)
 {
+	if(obj == nullptr) { return nullptr; }  // None
 	return (TO::kindof(obj->kind)) ? static_cast<TO *>(obj) : nullptr;
 }
 
 template<typename TO, typename FROM>
 const TO *cast(const FROM *obj)
 {
+	if(obj == nullptr) { return nullptr; }  // None
 	return (TO::kindof(obj->kind)) ? static_cast<const TO *>(obj) : nullptr;
 }
 
@@ -419,8 +421,12 @@
 	template<typename ID, typename T>
 	void add(ID id, T *);
 
+	// addNone() registers given id as a None value or type.
+	void addNone(debug::Object::ID id);
+
 	// get() returns the debug object with the given id.
 	// The object must exist and be of type (or derive from type) T.
+	// A returned nullptr represents a None value or type.
 	template<typename T>
 	T *get(SpirvID<T> id) const;
 
@@ -797,6 +803,12 @@
 	auto extInstIndex = insn.word(4);
 	switch(extInstIndex)
 	{
+		case OpenCLDebugInfo100DebugInfoNone:
+			if(pass == Pass::Define)
+			{
+				addNone(debug::Object::ID(insn.word(2)));
+			}
+			break;
 		case OpenCLDebugInfo100DebugCompilationUnit:
 			defineOrEmit(insn, pass, [&](debug::CompilationUnit *cu) {
 				cu->source = get(debug::Source::ID(insn.word(7)));
@@ -977,7 +989,6 @@
 			});
 			break;
 
-		case OpenCLDebugInfo100DebugInfoNone:
 		case OpenCLDebugInfo100DebugTypePointer:
 		case OpenCLDebugInfo100DebugTypeQualifier:
 		case OpenCLDebugInfo100DebugTypeArray:
@@ -1016,7 +1027,14 @@
 template<typename ID, typename T>
 void SpirvShader::Impl::Debugger::add(ID id, T *obj)
 {
-	auto added = objects.emplace(debug::Object::ID(id.value()), obj).second;
+	ASSERT_MSG(obj != nullptr, "add() called with nullptr obj");
+	bool added = objects.emplace(debug::Object::ID(id.value()), obj).second;
+	ASSERT_MSG(added, "Debug object with %d already exists", id.value());
+}
+
+void SpirvShader::Impl::Debugger::addNone(debug::Object::ID id)
+{
+	bool added = objects.emplace(debug::Object::ID(id.value()), nullptr).second;
 	ASSERT_MSG(added, "Debug object with %d already exists", id.value());
 }