Dear all,

the attached simple and obvious patch fixes an issue found when running
a UBSAN instrumented compiler on a recent testcase, see PR.  Also
verified when running f951 under gdb on that testcase.

I intend to commit within the next 24 hours unless there are comments.

Regtested on x86_64-pc-linux-gnu.

Will also backport to 14-branch, which has the same code.

Thanks,
Harald

From b6309e6fe318b8f63eed1a1a68c78c43fcf38ab4 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anl...@gmx.de>
Date: Tue, 28 Jan 2025 21:21:40 +0100
Subject: [PATCH] Fortran: fix passing of component ref to assumed-rank dummy
 [PR118683]

While the fix for pr117774 addressed the passing of an inquiry reference
to an assumed-rank dummy, it missed the similar case of passing a component
reference.  The newer testcase gfortran.dg/pr81978.f90 uncovered this
latent issue with a UBSAN instrumented compiler.

	PR fortran/118683

gcc/fortran/ChangeLog:

	* trans-expr.cc (gfc_conv_procedure_call): The bounds update for
	passing to assumed-rank dummies shall also handle component
	references besides inquiry references.
---
 gcc/fortran/trans-expr.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 78caf1f8996..24b1d19537b 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -7495,6 +7495,9 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 		    {
 		      if (ref->next->type == REF_INQUIRY)
 			break;
+		      if (ref->type == REF_ARRAY
+			  && ref->u.ar.type != AR_ELEMENT)
+			break;
 		    };
 		  if (ref->u.ar.type == AR_FULL
 		      && ref->u.ar.as->type != AS_ASSUMED_SIZE)
-- 
2.43.0

Reply via email to