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: 1889545 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Me+9fJgD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TK0BJ6NQ6z1yPg for ; Tue, 23 Jan 2024 19:10:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7C0E4385841A for ; Tue, 23 Jan 2024 08:09:58 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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