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

Message ID 20220123212024.19747-1-mikeb01@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v4] Add pragma to ignore gcc-compat warnings in clang when used with diagnose_if. |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Michael Barker Jan. 23, 2022, 9:20 p.m. UTC
  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.

Signed-off-by: Michael Barker <mikeb01@gmail.com>
---
 lib/eal/include/rte_compat.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Stephen Hemminger Jan. 23, 2022, 11:55 p.m. UTC | #1
On Mon, 24 Jan 2022 10:20:24 +1300
Michael Barker <mikeb01@gmail.com> 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?
  
Ray Kinsella Jan. 25, 2022, 10:33 a.m. UTC | #2
Michael Barker <mikeb01@gmail.com> writes:

> 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.
>
> Signed-off-by: Michael Barker <mikeb01@gmail.com>
> ---
>  lib/eal/include/rte_compat.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/lib/eal/include/rte_compat.h b/lib/eal/include/rte_compat.h
> index 2718612cce..9556bbf4d0 100644
> --- a/lib/eal/include/rte_compat.h
> +++ b/lib/eal/include/rte_compat.h
> @@ -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?

>  
>  #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
  
Michael Barker Jan. 31, 2022, 12:08 a.m. UTC | #3
> > extension [-Werror,-Wgcc-compat]
> > __rte_internal
> > ^
>
> Which clang version is this?
>

Clang 10, 11, 12 and 13.


> 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.
  
Michael Barker Jan. 31, 2022, 12:10 a.m. UTC | #4
>
> > +++ b/lib/eal/include/rte_compat.h
> > @@ -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.
  

Patch

diff --git a/lib/eal/include/rte_compat.h b/lib/eal/include/rte_compat.h
index 2718612cce..9556bbf4d0 100644
--- a/lib/eal/include/rte_compat.h
+++ b/lib/eal/include/rte_compat.h
@@ -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