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 37F21385840D for ; Tue, 19 Dec 2023 19:47:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37F21385840D 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 37F21385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703015280; cv=none; b=KuHAUSZj2NTI/IYXa7eSVzW2rEM1+ShDgJp0W+rKyD54z+20EVLx44p/KoSQ2w0DEDjkaM8WVXVEmYeZcXaedf8VXC9gSKwKjuo1+zVtMw1G6EvGQ4LG+NWfyEwQ9gMwbgdzR7zmqFpziGjG7rOszXQuZQenMFKIAncDpHueMvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703015280; c=relaxed/simple; bh=tVlIXTTV1jWTbNy2O4yWavovX+KFHT8mwoKJenlLgqg=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=X/ullS5jYC+x8prRM7vzAOBQhbWh1wR4NdMKVEjdJnQVr78CySSPDJkJH3IVX8pwbP2Q6tQ2hS0CFAj1b9HiNnODVZRxv6iIgGJFFLY8b6E1BMHIoctqKihcIfs67ra3WDwRmuE4QB7UM3Z+bh7ebDlEOH4Rq+X2tgn1V0GDweM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703015277; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oW1jXVM5NowFjY6gbLJ1NX6LXYARgy2oxgGUaZ8M8iM=; b=fW5sdjc9Ba8uJO/ZvNX3wSRh3AO8ibML8QBRxJux1C7kc91GkWYuVAtRNDcIg8IYgon/4L 4cSU6eGcxOv8X8DZSdtGUN/bboSFANHd6ByMIsDuQyCy4avXHKyRG5Q8pbyy0Hz2elhluj 8/jP/75O6R7gTahRoV7sCjNCdHwoQV8= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-131-sfkSBZ6LNverWgYIa6F9wg-1; Tue, 19 Dec 2023 14:47:56 -0500 X-MC-Unique: sfkSBZ6LNverWgYIa6F9wg-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-67ee8a447b3so693956d6.0 for ; Tue, 19 Dec 2023 11:47:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703015275; x=1703620075; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oW1jXVM5NowFjY6gbLJ1NX6LXYARgy2oxgGUaZ8M8iM=; b=CSR+zc3INO4YMylKvgsK/H7FBAt02UGZ58EBpnYB2y0oLwIX76NgIAzBEZBR7o8xEj rtPpTAN3d4RLf/O1MHf12p9pv+MrYWiAe9dD6MijzDsRxfS1c22kID63v2qhyee1QeBM k4f0Sl3+0/fJ5Wg28DMeeJQ9wZR6Ax9/WykCm40zvd4FhfM7g5CHRYfj6B8xmf9jRQjv u/Fc2Q3Y4nZgnIsL3g/oxalOxRbm3oIeHhuBuODWSO5MCWHNjuCKVLsf09/ca0TYrWUY rwuClcpQ5Haq23VVGEKnxzAoIiwk6IPc9UMU+tJC/TOKm++FuKqqoCdAV3kOXj9ZDREl YIiA== X-Gm-Message-State: AOJu0Yz5rwVbozOczaFIAW9BiQDnGfz2B0Q3tqe/sQGALL5TYfmST9BS Hi9p6Ggtf/f8SD9VAY2eE8WiM/K6ZFXpTtyfDhQaPCJRqqhq3aCynk2sqFgy5eiJnaEndTcA2AN yd9wn8fR9Mvdk1/AbxlTPCLUxHw== X-Received: by 2002:ad4:5f4d:0:b0:67f:2201:81df with SMTP id p13-20020ad45f4d000000b0067f220181dfmr2397630qvg.28.1703015275524; Tue, 19 Dec 2023 11:47:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjDuAQrzAs/VBOrW4nXYyYL6/EvnXrxUjCa6tFXWLmARGqIw17izROfaW3d17Jfsew5GiVvA== X-Received: by 2002:ad4:5f4d:0:b0:67f:2201:81df with SMTP id p13-20020ad45f4d000000b0067f220181dfmr2397617qvg.28.1703015275187; Tue, 19 Dec 2023 11:47:55 -0800 (PST) Received: from [192.168.1.146] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id r7-20020ad44047000000b0067f4807de3asm1957615qvp.75.2023.12.19.11.47.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Dec 2023 11:47:54 -0800 (PST) Message-ID: Date: Tue, 19 Dec 2023 14:47:53 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [pushed] c++: array DMI and member fn [PR109666] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20230501205454.1627105-1-jason@redhat.com> <1eefca04-d00d-f53b-5d81-5a95890ccaeb@idea> From: Jason Merrill In-Reply-To: <1eefca04-d00d-f53b-5d81-5a95890ccaeb@idea> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.5 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,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 12/19/23 14:08, Patrick Palka wrote: > 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. I might call these local_state_t/local_state_stack since that's the case they're used for? OK either way. > (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; > }