[binutils-gdb] sim: sprinkle some ATTRIBUTE_PRINTF

Simon Marchi simark@sourceware.org
Thu Apr 22 16:07:48 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2f63213381e3b073f169ee776043486b44ea2e68

commit 2f63213381e3b073f169ee776043486b44ea2e68
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Thu Apr 22 12:07:14 2021 -0400

    sim: sprinkle some ATTRIBUTE_PRINTF
    
    Add some ATTRIBUTE_PRINTF attributes to functions that take a format
    string, to fix a few -Wformat-nonliteral warnings.  Use the
    ATTRIBUTE_PRINTF macro like we use in GDB, instead of spelling out
    __attribute__((format...)).  Use ATTRIBUTE_NULL_PRINTF at one place,
    because callers expect to be able to pass NULL.
    
    sim/common/ChangeLog:
    
            * callback.c (os_printf_filtered, os_vprintf_filtered,
            os_evprintf_filtered, os_error): Use ATTRIBUTE_PRINTF.
            * sim-engine.h (sim_engine_abort, sim_engine_vabort): Likewise.
            * sim-events.h (sim_events_schedule_tracef,
            sim_events_schedule_vtracef): Use ATTRIBUTE_NULL_PRINTF.
    
    Change-Id: Icd206f7b2c325e8b144f72eb129fb2a6b5af2fa3

Diff:
---
 sim/common/ChangeLog    | 8 ++++++++
 sim/common/callback.c   | 8 ++++----
 sim/common/sim-engine.h | 4 ++--
 sim/common/sim-events.h | 4 ++--
 4 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index d62a40d5db8..c6a0b83d011 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,11 @@
+2021-04-22  Simon Marchi  <simon.marchi@polymtl.ca>
+
+	* callback.c (os_printf_filtered, os_vprintf_filtered,
+	os_evprintf_filtered, os_error): Use ATTRIBUTE_PRINTF.
+	* sim-engine.h (sim_engine_abort, sim_engine_vabort): Likewise.
+	* sim-events.h (sim_events_schedule_tracef,
+	sim_events_schedule_vtracef): Use ATTRIBUTE_NULL_PRINTF.
+
 2021-04-18  Mike Frysinger  <vapier@gentoo.org>
 
 	* gennltvals.py (TARGETS): Add moxie.
diff --git a/sim/common/callback.c b/sim/common/callback.c
index f9e848fd913..2fec2704f3e 100644
--- a/sim/common/callback.c
+++ b/sim/common/callback.c
@@ -639,7 +639,7 @@ os_init (host_callback *p)
 /* DEPRECATED */
 
 /* VARARGS */
-static void
+static void ATTRIBUTE_PRINTF (2, 3)
 os_printf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, ...)
 {
   va_list args;
@@ -650,14 +650,14 @@ os_printf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, ...)
 }
 
 /* VARARGS */
-static void
+static void ATTRIBUTE_PRINTF (2, 0)
 os_vprintf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, va_list args)
 {
   vprintf (format, args);
 }
 
 /* VARARGS */
-static void
+static void ATTRIBUTE_PRINTF (2, 0)
 os_evprintf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, va_list args)
 {
   vfprintf (stderr, format, args);
@@ -667,7 +667,7 @@ os_evprintf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, va_
 #ifdef __GNUC__
 __attribute__ ((__noreturn__))
 #endif
-static void
+static void ATTRIBUTE_PRINTF (2, 3)
 os_error (host_callback *p ATTRIBUTE_UNUSED, const char *format, ...)
 {
   va_list args;
diff --git a/sim/common/sim-engine.h b/sim/common/sim-engine.h
index 25d06f774de..5adce8deedb 100644
--- a/sim/common/sim-engine.h
+++ b/sim/common/sim-engine.h
@@ -115,14 +115,14 @@ extern void sim_engine_abort
  sim_cpu *cpu,
  sim_cia cia,
  const char *fmt,
- ...) __attribute__ ((format (printf, 4, 5))) __attribute__ ((noreturn));
+ ...) ATTRIBUTE_PRINTF (4, 5) __attribute__ ((noreturn));
 
 extern void sim_engine_vabort
 (SIM_DESC sd,
  sim_cpu *cpu,
  sim_cia cia,
  const char *fmt,
- va_list ap) __attribute__ ((noreturn));
+ va_list ap) ATTRIBUTE_PRINTF (4, 0) __attribute__ ((noreturn));
 
 /* No abort hook - when possible this function exits using the
    engine_halt function (and SIM_ENGINE_HALT_HOOK). */
diff --git a/sim/common/sim-events.h b/sim/common/sim-events.h
index 7a5fc9665d2..3f1501ea67c 100644
--- a/sim/common/sim-events.h
+++ b/sim/common/sim-events.h
@@ -117,7 +117,7 @@ extern sim_event *sim_events_schedule_tracef
  sim_event_handler *handler,
  void *data,
  const char *fmt,
- ...) __attribute__ ((format (printf, 5, 6)));
+ ...) ATTRIBUTE_NULL_PRINTF (5, 6);
 
 extern sim_event *sim_events_schedule_vtracef
 (SIM_DESC sd,
@@ -125,7 +125,7 @@ extern sim_event *sim_events_schedule_vtracef
  sim_event_handler *handler,
  void *data,
  const char *fmt,
- va_list ap);
+ va_list ap) ATTRIBUTE_NULL_PRINTF (5, 0);
 
 
 extern void sim_events_schedule_after_signal


More information about the Gdb-cvs mailing list