Received: from eggs.gnu.org ([2001:4830:134:3::10]:43948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWgqH-00014P-Dz for qemu-devel@nongnu.org; Mon, 08 Aug 2016 05:27:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWgqD-0003w9-8E for qemu-devel@nongnu.org; Mon, 08 Aug 2016 05:27:28 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36473) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWgqC-0003w3-U5 for qemu-devel@nongnu.org; Mon, 08 Aug 2016 05:27:25 -0400 Received: by mail-wm0-x243.google.com with SMTP id x83so14218085wma.3 for ; Mon, 08 Aug 2016 02:27:24 -0700 (PDT) Sender: Paolo Bonzini References: <20160807014121.18739-1-bobby.prani@gmail.com> <31b8d7c7-6a5c-910f-b799-25a8e00c8908@redhat.com> From: Paolo Bonzini Message-ID: Date: Mon, 8 Aug 2016 11:27:22 +0200 MIME-Version: 1.0 In-Reply-To: <31b8d7c7-6a5c-910f-b799-25a8e00c8908@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/1] seqlock: Fix warning reg. incompatible cast List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pranith Kumar , Richard Henderson , "Emilio G. Cota" , =?UTF-8?Q?Alex_Benn=c3=a9e?= , Sergey Fedorov , Markus Armbruster , "open list:All patches CC here" On 08/08/2016 11:05, Paolo Bonzini wrote: >> > /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 qualifier >> > s [-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); \ >> > ^~~~~ >> > /home/pranith/devops/code/qemu/include/qemu/compiler.h:62:43: note: expanded from macro 'unlikely' >> > #define unlikely(x) __builtin_expect(!!(x), 0) >> > >> > Signed-off-by: Pranith Kumar > This is a compiler bug, isn't it? Atomic loads of a const pointer > should be allowed. Oh, this is &_val having a const type. That makes more sense indeed, but it should be worked around in qemu/atomic.h. Can you check if this works? diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 7e13fca..9c664a7 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -54,7 +54,7 @@ #define atomic_read(ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val; \ + typeof(*ptr+0) _val; \ __atomic_load(ptr, &_val, __ATOMIC_RELAXED); \ _val; \ }) @@ -80,7 +80,7 @@ #define atomic_rcu_read(ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val; \ + typeof(*ptr+0) _val; \ atomic_rcu_read__nocheck(ptr, &_val); \ _val; \ }) @@ -103,7 +103,7 @@ #define atomic_mb_read(ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val; \ + typeof(*ptr+0) _val; \ __atomic_load(ptr, &_val, __ATOMIC_RELAXED); \ smp_rmb(); \ _val; \ @@ -120,7 +120,7 @@ #define atomic_mb_read(ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val; \ + typeof(*ptr+0) _val; \ __atomic_load(ptr, &_val, __ATOMIC_SEQ_CST); \ _val; \ }) @@ -137,7 +137,7 @@ #define atomic_xchg(ptr, i) ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _new = (i), _old; \ + typeof(*ptr+0) _new = (i), _old; \ __atomic_exchange(ptr, &_new, &_old, __ATOMIC_SEQ_CST); \ _old; \ }) @@ -146,7 +146,7 @@ #define atomic_cmpxchg(ptr, old, new) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _old = (old), _new = (new); \ + typeof(*ptr+0) _old = (old), _new = (new); \ __atomic_compare_exchange(ptr, &_old, &_new, false, \ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ _old; \