[obvious] Fix for ICE in tree-nested.cc

Message ID 952104c6-b547-4b6e-afa6-84ca213cfb13@baylibre.com
State New
Headers
Series [obvious] Fix for ICE in tree-nested.cc |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed

Commit Message

Sandra Loosemore May 3, 2024, 9:47 p.m. UTC
  I'm planning to push the attached patch to mainline in a couple days, 
unless someone disputes that it's "obvious" or has some other objection. 
  I think it qualifies because the code immediately following the loop 
with the bad initializer is already conditionalized on GIMPLE_OMP_TARGET 
in the same way.

I think this patch is a candidate for backporting to the GCC 14 branch 
once it is unfrozen after the release, too.

-Sandra
  

Patch

From 001d166819525dcef43b980298c2f85af77cd8ad Mon Sep 17 00:00:00 2001
From: Sandra Loosemore <sloosemore@baylibre.com>
Date: Mon, 22 Apr 2024 18:24:25 +0000
Subject: [PATCH, obvious] OpenMP: Fix for ICE in tree-nested.cc.

Use gimple_omp_target_clauses() instead of gimple_omp_taskreg_clauses()
when stmt is GIMPLE_OMP_TARGET, to avoid an as_a<> ICE.  The code
immediately following this is already conditionalized in the same way.

gcc/ChangeLog
	* tree-nested.cc (convert_tramp_reference_stmt): Use the correct
	accessor for GIMPLE_OMP_TARGET clauses.
---
 gcc/tree-nested.cc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc
index 4e5f3be7676..fc0495d6443 100644
--- a/gcc/tree-nested.cc
+++ b/gcc/tree-nested.cc
@@ -2906,9 +2906,11 @@  convert_tramp_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
 	      continue;
 	    decl = i ? get_chain_decl (info) : info->frame_decl;
 	    /* Don't add CHAIN.* or FRAME.* twice.  */
-	    for (c = gimple_omp_taskreg_clauses (stmt);
-		 c;
-		 c = OMP_CLAUSE_CHAIN (c))
+	    if (gimple_code (stmt) == GIMPLE_OMP_TARGET)
+	      c = gimple_omp_target_clauses (stmt);
+	    else
+	      c = gimple_omp_taskreg_clauses (stmt);
+	    for (; c; c = OMP_CLAUSE_CHAIN (c))
 	      if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
 		   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED)
 		  && OMP_CLAUSE_DECL (c) == decl)
-- 
2.25.1