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: 205229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp456853dyb; Fri, 23 Feb 2024 00:43:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVT5GJvKOch5DGWF8+j/iTSSHSIfi5dHZormMAmuat5FYZ/JHNKBU4CaDn3x4A74cY1Bvgc2wAjfWlqpaMTgmP08i+suQ== X-Google-Smtp-Source: AGHT+IHBtDksxdbIMMtbGXa4GN8GR8eWYzX4L6k6SCthRyf0C51SZdURsrwrO3J2tL+XLwqfAAbN X-Received: by 2002:a05:620a:cc7:b0:787:7e5e:c667 with SMTP id b7-20020a05620a0cc700b007877e5ec667mr1182623qkj.55.1708677805940; Fri, 23 Feb 2024 00:43:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708677805; cv=pass; d=google.com; s=arc-20160816; b=f6JtLYcSXsOS1+QGAy0Vp8J6LvrkmMJy3voKkRIhKZRHlKQA8u4shi65HNBaB2l2Fd GvTMxr59jiI9qHLcN4sb36wjhtFfcYyCUD6NGQqigzxHuLZUFwPOkIq/RU/AJyupE1uO MY0x6JkDDZ8k3HB0iwKMh45ieVbcCg7AP8ZvgNTad0fbkec0jb80bdGHNgPdSy94qfN7 5QbAy0Bb5VjR4NLrnjNFxRz3aDaGeKpIpI0yzfPuw4C4NnCm2ReWh41HNtBHMnJLyb/r GQhnR5gAb1e8/jLQ3pKg01+qAGp2SsRfwsmFU4bP09ys9vWazSKkOFuZc2hEUBvtjLWx BfZA== 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=hNJhZn/Iuw48TLiYerKgcojJWtvwKVcUmhR0MmU9V9Y=; fh=R0O4CZM5iKUEIHLJRgjWfIasCES7jZ36ABmaOwutFk8=; b=fnLTETcazpbtfj8Fr6njQ1rOv6X8UohCaAFxHhGdYwq+qOG6YnnquJ2OropGq4sQsr 4FxEU/8wRPR9SRuWjx5IaDUQkT/kNR5ksVGd5VZbDEflt2O62l4pZQDiNl/B6VoIdf0S YBN37LQnbAs2dcqg11qjBoSeoZn+lN8JOoiXj60eHnBsDhcERdRkEtgxYeS/Z1aWpfu5 dcTVqb94ro8mMJCwDGCMDOcrRoK1TV8i2WXV+zh+QFUF+PxbPDu7lDKyhN1FG0o2P2XX BSZPIVDGB+XxZ0fQywr3kZHIQMx5Dm1vGYpEw9wvbKXQ88jBu8ZsVouBmpLTQUWffVfj N61g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SGL0v2Gs; 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 p15-20020ae9f30f000000b007872ed36bcesi14235158qkg.636.2024.02.23.00.43.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 00:43: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=SGL0v2Gs; 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 9148B3858281 for ; Fri, 23 Feb 2024 08:43:25 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791678538946913250 X-GMAIL-MSGID: 1791678538946913250 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 () +{ +}