From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 60EF01F47C for ; Sun, 15 Jan 2023 01:20:40 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=VSI1Xqy/; dkim-atps=neutral Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGrh2-0006vt-Ir; Sat, 14 Jan 2023 20:20:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGrh1-0006tt-4t for bug-gnulib@gnu.org; Sat, 14 Jan 2023 20:20:15 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pGrgz-00021b-Eq for bug-gnulib@gnu.org; Sat, 14 Jan 2023 20:20:14 -0500 Received: by mail-pj1-x1030.google.com with SMTP id z9-20020a17090a468900b00226b6e7aeeaso27978645pjf.1 for ; Sat, 14 Jan 2023 17:20:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7ll9cTxdba0wMySoYwt8NESiVBFAfWZXJIwzzPWG6zs=; b=VSI1Xqy/X5yJ+zivU94RrRssmHOQcVUBfImS2b0tc6qSm8edtQHB/4HPH73NZDIQ6G +4EOrXec4R6fWmPN5rDxbSu2fR2D9KsJ1EB0VbOw5mHLvB8sXC1da0b0khg2VBhMQY1K HG2eG5gLymaA+vCNIINFwY4wk5wVN1rmspurapd7dIUwi4hx9+Mc0elRuY0TsrNPpTAx wBOdv6lsybKxjfs3j71RyrSTQnGdb9mSDGi+TXOYNWcctO+SJsmV+o9DkgY3fB7kGu3s dhum8KZzI0JCp488g6oziqcSedf26KGFQzmK538/VAF6eaQhE9HvGpwGrHaaQCKApmJr MfbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7ll9cTxdba0wMySoYwt8NESiVBFAfWZXJIwzzPWG6zs=; b=HR2RSF2od4qmiADi9PKLMNXCaRetL1OdELxcZIbEMy2QUaBeJDEga+qKHAZbMpUYXv KLQy3yAmwErUAu1YCahOKA/2gs224u/XthTtLUiRuolI69DoKzMdOgj+RFZf48W7w5MB JeQs8M8R2jNZji00zpWN0Ql+eW7C9XANNsLpfv1uF07U1VmlVQ+LQXLp7noItF5OeNhc TYsfEQnIjLpIe/NmOOOrE6Vd2AbFBz40zyHANrKuchnaXKyBRnQJMzPqFO0qzfU8IR3l nXBgoD6qtFCBTHBWThQKE8seKzNikN2QM7TARoPo612Vk5uj0ATArJ1vwSWl5F7yYPLL mXqQ== X-Gm-Message-State: AFqh2kpBVVF3UEBIa2cetOk3lDCfb2PL5vZ+rYTFyeFxBdaMK1iufHFU 29pWj2/MzV9VoPkjtSE4DOo5KIx6joyMbA== X-Google-Smtp-Source: AMrXdXtvdRcg0f79y03aCtGS2t08EHLE16pPU5voHyZ/9c+fDVyOe3ZGIIvwWHOOVVoHiW5Bo7u+gQ== X-Received: by 2002:a17:903:3245:b0:194:75cf:71b3 with SMTP id ji5-20020a170903324500b0019475cf71b3mr6086970plb.53.1673745611548; Sat, 14 Jan 2023 17:20:11 -0800 (PST) Received: from apollo.hsd1.ca.comcast.net ([2601:646:9181:1cf0::b940]) by smtp.gmail.com with ESMTPSA id z15-20020a170903018f00b00189f2fdc178sm16526927plg.177.2023.01.14.17.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 17:20:10 -0800 (PST) From: Khem Raj To: bug-gnulib@gnu.org Cc: Khem Raj Subject: [PATCH v2] Define alignof_slot using _Alignof when using C11 or newer Date: Sat, 14 Jan 2023 17:20:07 -0800 Message-Id: <20230115012007.2175339-1-raj.khem@gmail.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=raj.khem@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org WG14 N2350 made very clear that it is an UB having type definitions within "offsetof" [1]. This patch enhances the implementation of macro alignof_slot to use builtin "_Alignof" to avoid undefined behavior on when using std=c11 or newer. Make exceptions for gcc < 4.9 and clang < 8 where there is bug [3] in _Alignof implementation clang 16+ has started to flag this [2] Fixes build when using -std >= gnu11 and using clang16+ [1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm [2] https://reviews.llvm.org/D133574 [3] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023 Signed-off-by: Khem Raj --- v1->v2: - Exclude gcc < 4.9 and clang < 8 even though they may have C11 support ChangeLog | 5 +++++ lib/alignof.h | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fb467a3c14..33c0a0bb8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2023-01-15 Khem Raj + + * lib/alignof.h (alignof_slot): Use _Alignof when using C11 or newer + standard barring GCC < 4.9 and clang < 8. + 2023-01-14 Bruno Haible error, verror tests: Fix link error when the package uses libintl. diff --git a/lib/alignof.h b/lib/alignof.h index 505ad97aa4..962c8f31f4 100644 --- a/lib/alignof.h +++ b/lib/alignof.h @@ -28,8 +28,16 @@ #if defined __cplusplus template struct alignof_helper { char __slot1; type __slot2; }; # define alignof_slot(type) offsetof (alignof_helper, __slot2) -#else +/* GCC releases before GCC 4.9 had a bug in _Alignof. See GCC bug 52023 + . + clang versions < 8.0.0 have the same bug. */ +#elif (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \ + || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \ + && !defined __clang__) \ + || (defined __clang__ && __clang_major__ < 8)) # define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, __slot2) +#else +# define alignof_slot(type) _Alignof(type) #endif /* alignof_type (TYPE) -- 2.39.0