Skip to contentSkip to conversation

Add pragma to ignore gcc-compat warnings in clang when used with diagnose_if.

PATCH Superseded Michael Barker 4 participants 13 messages Jan 17, 2022 – Feb 12, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add pragma to ignore gcc-compat warnings in clang when used with diagnose_if.

---
 lib/eal/include/rte_compat.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/include/rte_compat.h +4 -1
index 2718612cce..9556bbf4d0 100644
@@ -33,8 +33,11 @@ section(".text.internal")))
 #elif !defined ALLOW_INTERNAL_API && __has_attribute(diagnose_if) /* For clang */
 
 #define __rte_internal \
+_Pragma("GCC diagnostic push") \
+_Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
 __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \
-section(".text.internal")))
+section(".text.internal"))) \
+_Pragma("GCC diagnostic pop")
 
 #else
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/1 Add pragma to ignore gcc-compat warnings in clang when used with diagnose_if.

When using clang with -Wall the use of diagnose_if kicks up a warning, requiring all dpdk includes to be wrapped with the pragma. This change isolates the ignore just the appropriate location and makes it easier for users to apply -Wall,-Werror

---
 lib/eal/include/rte_compat.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/include/rte_compat.h +4 -1
index 2718612cce..9556bbf4d0 100644
@@ -33,8 +33,11 @@ section(".text.internal")))
 #elif !defined ALLOW_INTERNAL_API && __has_attribute(diagnose_if) /* For clang */
 
 #define __rte_internal \
+_Pragma("GCC diagnostic push") \
+_Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
 __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \
-section(".text.internal")))
+section(".text.internal"))) \
+_Pragma("GCC diagnostic pop")
 
 #else
 
Signature · 1 line
2.25.1
#2 lore raw

18/01/2022 00:23, Michael Barker:

Quoted 1 line

When using clang with -Wall the use of diagnose_if kicks up a warning,

Please could you copy the warning in the commit log?

Quoted 3 lines

requiring all dpdk includes to be wrapped with the pragma. This change isolates the ignore just the appropriate location and makes it easier for users to apply -Wall,-Werror

Please could you explain how it is related to -Wgcc-compat?

[...]

Quoted 7 lines

#define __rte_internal \

lib/eal/include/rte_compat.h +4 -1
+_Pragma("GCC diagnostic push") \
+_Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
 __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \
-section(".text.internal")))
+section(".text.internal"))) \
+_Pragma("GCC diagnostic pop")
#3 lore raw
Quoted 5 lines · Thomas Monjalon

18/01/2022 00:23, Michael Barker:

Quoted 1 line

When using clang with -Wall the use of diagnose_if kicks up a warning,

Please could you copy the warning in the commit log?

I've updated the commit log to be more descriptive (and included the associated warning).

Quoted 6 lines

requiring all dpdk includes to be wrapped with the pragma. This change

Quoted 2 lines

isolates the ignore just the appropriate location and makes it easier for users to apply -Wall,-Werror

Please could you explain how it is related to -Wgcc-compat?

I'm currently working on some code that makes use of DPDK, which is built with '-Wall,-Werror' enabled. When using the clang toolchain the build fails as a result of this macro that this patch updates. The workaround from my application is to wrap all of the DPDK header includes in pragma to disable the warnings (see below). This has the unfortunate side effect of disabling this warning across all of the included DPDK headers, which is not ideal. Hence the reason to submit the patch which disables the warning just in the location where it occurs.

#if defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgcc-compat"
#endif
#include <rte_ethdev.h>
#if defined(__clang__)
#pragma GCC diagnostic pop "-Wgcc-compat"
#endif

Quoted 13 lines

[...]

Quoted 7 lines

#define __rte_internal \

lib/eal/include/rte_compat.h +4 -1
+_Pragma("GCC diagnostic push") \
+_Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
 __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \
-section(".text.internal")))
+section(".text.internal"))) \
+_Pragma("GCC diagnostic pop")
#4 lore raw
Quoted 18 lines · On Mon, 24 Jan 2022 10:17:37 +1300 Michael Barker <[email protected]> wrote:
Quoted 5 lines · Thomas Monjalon

18/01/2022 00:23, Michael Barker:

Quoted 1 line

When using clang with -Wall the use of diagnose_if kicks up a warning,

Please could you copy the warning in the commit log?

I've updated the commit log to be more descriptive (and included the associated warning).

Quoted 6 lines

requiring all dpdk includes to be wrapped with the pragma. This change

Quoted 2 lines

isolates the ignore just the appropriate location and makes it easier for users to apply -Wall,-Werror

Please could you explain how it is related to -Wgcc-compat?

Quoted 9 lines

I'm currently working on some code that makes use of DPDK, which is built with '-Wall,-Werror' enabled. When using the clang toolchain the build fails as a result of this macro that this patch updates. The workaround from my application is to wrap all of the DPDK header includes in pragma to disable the warnings (see below). This has the unfortunate side effect of disabling this warning across all of the included DPDK headers, which is not ideal. Hence the reason to submit the patch which disables the warning just in the location where it occurs.

Fix the issue please, don't suppress it.

#5 lore raw

PATCH v3 1/1 Add pragma to ignore gcc-compat warnings in clang when used with diagnose_if.

In reply to Michael Barker

When compiling with clang using -Wall (or -Wgcc-compat) the use of diagnose_if kicks up a warning:

.../include/rte_interrupts.h:623:1: error: 'diagnose_if' is a clang extension [-Werror,-Wgcc-compat] __rte_internal
^
.../include/rte_compat.h:36:16: note: expanded from macro '__rte_internal' __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \

This change ignores the '-Wgcc-compat' warning in the specific location where the warning occurs. It is safe to do in this circumstance as the specific macro is only defined when using the clang compiler.

---
 lib/eal/include/rte_compat.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/include/rte_compat.h +4 -1
index 2718612cce..9556bbf4d0 100644
@@ -33,8 +33,11 @@ section(".text.internal")))
 #elif !defined ALLOW_INTERNAL_API && __has_attribute(diagnose_if) /* For clang */
 
 #define __rte_internal \
+_Pragma("GCC diagnostic push") \
+_Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
 __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \
-section(".text.internal")))
+section(".text.internal"))) \
+_Pragma("GCC diagnostic pop")
 
 #else
 
Signature · 1 line
2.25.1
#6 lore raw

PATCH v4 1/1 Add pragma to ignore gcc-compat warnings in clang when used with diagnose_if.

When compiling with clang using -Wall (or -Wgcc-compat) the use of diagnose_if kicks up a warning:

.../include/rte_interrupts.h:623:1: error: 'diagnose_if' is a clang extension [-Werror,-Wgcc-compat]
__rte_internal
^
.../include/rte_compat.h:36:16: note: expanded from macro '__rte_internal' __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \

This change ignores the '-Wgcc-compat' warning in the specific location where the warning occurs. It is safe to do in this circumstance as the specific macro is only defined when using the clang compiler.

---
 lib/eal/include/rte_compat.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/include/rte_compat.h +4 -1
index 2718612cce..9556bbf4d0 100644
@@ -33,8 +33,11 @@ section(".text.internal")))
 #elif !defined ALLOW_INTERNAL_API && __has_attribute(diagnose_if) /* For clang */
 
 #define __rte_internal \
+_Pragma("GCC diagnostic push") \
+_Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
 __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \
-section(".text.internal")))
+section(".text.internal"))) \
+_Pragma("GCC diagnostic pop")
 
 #else
 
Signature · 1 line
2.25.1
#7 lore raw
Quoted 7 lines · On Mon, 24 Jan 2022 10:20:24 +1300 Michael Barker <[email protected]> wrote:

When compiling with clang using -Wall (or -Wgcc-compat) the use of diagnose_if kicks up a warning:

.../include/rte_interrupts.h:623:1: error: 'diagnose_if' is a clang extension [-Werror,-Wgcc-compat]
__rte_internal
^

Which clang version is this?
Perhaps the allow internal API could use a different attribute that could work in both cases?

#8 lore raw
Quoted 6 lines
Quoted 3 lines

extension [-Werror,-Wgcc-compat]
__rte_internal
^

Which clang version is this?

Clang 10, 11, 12 and 13.

Quoted 3 lines

Perhaps the allow internal API could use a different attribute that could work in both cases?

I've realised I've made a small error. It is not -Wall that includes this particular check, but -Wpendantic. I'll update the commit message.

However I can't find an attribute that is cross platform. There is the #error directive, but it does not work as an attribute. I've also tried adding #if __clang__ around the macro as well, but the warning still gets triggered by clang.

If there are any other options that I've missed, let me know and I can try them out.

Mike.

#9 lore raw
In reply to Michael Barker
Quoted 25 lines · Michael Barker

When compiling with clang using -Wall (or -Wgcc-compat) the use of diagnose_if kicks up a warning:

.../include/rte_interrupts.h:623:1: error: 'diagnose_if' is a clang extension [-Werror,-Wgcc-compat]
__rte_internal
^
.../include/rte_compat.h:36:16: note: expanded from macro '__rte_internal' __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \

This change ignores the '-Wgcc-compat' warning in the specific location where the warning occurs. It is safe to do in this circumstance as the specific macro is only defined when using the clang compiler.

---
 lib/eal/include/rte_compat.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/include/rte_compat.h +0 -0
index 2718612cce..9556bbf4d0 100644
@@ -33,8 +33,11 @@ section(".text.internal")))
 #elif !defined ALLOW_INTERNAL_API && __has_attribute(diagnose_if) /*
Quoted 1 line

For clang */

Why doesn't the __has_attribute take care of this?
I would have thought that gcc would check the for the attribute, find it doesn't support it and ignore the whole thing?

Quoted 10 lines

#define __rte_internal \

lib/eal/include/rte_compat.h +4 -1
+_Pragma("GCC diagnostic push") \
+_Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
 __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \
-section(".text.internal")))
+section(".text.internal"))) \
+_Pragma("GCC diagnostic pop")
 
 #else
Signature · 1 line
Regards, Ray K
#10 lore raw
Quoted 10 lines
Quoted 5 lines

+++ b/lib/eal/include/rte_compat.h

(quoted diff) +0 -0
@@ -33,8 +33,11 @@ section(".text.internal")))
 #elif !defined ALLOW_INTERNAL_API && __has_attribute(diagnose_if) /*

For clang */

Why doesn't the __has_attribute take care of this?
I would have thought that gcc would check the for the attribute, find it doesn't support it and ignore the whole thing?

It appears that the '-Wgcc-compat' check is too naive and doesn't pick up the __has_attribute or #if __clang__ and realise that there isn't really a compatibility issue with the code.

Mike.

#11 lore raw

PATCH v5 1/1 Add pragma to ignore gcc-compat warnings in clang when used with diagnose_if.

In reply to Michael Barker

When compiling with clang using -Wpedantic (or -Wgcc-compat) the use of diagnose_if kicks up a warning:

.../include/rte_interrupts.h:623:1: error: 'diagnose_if' is a clang extension [-Werror,-Wgcc-compat]
__rte_internal
^
.../include/rte_compat.h:36:16: note: expanded from macro '__rte_internal' __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \

This change ignores the '-Wgcc-compat' warning in the specific location where the warning occurs. It is safe to do in this circumstance as the specific macro is only defined when using the clang compiler.

---
 lib/eal/include/rte_compat.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/include/rte_compat.h +4 -1
index 2718612cce..9556bbf4d0 100644
@@ -33,8 +33,11 @@ section(".text.internal")))
 #elif !defined ALLOW_INTERNAL_API && __has_attribute(diagnose_if) /* For clang */
 
 #define __rte_internal \
+_Pragma("GCC diagnostic push") \
+_Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
 __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \
-section(".text.internal")))
+section(".text.internal"))) \
+_Pragma("GCC diagnostic pop")
 
 #else
 
Signature · 1 line
2.25.1
#12 lore raw

31/01/2022 01:05, Michael Barker:

Quoted 10 lines

When compiling with clang using -Wpedantic (or -Wgcc-compat) the use of diagnose_if kicks up a warning:

.../include/rte_interrupts.h:623:1: error: 'diagnose_if' is a clang extension [-Werror,-Wgcc-compat]
__rte_internal
^
.../include/rte_compat.h:36:16: note: expanded from macro '__rte_internal' __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \

Quoted 5 lines

This change ignores the '-Wgcc-compat' warning in the specific location where the warning occurs. It is safe to do in this circumstance as the specific macro is only defined when using the clang compiler.

Applied with following title, thanks:
eal: ignore gcc-compat warning in clang-only macro