From patchwork Fri Sep 20 15:21:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Martin X-Patchwork-Id: 1987929 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=nasilyan.com header.i=@nasilyan.com header.a=rsa-sha256 header.s=tey23rxsjton5kop5bydp3vc5ylkyjkg header.b=aQJx4+nj; dkim=pass (1024-bit key; unprotected) header.d=amazonses.com header.i=@amazonses.com header.a=rsa-sha256 header.s=uku4taia5b5tsbglxyj6zym32efj7xqv header.b=ONVEzHXk; 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 4X9GLv3V16z1y27 for ; Sat, 21 Sep 2024 01:21:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D68623858C5F for ; Fri, 20 Sep 2024 15:21:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from a2-122.smtp-out.eu-west-1.amazonses.com (a2-122.smtp-out.eu-west-1.amazonses.com [54.240.2.122]) by sourceware.org (Postfix) with ESMTPS id 816103858D29 for ; Fri, 20 Sep 2024 15:21:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 816103858D29 Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=nasilyan.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eu-west-1.amazonses.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 816103858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.240.2.122 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726845665; cv=none; b=WpGIfHmyswMadtnJME7jJElY+jHXcL4VPD1rTKiLzKXEVpXkUPknlPUMjGCShctO1lXkiXHdMfM2p07DicXYN/IVrCyXF19/qkPX8q7sIY9UP7xQ/B2Z8w5nWBpeoMoaUSrZhT2vYwO+HpFN0/EjP7TNFR5Wodl5H7RbTCSe+YA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726845665; c=relaxed/simple; bh=dYzSUoA0xyINs2+8Ewnt2CI2WgPtX2ju7W0EYZ6Hwsk=; h=DKIM-Signature:DKIM-Signature:Subject:From:To:Date:Mime-Version: Message-ID; b=aByaDKytucWusXjCJVqoLo+e+rvV5shQYhds0BZ/JRB6DUHWi77e0GAn1LcWvnrogPMs5pVqA26MA35fyrknc06kv5zgHdzdGlpcn+aNCqya2KewzUA5EsCp63ykIuWCOqdBA4k93gvsDvLWPIXylzruftdZbSy1y9j8mEX3ccg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=tey23rxsjton5kop5bydp3vc5ylkyjkg; d=nasilyan.com; t=1726845661; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id; bh=dYzSUoA0xyINs2+8Ewnt2CI2WgPtX2ju7W0EYZ6Hwsk=; b=aQJx4+njmJrzLYZNGNThc8rmLF2/Cs4GMJCMxAyp46ksYhB8WW0lSzCE5ewbBaVW b9irnB/5OAFylHGv4ka2+TgGSFFhQt3fZt4a8xe1WMZ+6nUR9mcnDebUjj7SvDu8a7J 6ApEGNrLDEVuI8lGZwNljQPtqrqn6n5R8XCYBgbQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1726845661; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id:Feedback-ID; bh=dYzSUoA0xyINs2+8Ewnt2CI2WgPtX2ju7W0EYZ6Hwsk=; b=ONVEzHXkuDeSYlJWT4AlKfVR3sPDXU42uNEvVRFvIpaxt0hnDiFmwSq4DT0Z+bpo 6Vuolx0Opj3Gm6PaMhiEuKuyfu2i8KttFmc1g4xbUT1hgnldMFilC5/L838EWJDOu9/ 47NC2a/1jm3Svjg3MZB+fQ0aenF4e76oCKMudVoc= Subject: [PATCH] c++: Don't ICE due to artificial constructor parameters [PR116722] From: =?utf-8?q?Simon_Martin?= To: =?utf-8?q?gcc-patches=40gcc=2Egnu=2Eorg?= Date: Fri, 20 Sep 2024 15:21:01 +0000 Mime-Version: 1.0 References: <20240920152057.29767-1-simon@nasilyan.com> X-Mailer: Amazon WorkMail Thread-Index: AQHbC3CyEirL5Pb1Q3aMXq8H35I4mg== Thread-Topic: [PATCH] c++: Don't ICE due to artificial constructor parameters [PR116722] X-Original-Mailer: git-send-email 2.44.0 X-Wm-Sent-Timestamp: 1726845660 Message-ID: <010201921005af84-94b13c14-e527-438d-bcd9-437f012338aa-000000@eu-west-1.amazonses.com> Feedback-ID: ::1.eu-west-1.b24dn6frgCi6dh20skzbuMRr7UL8M6Soir/3ogtEjHQ=:AmazonSES X-SES-Outgoing: 2024.09.20-54.240.2.122 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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~incoming=patchwork.ozlabs.org@gcc.gnu.org The following code triggers an ICE === cut here === class base {}; class derived : virtual public base { public: template constexpr derived(Arg) {} }; int main() { derived obj(1.); } === cut here === The problem is that cxx_bind_parameters_in_call ends up attempting to convert a REAL_CST (the first non artificial parameter) to INTEGER_TYPE (the type of the __in_chrg parameter), which ICEs. This patch teaches cxx_bind_parameters_in_call to handle the __in_chrg and __vtt_parm parameters that {con,de}structors might have. Note that in the test case, the constructor is not constexpr-suitable, however it's OK since it's a template according to my read of paragraph (3) of [dcl.constexpr]. Successfully tested on x86_64-pc-linux-gnu. PR c++/116722 gcc/cp/ChangeLog: * constexpr.cc (cxx_bind_parameters_in_call): Leave artificial constructor parameters as is. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-ctor22.C: New test. --- gcc/cp/constexpr.cc | 10 +++++++++- gcc/testsuite/g++.dg/cpp0x/constexpr-ctor22.C | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-ctor22.C diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index f6fd059be46..815f93b1d47 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -1871,13 +1871,21 @@ cxx_bind_parameters_in_call (const constexpr_ctx *ctx, tree t, tree fun, x = get_nth_callarg (t, i); /* For member function, the first argument is a pointer to the implied object. For a constructor, it might still be a dummy object, in - which case we get the real argument from ctx. */ + which case we get the real argument from ctx. */ if (i == 0 && DECL_CONSTRUCTOR_P (fun) && is_dummy_object (x)) { x = ctx->object; x = build_address (x); } + /* Leave the __in_chrg and __vtt_parm parameters of *structors of classes + with virtual bases as is. */ + if ((i == 1 && DECL_HAS_IN_CHARGE_PARM_P (fun)) + || (i == 2 && DECL_HAS_VTT_PARM_P (fun))) + { + TREE_VEC_ELT (binds, i) = arg; + continue; + } if (TREE_ADDRESSABLE (type)) { /* Undo convert_for_arg_passing work here. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor22.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor22.C new file mode 100644 index 00000000000..279f6ec4454 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor22.C @@ -0,0 +1,15 @@ +// PR c++/116722 +// We're now accepting this in spite of the virtual base class. This is OK +// according to [dcl.constexpr] 3: "Except for instantiated constexpr functions +// non-templated constexpr functions shall be constexpr-suitable". +// { dg-do compile { target c++11 } } + +class base {}; +class derived : virtual public base { +public: + template + constexpr derived(Arg) {} +}; +int main() { + derived obj(1.); +}