[PATCH] tst-atomic.c: Mark as UNSUPPORTED when compiled with Clang

Andrew Pinski pinskia@gmail.com
Wed Dec 18 01:53:48 GMT 2024


On Tue, Dec 17, 2024 at 5:41 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Since Clang can't remove the dead statement and issues an error:
>
> tst-atomic.c:463:7: error: unsupported inline asm: input with type 'int64_t' (aka 'long') matching output with type 'typeof (*&mem)' (aka 'int')
>   463 |   if (catomic_exchange_and_add (&mem, 11) != 2
>       |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../sysdeps/x86/atomic-machine.h:213:3: note: expanded from macro 'catomic_exchange_and_add'
>   213 |   __arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c,    \
>       |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   214 |                                 mem, value)
>       |                                 ~~~~~~~~~~~
> ../sysdeps/x86/atomic-machine.h:199:12: note: expanded from macro '__arch_exchange_and_add_body'
>   198 |                          : "=r" (__result), "=m" (*mem)                       \
>       |                                  ~~~~~~~~
>   199 |                          : "0" ((int64_t) cast_to_integer (__addval)),     \
>       |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> tst-atomic.c:487:7: error: unsupported inline asm: input with type 'int64_t' (aka 'long') matching output with type 'typeof (*(&mem))' (aka 'int')
>   487 |   if (catomic_increment_val (&mem) != 3)
>       |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../include/atomic.h:313:38: note: expanded from macro 'catomic_increment_val'
>   313 | # define catomic_increment_val(mem) (catomic_exchange_and_add ((mem), 1) + 1)
>       |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../sysdeps/x86/atomic-machine.h:213:3: note: expanded from macro 'catomic_exchange_and_add'
>   213 |   __arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c,    \
>       |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   214 |                                 mem, value)
>       |                                 ~~~~~~~~~~~
> ../sysdeps/x86/atomic-machine.h:199:12: note: expanded from macro '__arch_exchange_and_add_body'
>   198 |                          : "=r" (__result), "=m" (*mem)                       \
>       |                                  ~~~~~~~~
>   199 |                          : "0" ((int64_t) cast_to_integer (__addval)),     \
>       |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> tst-atomic.c:501:7: error: unsupported inline asm: input with type 'int64_t' (aka 'long') matching output with type 'typeof (*(&mem))' (aka 'int')
>   501 |   if (catomic_decrement_val (&mem) != 15)
>       |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../include/atomic.h:340:38: note: expanded from macro 'catomic_decrement_val'
>   340 | # define catomic_decrement_val(mem) (catomic_exchange_and_add ((mem), -1) - 1)
>       |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../sysdeps/x86/atomic-machine.h:213:3: note: expanded from macro 'catomic_exchange_and_add'
>   213 |   __arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c,    \
>       |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   214 |                                 mem, value)
>       |                                 ~~~~~~~~~~~
> ../sysdeps/x86/atomic-machine.h:199:12: note: expanded from macro '__arch_exchange_and_add_body'
>   198 |                          : "=r" (__result), "=m" (*mem)                       \
>       |                                  ~~~~~~~~
>   199 |                          : "0" ((int64_t) cast_to_integer (__addval)),     \
>       |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> mark tst-atomic.c as UNSUPPORTED when compiled with Clang.

This is also a bug in how clang implements inline-asm and should be
filed upstream as a bug.  If clang folks think this is not a bug, then
clang does not implement GCC semantics for inline-asm and clang should
not mention it implements GCC inline-asm.

On another note you might be able to get around it via a small change
to the x86 headers:
       __asm __volatile (lock "xaddq %q0, %1"                                 \
                         : "=r" (__result), "=m" (*(int64_t*)mem)
                 \
                         : "0" ((int64_t) cast_to_integer (__addval)),     \
                           "m" (*(int64_t*)mem),
                 \
                           "i" (offsetof (tcbhead_t, multiple_threads)));     \

Thanks,
Andrew Pinski


>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  misc/tst-atomic.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/misc/tst-atomic.c b/misc/tst-atomic.c
> index 65d0752c91..5576f682ca 100644
> --- a/misc/tst-atomic.c
> +++ b/misc/tst-atomic.c
> @@ -16,6 +16,7 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>
> +#ifndef __clang__
>  #include <stdio.h>
>  #include <atomic.h>
>
> @@ -636,3 +637,12 @@ do_test (void)
>  }
>
>  #include <support/test-driver.c>
> +#else
> +#include <support/test-driver.h>
> +
> +int
> +main (void)
> +{
> +  return EXIT_UNSUPPORTED;
> +}
> +#endif
> --
> 2.47.1
>


More information about the Libc-alpha mailing list