Skip to contentSkip to conversation

eal/windows: vfprintf build warning with clang

PATCH Superseded Nick Connolly 4 participants 7 messages Nov 27, 2020 – Dec 7, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal/windows: vfprintf build warning with clang

When building with clang (11.0,--buildtype=debug), eal_lcore.c produces a -Wformat-nonliteral warning from the vfprintf call in log_early.

Disable the warning for log_early when building with clang. MinGW does not seem to detect the warning.

Fixes b8a36b086625 ("eal/windows: improve CPU and NUMA node detection")
---
 lib/librte_eal/windows/eal_lcore.c | 9 +++++++++
 1 file changed, 9 insertions(+)
lib/librte_eal/windows/eal_lcore.c +9 -0
index d5ff721e0..d996b4f89 100644
@@ -36,6 +36,11 @@ struct cpu_map {
 
 static struct cpu_map cpu_map = { 0 };
 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+#endif
+
 /* eal_create_cpu_map() is called before logging is initialized */
 static void
 log_early(const char *format, ...)
@@ -47,6 +52,10 @@ log_early(const char *format, ...)
 	va_end(va);
 }
 
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
 int
 eal_create_cpu_map(void)
 {
Signature · 1 line
2.25.1
#1 lore raw

Review

Quoted 6 lines · Nick Connolly

[...]

(quoted diff) +4 -0
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+#endif
[...]

How about a more safe approach?

lib/librte_eal/windows/eal_lcore.c +1 -0
index d5ff721e0..ebcd3474e 100644
@@ -37,6 +37,7 @@ struct cpu_map {
 static struct cpu_map cpu_map = { 0 };
 
 /* eal_create_cpu_map() is called before logging is initialized */
+__rte_format_printf(1, 2)
 static void
 log_early(const char *format, ...)
 {
#2 lore raw

Looks good to me!

Quoted 21 lines · Dmitry Kozlyuk

Review

Quoted 6 lines · Nick Connolly

[...]

(quoted diff) +4 -0
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+#endif
[...]

How about a more safe approach?

lib/librte_eal/windows/eal_lcore.c +1 -0
index d5ff721e0..ebcd3474e 100644
@@ -37,6 +37,7 @@ struct cpu_map {
  static struct cpu_map cpu_map = { 0 };
 
  /* eal_create_cpu_map() is called before logging is initialized */
+__rte_format_printf(1, 2)
  static void
  log_early(const char *format, ...)
  {
#3 lore raw

PATCH v2 1/1 eal/windows: vfprintf build warning with clang

In reply to Nick Connolly

When building with clang (11.0,--buildtype=debug), eal_lcore.c produces a -Wformat-nonliteral warning from the vfprintf call in log_early.

Add __rte_format_printf annotation.

Fixes b8a36b086625 ("eal/windows: improve CPU and NUMA node detection")

---
v2:
* Use __rte_format_printf instead of disabling the warning

 lib/librte_eal/windows/eal_lcore.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_eal/windows/eal_lcore.c +1 -0
index d5ff721e0..a85149be9 100644
@@ -38,6 +38,7 @@ static struct cpu_map cpu_map = { 0 };
 
 /* eal_create_cpu_map() is called before logging is initialized */
 static void
+__rte_format_printf(1, 2)
 log_early(const char *format, ...)
 {
 	va_list va;
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#4 lore raw
Quoted 23 lines · Nick Connolly

When building with clang (11.0,--buildtype=debug), eal_lcore.c produces a -Wformat-nonliteral warning from the vfprintf call in log_early.

Add __rte_format_printf annotation.

Fixes b8a36b086625 ("eal/windows: improve CPU and NUMA node detection")

---
v2:
* Use __rte_format_printf instead of disabling the warning

 lib/librte_eal/windows/eal_lcore.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_eal/windows/eal_lcore.c +0 -0
index d5ff721e0..a85149be9 100644

lib/librte_eal/windows/eal_lcore.c static struct cpu_map cpu_map = { 0 }; · line 44

Quoted 7 lines
lib/librte_eal/windows/eal_lcore.c +1 -0
@@ -38,6 +38,7 @@ static struct cpu_map cpu_map = { 0 };
 
 /* eal_create_cpu_map() is called before logging is initialized */
 static void
+__rte_format_printf(1, 2)
 log_early(const char *format, ...)
 {
 	va_list va;
#5 lore raw

29/11/2020 14:42, Dmitry Kozlyuk:

Quoted 7 lines · Nick Connolly
Quoted 6 lines

When building with clang (11.0,--buildtype=debug), eal_lcore.c produces a -Wformat-nonliteral warning from the vfprintf call in log_early.

Add __rte_format_printf annotation.

Quoted 7 lines
Quoted 5 lines
Fixes b8a36b086625 ("eal/windows: improve CPU and NUMA node detection")

Applied, thanks

Acked-by on v2 1/1
#6 lore raw
In reply to Nick Connolly
Quoted 4 lines · Nick Connolly

When building with clang (11.0,--buildtype=debug), eal_lcore.c produces a -Wformat-nonliteral warning from the vfprintf call in log_early.

Quoted 8 lines

Add __rte_format_printf annotation.

Fixes b8a36b086625 ("eal/windows: improve CPU and NUMA node detection")

---