[09/13,C++] constexpr: request insert iff depth is ok

Message ID orzgb9eaev.fsf@lxoliva.fsfla.org
State Accepted
Headers
Series [01/13] scoped tables: insert before further lookups |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Alexandre Oliva Dec. 27, 2022, 4:30 a.m. UTC
  cxx_eval_call_expression requests an INSERT even in cases when it
would later decide not to insert.  This could break double-hashing
chains.  Arrange for it to use NO_INSERT when the insertion would not
be completed.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/cp/ChangeLog

	* constexpr.cc (cxx_eval_call_expression): Do not request an
	INSERT that would not be completed.
---
 gcc/cp/constexpr.cc |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Comments

Jeff Law Dec. 27, 2022, 3:38 p.m. UTC | #1
On 12/26/22 21:30, Alexandre Oliva via Gcc-patches wrote:
> 
> cxx_eval_call_expression requests an INSERT even in cases when it
> would later decide not to insert.  This could break double-hashing
> chains.  Arrange for it to use NO_INSERT when the insertion would not
> be completed.
> 
> Regstrapped on x86_64-linux-gnu.  Ok to install?
> 
> 
> for  gcc/cp/ChangeLog
> 
> 	* constexpr.cc (cxx_eval_call_expression): Do not request an
> 	INSERT that would not be completed.
OK.
Jeff
  

Patch

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index d99c49bdbe282..6d20ffa2cdeb6 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -3000,13 +3000,15 @@  cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
 
       /* If we have seen this call before, we are done.  */
       maybe_initialize_constexpr_call_table ();
+      bool insert = depth_ok < constexpr_cache_depth;
       constexpr_call **slot
-	= constexpr_call_table->find_slot (&new_call, INSERT);
-      entry = *slot;
+	= constexpr_call_table->find_slot (&new_call,
+					   insert ? INSERT : NO_INSERT);
+      entry = slot ? *slot : NULL;
       if (entry == NULL)
 	{
 	  /* Only cache up to constexpr_cache_depth to limit memory use.  */
-	  if (depth_ok < constexpr_cache_depth)
+	  if (insert)
 	    {
 	      /* We need to keep a pointer to the entry, not just the slot, as
 		 the slot can move during evaluation of the body.  */