[PATCH v3 01/10] qemu/atomic: Use macros for CONFIG_ATOMIC64

Richard Henderson posted 10 patches 4 years, 6 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <ehabkost@redhat.com>, David Gibson <david@gibson.dropbear.id.au>, Cornelia Huck <cohuck@redhat.com>, Riku Voipio <riku.voipio@iki.fi>, Laurent Vivier <laurent@vivier.eu>, Peter Maydell <peter.maydell@linaro.org>, David Hildenbrand <david@redhat.com>, Thomas Huth <thuth@redhat.com>, Greg Kurz <groug@kaod.org>
There is a newer version of this series
[PATCH v3 01/10] qemu/atomic: Use macros for CONFIG_ATOMIC64
Posted by Richard Henderson 4 years, 6 months ago
Clang warnings about questionable atomic usage get localized
to the inline function in atomic.h.  By using a macro, we get
the full traceback to the original use that caused the warning.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/qemu/atomic.h | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h
index 3ccf84fd46..99d6030095 100644
--- a/include/qemu/atomic.h
+++ b/include/qemu/atomic.h
@@ -457,26 +457,11 @@
 
 /* Abstractions to access atomically (i.e. "once") i64/u64 variables */
 #ifdef CONFIG_ATOMIC64
-static inline int64_t qatomic_read_i64(const int64_t *ptr)
-{
-    /* use __nocheck because sizeof(void *) might be < sizeof(u64) */
-    return qatomic_read__nocheck(ptr);
-}
-
-static inline uint64_t qatomic_read_u64(const uint64_t *ptr)
-{
-    return qatomic_read__nocheck(ptr);
-}
-
-static inline void qatomic_set_i64(int64_t *ptr, int64_t val)
-{
-    qatomic_set__nocheck(ptr, val);
-}
-
-static inline void qatomic_set_u64(uint64_t *ptr, uint64_t val)
-{
-    qatomic_set__nocheck(ptr, val);
-}
+/* Use __nocheck because sizeof(void *) might be < sizeof(u64) */
+#define qatomic_read_i64  qatomic_read__nocheck
+#define qatomic_read_u64  qatomic_read__nocheck
+#define qatomic_set_i64   qatomic_set__nocheck
+#define qatomic_set_u64   qatomic_set__nocheck
 
 static inline void qatomic64_init(void)
 {
-- 
2.25.1


Re: [PATCH v3 01/10] qemu/atomic: Use macros for CONFIG_ATOMIC64
Posted by Peter Maydell 4 years, 6 months ago
On Sat, 17 Jul 2021 at 20:24, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Clang warnings about questionable atomic usage get localized
> to the inline function in atomic.h.  By using a macro, we get
> the full traceback to the original use that caused the warning.
>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  include/qemu/atomic.h | 25 +++++--------------------
>  1 file changed, 5 insertions(+), 20 deletions(-)
>
> diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h
> index 3ccf84fd46..99d6030095 100644
> --- a/include/qemu/atomic.h
> +++ b/include/qemu/atomic.h
> @@ -457,26 +457,11 @@
>
>  /* Abstractions to access atomically (i.e. "once") i64/u64 variables */
>  #ifdef CONFIG_ATOMIC64
> -static inline int64_t qatomic_read_i64(const int64_t *ptr)
> -{
> -    /* use __nocheck because sizeof(void *) might be < sizeof(u64) */
> -    return qatomic_read__nocheck(ptr);
> -}
> -
> -static inline uint64_t qatomic_read_u64(const uint64_t *ptr)
> -{
> -    return qatomic_read__nocheck(ptr);
> -}
> -
> -static inline void qatomic_set_i64(int64_t *ptr, int64_t val)
> -{
> -    qatomic_set__nocheck(ptr, val);
> -}
> -
> -static inline void qatomic_set_u64(uint64_t *ptr, uint64_t val)
> -{
> -    qatomic_set__nocheck(ptr, val);
> -}
> +/* Use __nocheck because sizeof(void *) might be < sizeof(u64) */
> +#define qatomic_read_i64  qatomic_read__nocheck
> +#define qatomic_read_u64  qatomic_read__nocheck
> +#define qatomic_set_i64   qatomic_set__nocheck
> +#define qatomic_set_u64   qatomic_set__nocheck

Previously if you tried to do qatomic_set_i64() etc on something
that wasn't an int64_t*, the compiler would complain. Now it will
silently store a different-sized value, I think. Is there a way
to retain the typechecking in the macro versions?

thanks
-- PMM

Re: [PATCH v3 01/10] qemu/atomic: Use macros for CONFIG_ATOMIC64
Posted by Richard Henderson 4 years, 6 months ago
On 7/19/21 2:01 AM, Peter Maydell wrote:
>> -static inline void qatomic_set_u64(uint64_t *ptr, uint64_t val)
>> -{
>> -    qatomic_set__nocheck(ptr, val);
>> -}
...
>> +#define qatomic_set_u64   qatomic_set__nocheck
> 
> Previously if you tried to do qatomic_set_i64() etc on something
> that wasn't an int64_t*, the compiler would complain. Now it will
> silently store a different-sized value, I think. Is there a way
> to retain the typechecking in the macro versions?

I can add a trivial _Generic wrapper.


r~