Check macro arguments match format specifier.

Prevents typos that can cause undefined behavior.

Bug: b/127433389
Change-Id: I6308831d9ae8ff3d6147c5a766de81fdc239fab5
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29931
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Reactor/Debug.hpp b/src/Reactor/Debug.hpp
index d2b3a1f..929a927 100644
--- a/src/Reactor/Debug.hpp
+++ b/src/Reactor/Debug.hpp
@@ -25,18 +25,24 @@
 #define TRACE_OUTPUT_FILE "debug.txt"
 #endif
 
+#if defined(__GNUC__) || defined(__clang__)
+#define CHECK_PRINTF_ARGS __attribute__((format(printf, 1, 2)))
+#else
+#define CHECK_PRINTF_ARGS
+#endif
+
 namespace rr
 {
 	// Outputs text to the debugging log
-	void trace(const char *format, ...);
+	void trace(const char *format, ...) CHECK_PRINTF_ARGS;
 	inline void trace() {}
 
 	// Outputs text to the debugging log and prints to stderr.
-	void warn(const char *format, ...);
+	void warn(const char *format, ...) CHECK_PRINTF_ARGS;
 	inline void warn() {}
 
 	// Outputs the message to the debugging log and stderr, and calls abort().
-	void abort(const char *format, ...);
+	void abort(const char *format, ...) CHECK_PRINTF_ARGS;
 }
 
 // A macro to output a trace of a function call and its arguments to the
diff --git a/src/Vulkan/VkDebug.hpp b/src/Vulkan/VkDebug.hpp
index 7798de1..31d62b2 100644
--- a/src/Vulkan/VkDebug.hpp
+++ b/src/Vulkan/VkDebug.hpp
@@ -25,18 +25,24 @@
 #define TRACE_OUTPUT_FILE "debug.txt"
 #endif
 
+#if defined(__GNUC__) || defined(__clang__)
+#define CHECK_PRINTF_ARGS __attribute__((format(printf, 1, 2)))
+#else
+#define CHECK_PRINTF_ARGS
+#endif
+
 namespace vk
 {
 	// Outputs text to the debugging log
-	void trace(const char *format, ...);
+	void trace(const char *format, ...) CHECK_PRINTF_ARGS;
 	inline void trace() {}
 
 	// Outputs text to the debugging log and prints to stderr.
-	void warn(const char *format, ...);
+	void warn(const char *format, ...) CHECK_PRINTF_ARGS;
 	inline void warn() {}
 
 	// Outputs the message to the debugging log and stderr, and calls abort().
-	void abort(const char *format, ...);
+	void abort(const char *format, ...) CHECK_PRINTF_ARGS;
 }
 
 // A macro to output a trace of a function call and its arguments to the