[COMMITTED 07/83] gccrs: Wrap rust_debugs into a do-while wrapper
arthur.cohen@opensrcsec.com
arthur.cohen@opensrcsec.com
Wed Sep 16 12:29:26 GMT 2026
From: Philip Herron <herron.philip@googlemail.com>
This reduces compile time when debug is turned off due to evaultion
of any passed arguments.
gcc/rust/ChangeLog:
* rust-diagnostics.cc (rust_debug_loc): rename
(rust_debug_loc_internal): no longer check if debug is enabled
* rust-diagnostics.h (rust_debug): new wrapper
(rust_debug_loc): likewise
(rust_debug_loc_internal): likewise
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/rust-diagnostics.cc | 5 +----
gcc/rust/rust-diagnostics.h | 20 +++++++++++++++++---
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/rust-diagnostics.cc b/gcc/rust/rust-diagnostics.cc
index 498805acc3e..bdd78f7f29d 100644
--- a/gcc/rust/rust-diagnostics.cc
+++ b/gcc/rust/rust-diagnostics.cc
@@ -398,11 +398,8 @@ rust_be_debug_p (void)
}
void
-rust_debug_loc (const location_t location, const char *fmt, ...)
+rust_debug_loc_internal (const location_t location, const char *fmt, ...)
{
- if (!rust_be_debug_p ())
- return;
-
va_list ap;
va_start (ap, fmt);
diff --git a/gcc/rust/rust-diagnostics.h b/gcc/rust/rust-diagnostics.h
index 7fe2596e8d1..e15c3a4508b 100644
--- a/gcc/rust/rust-diagnostics.h
+++ b/gcc/rust/rust-diagnostics.h
@@ -300,12 +300,26 @@ struct Error
} // namespace Rust
// rust_debug uses normal printf formatting, not GCC diagnostic formatting.
-#define rust_debug(...) rust_debug_loc (UNDEF_LOCATION, __VA_ARGS__)
+#define rust_debug(...) \
+ do \
+ { \
+ if (rust_be_debug_p ()) \
+ rust_debug_loc_internal (UNDEF_LOCATION, __VA_ARGS__); \
+ } \
+ while (0)
+
+#define rust_debug_loc(location, ...) \
+ do \
+ { \
+ if (rust_be_debug_p ()) \
+ rust_debug_loc_internal (location, __VA_ARGS__); \
+ } \
+ while (0)
#define rust_sorry_at(location, ...) sorry_at (location, __VA_ARGS__)
-void rust_debug_loc (const location_t location, const char *fmt,
- ...) ATTRIBUTE_PRINTF_2;
+void rust_debug_loc_internal (const location_t location, const char *fmt,
+ ...) ATTRIBUTE_PRINTF_2;
// like rust_debug, but has gcc diagnostic formatting
#define rust_debug_fmt(...) rust_debug_fmt_at (UNDEF_LOCATION, __VA_ARGS__)
--
2.50.1
More information about the Gcc-rust
mailing list