Commit 46e28cb3 by Ben Clayton

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/+/29931Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 4bade2e3
......@@ -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
......
......@@ -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
......
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