From patchwork Fri Feb 23 08:42:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 86257 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 600F93858283 for ; Fri, 23 Feb 2024 08:43:05 +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 18ED43858437 for ; Fri, 23 Feb 2024 08:42:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18ED43858437 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 18ED43858437 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=1708677743; cv=none; b=qi0i3sYvmutK84V7qJvml+iFVX8b6XS0cbxHZ+XcQsU6A604RuLn9jBF5C7CG4Q22ZPDqjNzR1Qxsl/ui0NFenrDh/kkoFrStGh5gfIW7+0LgF2DarFuZ7g2ASMMu4uObrntAqZ1X+3unocIQvQjWdYmi7Ak7GeO+wkgMkL9TcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708677743; c=relaxed/simple; bh=abIe3RTvII33KnjkOjr08joTWgJjZ29S6COZdz/MkXM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=v0IaxIDRYuktgsBzyYbvMmXkUS0a1Kv8Slrml5lcrB+NrXzitdxwPbWSTFjoZUYNAsHUV2Fed2RyTOEv9RZvGErlpF2gZMqAH0rO0FP+XlTknfjovt7ohmgAU2NbKR5pub/wGoGVAItIL9JQUmZl8R2WfUcANY+p4AQvnaJnhrA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708677741; 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=hNJhZn/Iuw48TLiYerKgcojJWtvwKVcUmhR0MmU9V9Y=; b=SGL0v2Gs/WxKXoEjyuVmW0zsDe0dTctulEn4cW+FUtTiy6zWDUbrnO/Ba0oSpWxV8cJlxK YGzaIX4/Fnf/dBcChP8HlFOkWr5825NPqIvlcv8DXsQsS1BSp1CfqAHPgtngMmYCFOHTHE MFI71ZOvQ2uhcB2jlRb5RO4h9GgFQ6s= 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-127-RIJdK9fGMP2nx53FdHLksg-1; Fri, 23 Feb 2024 03:42:18 -0500 X-MC-Unique: RIJdK9fGMP2nx53FdHLksg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 2830D1065170; Fri, 23 Feb 2024 08:42:18 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E0030C185C0; Fri, 23 Feb 2024 08:42:17 +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 41N8gF2c956020 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 09:42:15 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41N8gEOR956019; Fri, 23 Feb 2024 09:42:14 +0100 Date: Fri, 23 Feb 2024 09:42:14 +0100 From: Jakub Jelinek To: Jason Merrill , Christophe Lyon Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix ICE due to folding a call to constructor on cdtor_returns_this arches (aka arm32) [PR113083] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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_H2, 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+patchwork=sourceware.org@gcc.gnu.org Hi! When targetm.cxx.cdtor_returns_this () (aka on arm32 TARGET_AAPCS_BASED) constructor is supposed to return this pointer, but when we cp_fold such a call, we don't take that into account and just INIT_EXPR the object, so we can later ICE during gimplification, because the expression doesn't have the right type. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux and tested with a cross to armv7-linux-gnueabi on the testcase, but unfortunately there are no 32-bit arm boxes in cfarm and arm32 is gone from Fedora for quite some time as well, so I have no easy way to test this. Christophe, do you think you could test this? Thanks. 2024-02-23 Jakub Jelinek PR c++/113083 * cp-gimplify.cc (cp_fold): For targetm.cxx.cdtor_returns_this () wrap r into a COMPOUND_EXPR and return folded CALL_EXPR_ARG (x, 0). * g++.dg/cpp0x/constexpr-113083.C: New test. Jakub --- gcc/cp/cp-gimplify.cc.jj 2024-02-22 21:45:09.663430066 +0100 +++ gcc/cp/cp-gimplify.cc 2024-02-22 22:30:23.481428242 +0100 @@ -3412,9 +3412,15 @@ cp_fold (tree x, fold_flags_t flags) if (DECL_CONSTRUCTOR_P (callee)) { loc = EXPR_LOCATION (x); - tree s = build_fold_indirect_ref_loc (loc, - CALL_EXPR_ARG (x, 0)); + tree a = CALL_EXPR_ARG (x, 0); + bool return_this = targetm.cxx.cdtor_returns_this (); + if (return_this) + a = cp_save_expr (a); + tree s = build_fold_indirect_ref_loc (loc, a); r = cp_build_init_expr (s, r); + if (return_this) + r = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (x), r, + fold_convert_loc (loc, TREE_TYPE (x), a)); } x = r; break; --- gcc/testsuite/g++.dg/cpp0x/constexpr-113083.C.jj 2024-01-13 00:05:00.077372302 +0100 +++ gcc/testsuite/g++.dg/cpp0x/constexpr-113083.C 2024-02-22 22:20:20.622618992 +0100 @@ -0,0 +1,16 @@ +// PR c++/113083 +// { dg-do compile { target c++11 } } +// { dg-options "-Os" } + +struct A { constexpr A (); }; + +void +foo () +{ + A b; +} + +constexpr +A::A () +{ +}