Hi all,

attached patch narrows the use of intrinsic functions in the caf accessor down
to pure elemental functions. This is needed because functions that get extracted
into the caf accessor routine, have no access to the source image's memory. E.g.
team_number() is marked as pure, but takes a pointer argument to an object in
the source image's memory, which is not available on the remote image where the
accessor is executed. This patch fixes that and also corrects the type in the
decl of the ABI of team_number. It is of the opaque type team_type aka void* now
and not integer as formerly declared.

Regtest ok on x86_64-pc-linux-gnu / F41. Ok for mainline?

Regards,
        Andre

On Tue, 1 Jul 2025 12:54:49 -0700
Jerry D <jvdelis...@gmail.com> wrote:

> On 7/1/25 12:51 PM, Harald Anlauf wrote:
> > Dear all,
> > 
> > the attached patch fixes the following minor issues found by running
> > f951 under valgrind for the just added new testcases coindexed_6.f90
> > and coindexed_7.f90:
> > 
> > - minor front-end memleaks with non-freed strings and lost GMP variables
> >   (these are simple and obvious fixes)
> > 
> > - an inconsistency between pure/elemental functions being either
> >   non-intrinsic or intrinsic.  Checking for the latter was likely missed
> >   from the beginning.
> > 
> > No new testcase.
> > 
> > Regtested on x86_64-pc-linux-gnu.  OK for mainline?
> > 
> > Thanks,
> > Harald
> >   
> 
> Yes, OK, straight-forward.
> 
> Thanks,
> 
> Jerry


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 
From 4b9181aab9fc1b3982724a442b19c69458459b5f Mon Sep 17 00:00:00 2001
From: Andre Vehreschild <ve...@gcc.gnu.org>
Date: Fri, 4 Jul 2025 11:26:46 +0200
Subject: [PATCH] Fortran: Fix pure/elemental function treatment and
 team_number parameter attribution.

gcc/fortran/ChangeLog:

	* coarray.cc (check_add_new_component): Only allow pure
	elemental intrinsic functions in a coarray accessor.
	* trans-decl.cc (gfc_build_builtin_function_decls): The only
	argument of team_number() is of type void* in the library ABI.
---
 gcc/fortran/coarray.cc    | 2 +-
 gcc/fortran/trans-decl.cc | 7 +++----
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
index ef8fd4e42d0..01aac581a74 100644
--- a/gcc/fortran/coarray.cc
+++ b/gcc/fortran/coarray.cc
@@ -700,7 +700,7 @@ check_add_new_component (gfc_symbol *type, gfc_expr *e, gfc_symbol *add_data)
 	      && !e->symtree->n.sym->attr.elemental
 	      && !(e->value.function.isym
 		   && (e->value.function.isym->pure
-		       || e->value.function.isym->elemental)))
+		       && e->value.function.isym->elemental)))
 	    /* Treat non-pure/non-elemental functions.  */
 	    check_add_new_comp_handle_array (e, type, add_data);
 	  else
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 43bd7be54cb..ba4a842a025 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -4223,10 +4223,9 @@ gfc_build_builtin_function_decls (void)
 	get_identifier (PREFIX ("caf_sync_team")), ". r w w w ", void_type_node,
 	4, pvoid_type_node, pint_type, pchar_type_node, size_type_node);
 
-      gfor_fndecl_caf_team_number
-      	= gfc_build_library_function_decl_with_spec (
-	    get_identifier (PREFIX("caf_team_number")), ". r ",
-      	    integer_type_node, 1, integer_type_node);
+      gfor_fndecl_caf_team_number = gfc_build_library_function_decl_with_spec (
+	get_identifier (PREFIX ("caf_team_number")), ". r ", integer_type_node,
+	1, pvoid_type_node);
 
       gfor_fndecl_caf_image_status = gfc_build_library_function_decl_with_spec (
 	get_identifier (PREFIX ("caf_image_status")), ". r r ",
-- 
2.50.0

Reply via email to