From patchwork Tue Aug 9 19:02:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pranith Kumar X-Patchwork-Id: 9272089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B39B60871 for ; Tue, 9 Aug 2016 19:10:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 060AD27D9B for ; Tue, 9 Aug 2016 19:10:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E26CA28389; Tue, 9 Aug 2016 19:10:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 57C1127D9B for ; Tue, 9 Aug 2016 19:10:00 +0000 (UTC) Received: from localhost ([::1]:37556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXCPX-0007OI-3m for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Aug 2016 15:09:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXCIN-0007fK-RQ for qemu-devel@nongnu.org; Tue, 09 Aug 2016 15:02:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXCIJ-0002fk-KT for qemu-devel@nongnu.org; Tue, 09 Aug 2016 15:02:34 -0400 Received: from mail-yw0-x241.google.com ([2607:f8b0:4002:c05::241]:35118) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXCIJ-0002fX-Dq for qemu-devel@nongnu.org; Tue, 09 Aug 2016 15:02:31 -0400 Received: by mail-yw0-x241.google.com with SMTP id r9so912635ywg.2 for ; Tue, 09 Aug 2016 12:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=oFetG2MJjZaRMH3Ib4Vfb0zDfV4Fl52n7XDr5vKFkeQ=; b=VtrZbez6IO5tVcbYpUAaSZXH7zmoWVNWG1qboMhuMgVADd7tkKotLAZVnkbIZrpYeS qjfuacM3ScinwosrFtktZV0RWOuj09Kh2LZ7KpHfpdJKmSA+TqEbJl5iOppdQnlDbsgE maYw3yGUs9ur/fsSDI9Tu619lOcJU7qxe+mPOpdWbpdzdL3Z3v8HyAq2exGXnW7Y7WSD 3cgkdFnItuS8pLKjNjRaezC+UHVoA5YY1ymnnt64dDVYQRL0xJHWJUoDWH0Gh/5NyrOG RiIdXoEDb/r0z3SQOu/bWYM0BLamRQ9YJjK2W3Xlia7fl8iFEHt22Cv5Q5tnEmCDKcaT Culw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oFetG2MJjZaRMH3Ib4Vfb0zDfV4Fl52n7XDr5vKFkeQ=; b=NDM1n1mqftfu8Cjoo7S0DMHp4OtFbApKc1g2UPh9lH48P3qU1P7C5CXJmE9e1H4gFd TFqbpd4zOYDOWDCzkg7zDNryhFNwUDO5SSxYUvpY7STGIwegH6KAtzMD5aogAgvGGbIt u5z+P4jFelu29P+2X7Dma7u8CsVG+SUh5RGirYyklhkUyyP82SfBdz+ybHmKFugq/azC NnzI6VA74uc9ySvgXkRnPcgpIgYc0Vs2AELcC/gIg4huv58/RpccpVMs61M4gfEPA2XN K5ktbadhVvL7vUfgYryIywTLuvLLI4iCM/as8JKe8cIPMNzEVk4jlY+0cpavpD6T+cBm SiNA== X-Gm-Message-State: AEkoouuMhT8A/UxeYJdw0zrN3jFsQUVMTNPm0nyuC1W69xVXKA4RzSaoZjWGz52WUlacAw== X-Received: by 10.13.240.68 with SMTP id z65mr70243571ywe.297.1470769350776; Tue, 09 Aug 2016 12:02:30 -0700 (PDT) Received: from evgadesktop.attlocal.net (108-232-152-155.lightspeed.tukrga.sbcglobal.net. [108.232.152.155]) by smtp.gmail.com with ESMTPSA id t67sm16659070ywa.33.2016.08.09.12.02.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Aug 2016 12:02:30 -0700 (PDT) From: Pranith Kumar To: Paolo Bonzini , "Emilio G. Cota" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson , Markus Armbruster , qemu-devel@nongnu.org (open list:All patches CC here) Date: Tue, 9 Aug 2016 15:02:24 -0400 Message-Id: <20160809190229.27871-1-bobby.prani@gmail.com> X-Mailer: git-send-email 2.9.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c05::241 Subject: [Qemu-devel] [PATCH 1/5] atomic: strip "const" from variables declared with typeof X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini 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. Reported-by: Pranith Kumar Signed-off-by: Paolo Bonzini [pranith: Add conversion for bool type] Signed-off-by: Pranith Kumar --- include/qemu/atomic.h | 54 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 7e13fca..43b0645 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -18,6 +18,48 @@ /* 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), bool) || \ + __builtin_types_compatible_p(typeof(expr), const bool) || \ + __builtin_types_compatible_p(typeof(expr), volatile bool) || \ + __builtin_types_compatible_p(typeof(expr), const volatile bool), \ + (bool)1, \ + __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 +96,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 +122,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 +145,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 +162,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 +179,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 +188,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; \