From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 967713858434 for ; Tue, 22 Mar 2022 23:56:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 967713858434 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-539-DQpL2TX4P8yLs29PKNJnJg-1; Tue, 22 Mar 2022 19:56:08 -0400 X-MC-Unique: DQpL2TX4P8yLs29PKNJnJg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 154501066543 for ; Tue, 22 Mar 2022 23:56:08 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.34.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5F4E2026614; Tue, 22 Mar 2022 23:56:04 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: FIX_TRUNC_EXPR in tsubst [PR102990] Date: Tue, 22 Mar 2022 19:55:57 -0400 Message-Id: <20220322235557.836257-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Mar 2022 23:56:13 -0000 This is a crash where a FIX_TRUNC_EXPR gets into tsubst_copy_and_build where it hits gcc_unreachable (). The history of tsubst_copy_and_build/FIX_TRUNC_EXPR is such that it was introduced in r181478, but it did the wrong thing, whereupon it was turned into gcc_unreachable () in r258821 (see this thread: ). In a template, we should never create a FIX_TRUNC_EXPR (that's what conv_unsafe_in_template_p is for). But in this test we are NOT in a template when we call digest_nsdmi_init which ends up calling convert_like, converting 1.0e+0 to int, so convert_to_integer_1 gives us a FIX_TRUNC_EXPR. But then when we get to parsing f's parameters, we are in a template when processing decltype(Helpers{}), and since r268321, when the compound literal isn't instantiation-dependent and the type isn't type-dependent, finish_compound_literal falls back to the normal processing, so it calls digest_init, which does fold_non_dependent_init and since the FIX_TRUNC_EXPR isn't dependent, we instantiate and therefore crash in tsubst_copy_and_build. Either I can tweak p_c_e to say that a FIX_TRUNC_EXPR in a template is not potentially constant, or I can just remove the whole F_T_E case, since: a) we could not have created an IMPLICIT_CONV_EXPR here, and b) similar code, FLOAT_EXPR, is not handled here, either. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11? PR c++/102990 gcc/cp/ChangeLog: * pt.cc (tsubst_copy_and_build) : Remove. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/nsdmi-template22.C: New test. * g++.dg/cpp0x/nsdmi-template23.C: New test. --- gcc/cp/pt.cc | 4 ---- gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C | 13 +++++++++++++ gcc/testsuite/g++.dg/cpp0x/nsdmi-template23.C | 13 +++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template23.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 715eea27577..a3becc19290 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -20184,10 +20184,6 @@ tsubst_copy_and_build (tree t, templated_operator_saved_lookups (t), complain|decltype_flag)); - case FIX_TRUNC_EXPR: - /* convert_like should have created an IMPLICIT_CONV_EXPR. */ - gcc_unreachable (); - case ADDR_EXPR: op1 = TREE_OPERAND (t, 0); if (TREE_CODE (op1) == LABEL_DECL) diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C new file mode 100644 index 00000000000..4ed2501035c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template22.C @@ -0,0 +1,13 @@ +// PR c++/102990 +// { dg-do compile { target c++11 } } + +struct knob_t { + /* Let's create a FIX_TRUNC_EXPR. */ + int value = 1.0; +}; + +struct Helpers { + knob_t inputs; +}; + +template void f(decltype(Helpers{})); diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template23.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template23.C new file mode 100644 index 00000000000..240cab4347a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template23.C @@ -0,0 +1,13 @@ +// PR c++/102990 +// { dg-do compile { target c++11 } } + +struct knob_t { + /* Let's create a FLOAT_EXPR. */ + double value = 1UL; +}; + +struct Helpers { + knob_t inputs; +}; + +template void f(decltype(Helpers{})); base-commit: 5d2233f4033dfa37ad88dc2eab138524fe64242e -- 2.35.1