See attached patch, simple and obvious.
I plan to commit this one as a precursor to the fix for PR127973.
This is also very simple.
Regression tested on x86_64.
Regards,
Jerry
---
fortran: Pass ERRMSG= of collective subroutines by reference
With -fcoarray=lib, CO_BROADCAST, CO_MAX, CO_MIN, CO_REDUCE and CO_SUM
passed the ERRMSG= variable by value instead of its address, so the
library received the string length where it expected the pointer and
crashed when it set ERRMSG=, e.g. when an image of the team had stopped.
Convert it with gfc_conv_expr_reference, as the image control statements
do.
Assisted-by: Claude Opus 5.5
gcc/fortran/ChangeLog:
* trans-intrinsic.cc (conv_co_collective): Pass errmsg by
reference.
gcc/testsuite/ChangeLog:
* gfortran.dg/coarray_collectives_6.f90: Expect the address of
errmsg.
* gfortran.dg/coarray_collectives_12.f90: Likewise.
* gfortran.dg/coarray_collectives_16.f90: Likewise.
commit 9f9ef0ebf25764537f6f879fb48df82589829619
Author: Jerry DeLisle <[email protected]>
Date: Sat Oct 17 09:59:15 2026 -0700
fortran: Pass ERRMSG= of collective subroutines by reference
With -fcoarray=lib, CO_BROADCAST, CO_MAX, CO_MIN, CO_REDUCE and CO_SUM
passed the ERRMSG= variable by value instead of its address, so the
library received the string length where it expected the pointer and
crashed when it set ERRMSG=, e.g. when an image of the team had stopped.
Convert it with gfc_conv_expr_reference, as the image control statements
do.
Assisted-by: Claude Opus 5.5
gcc/fortran/ChangeLog:
* trans-intrinsic.cc (conv_co_collective): Pass errmsg by
reference.
gcc/testsuite/ChangeLog:
* gfortran.dg/coarray_collectives_6.f90: Expect the address of
errmsg.
* gfortran.dg/coarray_collectives_12.f90: Likewise.
* gfortran.dg/coarray_collectives_16.f90: Likewise.
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index fe271609671..b39216f527e 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -12606,7 +12606,7 @@ conv_co_collective (gfc_code *code)
if (errmsg_expr)
{
gfc_init_se (&argse, NULL);
- gfc_conv_expr (&argse, errmsg_expr);
+ gfc_conv_expr_reference (&argse, errmsg_expr);
gfc_add_block_to_block (&block, &argse.pre);
gfc_add_block_to_block (&post_block, &argse.post);
errmsg = argse.expr;
diff --git a/gcc/testsuite/gfortran.dg/coarray_collectives_12.f90 b/gcc/testsuite/gfortran.dg/coarray_collectives_12.f90
index 2d8a39a9084..9fed35a3768 100644
--- a/gcc/testsuite/gfortran.dg/coarray_collectives_12.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_collectives_12.f90
@@ -20,6 +20,6 @@ program test
call co_broadcast(val3, source_image=res,stat=stat3, errmsg=errmesg3)
end program test
-! { dg-final { scan-tree-dump-times "_gfortran_caf_co_broadcast \\(&desc.., _gfortran_caf_num_images \\(0B, 0B\\), &stat1, errmesg1, 6\\);" 1 "original" } }
-! { dg-final { scan-tree-dump-times "_gfortran_caf_co_broadcast \\(&val2, 4, &stat2, errmesg2, 7\\);" 1 "original" } }
-! { dg-final { scan-tree-dump-times "_gfortran_caf_co_broadcast \\(&desc.., res, &stat3, errmesg3, 8\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_co_broadcast \\(&desc.., _gfortran_caf_num_images \\(0B, 0B\\), &stat1, &errmesg1, 6\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_co_broadcast \\(&val2, 4, &stat2, &errmesg2, 7\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_co_broadcast \\(&desc.., res, &stat3, &errmesg3, 8\\);" 1 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/coarray_collectives_16.f90 b/gcc/testsuite/gfortran.dg/coarray_collectives_16.f90
index 05a135012d8..ad4041add32 100644
--- a/gcc/testsuite/gfortran.dg/coarray_collectives_16.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_collectives_16.f90
@@ -33,6 +33,6 @@ contains
end function hc
end program test
-! { dg-final { scan-tree-dump-times "_gfortran_caf_co_reduce \\(&desc.., fr, 4, _gfortran_caf_num_images \\(0B, 0B\\), &stat1, errmesg1, 0, 6\\);" 1 "original" } }
-! { dg-final { scan-tree-dump-times "_gfortran_caf_co_reduce \\(&val2, gz, 0, 4, &stat2, errmesg2, 0, 7\\);" 1 "original" } }
-! { dg-final { scan-tree-dump-times "_gfortran_caf_co_reduce \\(&desc.., hc, 1, res, &stat3, errmesg3, 99, 8\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_co_reduce \\(&desc.., fr, 4, _gfortran_caf_num_images \\(0B, 0B\\), &stat1, &errmesg1, 0, 6\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_co_reduce \\(&val2, gz, 0, 4, &stat2, &errmesg2, 0, 7\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_co_reduce \\(&desc.., hc, 1, res, &stat3, &errmesg3, 99, 8\\);" 1 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/coarray_collectives_6.f90 b/gcc/testsuite/gfortran.dg/coarray_collectives_6.f90
index af728287242..3119336125d 100644
--- a/gcc/testsuite/gfortran.dg/coarray_collectives_6.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_collectives_6.f90
@@ -20,6 +20,6 @@ program test
call co_min(val3, result_image=res,stat=stat3, errmsg=errmesg3)
end program test
-! { dg-final { scan-tree-dump-times "_gfortran_caf_co_max \\(&desc.., 0, &stat1, errmesg1, 0, 6\\);" 1 "original" } }
-! { dg-final { scan-tree-dump-times "_gfortran_caf_co_sum \\(&val2, 4, &stat2, errmesg2, 7\\);" 1 "original" } }
-! { dg-final { scan-tree-dump-times "_gfortran_caf_co_min \\(&desc.., res, &stat3, errmesg3, 99, 8\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_co_max \\(&desc.., 0, &stat1, &errmesg1, 0, 6\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_co_sum \\(&val2, 4, &stat2, &errmesg2, 7\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_co_min \\(&desc.., res, &stat3, &errmesg3, 99, 8\\);" 1 "original" } }