From patchwork Tue Jan 23 08:09:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 190768 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp186232dyi; Tue, 23 Jan 2024 00:10:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4BTOYXmSz4EGeJMC5FlakVH4l+ln39zsqsG4QiaNIaUXqaWSQnzgHhyXhVf3YGOS42MeR X-Received: by 2002:a05:6214:21ec:b0:681:8937:952e with SMTP id p12-20020a05621421ec00b006818937952emr568187qvj.57.1705997425054; Tue, 23 Jan 2024 00:10:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705997425; cv=pass; d=google.com; s=arc-20160816; b=IA9aEnL+s2s3DZA1CccwQsGSojNi60gd3sIZiIPQa4S/0ChKCW03AlQihdguSqdBnr f0U2TprOGAmwpycl4PBUxOwMnrWXYOBYkdbEZ+xpY6egm9WQ1TKn6irbR2xIpeOKTH4S diUthdrUhEi9YKm/VoSsXIqVaJW2gRUAlAdbLMRjqmDOx0XKE1Ijp+0BzgQNe992h6Mf t1IPCuoudgYGEk9BfHiUX6InwVQnERnKkO8FRo7sdVNGnsCnxS8TDrVsLr1GYHOzmBdg jmTcMMiCEVqcZVFZ0bc7S2nHRTHt3IT7PVoDO2N0gGZVSdPnv4qR/GN5FxkTnqVHBY+1 kJTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=kRxvRlcGvp1qizEOTjLO6VxHgy06eN/hoiH+D2f29aY=; fh=6Jq54U7/S3hLEk833LS+nb8PUV/tyyLGSWSrl1I2JxE=; b=Jldx5u1IOquwrNMIqhdIQo87zTADWkc+Cwe31T6Ik6JGjRxR9NZN8l6+2jRQtI/UxT KcxH4Rr/WMnZZ7j244mIBAXZ50eDvW3BNHjARi2azz01YtCeBTVbbMeO6yqx9miAyAm+ zwJDFnhfaY9YWkmXJaYaTrmtKKSKGw+y06iAcjoo1XitIXxdc/dgpqnquuAkzplIVOpC Vv9mPY1Dwqw7VYcPaVHiAj9bpvgvlRl/krZPESGbcoFevyRLglu3N+Rb58dS59ymOWzl 8YSW52xK/DnQ9DsH5E/PZVfiNIRksEBrA5sUFAE0xNnnneGLHDrjsJjq6KecX+UWXPEx yEmw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Me+9fJgD; 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=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e13-20020a05620a208d00b00781d12ac757si7217265qka.783.2024.01.23.00.10.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 00:10:25 -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=@redhat.com header.s=mimecast20190719 header.b=Me+9fJgD; 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=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE6D0385843A for ; Tue, 23 Jan 2024 08:10:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 7EDFD3858C5E for ; Tue, 23 Jan 2024 08:09:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7EDFD3858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7EDFD3858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705997376; cv=none; b=VQFjFA5hTlMPsrsdiO+/8vM1he4CAFcdNh8YZdtk99dv6iMu5pWq053+xUZQfzvQYGqY4f2wDHpj84ILDVytwkly2hmItWFXMUti/9XeVSAwC1OwBTnTgztXuc2YhqAdqKxithKm40MSqnx5AYjr8G7XcDFrT9dcvntXEkfMB0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705997376; c=relaxed/simple; bh=AB+FhQ2xhZZk8FuUgaWGM+MAbZ7GmCJiSQbS2ZSAHGg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=u/beCdQ7OMS8JktLcWasNVu9VJK9i6XNkuEv8DFj32W/T5VsdYgWvhSBoR4G7c+HQxEUN8AO1w3Mc96XD0EWSBMqBfuVpfu8zn1k+v0wbwxxl2vRPyTOPOcurMtMjMpchpSkdBnRLnXAjkIQB3h0g4sxLzbA46Xo+5x9P5ImuBM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705997372; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=kRxvRlcGvp1qizEOTjLO6VxHgy06eN/hoiH+D2f29aY=; b=Me+9fJgDDKmgqosnEJfC0HnCj14wRYATX+RUv1gcciCxdeYqyz+c3hEvbmz0QmSE/UWg6Y hdcIPXFsIRz68pWiipnbb0EVbRziGty4Lrn5FQEF0kLkvaopHFT+fZ1bJ1RGctEUEKkn/E 2WCOtOYGrUVbRrmzruXO0zx2XFPX0B4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-91-R45KbT9kNXGa3yPcJYpqDw-1; Tue, 23 Jan 2024 03:09:30 -0500 X-MC-Unique: R45KbT9kNXGa3yPcJYpqDw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3A1161065221 for ; Tue, 23 Jan 2024 08:09:30 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE91440D1B60; Tue, 23 Jan 2024 08:09:29 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 40N89R0e1250007 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 23 Jan 2024 09:09:28 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40N89Rx41250006; Tue, 23 Jan 2024 09:09:27 +0100 Date: Tue, 23 Jan 2024 09:09:26 +0100 From: Jakub Jelinek To: Joseph Myers , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Call c_fully_fold on __atomic_* operands in atomic_bitint_fetch_using_cas_loop [PR113518] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788867955597564304 X-GMAIL-MSGID: 1788867955597564304 Hi! As the following testcase shows, I forgot to call c_fully_fold on the __atomic_*/__sync_* operands called on _BitInt address, the expressions are then used inside of TARGET_EXPR initializers etc. and are never fully folded later, which means we can ICE e.g. on C_MAYBE_CONST_EXPR trees inside of those. The following patch fixes it, while the function currently is only called in the C FE because C++ doesn't support BITINT_TYPE, I think guarding the calls on !c_dialect_cxx () is safer. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-22 Jakub Jelinek PR c/113518 * c-common.cc (atomic_bitint_fetch_using_cas_loop): Call c_fully_fold on lhs_addr, val and model for C. * gcc.dg/bitint-77.c: New test. Jakub --- gcc/c-family/c-common.cc.jj 2024-01-03 12:07:03.384717147 +0100 +++ gcc/c-family/c-common.cc 2024-01-22 14:24:44.209262552 +0100 @@ -8082,6 +8082,12 @@ atomic_bitint_fetch_using_cas_loop (loca tree lhs_addr = (*orig_params)[0]; tree val = convert (nonatomic_lhs_type, (*orig_params)[1]); tree model = convert (integer_type_node, (*orig_params)[2]); + if (!c_dialect_cxx ()) + { + lhs_addr = c_fully_fold (lhs_addr, false, NULL); + val = c_fully_fold (val, false, NULL); + model = c_fully_fold (model, false, NULL); + } if (TREE_SIDE_EFFECTS (lhs_addr)) { tree var = create_tmp_var_raw (TREE_TYPE (lhs_addr)); --- gcc/testsuite/gcc.dg/bitint-77.c.jj 2024-01-22 14:40:22.505993511 +0100 +++ gcc/testsuite/gcc.dg/bitint-77.c 2024-01-22 14:40:02.445276390 +0100 @@ -0,0 +1,25 @@ +/* PR c/113518 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -std=c23" } */ + +#if __BITINT_MAXWIDTH__ >= 607 +_BitInt(607) v; +#else +_BitInt(63) v; +#endif + +void +foo (void) +{ + __atomic_fetch_or (&v, 1 << 31, __ATOMIC_RELAXED); +} + +#if __BITINT_MAXWIDTH__ >= 16321 +_BitInt(16321) w; + +void +bar (void) +{ + __atomic_fetch_add (&w, 1 << 31, __ATOMIC_SEQ_CST); +} +#endif