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: 35391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3566553wrn; Wed, 21 Dec 2022 06:53:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXvipcSNp362+qOT7dlKy9JsGxR/VH/P3bovjvn39a3v/zuvbze+ydJa/QUNGd4TwUW8ynsc X-Received: by 2002:aa7:d04f:0:b0:46f:97fb:1321 with SMTP id n15-20020aa7d04f000000b0046f97fb1321mr1577161edo.35.1671634426092; Wed, 21 Dec 2022 06:53:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671634426; cv=none; d=google.com; s=arc-20160816; b=dcrJ+mtM7RkHOOmNdIO23N9DoL3cVfgdPzQeuvxVRtqj2Oxwra14RGF1bLBVQlQKh+ fbentk1rcqDrodBwVihvhHWX6MtF2VPbO5bNl23UD+mF3McLFFLk5fBiTddz2CQXaGgq Yng0556sJXYrnqyy17qOtfmuT0O92v2TcqPh3lWjXuFv41Wj+cN+sMS5iKrKSmztOrXg HfUvhsQSapFtXUxcDgJg0FZN51hfQ3iOhXLzYpgG1Pk3f0aUjroVFiC1GqVWrW+dWlou eopnuZEGc3eZAPoFR6/r8S7bQ9fXEEHeJfoWMOf9c8UkFTmczwyEgOWa0LP6l9cocAvR LjAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=pqOO+KJMz2R6z/rWwXAATglUiNBwFOawoLJCyN7hLFY=; b=Z23RkzEe2WiCnxvflZTyOM2KJ0cW7yjNXvKSYf/uX+VPyTJ46+wb3yB/G3HtE1Cmad Ew7DW0yG1J9FwS4PZgtvDWcalcidFuscPLXaY14TA9cnIpKHEkdUz8fksdY4AYZskV48 va3+S3pIvibp8qmtzw+cJMOGyqoKuKDDxhxsdLgg5Ea2P6wmkBITD0xXFbjACEM8iecn 8BqcPHTzvTIDXIo6xZt9Igh9LarA+oHdba20Ut0SDS3y5gasr4DMBqamK57ZgnILvTkG YKoIZXImN2lhmVojptYSTZYQrVyf6elEe+ahEn+hvCqkpXvfKqp7myu9GlJ5IQ7+g4Mw xHBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iGebrNP3; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gv11-20020a1709072bcb00b0079dc9dcbbb6si11462218ejc.337.2022.12.21.06.53.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 06:53:46 -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=@gcc.gnu.org header.s=default header.b=iGebrNP3; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E09C43858023 for ; Wed, 21 Dec 2022 14:53:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E09C43858023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671634424; 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=iGebrNP3TZecCyQscJHSXNzsu2qwRwAJhOMSakuFZwYr8L2o6/PIUR7zrvr23sqf9 fX/Pjdbx6ao0jov7U12q+4Ccar4lmUqqq9Y9T8StcfGrVwHD0LnXpquPbYfFxh9BHh TvqmC02I+lnl5UHLT+dcm5yVXAeputwf4ZSnftTg= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752835740261148738?= X-GMAIL-MSGID: =?utf-8?q?1752835740261148738?= 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{}; +};