debug: Introduce VREND_DEBUG_ENABLED flag
VREND_DEBUG_ENABLED represents if debugging features are enabled and is
controlled by NDEBUG macro. By using VREND_DEBUG_ENABLED in
an if statement instead of using NDEBUG in ifdef, the compiler can
validate the content of the conditional and know its variable usage to
avoid meaningless warnings.
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/715>
diff --git a/src/vrend_debug.h b/src/vrend_debug.h
index 40ff226..7afa69b 100644
--- a/src/vrend_debug.h
+++ b/src/vrend_debug.h
@@ -79,31 +79,30 @@
va_end(va);
}
-#ifndef NDEBUG
+#ifdef NDEBUG
+#define VREND_DEBUG_ENABLED (false)
+#else
+#define VREND_DEBUG_ENABLED (true)
+#endif
+
#define VREND_DEBUG(flag, ctx, ...) \
- if (vrend_debug(ctx, flag)) \
+ if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
do { \
vrend_print_context_name(ctx); \
vrend_printf(__VA_ARGS__); \
} while (0)
#define VREND_DEBUG_EXT(flag, ctx, X) \
- if (vrend_debug(ctx, flag)) \
+ if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
do { \
vrend_print_context_name(ctx); \
X; \
} while (0)
#define VREND_DEBUG_NOCTX(flag, ctx, ...) \
- if (vrend_debug(ctx, flag)) \
+ if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
do { \
vrend_printf(__VA_ARGS__); \
} while (0)
-#else
-#define VREND_DEBUG(flag, ctx, ...) (void)ctx
-#define VREND_DEBUG_EXT(flag, ctx, X) (void)ctx
-#define VREND_DEBUG_NOCTX(flag, ctx, ...) (void)ctx
-#endif
-
#endif
diff --git a/src/vrend_decode.c b/src/vrend_decode.c
index 3bc5e16..b734512 100644
--- a/src/vrend_decode.c
+++ b/src/vrend_decode.c
@@ -1711,10 +1711,7 @@
uint32_t buf_offset = 0;
while (buf_offset < buf_total) {
-#ifndef NDEBUG
const uint32_t cur_offset = buf_offset;
-#endif
-
const uint32_t *buf = &typed_buf[buf_offset];
uint32_t len = *buf >> 16;
uint32_t cmd = *buf & 0xff;
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index 640c44e..626b5f6 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -3864,11 +3864,9 @@
free(tokens);
ret = EINVAL;
goto error;
- } else {
-#ifdef NDEBUG
- free(sel->tmp_buf);
- sel->tmp_buf = NULL;
-#endif
+ } else if (!VREND_DEBUG_ENABLED) {
+ free(sel->tmp_buf);
+ sel->tmp_buf = NULL;
}
free(tokens);
sub_ctx->long_shader_in_progress_handle[type] = 0;
@@ -6489,9 +6487,9 @@
vrend_state.max_texture_3d_size =
vrend_state.max_texture_cube_size = 16384;
-#ifndef NDEBUG
- vrend_init_debug_flags();
-#endif
+ if (VREND_DEBUG_ENABLED) {
+ vrend_init_debug_flags();
+ }
ctx_params.shared = false;
for (uint32_t i = 0; i < ARRAY_SIZE(gl_versions); i++) {