From patchwork Mon Jan 8 01:01:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xndcn X-Patchwork-Id: 185777 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp772909dyq; Sun, 7 Jan 2024 17:02:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRLrZeJWmuSGUhcVyNfND+H8RD9v0HNKdGknjftlI/2ldprFBfN0BUmlMNR7rSAjxX/hmg X-Received: by 2002:a05:6358:42aa:b0:175:5832:4392 with SMTP id s42-20020a05635842aa00b0017558324392mr3184148rwc.12.1704675767406; Sun, 07 Jan 2024 17:02:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704675767; cv=pass; d=google.com; s=arc-20160816; b=HIUnEAbZASRG2jEc1yZ5o+JVp3z0L/g4Gon7Kz1oCPQyyaNPTkhZ4r2rnIHOb6d3wy LteoyQDK83tSD+xnwRVoXkb+gmLkSshiWLboRfjxVStRus9gyGdDTSx10rZPP5LIzxwc yaaEyINWMAOj4oI2Sc/lQsKVmcRFWb3/DgOnOUqoC433GqD2nba1c+mMZEb75tZkk35j tsGoM+IFeypyDM1xC4m7VpvRCHPiZkjfKjN++TVrtiatiAiUE45DxWUf4pbEPFIpvFBJ OkWKYdkuCnuQ+xX2VXMeoAE8a/bNfuBB25FWylX7ZkmQoQvXcN0Qvcp2WYdz8fuLKEbx zVYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:to:subject:message-id:date:from :mime-version:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=8UCSnpdpk7sINdyocMb15VDEr8ErtuPWtuQBTBYn1GI=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=r3StQfe1bNqatPcVqps1TApz9a2amqLSaiU63dJaLqAw21sWKXd69Qe8ozG4uaWddj GLZvuqrtfvgNhjTSEVLnFcAGBiiQl6x9HbqycR2UWNhOCeWQdAxL+yyTVINR3H3RUd1d fQzN/6Z/sqAfLopWvrfzj63Kpb3FGMS+VeNelNtPr28L+MU0yw5em/ulvsNStw4QefxV QmahQGbtvzdSM9DEgPELDnuh9Ru+sn0LVXqj9atvrSf+vuJFD+1BehCzWq4fw+TVvvLD JYj9QEMlRNOyLi81wfLiRYDDYHWaT+G1+B36R4uIY7JXqOwiO/KYWh3jxfO2H08rjUz+ sOBQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Rr1iQY1/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id r25-20020a0c9e99000000b006794ec8bf24si6876507qvd.384.2024.01.07.17.02.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 17:02:47 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Rr1iQY1/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1BEF43858427 for ; Mon, 8 Jan 2024 01:02:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 4C3493858C62 for ; Mon, 8 Jan 2024 01:02:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C3493858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4C3493858C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704675724; cv=none; b=gQEvCvN9cOADVXA/qBwRByIcKL3Zi6ZeyzaRCr1GF4dfETc/roQTAPIRQ7/Gz3DUsD9+4jX6xhFpxk/PGAD5bKNbbUA7oqXTdB5jGP5emirgYgM4NTV3GjJFHmDcUsnxj9GSOr9sHSaGQVDsW0dN2VxIp0Xg/Aa8wOF+FahSEo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704675724; c=relaxed/simple; bh=TzBr/KjAZBPPvW5Ez/fEWiqdfn9Hl1ia5qaj7smZJgI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=DuxrWQJgSG9vYUgiM4UbvbxvvUx+96wfIQWnJoeHKAKnJ73wVcFiaymSdtpFCKM2C1UkBgTDU8rUC3xtau3e9X3/9cFnuBm3//ER15wMbEdmjTN6yDbv6qAKqYJsCyxBzhh+6mChxQBJV1NpathfDxLHGrWdKCOeIiNB0q22WeY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5576fae29ffso1032110a12.1 for ; Sun, 07 Jan 2024 17:02:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704675720; x=1705280520; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=8UCSnpdpk7sINdyocMb15VDEr8ErtuPWtuQBTBYn1GI=; b=Rr1iQY1/lPqL2qcrSrBfCMEEbWbki+nVYbC52vtzZmtTWyZwN3FtSU3AeH4m843+EO LSUJ6oc3z5b82RdCrOg2N2eukyTybkuKCN3g019JkVzuD30RFMstfmUggfIXYScyyX1R FVoDzU4g2I58cxG0CGmIBw9lXGCNBl/xiAnZ+8MC8wzJheQ29ZC44bUhcKF7En13DMfL rfT0ZYS8Oud4b/sKGvip4LQrzW2YmcLb4PhB30jyLLLb/BARyfgoru/YGxC5xdaSTaxo lRYHrEYZ/tv4npEg/W0I8T04yml0hfNhuD4fuZvRyNkuxdz+q/TpIj6N3hFk+g4zrQwc n6uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704675720; x=1705280520; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8UCSnpdpk7sINdyocMb15VDEr8ErtuPWtuQBTBYn1GI=; b=ToZCFZRiu7AUau9IuF0Znx2/SuJCeYSbGavcKWjZ/l6y6m8z7VrCwZkcHO9bQrvoRZ 9gg/CN1Dg6sAGV/xnd4lQ4USaQnflTlT+12pKV1vxWBNWXyAWdSssjqVKhKUn8h6K8jN Op6xl1EdaQQSD/6Tl4IwRJfY6KDOeXCFXPkCrKNMWQzBaehNVChjrDRlc9IfEfgZcdsG GEHyolIbgXfzR9+LFzA3aQr2OuFQEqc61eu2kgpyOdc/rrl0LAC0L5OOQCpzuKFCtp7L kSa86vq6jnDWjg4as86rvXG0UJHSpTy/WGndppa+6w7Iy+Gix/QT3fbN1Dh/ZKPRNcIA Tnzg== X-Gm-Message-State: AOJu0YyAKihEUGdTtzKLmZ/Qjw0u7I8hrOoKBF/WXBB94eZGL43Ti6C2 T7EAdU6u50qSwR9bHoy8ZNGnPdtP2uHfNlERgbgDyi2YMKA= X-Received: by 2002:a17:906:16cb:b0:a26:84d8:9411 with SMTP id t11-20020a17090616cb00b00a2684d89411mr1100691ejd.128.1704675720461; Sun, 07 Jan 2024 17:02:00 -0800 (PST) MIME-Version: 1.0 From: xndcn Date: Mon, 8 Jan 2024 09:01:48 +0800 Message-ID: Subject: [PATCH] libstdc++: atomic: Add missing clear_padding in __atomic_float constructor To: gcc-patches@gcc.gnu.org X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787482097567618415 X-GMAIL-MSGID: 1787482097567618415 Hi, I found __atomic_float constructor does not clear padding, while __compare_exchange assumes it as zeroed padding. So it is easy to reproducing a infinite loop in X86-64 with long double type like: Signed-off-by: xndcn Signed-off-by: xndcn --- -O0 -std=c++23 -mlong-double-80 #include #include #define T long double int main() { std::atomic t(0.5); t.fetch_add(0.5); float x = t; printf("%f\n", x); } --- So we should add __builtin_clear_padding in __atomic_float constructor, just like the generic atomic struct. regtested on x86_64-linux. Is it OK for trunk? --- libstdc++: atomic: Add missing clear_padding in __atomic_float constructor. libstdc++-v3/ChangeLog: * include/bits/atomic_base.h: add __builtin_clear_padding in __atomic_float constructor. --- libstdc++-v3/include/bits/atomic_base.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index f4ce0fa53..d59c2209e 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -1283,7 +1283,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr __atomic_float(_Fp __t) : _M_fp(__t) - { } + { +#if __has_builtin(__builtin_clear_padding) + if _GLIBCXX17_CONSTEXPR (__atomic_impl::__maybe_has_padding<_Fp>()) + __builtin_clear_padding(std::__addressof(_M_fp)); +#endif + } __atomic_float(const __atomic_float&) = delete; __atomic_float& operator=(const __atomic_float&) = delete;