Make Vk::Stringify return std::string

We want Vk::Stringify to return the numeric value passed to it when it's
in release mode or when it fails to find the matching string. However,
we can't do that if we return a char* because the char* will be a
pointer to a point on the stack.

Bug: b/139528538
Change-Id: I1bab741e7e7aceea44c6179b2159f8a55497d3e0
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/38868
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Sean Risser <srisser@google.com>
Presubmit-Ready: Sean Risser <srisser@google.com>
diff --git a/src/Vulkan/VkPipeline.cpp b/src/Vulkan/VkPipeline.cpp
index 9bd188b..5baa9dd 100644
--- a/src/Vulkan/VkPipeline.cpp
+++ b/src/Vulkan/VkPipeline.cpp
@@ -387,7 +387,7 @@
 		}
 		break;
 		default:
-			WARN("pCreateInfo->pRasterizationState->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType));
+			WARN("pCreateInfo->pRasterizationState->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType).c_str());
 			break;
 		}
 
diff --git a/src/Vulkan/VkRenderPass.cpp b/src/Vulkan/VkRenderPass.cpp
index 89632e3..2a360c0 100644
--- a/src/Vulkan/VkRenderPass.cpp
+++ b/src/Vulkan/VkRenderPass.cpp
@@ -77,7 +77,7 @@
 			break;
 		}
 		default:
-			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType));
+			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType).c_str());
 			break;
 		}
 
@@ -221,4 +221,4 @@
 		attachmentViewMasks[attachment] |= viewMasks[subpass];
 }
 
-} // namespace vk
\ No newline at end of file
+} // namespace vk
diff --git a/src/Vulkan/VkStringify.cpp b/src/Vulkan/VkStringify.cpp
index 61ab208..e7ac2d4 100644
--- a/src/Vulkan/VkStringify.cpp
+++ b/src/Vulkan/VkStringify.cpp
@@ -21,7 +21,7 @@
 
 namespace vk {
 
-const char *Stringify(VkStructureType value)
+std::string Stringify(VkStructureType value)
 {
 #ifndef NDEBUG
 	// Since C++ hasn't given us introspection on enums, we can't just "get" an
@@ -459,15 +459,15 @@
 	auto it = strings.find(value);
 	if (it != strings.end())
 	{
-		return it->second;
+		return std::string(it->second);
 	}
 	else
 	{
 		WARN("Stringify(VkStructureType v) is out of date. Please update it to match vulkan/vulkan_core.h");
-		return "";
+		return std::to_string(value);
 	}
 #else // if not debug:
-	return "";
+	return std::to_string(value);
 #endif
 }
 
diff --git a/src/Vulkan/VkStringify.hpp b/src/Vulkan/VkStringify.hpp
index 247310f..4da04df 100644
--- a/src/Vulkan/VkStringify.hpp
+++ b/src/Vulkan/VkStringify.hpp
@@ -22,7 +22,7 @@
 
 namespace vk {
 
-const char *Stringify(VkStructureType value);
+std::string Stringify(VkStructureType value);
 
 }
 
diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp
index edf408d..28ad813 100644
--- a/src/Vulkan/libVulkan.cpp
+++ b/src/Vulkan/libVulkan.cpp
@@ -294,7 +294,7 @@
 			//  Vulkan structures in this Specification."
 			break;
 		default:
-			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(createInfo->sType));
+			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(createInfo->sType).c_str());
 			break;
 		}
 	}
@@ -640,7 +640,7 @@
 			break;
 		default:
 			// "the [driver] must skip over, without processing (other than reading the sType and pNext members) any structures in the chain with sType values not defined by [supported extenions]"
-			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType));
+			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType).c_str());
 			break;
 		}
 
@@ -670,7 +670,7 @@
 		auto extInfo = reinterpret_cast<VkBaseInStructure const*>(queueCreateInfo.pNext);
 		while(extInfo)
 		{
-			WARN("pCreateInfo->pQueueCreateInfos[%d].pNext sType = %s", i, vk::Stringify(extInfo->sType));
+			WARN("pCreateInfo->pQueueCreateInfos[%d].pNext sType = %s", i, vk::Stringify(extInfo->sType).c_str());
 			extInfo = extInfo->pNext;
 		}
 
@@ -832,7 +832,7 @@
 		}
 #endif
 		default:
-			WARN("pAllocateInfo->pNext sType = %s", vk::Stringify(allocationInfo->sType));
+			WARN("pAllocateInfo->pNext sType = %s", vk::Stringify(allocationInfo->sType).c_str());
 			break;
 		}
 
@@ -1034,7 +1034,7 @@
 	auto* nextInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
 	while(nextInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType).c_str());
 		nextInfo = nextInfo->pNext;
 	}
 
@@ -1176,7 +1176,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pCreateInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -1229,7 +1229,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pCreateInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -1266,7 +1266,7 @@
 			// Do nothing. Should be handled by vk::Buffer::Create().
 			break;
 		default:
-			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType));
+			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType).c_str());
 			break;
 		}
 		nextInfo = nextInfo->pNext;
@@ -1296,7 +1296,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pCreateInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -1351,7 +1351,7 @@
 			break;
 		default:
 			// "the [driver] must skip over, without processing (other than reading the sType and pNext members) any structures in the chain with sType values not defined by [supported extenions]"
-			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType));
+			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType).c_str());
 			break;
 		}
 
@@ -1455,7 +1455,7 @@
 		}
 		break;
 		default:
-			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType));
+			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType).c_str());
 			break;
 		}
 
@@ -1486,7 +1486,7 @@
 	auto* nextInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
 	while(nextInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType).c_str());
 		nextInfo = nextInfo->pNext;
 	}
 
@@ -1514,7 +1514,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pCreateInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -1630,7 +1630,7 @@
 	auto* nextInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
 	while(nextInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType).c_str());
 		nextInfo = nextInfo->pNext;
 	}
 
@@ -1669,7 +1669,7 @@
 			}
 			break;
 		default:
-			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType));
+			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType).c_str());
 			break;
 		}
 
@@ -1702,7 +1702,7 @@
 			ASSERT(!vk::Cast(device)->hasExtension(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME));
 			break;
 		default:
-			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType));
+			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType).c_str());
 			break;
 		}
 
@@ -1728,7 +1728,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pCreateInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -1764,7 +1764,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pAllocateInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pAllocateInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pAllocateInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -1803,7 +1803,7 @@
 	auto* nextInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
 	while(nextInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType).c_str());
 		nextInfo = nextInfo->pNext;
 	}
 
@@ -1903,7 +1903,7 @@
 		}
 		break;
 		default:
-			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType));
+			WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extensionCreateInfo->sType).c_str());
 			break;
 		}
 
@@ -1937,7 +1937,7 @@
 	auto* nextInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
 	while(nextInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType).c_str());
 		nextInfo = nextInfo->pNext;
 	}
 
@@ -1968,7 +1968,7 @@
 	auto* nextInfo = reinterpret_cast<const VkBaseInStructure*>(pAllocateInfo->pNext);
 	while(nextInfo)
 	{
-		WARN("pAllocateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType));
+		WARN("pAllocateInfo->pNext sType = %s", vk::Stringify(nextInfo->sType).c_str());
 		nextInfo = nextInfo->pNext;
 	}
 
@@ -1992,7 +1992,7 @@
 	auto* nextInfo = reinterpret_cast<const VkBaseInStructure*>(pBeginInfo->pNext);
 	while(nextInfo)
 	{
-		WARN("pBeginInfo->pNext sType = %s", vk::Stringify(nextInfo->sType));
+		WARN("pBeginInfo->pNext sType = %s", vk::Stringify(nextInfo->sType).c_str());
 		nextInfo = nextInfo->pNext;
 	}
 
@@ -2352,7 +2352,7 @@
 			// SwiftShader only has a single physical device, so this extension does nothing in this case.
 			break;
 		default:
-			WARN("pRenderPassBegin->pNext sType = %s", vk::Stringify(renderPassBeginInfo->sType));
+			WARN("pRenderPassBegin->pNext sType = %s", vk::Stringify(renderPassBeginInfo->sType).c_str());
 			break;
 		}
 
@@ -2404,7 +2404,7 @@
 		auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pBindInfos[i].pNext);
 		while(extInfo)
 		{
-			WARN("pBindInfos[%d].pNext sType = %s", i, vk::Stringify(extInfo->sType));
+			WARN("pBindInfos[%d].pNext sType = %s", i, vk::Stringify(extInfo->sType).c_str());
 			extInfo = extInfo->pNext;
 		}
 
@@ -2462,7 +2462,7 @@
 #endif
 
 			default:
-				WARN("pBindInfos[%d].pNext sType = %s", i, vk::Stringify(extInfo->sType));
+				WARN("pBindInfos[%d].pNext sType = %s", i, vk::Stringify(extInfo->sType).c_str());
 				break;
 			}
 			extInfo = extInfo->pNext;
@@ -2514,7 +2514,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -2530,7 +2530,7 @@
 		}
 		break;
 		default:
-			WARN("pMemoryRequirements->pNext sType = %s", vk::Stringify(extensionRequirements->sType));
+			WARN("pMemoryRequirements->pNext sType = %s", vk::Stringify(extensionRequirements->sType).c_str());
 			break;
 		}
 
@@ -2548,7 +2548,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -2564,7 +2564,7 @@
 			}
 			break;
 		default:
-			WARN("pMemoryRequirements->pNext sType = %s", vk::Stringify(extensionRequirements->sType));
+			WARN("pMemoryRequirements->pNext sType = %s", vk::Stringify(extensionRequirements->sType).c_str());
 			break;
 		}
 
@@ -2582,14 +2582,14 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
 	auto extensionRequirements = reinterpret_cast<VkBaseInStructure const*>(pSparseMemoryRequirements->pNext);
 	while(extensionRequirements)
 	{
-		WARN("pSparseMemoryRequirements->pNext sType = %s", vk::Stringify(extensionRequirements->sType));
+		WARN("pSparseMemoryRequirements->pNext sType = %s", vk::Stringify(extensionRequirements->sType).c_str());
 		extensionRequirements = extensionRequirements->pNext;
 	}
 
@@ -2678,7 +2678,7 @@
 										 sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
 			break;
 		default:
-			WARN("pFeatures->pNext sType = %s", vk::Stringify(extensionFeatures->sType));
+			WARN("pFeatures->pNext sType = %s", vk::Stringify(extensionFeatures->sType).c_str());
 			break;
 		}
 
@@ -2774,7 +2774,7 @@
 			break;
 		default:
 			// "the [driver] must skip over, without processing (other than reading the sType and pNext members) any structures in the chain with sType values not defined by [supported extenions]"
-			WARN("pProperties->pNext sType = %s", vk::Stringify(extensionProperties->sType));
+			WARN("pProperties->pNext sType = %s", vk::Stringify(extensionProperties->sType).c_str());
 			break;
 		}
 
@@ -2792,7 +2792,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pFormatProperties->pNext);
 	while(extInfo)
 	{
-		WARN("pFormatProperties->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pFormatProperties->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -2839,7 +2839,7 @@
 		}
 		break;
 		default:
-			WARN("pImageFormatInfo->pNext sType = %s", vk::Stringify(extensionFormatInfo->sType));
+			WARN("pImageFormatInfo->pNext sType = %s", vk::Stringify(extensionFormatInfo->sType).c_str());
 			break;
 		}
 
@@ -2872,7 +2872,7 @@
 		}
 		break;
 		default:
-			WARN("pImageFormatProperties->pNext sType = %s", vk::Stringify(extensionProperties->sType));
+			WARN("pImageFormatProperties->pNext sType = %s", vk::Stringify(extensionProperties->sType).c_str());
 			break;
 		}
 
@@ -2898,7 +2898,7 @@
 		auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pQueueFamilyProperties->pNext);
 		while(extInfo)
 		{
-			WARN("pQueueFamilyProperties->pNext sType = %s", vk::Stringify(extInfo->sType));
+			WARN("pQueueFamilyProperties->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 			extInfo = extInfo->pNext;
 		}
 	}
@@ -2920,7 +2920,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pMemoryProperties->pNext);
 	while(extInfo)
 	{
-		WARN("pMemoryProperties->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pMemoryProperties->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -2937,7 +2937,7 @@
 		auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pProperties->pNext);
 		while(extInfo)
 		{
-			WARN("pProperties->pNext sType = %s", vk::Stringify(extInfo->sType));
+			WARN("pProperties->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 			extInfo = extInfo->pNext;
 		}
 	}
@@ -2962,7 +2962,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pQueueInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pQueueInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pQueueInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -2989,7 +2989,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pCreateInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}
 
@@ -3017,7 +3017,7 @@
 	auto extInfo = reinterpret_cast<VkBaseInStructure const*>(pCreateInfo->pNext);
 	while(extInfo)
 	{
-		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType));
+		WARN("pCreateInfo->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
 		extInfo = extInfo->pNext;
 	}