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.133.124]) by sourceware.org (Postfix) with ESMTPS id 44C1A385840D for ; Tue, 19 Dec 2023 19:08:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44C1A385840D 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 44C1A385840D 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=1703012918; cv=none; b=HU9xz1QZ23m1LFMuK+yC4pMhJXvarQGgL/Ps2304E7fp3RF0pIYGyUGAbLihhtCnOMVtETbsCnxI2jLHL4vEEKLex9SrDNmY0qeem3dhDdhgXek+3Z7DuDjcOeng/sEuX3uI/pkSAueU9P/wvG+60GNgSoEVY4uaq8CiZn/KiWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703012918; c=relaxed/simple; bh=vAgSM18pFVUqWOJaMRV/YAsS6cofIcCpg2wn2YBYOag=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=pY8RpwqTCmen+VJgNZxSy0WZktiVm0nE8+5GkbpKk8fI3zmT2xr71I2seqMIjJ/MeoD4hWH7QxwlOsRlpPdL2T49ddfAurypB9cKrK9AueMZXyKHZT4P9t8uHdC5jD9qK7p0leWJJDAsApM8NSCtwa+cP/Y6ukSHu5KU4cXFE8k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703012916; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HxhFo09i+2p6hckF3LJdZI1lFEu9twNbgyxZcfTLZu4=; b=OT+5Jig4QCAWWUa8MS2xFO8wQo/XfEduwKv9wYTRZwNbP/qoFQBz5W6LE94XfjswZIlXBd bDK/DL13CJlpnip3dFGVM/ckb1gkH+XDCEIoWLYbM9TSGZhQNv4qzAfoUsVEulfnSaRYJT HdE1nrdr4AOIecmqs+Pz+XnVh6Lv3uo= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-d8RRJiyCNVujYyMrFBAlRA-1; Tue, 19 Dec 2023 14:08:33 -0500 X-MC-Unique: d8RRJiyCNVujYyMrFBAlRA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-67f2dff7b26so58069556d6.1 for ; Tue, 19 Dec 2023 11:08:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703012913; x=1703617713; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HxhFo09i+2p6hckF3LJdZI1lFEu9twNbgyxZcfTLZu4=; b=N5LE+iOsbntPaBw5d4hgukMsES05jW3HP4CHwaH57HTV2jJMT8b3xyR9/uOLSMuYDh raJskgkH10HshifTHujNNHf2tDMxWcXQpMPb51RvJ6Zk4FxUZOzPE8ojdtAUXfS7dKWf tZOIGD9zlQcvrbKkTj9c/snG1aMAJagzxiH6PoR2KLc3oqiyLXylaBB+CjnQdioIUSJx YG3328rAIVTYgkMITEliZUtxY3r0tEta0nqbaqQ5/m2oH6lOGBAmG1qQGmB0UuzEpBXb mVrQ0OcJP68bPnE8d4gR0TNMzDfVnDsfu80ytPM1SoJzrTiER7/F9mDFndvWjV1PcpqH jhYw== X-Gm-Message-State: AOJu0Yy7FTwqWxcraZzrM3xUMJevUNu/j5V5GfoN5cM3GqxS+RG1fLr1 d02093b5TRtWZ8uaZgi+KaApHYAqqqWUktK49U65Gh2R8lfaGPjKha2BteR2G97Lvl/aOp/tpQN JQLVuOiPSk1lFPwnv2w== X-Received: by 2002:a05:6214:27eb:b0:67f:d1a:8bb3 with SMTP id jt11-20020a05621427eb00b0067f0d1a8bb3mr2462805qvb.53.1703012913076; Tue, 19 Dec 2023 11:08:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcuOXuTsJzp//hrbSMhGXH1qSKjlTHkMgq4dDBYA+BHLiTxCfWqwBK2Df6pl3HZuOwthBArA== X-Received: by 2002:a05:6214:27eb:b0:67f:d1a:8bb3 with SMTP id jt11-20020a05621427eb00b0067f0d1a8bb3mr2462791qvb.53.1703012912727; Tue, 19 Dec 2023 11:08:32 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id h4-20020a05620a13e400b0077dd463da60sm9313630qkl.126.2023.12.19.11.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 11:08:32 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Tue, 19 Dec 2023 14:08:31 -0500 (EST) To: Jason Merrill cc: gcc-patches@gcc.gnu.org, Patrick Palka Subject: Re: [pushed] c++: array DMI and member fn [PR109666] In-Reply-To: <20230501205454.1627105-1-jason@redhat.com> Message-ID: <1eefca04-d00d-f53b-5d81-5a95890ccaeb@idea> References: <20230501205454.1627105-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.0 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_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, 1 May 2023, Jason Merrill wrote: > Tested x86_64-pc-linux-gnu, applying to trunk. > > Patrick, can you verify that this resolves 109506 and add whatever testcase(s) > seem appropriate from that PR? > > -- 8< -- > > Here it turns out I also needed to adjust cfun when stepping out of the > member function to instantiate the DMI. But instead of adding that tweak, > let's unify with instantiate_body and just push_to_top_level instead of > trying to do the minimum subset of it. There was no measurable change in > compile time on stdc++.h. > > This should also resolve 109506 without yet another tweak. > > PR c++/109666 > > gcc/cp/ChangeLog: > > * name-lookup.cc (maybe_push_to_top_level) > (maybe_pop_from_top_level): Split out... > * pt.cc (instantiate_body): ...from here. > * init.cc (maybe_instantiate_nsdmi_init): Use them. > * name-lookup.h: Declare them.. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/nsdmi-array2.C: New test. > --- > gcc/cp/name-lookup.h | 2 ++ > gcc/cp/init.cc | 25 ++------------- > gcc/cp/name-lookup.cc | 37 +++++++++++++++++++++++ > gcc/cp/pt.cc | 20 ++---------- > gcc/testsuite/g++.dg/cpp0x/nsdmi-array2.C | 15 +++++++++ > 5 files changed, 58 insertions(+), 41 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-array2.C > > diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h > index c234cd44356..b3e708561d8 100644 > --- a/gcc/cp/name-lookup.h > +++ b/gcc/cp/name-lookup.h > @@ -466,6 +466,8 @@ extern void push_nested_namespace (tree); > extern void pop_nested_namespace (tree); > extern void push_to_top_level (void); > extern void pop_from_top_level (void); > +extern bool maybe_push_to_top_level (tree); > +extern void maybe_pop_from_top_level (bool); > extern void push_using_decl_bindings (tree, tree); > > /* Lower level interface for modules. */ > diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc > index 1dd24e30d7c..0b35e1092e9 100644 > --- a/gcc/cp/init.cc > +++ b/gcc/cp/init.cc > @@ -597,32 +597,14 @@ maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t complain) > bool pushed = false; > tree ctx = type_context_for_name_lookup (member); > > - processing_template_decl_sentinel ptds (/*reset*/false); > + bool push_to_top = maybe_push_to_top_level (member); > if (!currently_open_class (ctx)) > { > - if (!LOCAL_CLASS_P (ctx)) > - push_to_top_level (); > - else > - /* push_to_top_level would lose the necessary function context, > - just reset processing_template_decl. */ > - processing_template_decl = 0; > push_nested_class (ctx); > push_deferring_access_checks (dk_no_deferred); > pushed = true; > } > > - /* If we didn't push_to_top_level, still step out of constructor > - scope so build_base_path doesn't try to use its __in_chrg. */ > - tree cfd = current_function_decl; > - auto cbl = current_binding_level; > - if (at_function_scope_p ()) > - { > - current_function_decl > - = decl_function_context (current_function_decl); > - while (current_binding_level->kind != sk_class) > - current_binding_level = current_binding_level->level_chain; > - } > - > inject_this_parameter (ctx, TYPE_UNQUALIFIED); > > start_lambda_scope (member); > @@ -639,15 +621,12 @@ maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t complain) > if (init != error_mark_node) > DECL_INITIAL (member) = init; > > - current_function_decl = cfd; > - current_binding_level = cbl; > if (pushed) > { > pop_deferring_access_checks (); > pop_nested_class (); > - if (!LOCAL_CLASS_P (ctx)) > - pop_from_top_level (); > } > + maybe_pop_from_top_level (push_to_top); > > input_location = sloc; > } > diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc > index 477cddd7543..7c61bc3bf61 100644 > --- a/gcc/cp/name-lookup.cc > +++ b/gcc/cp/name-lookup.cc > @@ -8236,6 +8236,43 @@ pop_from_top_level (void) > free_saved_scope = s; > } > > +/* Like push_to_top_level, but not if D is function-local. Returns whether we > + did push to top. */ > + > +bool > +maybe_push_to_top_level (tree d) > +{ > + /* Push if D isn't function-local, or is a lambda function, for which name > + resolution is already done. */ > + bool push_to_top > + = !(current_function_decl > + && !LAMBDA_FUNCTION_P (d) > + && decl_function_context (d) == current_function_decl); > + > + if (push_to_top) > + push_to_top_level (); > + else > + { > + gcc_assert (!processing_template_decl); > + push_function_context (); > + cp_unevaluated_operand = 0; > + c_inhibit_evaluation_warnings = 0; I think we need to restore these flags in maybe_pop_from_top_level, like so perhaps? Bootstrap and regtest running on x86_64-pc-linux-gnu. -- >8 -- Subject: [PATCH] c++: missing state restoration in maybe_pop_from_top_level gcc/cp/ChangeLog: * name-lookup.cc (struct maybe_push_state_t): Define. (maybe_push_state_stack): Define. (maybe_push_to_top_level): Use them. (maybe_pop_from_top_level): Likewise. * pt.cc (instantiate_decl): Remove dead code for saving/restoring cp_unevaluated_operand and c_inhibit_evaluation_warnings. --- gcc/cp/name-lookup.cc | 37 ++++++++++++++++++++++++++++++++++--- gcc/cp/pt.cc | 4 ---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index 09dc6ef3e5a..aaedfaa45b3 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -8553,6 +8553,35 @@ pop_from_top_level (void) free_saved_scope = s; } +/* Helper class for saving/restoring relevant global flags in the + function-local case of maybe_push_to_top_level. */ + +struct maybe_push_state_t +{ + int cp_unevaluated_operand; + int c_inhibit_evaluation_warnings; + + static maybe_push_state_t + save_and_clear () + { + maybe_push_state_t s; + s.cp_unevaluated_operand = ::cp_unevaluated_operand; + ::cp_unevaluated_operand = 0; + s.c_inhibit_evaluation_warnings = ::c_inhibit_evaluation_warnings; + ::c_inhibit_evaluation_warnings = 0; + return s; + } + + void + restore () const + { + ::cp_unevaluated_operand = this->cp_unevaluated_operand; + ::c_inhibit_evaluation_warnings = this->c_inhibit_evaluation_warnings; + } +}; + +static vec maybe_push_state_stack; + /* Like push_to_top_level, but not if D is function-local. Returns whether we did push to top. */ @@ -8572,8 +8601,7 @@ maybe_push_to_top_level (tree d) { gcc_assert (!processing_template_decl); push_function_context (); - cp_unevaluated_operand = 0; - c_inhibit_evaluation_warnings = 0; + maybe_push_state_stack.safe_push (maybe_push_state_t::save_and_clear ()); } return push_to_top; @@ -8587,7 +8615,10 @@ maybe_pop_from_top_level (bool push_to_top) if (push_to_top) pop_from_top_level (); else - pop_function_context (); + { + maybe_push_state_stack.pop ().restore (); + pop_function_context (); + } } /* Push into the scope of the namespace NS, even if it is deeply diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index a82d7ae93aa..74da35596a5 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -26833,8 +26833,6 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p) tree gen_tmpl; bool pattern_defined; location_t saved_loc = input_location; - int saved_unevaluated_operand = cp_unevaluated_operand; - int saved_inhibit_evaluation_warnings = c_inhibit_evaluation_warnings; bool external_p; bool deleted_p; @@ -27071,8 +27069,6 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p) pop_deferring_access_checks (); pop_tinst_level (); input_location = saved_loc; - cp_unevaluated_operand = saved_unevaluated_operand; - c_inhibit_evaluation_warnings = saved_inhibit_evaluation_warnings; return d; } -- 2.43.0.121.g624eb90fa8