On Wed, Feb 16, 2022 at 2:25 AM Richard Sandiford via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> atomic-inst-cas.c has code to skip __atomic_compare_exchange_n
> calls for invalid memory orderings, but -Winvalid-memory-model
> applies before the dead code is removed (which is the right
> behaviour IMO).  This patch therefore suppresses the warning
> for this test.

It is a bit more complex than that, see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104200#c3 for the reduced
testcase.
The undefined (invalid) arguments to __atomic_compare_exchange_n are
only after constant propagation really which is not done at -O0,
though the warning does it.
So the warning does constant propagation of the arguments but not if
it was conditionally executed.
Most likely waccess should do a similar thing like it was done for the
uninitialized warnings in
https://gcc.gnu.org/pipermail/gcc-patches/2022-February/589983.html .

Thanks,
Andrew Pinski

>
> Tested on aarch64-linux-gnu & pushed.
>
> Richard
>
>
> gcc/testsuite/
>         * gcc.target/aarch64/atomic-inst-cas.c: Add
>         -Wno-invalid-memory-model.
> ---
>  gcc/testsuite/gcc.target/aarch64/atomic-inst-cas.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/testsuite/gcc.target/aarch64/atomic-inst-cas.c 
> b/gcc/testsuite/gcc.target/aarch64/atomic-inst-cas.c
> index f6f28922319..0b4533adade 100644
> --- a/gcc/testsuite/gcc.target/aarch64/atomic-inst-cas.c
> +++ b/gcc/testsuite/gcc.target/aarch64/atomic-inst-cas.c
> @@ -1,5 +1,7 @@
>  /* { dg-do compile } */
> -/* { dg-options "-O2 -march=armv8-a+lse" } */
> +/* -Winvalid-memory-model warnings are issued before the dead invalid calls
> +   are removed.  */
> +/* { dg-options "-O2 -march=armv8-a+lse -Wno-invalid-memory-model" } */
>
>  /* Test ARMv8.1-A CAS instruction.  */
>
> --
> 2.25.1

Reply via email to