From patchwork Thu Mar 21 21:01:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1914611 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=QWBqIXQZ; 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 4V0yZ16Zltz1yWp for ; Fri, 22 Mar 2024 08:01:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DCE483858407 for ; Thu, 21 Mar 2024 21:01:43 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id DC0063858D28 for ; Thu, 21 Mar 2024 21:01:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC0063858D28 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 DC0063858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711054889; cv=none; b=bpalMPR/TKygJBu9+18VeLREOzpOJVV/r4IWuWUR+3ms3oRGzlSNzD9JKk7JGCsDS7MzFYGMpyAH/So9IHu73L2fud/fe48EzsTEt52drmOtbCq3FZOyPbYGiFIJJKbrpTAZllbpOC7QOpGJj+WxF1SCYM1lOKORsci+UoVumpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711054889; c=relaxed/simple; bh=pTB5KCfvm9yM1Z/dUOD0X17SCpAg1XerEs15rK2509o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ouZcNET29ypMRlt6xNKopgsBzbsWvK6WtlMGhPqWod5Hs123+bs3A0Fv0m7UNNFcn3sAn9H1VxVZ7H0oMSwUUPgUt4JZJ9isBhO90aN2j2Vm1eFkArzIFN666b6hWtnYIFMSMthwfBH9lt/rNmlL0KVyAsdYPdrCyrBIx8+IdHE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711054887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=T4HlKGRQoIVLZ+qwv0zv7k+rhT7uZeoJ6iOWBIW+I50=; b=QWBqIXQZiKWIHodP7vamipavstPAIuqXfVkpu8rzjqsna0P2GG0oP9RH7YUZ6/o5YikdHx UKXo/McU+HrpUg/fir+dMgP4ewZuPLrHOhR3JAFpmOYH38naiYFHUscdkGmV9SeMwy9Mqd rBVI7qIXBIK5gq89sYT2tvn7CV7Fc7Y= 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-614-cv_WPH7vMRCPxMsHwqh6aw-1; Thu, 21 Mar 2024 17:01:25 -0400 X-MC-Unique: cv_WPH7vMRCPxMsHwqh6aw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 CD58F89C56D for ; Thu, 21 Mar 2024 21:01:24 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.33.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id A63951C060A4; Thu, 21 Mar 2024 21:01:24 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill , Patrick Palka Subject: [PATCH] c++: ICE with noexcept and local specialization, again [PR114349] Date: Thu, 21 Mar 2024 17:01:12 -0400 Message-ID: <20240321210112.941228-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- Patrick noticed that my r14-9339-gdc6c3bfb59baab patch is wrong; we're dealing with a noexcept-spec there, not a noexcept-expr, so setting cp_noexcept_operand et al is incorrect. Back to the drawing board then. To fix noexcept84.C, we should probably avoid doing push_to_top_level in certain cases. Patrick suggested checking: const bool push_to_top = current_function_decl != fn; which works, but I'm not sure I follow the logic there. I also came up with const bool push_to_top = !decl_function_context (fn); which also works. But ultimately I went with !DECL_TEMPLATE_INSTANTIATED; if DECL_TEMPLATE_INSTANTIATED is set, we've already pushed to top level if it was necessary in instantiate_body. This also fixes c++/114349, introduced by r14-9339. PR c++/114349 gcc/cp/ChangeLog: * pt.cc (maybe_instantiate_noexcept): Don't push_to_top_level if fn has already been instantiated. Don't save/restore cp_unevaluated_operand, c_inhibit_evaluation_warnings, and cp_noexcept_operand around the tsubst_expr call. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept85.C: New test. * g++.dg/cpp0x/noexcept86.C: New test. --- gcc/cp/pt.cc | 17 ++++++------- gcc/testsuite/g++.dg/cpp0x/noexcept85.C | 33 +++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/noexcept86.C | 25 +++++++++++++++++++ 3 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept85.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept86.C base-commit: 48d49200510198cafcab55601cd8e5f8eb541f01 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 8cf0d5b7a8d..b7ebd93ac7d 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -26855,7 +26855,12 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) } else if (push_tinst_level (fn)) { - push_to_top_level (); + /* If we've already instantiated FN, there's no need to push to + top level (as instantiate_body already pushed to top level if + needed). */ + const bool push_to_top = !DECL_TEMPLATE_INSTANTIATED (fn); + if (push_to_top) + push_to_top_level (); push_access_scope (fn); push_deferring_access_checks (dk_no_deferred); input_location = DECL_SOURCE_LOCATION (fn); @@ -26878,17 +26883,10 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) if (orig_fn) ++processing_template_decl; - ++cp_unevaluated_operand; - ++c_inhibit_evaluation_warnings; - ++cp_noexcept_operand; /* Do deferred instantiation of the noexcept-specifier. */ noex = tsubst_expr (DEFERRED_NOEXCEPT_PATTERN (noex), DEFERRED_NOEXCEPT_ARGS (noex), tf_warning_or_error, fn); - --cp_unevaluated_operand; - --c_inhibit_evaluation_warnings; - --cp_noexcept_operand; - /* Build up the noexcept-specification. */ spec = build_noexcept_spec (noex, tf_warning_or_error); @@ -26898,7 +26896,8 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) pop_deferring_access_checks (); pop_access_scope (fn); pop_tinst_level (); - pop_from_top_level (); + if (push_to_top) + pop_from_top_level (); } else spec = noexcept_false_spec; diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept85.C b/gcc/testsuite/g++.dg/cpp0x/noexcept85.C new file mode 100644 index 00000000000..b415bb46bc9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept85.C @@ -0,0 +1,33 @@ +// PR c++/114349 +// { dg-do compile { target c++11 } } + +using A = struct {}; +template