atomic: strip "const" from variables declared with typeof
PATCH 1/1 atomic: strip "const" from variables declared with typeof
With the latest clang, we have the following warning:
/home/pranith/devops/code/qemu/include/qemu/seqlock.h:62:21: warning: passing 'typeof (*&sl->sequence) *' (aka 'const unsigned int *') to parameter of type 'unsigned int *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
return unlikely(atomic_read(&sl->sequence) != start);
^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pranith/devops/code/qemu/include/qemu/atomic.h:58:25: note: expanded from macro 'atomic_read'
__atomic_load(ptr, &_val, __ATOMIC_RELAXED); \
^~~~~Stripping const is a bit tricky due to promotions, but it is doable with either C11 _Generic or GCC extensions. Use the latter.
--- include/qemu/atomic.h | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-)
include/qemu/atomic.h +42 -6
@@ -18,6 +18,42 @@/* Compiler barrier */ #define barrier () ({ asm volatile("" ::: "memory"); (void)0; }) +/* The variable that receives the old value of an atomically-accessed +* variable must be non-qualified, because atomic builtins return values +* through a pointer-type argument as in __atomic_load(&var, &old, MODEL). +* +* This macro has to handle types smaller than int manually, because of +* implicit promotion. int and larger types, as well as pointers, can be +* converted to a non-qualified type just by applying a binary operator. +*/ +#define typeof_strip_qual (expr) \ + typeof( \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(typeof(expr), signed char) || \ + __builtin_types_compatible_p(typeof(expr), const signed char) || \ + __builtin_types_compatible_p(typeof(expr), volatile signed char) || \ + __builtin_types_compatible_p(typeof(expr), const volatile signed char), \ + (signed char)1, \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(typeof(expr), unsigned char) || \ + __builtin_types_compatible_p(typeof(expr), const unsigned char) || \ + __builtin_types_compatible_p(typeof(expr), volatile unsigned char) || \ + __builtin_types_compatible_p(typeof(expr), const volatile unsigned char), \ + (unsigned char)1, \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(typeof(expr), signed short) || \ + __builtin_types_compatible_p(typeof(expr), const signed short) || \ + __builtin_types_compatible_p(typeof(expr), volatile signed short) || \ + __builtin_types_compatible_p(typeof(expr), const volatile signed short), \ + (signed short)1, \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(typeof(expr), unsigned short) || \ + __builtin_types_compatible_p(typeof(expr), const unsigned short) || \ + __builtin_types_compatible_p(typeof(expr), volatile unsigned short) || \ + __builtin_types_compatible_p(typeof(expr), const volatile unsigned short), \ + (unsigned short)1, \ + (expr)+0))))) +#ifdef __ATOMIC_RELAXED/* For C11 atomic ops */
@@ -54,7 +90,7 @@#define atomic_read (ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val; \ + typeof_strip_qual(*ptr) _val; \ __atomic_load(ptr, &_val, __ATOMIC_RELAXED); \ _val; \ })
@@ -80,7 +116,7 @@#define atomic_rcu_read (ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val; \ + typeof_strip_qual(*ptr) _val; \ atomic_rcu_read__nocheck(ptr, &_val); \ _val; \ })
@@ -103,7 +139,7 @@#define atomic_mb_read (ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val; \ + typeof_strip_qual(*ptr) _val; \ __atomic_load(ptr, &_val, __ATOMIC_RELAXED); \ smp_rmb(); \ _val; \
@@ -120,7 +156,7 @@#define atomic_mb_read (ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val; \ + typeof_strip_qual(*ptr) _val; \ __atomic_load(ptr, &_val, __ATOMIC_SEQ_CST); \ _val; \ })
@@ -137,7 +173,7 @@#define atomic_xchg (ptr, i) ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _new = (i), _old; \ + typeof_strip_qual(*ptr) _new = (i), _old; \ __atomic_exchange(ptr, &_new, &_old, __ATOMIC_SEQ_CST); \ _old; \ })
@@ -146,7 +182,7 @@#define atomic_cmpxchg (ptr, old, new) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _old = (old), _new = (new); \ + typeof_strip_qual(*ptr) _old = (old), _new = (new); \ __atomic_compare_exchange(ptr, &_old, &_new, false, \ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ _old; \
Signature · 1 line
2.7.4
Your series seems to have some coding style problems. See output below for more information:
Hi,
Your series seems to have some coding style problems. See output below for more information:
Message-id: [email protected]
Type: series
Subject: [Qemu-devel] [PATCH for 2.7] atomic: strip "const" from variables declared with typeof
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git show --no-patch --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
5cd912b atomic: strip "const" from variables declared with typeof
=== OUTPUT BEGIN ===
Checking PATCH 1/1: atomic: strip "const" from variables declared with typeof...
WARNING: line over 80 characters
#38: FILE: include/qemu/atomic.h:29:
+#define typeof_strip_qual(expr) \
WARNING: line over 80 characters
#39: FILE: include/qemu/atomic.h:30:
+ typeof( \
WARNING: line over 80 characters
#40: FILE: include/qemu/atomic.h:31:
+ __builtin_choose_expr( \
WARNING: line over 80 characters
#41: FILE: include/qemu/atomic.h:32:
+ __builtin_types_compatible_p(typeof(expr), signed char) || \
WARNING: line over 80 characters
#42: FILE: include/qemu/atomic.h:33:
+ __builtin_types_compatible_p(typeof(expr), const signed char) || \
WARNING: line over 80 characters
#43: FILE: include/qemu/atomic.h:34:
+ __builtin_types_compatible_p(typeof(expr), volatile signed char) || \
WARNING: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #43: FILE: include/qemu/atomic.h:34:
+ __builtin_types_compatible_p(typeof(expr), volatile signed char) || \
WARNING: line over 80 characters
#44: FILE: include/qemu/atomic.h:35:
+ __builtin_types_compatible_p(typeof(expr), const volatile signed char), \
WARNING: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #44: FILE: include/qemu/atomic.h:35:
+ __builtin_types_compatible_p(typeof(expr), const volatile signed char), \
WARNING: line over 80 characters
#45: FILE: include/qemu/atomic.h:36:
+ (signed char)1, \
WARNING: line over 80 characters
#46: FILE: include/qemu/atomic.h:37:
+ __builtin_choose_expr( \
WARNING: line over 80 characters
#47: FILE: include/qemu/atomic.h:38:
+ __builtin_types_compatible_p(typeof(expr), unsigned char) || \
WARNING: line over 80 characters
#48: FILE: include/qemu/atomic.h:39:
+ __builtin_types_compatible_p(typeof(expr), const unsigned char) || \
WARNING: line over 80 characters
#49: FILE: include/qemu/atomic.h:40:
+ __builtin_types_compatible_p(typeof(expr), volatile unsigned char) || \
WARNING: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #49: FILE: include/qemu/atomic.h:40:
+ __builtin_types_compatible_p(typeof(expr), volatile unsigned char) || \
WARNING: line over 80 characters
#50: FILE: include/qemu/atomic.h:41:
+ __builtin_types_compatible_p(typeof(expr), const volatile unsigned char), \
WARNING: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #50: FILE: include/qemu/atomic.h:41:
+ __builtin_types_compatible_p(typeof(expr), const volatile unsigned char), \
WARNING: line over 80 characters
#51: FILE: include/qemu/atomic.h:42:
+ (unsigned char)1, \
WARNING: line over 80 characters
#52: FILE: include/qemu/atomic.h:43:
+ __builtin_choose_expr( \
WARNING: line over 80 characters
#53: FILE: include/qemu/atomic.h:44:
+ __builtin_types_compatible_p(typeof(expr), signed short) || \
WARNING: line over 80 characters
#54: FILE: include/qemu/atomic.h:45:
+ __builtin_types_compatible_p(typeof(expr), const signed short) || \
WARNING: line over 80 characters
#55: FILE: include/qemu/atomic.h:46:
+ __builtin_types_compatible_p(typeof(expr), volatile signed short) || \
WARNING: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #55: FILE: include/qemu/atomic.h:46:
+ __builtin_types_compatible_p(typeof(expr), volatile signed short) || \
WARNING: line over 80 characters
#56: FILE: include/qemu/atomic.h:47:
+ __builtin_types_compatible_p(typeof(expr), const volatile signed short), \
WARNING: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #56: FILE: include/qemu/atomic.h:47:
+ __builtin_types_compatible_p(typeof(expr), const volatile signed short), \
WARNING: line over 80 characters
#57: FILE: include/qemu/atomic.h:48:
+ (signed short)1, \
WARNING: line over 80 characters
#58: FILE: include/qemu/atomic.h:49:
+ __builtin_choose_expr( \
WARNING: line over 80 characters
#59: FILE: include/qemu/atomic.h:50:
+ __builtin_types_compatible_p(typeof(expr), unsigned short) || \
WARNING: line over 80 characters
#60: FILE: include/qemu/atomic.h:51:
+ __builtin_types_compatible_p(typeof(expr), const unsigned short) || \
WARNING: line over 80 characters
#61: FILE: include/qemu/atomic.h:52:
+ __builtin_types_compatible_p(typeof(expr), volatile unsigned short) || \
WARNING: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #61: FILE: include/qemu/atomic.h:52:
+ __builtin_types_compatible_p(typeof(expr), volatile unsigned short) || \
WARNING: line over 80 characters
#62: FILE: include/qemu/atomic.h:53:
+ __builtin_types_compatible_p(typeof(expr), const volatile unsigned short), \
WARNING: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #62: FILE: include/qemu/atomic.h:53:
+ __builtin_types_compatible_p(typeof(expr), const volatile unsigned short), \
WARNING: line over 80 characters
#63: FILE: include/qemu/atomic.h:54:
+ (unsigned short)1, \
ERROR: spaces required around that '+' (ctx:VxV)
#64: FILE: include/qemu/atomic.h:55:
+ (expr)+0)))))
^
total: 1 errors, 34 warnings, 90 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1