From nobody Wed Nov 5 22:17:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538145475959414.52878845362227; Fri, 28 Sep 2018 07:37:55 -0700 (PDT) Received: from localhost ([::1]:43712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5ttv-0004SG-Fr for importer@patchew.org; Fri, 28 Sep 2018 10:37:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5tsU-0003eq-0n for qemu-devel@nongnu.org; Fri, 28 Sep 2018 10:36:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5tiE-000760-7D for qemu-devel@nongnu.org; Fri, 28 Sep 2018 10:25:47 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48708) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5tiD-00074H-VY for qemu-devel@nongnu.org; Fri, 28 Sep 2018 10:25:46 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1g5ti5-0003mO-8H; Fri, 28 Sep 2018 15:25:37 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 28 Sep 2018 15:25:33 +0100 Message-Id: <20180928142533.8451-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e 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: Riku Voipio , Richard Henderson , Laurent Vivier , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Our __get_user_e() and __put_user_e() macros cause newer versions of clang to generate false-positive -Waddress-of-packed-member warnings if they are passed the address of a member of a packed struct (see https://bugs.llvm.org/show_bug.cgi?id=3D39113). Suppress these using the _Pragma() operator. To put in the pragmas we need to convert the macros from expressions to statements, but all the callsites effectively treat them as statements already so this is OK. Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Reviewed-by: Liam Merwick --- linux-user/qemu.h | 57 +++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index b4959e41c6e..56c4f2d5374 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -461,27 +461,46 @@ static inline int access_ok(int type, abi_ulong addr,= abi_ulong size) These are usually used to access struct data members once the struct has been locked - usually with lock_user_struct. */ =20 -/* Tricky points: - - Use __builtin_choose_expr to avoid type promotion from ?:, - - Invalid sizes result in a compile time error stemming from - the fact that abort has no parameters. - - It's easier to use the endian-specific unaligned load/store - functions than host-endian unaligned load/store plus tswapN. */ +/* + * Tricky points: + * - Use __builtin_choose_expr to avoid type promotion from ?:, + * - Invalid sizes result in a compile time error stemming from + * the fact that abort has no parameters. + * - It's easier to use the endian-specific unaligned load/store + * functions than host-endian unaligned load/store plus tswapN. + * - The pragmas are necessary only to silence a clang false-positive + * warning: see https://bugs.llvm.org/show_bug.cgi?id=3D39113 . + * - We have to disable -Wpragmas warnings to avoid a complaint about + * an unknown warning type from older compilers that don't know about + * -Waddress-of-packed-member. + */ +#define __put_user_e(x, hptr, e) = \ + do { = \ + _Pragma("GCC diagnostic push"); = \ + _Pragma("GCC diagnostic ignored \"-Wpragmas\""); = \ + _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\""); = \ + (__builtin_choose_expr(sizeof(*(hptr)) =3D=3D 1, stb_p, = \ + __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 2, stw_##e##_p, = \ + __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 4, stl_##e##_p, = \ + __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 8, stq_##e##_p, abort= )))) \ + ((hptr), (x)), (void)0); = \ + _Pragma("GCC diagnostic pop"); = \ + } while (0) =20 -#define __put_user_e(x, hptr, e) \ - (__builtin_choose_expr(sizeof(*(hptr)) =3D=3D 1, stb_p, = \ - __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 2, stw_##e##_p, = \ - __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 4, stl_##e##_p, = \ - __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 8, stq_##e##_p, abort)))) = \ - ((hptr), (x)), (void)0) +#define __get_user_e(x, hptr, e) = \ + do { = \ + _Pragma("GCC diagnostic push"); = \ + _Pragma("GCC diagnostic ignored \"-Wpragmas\""); = \ + _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\""); = \ + ((x) =3D (typeof(*hptr))( = \ + __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 1, ldub_p, = \ + __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 2, lduw_##e##_p, = \ + __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 4, ldl_##e##_p, = \ + __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 8, ldq_##e##_p, abort= )))) \ + (hptr)), (void)0); = \ + _Pragma("GCC diagnostic pop"); = \ + } while (0) =20 -#define __get_user_e(x, hptr, e) \ - ((x) =3D (typeof(*hptr))( \ - __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 1, ldub_p, = \ - __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 2, lduw_##e##_p, = \ - __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 4, ldl_##e##_p, = \ - __builtin_choose_expr(sizeof(*(hptr)) =3D=3D 8, ldq_##e##_p, abort)))) = \ - (hptr)), (void)0) =20 #ifdef TARGET_WORDS_BIGENDIAN # define __put_user(x, hptr) __put_user_e(x, hptr, be) --=20 2.19.0