From patchwork Wed Dec 21 14:52:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 62231 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 1E50C385802F for ; Wed, 21 Dec 2022 14:53:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E50C385802F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671634410; bh=pqOO+KJMz2R6z/rWwXAATglUiNBwFOawoLJCyN7hLFY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=U+20R+kKNQizX5zWtQATVHaTf9xZkD8zo8HxzJjCM82y9+cJphlBNZG3THGKSdY4y 4/pqrVHzF4BqZkiwvIFZeoRwlQx4aBe+tZu+S9PHFoWift8sWLtMj5pGGcIlSHQhaR r5ZQfwOScxjER2cJqLbUg0kU5XU1WE0JyZBJhbhI= 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 126F73858D1E for ; Wed, 21 Dec 2022 14:53:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 126F73858D1E Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-582-3Dys4rPDNDOOwwC7aJR1-g-1; Wed, 21 Dec 2022 09:52:58 -0500 X-MC-Unique: 3Dys4rPDNDOOwwC7aJR1-g-1 Received: by mail-qv1-f72.google.com with SMTP id nh4-20020a056214390400b004e36a91ecffso8787496qvb.19 for ; Wed, 21 Dec 2022 06:52:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pqOO+KJMz2R6z/rWwXAATglUiNBwFOawoLJCyN7hLFY=; b=2QZnpvfGrVc3DM3/8cRYoBK/TJd4q+9DgEmEhDWjtVUxVWCTmR1amKvkp80Ey3g/u3 ioYjccgs6OeFr83IoCwlRudAG0QaMRmY8dU1FbFsKtyK8gTeELMkDU/0/xwIQQ330lrE mAoWsLtSBJo8gyzmmerCsCYZuZAiCmRKon/IrMmuifpE9dJOXKVWn3Fa9McYEb2mgQ56 OVnnBgBMeSEW2581ggf1z/2SGOwhjlLIHWCB9UP23i2D0bqhHTXK+Ya26IBvS6vTjDsm pASRMvkCe4hlgKQYTuixjta0OX2hVcFztMc883T5GqFOPk28tzNPQowfjqBfWFHKdTqb T63w== X-Gm-Message-State: AFqh2kpK9QfDJbVI4eLAuUDuwo4ZecBWPBehY23G7QlmOxDBnOAhf+qg qeBCaVZYPH5eMlK+aWP5ktMz/EhmPTmwEj6RoFIinwSpabLQsBBl+P9tmLN357p+fiqPApMLFP1 PXZ4DoBV8gu2XIIlkbtqkLBXQhFO/EEyYR1HVgBuNhlcY4ssifKjvesMF839t/zdqqn8= X-Received: by 2002:ac8:5299:0:b0:3a8:15d2:6e8e with SMTP id s25-20020ac85299000000b003a815d26e8emr2082024qtn.41.1671634377686; Wed, 21 Dec 2022 06:52:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXsbkpsDoV7s9RKezu+wbewfIa0G8/rjQRnDQMp/2SmcVySAM7UjmRVAYnJFlZGIO9qwRaYJrQ== X-Received: by 2002:ac8:5299:0:b0:3a8:15d2:6e8e with SMTP id s25-20020ac85299000000b003a815d26e8emr2081994qtn.41.1671634377257; Wed, 21 Dec 2022 06:52:57 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id de36-20020a05620a372400b006cf19068261sm11046278qkb.116.2022.12.21.06.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 06:52:56 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: get_nsdmi in template context [PR108116] Date: Wed, 21 Dec 2022 09:52:54 -0500 Message-Id: <20221221145254.389983-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.0.95.g7c2ef319c5 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Here during ahead of time checking of C{}, we indirectly call get_nsdmi for C::m from finish_compound_literal, which in turn calls break_out_target_exprs for C::m's (non-templated) initializer, during which we end up building a call to A::~A and checking expr_noexcept_p for it (from build_vec_delete_1). But this is all done with processing_template_decl set, so the built A::~A call is templated (whose form r12-6897-gdec8d0e5fa00ceb2 recently changed) which expr_noexcept_p doesn't expect and we crash. In r10-6183-g20afdcd3698275 we fixed a similar issue by guarding a expr_noexcept_p call with !processing_template_decl, which works here too. But it seems to me since the initializer we obtain in get_nsdmi is always non-templated, it should be calling break_out_target_exprs with processing_template_decl cleared since otherwise the function might end up mixing templated and non-templated trees. I'm not sure about this though, perhaps this is not the best fix here. Alternatively, when processing_template_decl we could make get_nsdmi avoid calling break_out_target_exprs at all or something. Additionally, perhaps break_out_target_exprs should be a no-op more generally when processing_template_decl since we shouldn't see any TARGET_EXPRs inside a template? Bootstrapped and regtested on x86_64-pc-linux-gnu. PR c++/108116 gcc/cp/ChangeLog: * init.cc (get_nsdmi): Clear processing_template_decl before processing the non-templated initializer. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/nsdmi-template24.C: New test. --- gcc/cp/init.cc | 8 ++++++- gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index 73e6547c076..c4345ebdaea 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -561,7 +561,8 @@ perform_target_ctor (tree init) return init; } -/* Return the non-static data initializer for FIELD_DECL MEMBER. */ +/* Return the non-static data initializer for FIELD_DECL MEMBER. + The initializer returned is always non-templated. */ static GTY((cache)) decl_tree_cache_map *nsdmi_inst; @@ -670,6 +671,11 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain) current_class_ptr = build_address (current_class_ref); } + /* Since INIT is always non-templated clear processing_template_decl + before processing it so that we don't interleave templated and + non-templated trees. */ + processing_template_decl_sentinel ptds; + /* Strip redundant TARGET_EXPR so we don't need to remap it, and so the aggregate init code below will see a CONSTRUCTOR. */ bool simple_target = (init && SIMPLE_TARGET_EXPR_P (init)); diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C new file mode 100644 index 00000000000..202c67d7321 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C @@ -0,0 +1,22 @@ +// PR c++/108116 +// { dg-do compile { target c++11 } } + +#include + +struct A { + A(int); + ~A(); +}; + +struct B { + B(std::initializer_list); +}; + +struct C { + B m{0}; +}; + +template +void f() { + C c = C{}; +};