fortran: Fix up hash table usage in gfc_trans_use_stmts [PR108451]

Message ID Y91ah+TPG01V1g/A@tucnak
State Unresolved
Headers
Series fortran: Fix up hash table usage in gfc_trans_use_stmts [PR108451] |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jakub Jelinek Feb. 3, 2023, 7:03 p.m. UTC
  Hi!

The first testcase in the PR (which I haven't included in the patch because
it is unclear to me if it is supposed to be valid or not) ICEs since extra
hash table checking has been added recently.  The problem is that
gfc_trans_use_stmts does
          tree *slot = entry->decls->find_slot_with_hash (rent->use_name, hash,
                                                          INSERT);
          if (*slot == NULL)
and later on doesn't store anything into *slot and continues.  Another spot
a few lines later correctly clears the slot if it decides not to use the
slot, so the following patch does the same.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-02-03  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/108451
	* trans-decl.cc (gfc_trans_use_stmts): Call clear_slot before
	doing continue.


	Jakub
  

Comments

Li, Pan2 via Gcc-patches Feb. 3, 2023, 8:20 p.m. UTC | #1
On Fri, Feb 03, 2023 at 08:03:36PM +0100, Jakub Jelinek via Fortran wrote:
> Hi!
> 
> The first testcase in the PR (which I haven't included in the patch because
> it is unclear to me if it is supposed to be valid or not) ICEs since extra
> hash table checking has been added recently.  The problem is that
> gfc_trans_use_stmts does
>           tree *slot = entry->decls->find_slot_with_hash (rent->use_name, hash,
>                                                           INSERT);
>           if (*slot == NULL)
> and later on doesn't store anything into *slot and continues.  Another spot
> a few lines later correctly clears the slot if it decides not to use the
> slot, so the following patch does the same.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 

Yes.

See my comment in the PR about the testcases being invalid Fortran.
  

Patch

--- gcc/fortran/trans-decl.cc.jj	2023-01-16 11:52:16.146733136 +0100
+++ gcc/fortran/trans-decl.cc	2023-02-03 14:41:40.503322954 +0100
@@ -5350,7 +5350,11 @@  gfc_trans_use_stmts (gfc_namespace * ns)
 	      /* Sometimes, generic interfaces wind up being over-ruled by a
 		 local symbol (see PR41062).  */
 	      if (!st->n.sym->attr.use_assoc)
-		continue;
+		{
+		  *slot = error_mark_node;
+		  entry->decls->clear_slot (slot);
+		  continue;
+		}
 
 	      if (st->n.sym->backend_decl
 		  && DECL_P (st->n.sym->backend_decl)