aboutsummaryrefslogtreecommitdiff
path: root/libgfortran
AgeCommit message (Collapse)AuthorFilesLines
2025-06-19Daily bump.GCC Administrator1-0/+21
2025-06-18Fortran: various fixes for STAT/LSTAT/FSTAT intrinsics [PR82480]Harald Anlauf1-124/+150
The GNU intrinsics STAT/LSTAT/FSTAT were inherited from g77, but changed the names of some keywords: FILE became NAME, and SARRAY became VALUES, which are the keywords documented in the gfortran manual. Adjust code and libgfortran error messages to reflect this change. Furthermore, add compile-time checking that INTENT(OUT) arguments are definable, and that array VALUES has at least size 13. Document that integer arguments are of default kind, and that overflows in conversion to integer return -1 in VALUES. PR fortran/82480 gcc/fortran/ChangeLog: * check.cc (gfc_check_fstat): Extend checks to INTENT(OUT) arguments. (gfc_check_fstat_sub): Likewise. (gfc_check_stat): Likewise. (gfc_check_stat_sub): Likewise. * intrinsic.texi: Adjust documentation. libgfortran/ChangeLog: * intrinsics/stat.c (stat_i4_sub_0): Fix argument names. Rename SARRAY to VALUES also in error message. When array VALUES is KIND=4, get only stat components that do not overflow INT32_MAX, otherwise set the corresponding VALUES elements to -1. (stat_i4_sub): Fix argument names. (lstat_i4_sub): Likewise. (stat_i8_sub_0): Likewise. (stat_i8_sub): Likewise. (lstat_i8_sub): Likewise. (stat_i4): Likewise. (stat_i8): Likewise. (lstat_i4): Likewise. (lstat_i8): Likewise. (fstat_i4_sub): Likewise. (fstat_i8_sub): Likewise. (fstat_i4): Likewise. (fstat_i8): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/stat_3.f90: New test.
2025-06-12Daily bump.GCC Administrator1-0/+7
2025-06-11libfortran: Simplify Makefile logicFrancois-Xavier Coudert3-1245/+967
Simplify the structure of the Makefile, because now we don't need so many different variables. Also, list the m4 directory entirely in EXTRA_DIST instead of individual files, to reduce information duplication. I also introduce some level of checking the regenerate.sh script. It should catch cases where the list of generated files gets out of sync between Makefile.am and regenerate.sh 2025-06-10 François-Xavier Coudert <fxcoudert@gcc.gnu.org> libgfortran/ChangeLog: PR libfortran/116400 * Makefile.am: Simplify logic. * Makefile.in: Regenerate. * regenerate.sh: Add some checks.
2025-06-11Daily bump.GCC Administrator1-0/+7
2025-06-10libfortran: Add script to regenerate source filesFrancois-Xavier Coudert3-341/+1237
Move the regeneration of libgfortran source files from the Makefile to a standalone script. We were previously highjacking the maintainer mode of autoconf/automake in a way that was not adequate, leading to various issues. Bring our behavior in line with other GCC libraries. 2025-06-09 François-Xavier Coudert <fxcoudert@gcc.gnu.org> libgfortran/ChangeLog: PR libfortran/116400 * Makefile.am: Remove source file regeneration rules. * Makefile.in: Regenerate. * regenerate.sh: New file.
2025-06-08Daily bump.GCC Administrator1-0/+124
2025-06-07libfortran: Regenerate filesFrancois-Xavier Coudert120-1105/+1105
In commit 5e918a4db9e4a5bdbeafec6881fa8b22a55d3789, regenerated files were not included in the commit as they should have been. Therefore, a whitespace fix was not propagated. Sync generated files now, as obtained from a run with --enable-maintainer-mode. 2025-06-06 François-Xavier Coudert <fxcoudert@gcc.gnu.org> libgfortran/ChangeLog: PR libfortran/116400 * generated/iall_i1.c: Regenerate. * generated/iall_i16.c: Regenerate. * generated/iall_i2.c: Regenerate. * generated/iall_i4.c: Regenerate. * generated/iall_i8.c: Regenerate. * generated/iany_i1.c: Regenerate. * generated/iany_i16.c: Regenerate. * generated/iany_i2.c: Regenerate. * generated/iany_i4.c: Regenerate. * generated/iany_i8.c: Regenerate. * generated/iparity_i1.c: Regenerate. * generated/iparity_i16.c: Regenerate. * generated/iparity_i2.c: Regenerate. * generated/iparity_i4.c: Regenerate. * generated/iparity_i8.c: Regenerate. * generated/matmulavx128_c10.c: Regenerate. * generated/matmulavx128_c16.c: Regenerate. * generated/matmulavx128_c17.c: Regenerate. * generated/matmulavx128_c4.c: Regenerate. * generated/matmulavx128_c8.c: Regenerate. * generated/matmulavx128_i1.c: Regenerate. * generated/matmulavx128_i16.c: Regenerate. * generated/matmulavx128_i2.c: Regenerate. * generated/matmulavx128_i4.c: Regenerate. * generated/matmulavx128_i8.c: Regenerate. * generated/matmulavx128_r10.c: Regenerate. * generated/matmulavx128_r16.c: Regenerate. * generated/matmulavx128_r17.c: Regenerate. * generated/matmulavx128_r4.c: Regenerate. * generated/matmulavx128_r8.c: Regenerate. * generated/maxloc1_16_i1.c: Regenerate. * generated/maxloc1_16_i16.c: Regenerate. * generated/maxloc1_16_i2.c: Regenerate. * generated/maxloc1_16_i4.c: Regenerate. * generated/maxloc1_16_i8.c: Regenerate. * generated/maxloc1_16_r10.c: Regenerate. * generated/maxloc1_16_r16.c: Regenerate. * generated/maxloc1_16_r17.c: Regenerate. * generated/maxloc1_16_r4.c: Regenerate. * generated/maxloc1_16_r8.c: Regenerate. * generated/maxloc1_4_i1.c: Regenerate. * generated/maxloc1_4_i16.c: Regenerate. * generated/maxloc1_4_i2.c: Regenerate. * generated/maxloc1_4_i4.c: Regenerate. * generated/maxloc1_4_i8.c: Regenerate. * generated/maxloc1_4_r10.c: Regenerate. * generated/maxloc1_4_r16.c: Regenerate. * generated/maxloc1_4_r17.c: Regenerate. * generated/maxloc1_4_r4.c: Regenerate. * generated/maxloc1_4_r8.c: Regenerate. * generated/maxloc1_8_i1.c: Regenerate. * generated/maxloc1_8_i16.c: Regenerate. * generated/maxloc1_8_i2.c: Regenerate. * generated/maxloc1_8_i4.c: Regenerate. * generated/maxloc1_8_i8.c: Regenerate. * generated/maxloc1_8_r10.c: Regenerate. * generated/maxloc1_8_r16.c: Regenerate. * generated/maxloc1_8_r17.c: Regenerate. * generated/maxloc1_8_r4.c: Regenerate. * generated/maxloc1_8_r8.c: Regenerate. * generated/maxval_i1.c: Regenerate. * generated/maxval_i16.c: Regenerate. * generated/maxval_i2.c: Regenerate. * generated/maxval_i4.c: Regenerate. * generated/maxval_i8.c: Regenerate. * generated/maxval_r10.c: Regenerate. * generated/maxval_r16.c: Regenerate. * generated/maxval_r17.c: Regenerate. * generated/maxval_r4.c: Regenerate. * generated/maxval_r8.c: Regenerate. * generated/minloc1_16_i1.c: Regenerate. * generated/minloc1_16_i16.c: Regenerate. * generated/minloc1_16_i2.c: Regenerate. * generated/minloc1_16_i4.c: Regenerate. * generated/minloc1_16_i8.c: Regenerate. * generated/minloc1_16_r10.c: Regenerate. * generated/minloc1_16_r16.c: Regenerate. * generated/minloc1_16_r17.c: Regenerate. * generated/minloc1_16_r4.c: Regenerate. * generated/minloc1_16_r8.c: Regenerate. * generated/minloc1_4_i1.c: Regenerate. * generated/minloc1_4_i16.c: Regenerate. * generated/minloc1_4_i2.c: Regenerate. * generated/minloc1_4_i4.c: Regenerate. * generated/minloc1_4_i8.c: Regenerate. * generated/minloc1_4_r10.c: Regenerate. * generated/minloc1_4_r16.c: Regenerate. * generated/minloc1_4_r17.c: Regenerate. * generated/minloc1_4_r4.c: Regenerate. * generated/minloc1_4_r8.c: Regenerate. * generated/minloc1_8_i1.c: Regenerate. * generated/minloc1_8_i16.c: Regenerate. * generated/minloc1_8_i2.c: Regenerate. * generated/minloc1_8_i4.c: Regenerate. * generated/minloc1_8_i8.c: Regenerate. * generated/minloc1_8_r10.c: Regenerate. * generated/minloc1_8_r16.c: Regenerate. * generated/minloc1_8_r17.c: Regenerate. * generated/minloc1_8_r4.c: Regenerate. * generated/minloc1_8_r8.c: Regenerate. * generated/minval_i1.c: Regenerate. * generated/minval_i16.c: Regenerate. * generated/minval_i2.c: Regenerate. * generated/minval_i4.c: Regenerate. * generated/minval_i8.c: Regenerate. * generated/minval_r10.c: Regenerate. * generated/minval_r16.c: Regenerate. * generated/minval_r17.c: Regenerate. * generated/minval_r4.c: Regenerate. * generated/minval_r8.c: Regenerate. * generated/norm2_r10.c: Regenerate. * generated/norm2_r16.c: Regenerate. * generated/norm2_r17.c: Regenerate. * generated/norm2_r4.c: Regenerate. * generated/norm2_r8.c: Regenerate. * generated/parity_l1.c: Regenerate. * generated/parity_l16.c: Regenerate. * generated/parity_l2.c: Regenerate. * generated/parity_l4.c: Regenerate. * generated/parity_l8.c: Regenerate.
2025-06-02Daily bump.GCC Administrator1-0/+8
2025-06-01Fortran: Fix handling of parsed format strings.Jerry DeLisle1-5/+5
Previously parsed strings with errors were being cached such that subsequent use of the format string were not being checked for errors. PR libfortran/119856 libgfortran/ChangeLog: * io/format.c (parse_format_list): Set the fmt->error message for missing comma. (parse_format): Do not cache the parsed format string if a previous error ocurred. gcc/testsuite/ChangeLog: * gfortran.dg/pr119856.f90: New test.
2025-05-14Daily bump.GCC Administrator1-0/+45
2025-05-13libfortran: Fix up _gfortran_{,m,s}findloc2_s{1,4} [PR120196]Jakub Jelinek3-6/+6
As mentioned in the PR, _gfortran_{,m,s}findloc2_s{1,4} iterate too many times in the back case if nothing is found. For !back, the loops are for (i = 1; i <= extent; i++) so i is in the body [1, extent] if nothing is found, but for back it is for (i = extent; i >= 0; i--) so i is in the body [0, extent] and compares one element before the start of the array. Note, findloc1_s{1,4} uses for (n = len; n > 0; n--, src -= delta * len_array) for the back loop and for (n = 1; n <= len; n++, src += delta * len_array) for !back. This patch fixes that. The testcase fails under valgrind without the libgfortran changes and succeeds with those. 2025-05-13 Jakub Jelinek <jakub@redhat.com> PR libfortran/120196 * m4/ifindloc2.m4 (header1, header2): For back use i > 0 rather than i >= 0 as for condition. * generated/findloc2_s1.c: Regenerate. * generated/findloc2_s4.c: Regenerate. * gfortran.dg/pr120196.f90: New test.
2025-05-13libfortran: Fix up _gfortran_s{max,min}loc1_{4,8,16}_s{1,4} [PR120191]Jakub Jelinek13-39/+26
There is a bug in _gfortran_s{max,min}loc1_{4,8,16}_s{1,4} which the following testcase shows. The functions return but then crash in the caller. Seems that is because buffer overflows, I believe those functions for if (mask == NULL || *mask) condition being false are supposed to fill in the result array with all zeros (or allocate it and fill it with zeros). My understanding is the result array in that case is integer(kind={4,8,16}) and should have the extents the character input array has. The problem is that it uses * string_len in the extent multiplication: extent[n] = GFC_DESCRIPTOR_EXTENT(array,n) * string_len; and extent[n] = GFC_DESCRIPTOR_EXTENT(array,n + 1) * string_len; which is I guess fine and desirable for the extents of the character array, but not for the extents of the destination array. Yet the code uses that extent array for that purpose (and no other purposes). Here it uses it to set the dimensions for the case where it needs to allocate (as well as size): for (n = 0; n < rank; n++) { if (n == 0) str = 1; else str = GFC_DESCRIPTOR_STRIDE(retarray,n-1) * extent[n-1]; GFC_DIMENSION_SET(retarray->dim[n], 0, extent[n] - 1, str); } Here it uses it for bounds checking of the destination: if (unlikely (compile_options.bounds_check)) { for (n=0; n < rank; n++) { index_type ret_extent; ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,n); if (extent[n] != ret_extent) runtime_error ("Incorrect extent in return value of" " MAXLOC intrinsic in dimension %ld:" " is %ld, should be %ld", (long int) n + 1, (long int) ret_extent, (long int) extent[n]); } } and here to find out how many retarray elements to actually fill in each dimension: while(1) { *dest = 0; count[0]++; dest += dstride[0]; n = 0; while (count[n] == extent[n]) { /* When we get to the end of a dimension, reset it and increment the next dimension. */ count[n] = 0; /* We could precalculate these products, but this is a less frequently used path so probably not worth it. */ dest -= dstride[n] * extent[n]; Seems maxloc1s.m4 and minloc1s.m4 are the only users of ifunction-s.m4, so we can change SCALAR_ARRAY_FUNCTION in there without breaking anything else. 2025-05-13 Jakub Jelinek <jakub@redhat.com> PR fortran/120191 * m4/ifunction-s.m4 (SCALAR_ARRAY_FUNCTION): Don't multiply GFC_DESCRIPTOR_EXTENT(array,) by string_len. * generated/maxloc1_4_s1.c: Regenerate. * generated/maxloc1_4_s4.c: Regenerate. * generated/maxloc1_8_s1.c: Regenerate. * generated/maxloc1_8_s4.c: Regenerate. * generated/maxloc1_16_s1.c: Regenerate. * generated/maxloc1_16_s4.c: Regenerate. * generated/minloc1_4_s1.c: Regenerate. * generated/minloc1_4_s4.c: Regenerate. * generated/minloc1_8_s1.c: Regenerate. * generated/minloc1_8_s4.c: Regenerate. * generated/minloc1_16_s1.c: Regenerate. * generated/minloc1_16_s4.c: Regenerate. * gfortran.dg/pr120191_3.f90: New test.
2025-05-13libfortran: Fix up _gfortran_s{max,min}loc2_{4,8,16}_s{1,4} [PR120191]Jakub Jelinek14-28/+28
I've tried to write a testcase for the BT_CHARACTER maxloc/minloc with named or unnamed arguments and indeed the just posted patch fixed the arguments in there in multiple cases to match what the library expects. But the testcase still fails, due to library problems. One dealt with in this patch are _gfortran_s{max,min}loc2_{4,8,16}_s{1,4} functions. Those are trivial wrappers around _gfortrani_{max,min}loc2_{4,8,16}_s{1,4} which should call those functions if the scalar mask is true and just return 0 otherwise. The two bugs I see there is that the back, len arguments are swapped, which means that it always acts as back=.true. and for len will use character length of 1 or 0 instead of the desired one. The _gfortrani_{max,min}loc2_{4,8,16}_s{1,4} functions have prototypes like GFC_INTEGER_4 maxloc2_4_s1 (gfc_array_s1 * const restrict array, GFC_LOGICAL_4 back, gfc_charlen_type len) so back comes before len, ditto for the GFC_INTEGER_4 smaxloc2_4_s1 (gfc_array_s1 * const restrict array, GFC_LOGICAL_4 *mask, GFC_LOGICAL_4 back, gfc_charlen_type len) The other problem is that it was just testing if (mask). In my limited Fortran understanding that means that the optional argument mask was supplied but nothing about its actual value. Other scalar mask generated routines use if (mask == NULL || *mask) as the condition when to call the non-masked function, i.e. when mask is not supplied (then it should act like .true. mask) or when it is supplied and evaluates to .true.). 2025-05-13 Jakub Jelinek <jakub@redhat.com> PR fortran/120191 * m4/maxloc2s.m4: For smaxloc2 call maxloc2 if mask is NULL or *mask. Swap back and len arguments. * m4/minloc2s.m4: Likewise. * generated/maxloc2_4_s1.c: Regenerate. * generated/maxloc2_4_s4.c: Regenerate. * generated/maxloc2_8_s1.c: Regenerate. * generated/maxloc2_8_s4.c: Regenerate. * generated/maxloc2_16_s1.c: Regenerate. * generated/maxloc2_16_s4.c: Regenerate. * generated/minloc2_4_s1.c: Regenerate. * generated/minloc2_4_s4.c: Regenerate. * generated/minloc2_8_s1.c: Regenerate. * generated/minloc2_8_s4.c: Regenerate. * generated/minloc2_16_s1.c: Regenerate. * generated/minloc2_16_s4.c: Regenerate. * gfortran.dg/pr120191_2.f90: New test.
2025-05-11Daily bump.GCC Administrator1-0/+4
2025-05-10fortran: fix simple typo in libgfortranYuao Ma1-1/+1
This patch fix a simple typo in the comment of libgfortran. No user facing change here. libgfortran/ChangeLog: * io/read.c (read_f): Comment typo, explict -> explicit. Signed-off-by: Yuao Ma <c8ef@outlook.com>
2025-05-09Daily bump.GCC Administrator1-0/+41
2025-05-08libfortran: Fix up maxval/maxloc for UNSIGNED [PR120158]Jakub Jelinek36-91/+91
When libgfortran is compiled, there are some -Woverflow warnings like ../../../libgfortran/generated/maxloc0_4_m1.c:99:14: warning: unsigned conversion from ‘int’ to ‘GFC_UINTEGER_1’ {aka ‘unsigned char’} changes value from ‘-255’ to ‘1’ [-Woverflow] 99 | maxval = -GFC_UINTEGER_1_HUGE; | ^ and those actually point a bug in the maxloc*/maxval* implementation for UNSIGNED. The intent of #if defined ('atype_inf`) result = -atype_inf; #else result = atype_min; #endif (or similar for maxval) is to initialize the variable with minimum value of the type, if the type has infinities, then negative infinity, otherwise the minimum (normalized) value. atype_min expands for signed integers to say (-GFC_INTEGER_4_HUGE-1) or for floating point to say -GFC_REAL_8_HUGE. For UNSIGNED it expands to e.g. -GFC_UINTEGER_4_HUGE, but that is -0xffffffffU which is 1U, while the minimum value of the type is 0. Haven't tried to construct testcases for that, but I believe e.g. maskval could return incorrectly 1 on an array (or masked array) full of 0s, or maxloc could identify incorrectly the maximum location. The following patch makes sure atype_min expands to 0 for atype_name GFC_UINTEGER*. 2025-05-07 Jakub Jelinek <jakub@redhat.com> PR libfortran/120158 * m4/iparm.m4 (atype_min): For atype_name starting with GFC_UINTEGER define to 0. * generated/maxloc0_16_m1.c: Regenerate. * generated/maxloc0_16_m2.c: Regenerate. * generated/maxloc0_16_m4.c: Regenerate. * generated/maxloc0_16_m8.c: Regenerate. * generated/maxloc0_16_m16.c: Regenerate. * generated/maxloc0_4_m1.c: Regenerate. * generated/maxloc0_4_m2.c: Regenerate. * generated/maxloc0_4_m4.c: Regenerate. * generated/maxloc0_4_m8.c: Regenerate. * generated/maxloc0_4_m16.c: Regenerate. * generated/maxloc0_8_m1.c: Regenerate. * generated/maxloc0_8_m2.c: Regenerate. * generated/maxloc0_8_m4.c: Regenerate. * generated/maxloc0_8_m8.c: Regenerate. * generated/maxloc0_8_m16.c: Regenerate. * generated/maxloc1_16_m1.c: Regenerate. * generated/maxloc1_16_m2.c: Regenerate. * generated/maxloc1_16_m4.c: Regenerate. * generated/maxloc1_16_m8.c: Regenerate. * generated/maxloc1_16_m16.c: Regenerate. * generated/maxloc1_4_m1.c: Regenerate. * generated/maxloc1_4_m2.c: Regenerate. * generated/maxloc1_4_m4.c: Regenerate. * generated/maxloc1_4_m8.c: Regenerate. * generated/maxloc1_4_m16.c: Regenerate. * generated/maxloc1_8_m1.c: Regenerate. * generated/maxloc1_8_m2.c: Regenerate. * generated/maxloc1_8_m4.c: Regenerate. * generated/maxloc1_8_m8.c: Regenerate. * generated/maxloc1_8_m16.c: Regenerate. * generated/maxval_m1.c: Regenerate. * generated/maxval_m2.c: Regenerate. * generated/maxval_m4.c: Regenerate. * generated/maxval_m8.c: Regenerate. * generated/maxval_m16.c: Regenerate.
2025-05-08Daily bump.GCC Administrator1-0/+22
2025-05-07libfortran: Add 5 missing UNSIGNED symbols [PR120153]Jakub Jelinek5-13/+614
While looking at PR120152, I have noticed that libgfortran.so doesn't export 5 *m16* symbols I would have expected that should be exported. This is caused by 2 issues, one filename was forgotten to be added in r15-4124 to i_maxloc1_c (guess because generated/maxloc1_16_i16.c was kept in the position after generated/maxloc1_8_m16.c and the i -> m difference wasn't spotted), and one some garbage prefix on HAVE_GFC_UINTEGER_16 macro. The first two hunks of this patch fix that. Though, as GCC 15.1 has been released already, we can't add these symbols to GFORTRAN_15 symbol version as they've never been there, so the patch adds them to a new GFORTRAN_15.2 symbol version instead. 2025-05-07 Jakub Jelinek <jakub@redhat.com> PR libfortran/120153 * Makefile.am (i_maxloc1_c): Add generated/maxloc1_16_m16.c. * intrinsics/random.c (arandom_m16): Use #ifdef HAVE_GFC_UINTEGER_16 guard rather than #ifdef GFC_HAVE_GFC_UINTEGER_16. * gfortran.map (GFORTRAN_15): Remove _gfortran_arandom_m16, _gfortran_maxloc1_16_m16, _gfortran_mmaxloc1_16_m16 and _gfortran_smaxloc1_16_m16. (GFORTRAN_15.2): New symbol version, add those 4 symbols to it. * generated/maxloc1_16_m16.c: New file. * Makefile.in: Regenerate.
2025-05-07ibfortran: Readd 15 accidentally removed libgfortran symbols [PR120152]Jakub Jelinek2-14/+41
The r15-4124-gc0002a675a92e76d change seems to have accidentally dropped 5 sourcefiles from i_maxloc1_c, which resulted in dropping 15 GFORTRAN_8 symbols on x86_64 and 6 on i686. The following patch adds it back, so that we export those symbols again, fixing the ABI problem. 2025-05-07 Jakub Jelinek <jakub@redhat.com> PR libfortran/120152 * Makefile.am (i_maxloc1_c): Readd generated/maxloc1_4_i8.c, generated/maxloc1_8_i8.c, generated/maxloc1_16_i8.c, generated/maxloc1_4_i16.c, generated/maxloc1_8_i16.c. Move generated/maxloc1_16_i16.c entry earlier in the list. * Makefile.in: Regenerated.
2025-04-23Daily bump.GCC Administrator1-0/+72
2025-04-22Fortran: Various fixes on F2018 teams.Andre Vehreschild2-13/+56
gcc/fortran/ChangeLog: * match.cc (match_exit_cycle): Allow to exit team block. (gfc_match_end_team): Create end_team node also without parameter list. * trans-intrinsic.cc (conv_stat_and_team): Team and team_number only need to be a single pointer. * trans-stmt.cc (trans_associate_var): Create a mapping coarray token for coarray associations or it is not addressed correctly. * trans.h (enum gfc_coarray_regtype): Add mapping mode to coarray register. libgfortran/ChangeLog: * caf/libcaf.h: Add mapping mode to coarray's register. * caf/single.c (_gfortran_caf_register): Create a token sharing another token's memory. (check_team): Check team parameters to coindexed expressions are valid. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/coindexed_3.f08: Add minimal test for get_team(). * gfortran.dg/team_change_2.f90: Add test for change team with label and exiting out of it. * gfortran.dg/team_end_2.f90: Check parsing to labeled team blocks is correct now. * gfortran.dg/team_end_3.f90: Check that end_team call is generated for labeled end_teams, too. * gfortran.dg/coarray/coindexed_5.f90: New test.
2025-04-22Fortran: Add teams support in image_index and num_images for F2018Andre Vehreschild2-3/+3
This more or less completes the set of functions that are affected by teams. gcc/fortran/ChangeLog: * check.cc (gfc_check_image_index): Check for team or team_number correctnes. (gfc_check_num_images): Same. * gfortran.texi: Update documentation on num_images' API function. * intrinsic.cc (add_functions): Update signature of image_index and num_images. Both can take either a team handle or number. * intrinsic.h (gfc_check_num_images): Update signature to take either team or team_number. (gfc_check_image_index): Can take coarray, subscripts and team or team number now. (gfc_simplify_image_index): Same. (gfc_simplify_num_images): Same. (gfc_resolve_image_index): Same. * intrinsic.texi: Update documentation of num_images() Fortran function. * iresolve.cc (gfc_resolve_image_index): Update signature. * simplify.cc (gfc_simplify_num_images): Update signature and remove undocumented failed argument. (gfc_simplify_image_index): Add team or team number argument. * trans-intrinsic.cc (conv_stat_and_team): Because being optional teams need to be a pointer to the opaque pointer. (conv_caf_sendget): Correct call; was two arguments short. (trans_image_index): Support team or team_number. (trans_num_images): Same. (conv_intrinsic_cobound): Adapt to changed signature of num_images in call. * trans-stmt.cc (gfc_trans_sync): Same. libgfortran/ChangeLog: * caf/libcaf.h (_gfortran_caf_num_images): Correct prototype. * caf/single.c (_gfortran_caf_num_images): Default implementation. gcc/testsuite/ChangeLog: * gfortran.dg/coarray_49.f90: Adapt to changed error message. * gfortran.dg/coarray_collectives_12.f90: Adapt to changed function signature of num_images. * gfortran.dg/coarray_collectives_16.f90: Same. * gfortran.dg/coarray_lib_this_image_1.f90: Same. * gfortran.dg/coarray_lib_this_image_2.f90: Same. * gfortran.dg/coarray_this_image_1.f90: Adapt tests for num_images. * gfortran.dg/coarray_this_image_2.f90: Same. * gfortran.dg/coarray_this_image_3.f90: Same. * gfortran.dg/num_images_1.f90: Check that deprecated syntax is no longer supported.
2025-04-22Fortran: Add team-support to this_image [PR87326]Andre Vehreschild2-8/+7
This_image() no longer has a distance formal argument, but a team one. The source of the distance argument could not be identified, i.e. whether it came from a TS or standard draft. To implement only the standard it is removed. Besides being defined, it was not used anyway. PR fortran/87326 gcc/fortran/ChangeLog: * check.cc (gfc_check_this_image): Check the three different parameter lists possible for this_image and sort them correctly. * gfortran.texi: Update documentation on this_image's API. * intrinsic.cc (add_functions): Update this_image's signature. (check_specific): Add specific check for this_image. * intrinsic.h (gfc_check_this_image): Change to flexible argument list. * intrinsic.texi: Update documentation on this_image(). * iresolve.cc (gfc_resolve_this_image): Resolve the different arguments. * simplify.cc (gfc_simplify_this_image): Simplify the simplify routine. * trans-decl.cc (gfc_build_builtin_function_decls): Update signature of this_image. * trans-expr.cc (gfc_caf_get_image_index): Use correct signature of this_image. * trans-intrinsic.cc (trans_this_image): Adapt to correct signature. libgfortran/ChangeLog: * caf/libcaf.h (_gfortran_caf_this_image): Correct prototype. * caf/single.c (struct caf_single_team): Add new_index of image. (_gfortran_caf_this_image): Return the image index in the given team. (_gfortran_caf_form_team): Set new_index in team structure. gcc/testsuite/ChangeLog: * gfortran.dg/coarray_10.f90: Update error messages. * gfortran.dg/coarray_lib_this_image_1.f90: Same. * gfortran.dg/coarray_lib_this_image_2.f90: Same. * gfortran.dg/coarray_this_image_1.f90: Add more tests and remove incorrect ones. * gfortran.dg/coarray_this_image_2.f90: Test more features. * gfortran.dg/coarray_this_image_3.f90: New test.
2025-04-22Fortran: Update get_team, team_number and image_status to F2018 [PR88154, ↵Andre Vehreschild2-1/+38
PR88960, PR97210, PR103001] Add functions get_team() and team_number() to comply with F2018 standard. Update image_status() to comply with F2018 standard. PR fortran/88154 PR fortran/88960 PR fortran/97210 PR fortran/103001 gcc/fortran/ChangeLog: * check.cc (team_type_check): Check a type for being team_type from the iso_fortran_env module. (gfc_check_image_status): Use team_type check. (gfc_check_get_team): Check for level argument. (gfc_check_team_number): Use team_type check. * expr.cc (gfc_check_assign): Add treatment for returning team_type in caf-single mode. * gfortran.texi: Add/Update documentation for get_team and team_number API functions. * intrinsic.cc (add_functions): Update get_team signature. * intrinsic.h (gfc_resolve_get_team): Add prototype. * intrinsic.texi: Add/Update documentation for get_team and team_number Fortran functions. * iresolve.cc (gfc_resolve_get_team): Resolve return type to be of type team_type. * iso-fortran-env.def: Update STAT_LOCK constants. They have nothing to do with files. Add level constants for get_team. * libgfortran.h: Add level and unlock_stat constants. * simplify.cc (gfc_simplify_get_team): Simply to correct return type team_type. * trans-decl.cc (gfc_build_builtin_function_decls): Update get_team and image_status API prototypes to correct signatures. * trans-intrinsic.cc (conv_intrinsic_image_status): Translate second parameter correctly. (conv_intrinsic_team_number): Translate optional single team argument correctly. (gfc_conv_intrinsic_function): Add translation of get_team. libgfortran/ChangeLog: * caf/libcaf.h: Add constants for get_team's level argument and update stat values for failed images. (_gfortran_caf_team_number): Add prototype. (_gfortran_caf_get_team): Same. * caf/single.c (_gfortran_caf_team_number): Get the given team's team number. (_gfortran_caf_get_team): Get the current team or the team given by level when the argument is present. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/image_status_1.f08: Correct check for team_type. * gfortran.dg/pr102458.f90: Adapt to multiple errors. * gfortran.dg/coarray/get_team_1.f90: New test. * gfortran.dg/team_get_1.f90: New test. * gfortran.dg/team_number_1.f90: Correct Fortran syntax.
2025-04-22Fortran: Improve F2018 TEAM handling [PR87326, PR87556, PR88254, PR103896]Andre Vehreschild2-19/+174
Improve the implementation of F2018 TEAM handling routines. Add runtime-functions to caf_single to allow testing. PR fortran/87326 PR fortran/87556 PR fortran/88254 PR fortran/103796 gcc/fortran/ChangeLog: * coarray.cc (split_expr_at_caf_ref): Treat polymorphic types correctly. Ensure resolve of expression after coindex. (create_allocated_callback): Fix parameter of allocated function for coarrays. (coindexed_expr_callback): Improve detection of coarrays in allocated function. * decl.cc (gfc_match_end): Add team block matching. * dump-parse-tree.cc (show_code_node): Dump change team block as such. * frontend-passes.cc (gfc_code_walker): Recognice team block. * gfortran.texi: Add documentation for team api functions. * intrinsic.texi: Add documentation about team_type in iso_fortran_env module. * iso-fortran-env.def (team_type): Use helper to get pointer kind. * match.cc (gfc_match_associate): Factor out matching of association list, because it is used in change team as well. (check_coarray_assoc): Ensure, that the association is to a coarray. (match_association_list): Match a list of association either in associate or in change team. (gfc_match_form_team): Match form team correctly include new_index. (gfc_match_change_team): Match change team with association list. (gfc_match_end_team): Match end team including stat and errmsg. (gfc_match_return): Prevent return from team block. * parse.cc (decode_statement): Sort team block. (next_statement): Same. (check_statement_label): Same. (accept_statement): Same. (verify_st_order): Same. (parse_associate): Renamed to move_associates_to_block... (move_associates_to_block): ... to enable reuse for change team. (parse_change_team): Parse it as block. (parse_executable): Same. * parse.h (enum gfc_compile_state): Add team block as compiler state. * resolve.cc (resolve_scalar_argument): New function to resolve an argument to a statement as a scalar. (resolve_form_team): Resolve its members. (resolve_change_team): Same. (resolve_branch): Prevent branch from jumping out of team block. (check_team): Removed. * trans-decl.cc (gfc_build_builtin_function_decls): Add stat and errmsg to team API functions and update their arguments. * trans-expr.cc (gfc_trans_subcomponent_assign): Also null the token when moving memory or an allocated() will not detect a free. * trans-intrinsic.cc (gfc_conv_intrinsic_caf_is_present_remote): Adapt to signature change no longer a pointer-pointer. * trans-stmt.cc (gfc_trans_form_team): Translate a form team including new_index. (gfc_trans_change_team): Translate a change team as a block. libgfortran/ChangeLog: * caf/libcaf.h: Remove commented block. (_gfortran_caf_form_team): Allow for all relevant arguments. (_gfortran_caf_change_team): Same. (_gfortran_caf_end_team): Same. (_gfortran_caf_sync_team): Same. * caf/single.c (struct caf_single_team): Team handling structures. (_gfortran_caf_init): Initialize initial team. (free_team_list): Free all teams and the memory they hold. (_gfortran_caf_finalize): Free initial and sibling teams. (_gfortran_caf_register): Add memory registered to current team. (_gfortran_caf_deregister): Unregister memory from current team. (_gfortran_caf_is_present_on_remote): Check token's memptr for llocation. May have been deallocated by an end team. (_gfortran_caf_form_team): Push a new team stub to the list. (_gfortran_caf_change_team): Push a formed team on top of the ctive teams stack. (_gfortran_caf_end_team): End the active team, free all memory allocated during its livespan. (_gfortran_caf_sync_team): Take stat and errmsg into account. gcc/testsuite/ChangeLog: * gfortran.dg/team_change_2.f90: New test. * gfortran.dg/team_change_3.f90: New test. * gfortran.dg/team_end_2.f90: New test. * gfortran.dg/team_end_3.f90: New test. * gfortran.dg/team_form_2.f90: New test. * gfortran.dg/team_form_3.f90: New test. * gfortran.dg/team_sync_2.f90: New test.
2025-04-22Fortran: Unify handling of STAT= and ERRMSG= optional arguments [PR87939]Andre Vehreschild1-4/+4
In preparing F2018 Teams handling improvements, unify handling of STAT= and ERRMSG= optional arguments. Handling of stat and errmsg in most teams statements is corrected in the next patch. Implement stat and errmsg for move_alloc () to comply with F2018. PR fortran/87939 gcc/fortran/ChangeLog: * check.cc (gfc_check_move_alloc): Add stat and errmsg to move_alloc. * dump-parse-tree.cc (show_sync_stat): New helper function. (show_code_node): Use show_sync_stat to print stat and errmsg. * gfortran.h (struct sync_stat): New struct to unify stat and errmsg handling. * intrinsic.cc (add_subroutines): Correct signature of move_alloc. * intrinsic.h (gfc_check_move_alloc): Correct signature of check_move_alloc. * match.cc (match_named_arg): Match an optional argument to a statement. (match_stat_errmsg): Match a stat= or errmsg= named argument. (gfc_match_critical): Use match_stat_errmsg to match the named arguments. (gfc_match_sync_team): Same. * resolve.cc (resolve_team_argument): Resolve an expr to have type TEAM_TYPE from iso_fortran_env. (resolve_scalar_variable_as_arg): Resolve an argument as a scalar type. (resolve_sync_stat): Resolve stat and errmsg expressions. (resolve_sync_team): Resolve a sync team statement using sync_stat helper. (resolve_end_team): Same. (resolve_critical): Same. * trans-decl.cc (gfc_build_builtin_function_decls): Correct sync_team signature. * trans-intrinsic.cc (conv_intrinsic_move_alloc): Store stat an errmsg optional arguments in helper struct and use helper to translate. * trans-stmt.cc (trans_exit): Implement DRY pattern for generating an _exit(). (gfc_trans_sync_stat): Translate stat and errmsg contents. (gfc_trans_end_team): Use helper to translate stat and errmsg. (gfc_trans_sync_team): Same. (gfc_trans_critical): Same. * trans-stmt.h (gfc_trans_sync_stat): New function. * trans.cc (gfc_deallocate_with_status): Parameterize check at runtime to allow unallocated (co-)array when freeing a structure. (gfc_deallocate_scalar_with_status): Same and also add errmsg. * trans.h (gfc_deallocate_with_status): Signature changes. (gfc_deallocate_scalar_with_status): Same. libgfortran/ChangeLog: * caf/single.c (_gfortran_caf_lock): Correct stat value, if lock is already locked by current image. (_gfortran_caf_unlock): Correct stat value, if lock is not locked. gcc/testsuite/ChangeLog: * gfortran.dg/coarray_critical_2.f90: New test. * gfortran.dg/coarray_critical_3.f90: New test. * gfortran.dg/team_sync_1.f90: New test. * gfortran.dg/move_alloc_11.f90: New test.
2025-04-14Daily bump.GCC Administrator1-0/+8
2025-04-13Fortran: Fix runtime segfault closing negative unitJerry DeLisle2-2/+21
When closing a UNIT with an invalid negative unit number, a segfault ensued. This patch adds checks for these conditions and issues errors. PR libfortran/119502 libgfortran/ChangeLog: * io/close.c (st_close): Issue an error and avoid calling close_share when there is no stream assigned. * io/open.c (st_open): If there is no stream assigned to the unit, unlock the unit and issue an error. gcc/testsuite/ChangeLog: * gfortran.dg/pr119502.f90: New test.
2025-04-10Daily bump.GCC Administrator1-0/+16
2025-04-09Fortran: Fix some problems with the reduce intrinsic [PR119460]Paul Thomas1-32/+45
2025-04-09 Paul Thomas <pault@gcc.gnu.org> and Harald Anlauf <anlauf@gcc.gnu.org> gcc/fortran PR fortran/119460 * iresolve.cc (generate_reduce_op_wrapper): Increase the size of 'tname'. Change intent of 'a' and 'b' to intent_in. * trans-decl.cc (add_argument_checking): Do not test artificial formal symbols. * trans-expr.cc (gfc_conv_procedure_call): Remove reduce_scalar and the blocks triggered by it. * trans-intrinsic.cc (gfc_conv_intrinsic_function): Set the result of non-character, scalar reduce to be allocatable. gcc/testsuite/ PR fortran/119460 * gfortran.dg/reduce_2.f90: Add test to check that deferred len characters cannot slip through. * gfortran.dg/reduce_3.f90: New test * gfortran.dg/reduce_4.f90: New test libgfortran/ PR libfortran/119460 * intrinsics/reduce.c (reduce): Correct error message about mismatch between dim and the rank of array. Output the values of both. Correct the evaluation of the result stride and extent. (reduce_scalar): The front end treats the result as an allocatable so eliminate memcpy and free. Return the base-addr of the local descriptor. (reduce_c): Correct the type of the string lengths. (reduce_scalar_c): Correct the type of the string lengths.Test to see if 'res' is allocated. If not then return the base_addr of the local descriptor.
2025-04-08Daily bump.GCC Administrator1-0/+7
2025-04-07LoongArch: Add LoongArch architecture detection to __float128 support in ↵Lulu Cheng2-0/+12
libgfortran and libquadmath [PR119408]. In GCC14, LoongArch added __float128 as an alias for _Float128. In commit r15-8962, support for q/Q suffixes for 128-bit floating point numbers. This will cause the compiler to automatically link libquadmath when compiling Fortran programs. But on LoongArch `long double` is IEEE quad, so there is no need to implement libquadmath. This causes link failure. PR target/119408 libgfortran/ChangeLog: * acinclude.m4: When checking for __float128 support, determine whether the current architecture is LoongArch. If so, return false. * configure: Regenerate. libquadmath/ChangeLog: * configure.ac: When checking for __float128 support, determine whether the current architecture is LoongArch. If so, return false. * configure: Regenerate. Sigend-off-by: Xi Ruoyao <xry111@xry111.site> Sigend-off-by: Jakub Jelinek <jakub@redhat.com>
2025-03-23Daily bump.GCC Administrator1-0/+4
2025-03-22libgfortran/intrinsics: Fix build for targets with int32_t=long intHans-Peter Nilsson1-1/+1
Without this, after r15-8650-g94fa9f4d27bac5, you'll see, for targets where GFC_INTEGER_4 alias int32_t is a typedef of long int (beware of artificially broken lines): /x/gcc/libgfortran/intrinsics/reduce.c:269:1: error: conflicting types for 'reduce_scalar_c'; have 'void(void *, index_type, parray *, void (*)(void *, void *, void *), int *, gfc_array_l4 *, void *, void *, index_type, index_type)' {aka 'void(void *, long int, parray *, void (*)(void *, void *, void *), int *, gfc_array_l4 *, void *, void *, long int, long int)'} 269 | reduce_scalar_c (void *res, | ^~~~~~~~~~~~~~~ [...] excessive error message verbiage deleted /x/gcc/libgfortran/intrinsics/reduce.c: In function 'reduce_scalar_c': /x/gcc/libgfortran/intrinsics/reduce.c:283:35: error: passing argument 4 of 'reduce' from incompatible pointer type [-Wincompatible-pointer-types] 283 | reduce (&ret, array, operation, dim, mask, identity, ordered); | ^~~ | | | int * /x/gcc/libgfortran/intrinsics/reduce.c:41:24: note: expected 'GFC_INTEGER_4 *' {aka 'long int *'} but argument is of type 'int *' 41 | GFC_INTEGER_4 *dim, | ~~~~~~~~~~~~~~~^~~ make[3]: *** [Makefile:4678: intrinsics/reduce.lo] Error 1 libgfortran: * intrinsics/reduce.c (reduce_scalar_c): Correct type of parameter DIM.
2025-03-22Daily bump.GCC Administrator1-0/+10
2025-03-21Fortran: Implement the F2018 reduce intrinsic [PR85836]Paul Thomas4-2/+296
2025-03-21 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/85836 * check.cc (get_ul_from_cst_cl): New function used in check_operation. (check_operation): New function used in check_reduce and check_co_reduce. (gfc_check_co_reduce): Use it. (gfc_check_reduce): New function. (gfc_check_rename): Add prototype for intrinsic with 6 arguments. * gfortran.h : Add isym id for reduce and prototype for f6. * intrinsic.cc (do_check): Add another argument expression and use it in the call to the six argument specific check. (add_sym_6): New function. (add_functions): Add the discription of the reduce intrinsic and add it to the intrinsic list. * intrinsic.h : Add prototypes for gfc_check_reduce and gfc_resolve_reduce. * iresolve.cc (generate_reduce_op_wrapper): Generate a wrapper subroutine for the 'operation' function to enable the library implementation to be type agnostic and use pointer arithmetic throughout. (gfc_resolve_reduce): New function. * trans-expr.cc (gfc_conv_procedure_call): Add flag for scalar reduce. Generate a return variable 'sr' for scalar reduce, pass its address to the library function and return it as the scalar result. * trans-intrinsic.cc (gfc_conv_intrinsic_function): Array valued reduce is called in same way as reshape. Fall through for call to the scalar version. gcc/testsuite/ PR fortran/85836 * gfortran.dg/reduce_1.f90: New test * gfortran.dg/reduce_2.f90: New test libgfortran/ PR libfortran/85836 * Makefile.am : Add reduce.c * Makefile.in : Regenerated * gfortran.map : Add _gfortran_reduce, _gfortran_reduce_scalar, _gfortran_reduce_c and _gfortran_reduce_scalar_c to the list. * intrinsics/reduce.c (reduce, reduce_scalar, reduce_c, reduce_scalar_c): New functions and prototypes
2025-02-28Daily bump.GCC Administrator1-0/+6
2025-02-27nvptx: Build libgfortran with '-mfake-ptx-alloca' [PR107635]Thomas Schwinge2-0/+6
As of recent commit 8bf0ee8d62b8a08e808344d31354ab713157e15d "Fortran: Add transfer_between_remotes [PR107635]", we've got 'alloca' usage in 'libgfortran/caf/single.c:_gfortran_caf_transfer_between_remotes', and the libgfortran target library fails to build for legacy configurations where PTX 'alloca' is not available: ../../../../source-gcc/libgfortran/caf/single.c: In function ‘_gfortran_caf_transfer_between_remotes’: ../../../../source-gcc/libgfortran/caf/single.c:675:23: sorry, unimplemented: dynamic stack allocation not supported 675 | transfer_desc = __builtin_alloca (desc_size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../../source-gcc/libgfortran/caf/single.c:680:20: sorry, unimplemented: dynamic stack allocation not supported 680 | transfer_ptr = __builtin_alloca (*opt_dst_charlen * src_size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make[6]: *** [Makefile:4675: caf/single.lo] Error 1 With '-mfake-ptx-alloca', libgfortran again succeeds to build, and compared to before, we've got only a small number of regressions due to nvptx 'ld' complaining about 'unresolved symbol __GCC_nvptx__PTX_alloca_not_supported': [-PASS:-]{+FAIL:+} gfortran.dg/coarray/codimension_2.f90 -fcoarray=lib -O2 -lcaf_single (test for excess errors) [-PASS:-]{+FAIL:+} gfortran.dg/coarray/event_4.f08 -fcoarray=lib -O2 -lcaf_single (test for excess errors) [-PASS:-]{+UNRESOLVED:+} gfortran.dg/coarray/event_4.f08 -fcoarray=lib -O2 -lcaf_single [-execution test-]{+compilation failed to produce executable+} [-PASS:-]{+FAIL:+} gfortran.dg/coarray/fail_image_2.f08 -fcoarray=lib -O2 -lcaf_single (test for excess errors) [-PASS:-]{+UNRESOLVED:+} gfortran.dg/coarray/fail_image_2.f08 -fcoarray=lib -O2 -lcaf_single [-execution test-]{+compilation failed to produce executable+} [-PASS:-]{+FAIL:+} gfortran.dg/coarray/proc_pointer_assign_1.f90 -fcoarray=lib -O2 -lcaf_single (test for excess errors) [-PASS:-]{+UNRESOLVED:+} gfortran.dg/coarray/proc_pointer_assign_1.f90 -fcoarray=lib -O2 -lcaf_single [-execution test-]{+compilation failed to produce executable+} [-PASS:-]{+FAIL:+} gfortran.dg/coarray_43.f90 -O (test for excess errors) That's acceptable for such legacy PTX configurations. PR target/107635 libgfortran/ * config/t-nvptx: New. * configure.host [nvptx] (tmake_file): Add it.
2025-02-22Daily bump.GCC Administrator1-0/+5
2025-02-21Fortran: Fix build on solaris [PR107635]Andre Vehreschild1-2/+2
libgfortran/ChangeLog: PR fortran/107635 * caf/single.c: Replace alloca with __builtin_alloca.
2025-02-21Daily bump.GCC Administrator1-0/+69
2025-02-20Fortran: Remove deprecated coarray routines [PR107635]Andre Vehreschild2-2499/+0
gcc/fortran/ChangeLog: PR fortran/107635 * gfortran.texi: Remove deprecated functions from documentation. * trans-decl.cc (gfc_build_builtin_function_decls): Remove decprecated function decls. * trans-intrinsic.cc (gfc_conv_intrinsic_exponent): Remove deprecated/no longer needed routines. * trans.h: Remove unused decls. libgfortran/ChangeLog: * caf/libcaf.h (_gfortran_caf_get): Removed because deprecated. (_gfortran_caf_send): Same. (_gfortran_caf_sendget): Same. (_gfortran_caf_send_by_ref): Same. * caf/single.c (assign_char4_from_char1): Same. (assign_char1_from_char4): Same. (convert_type): Same. (defined): Same. (_gfortran_caf_get): Same. (_gfortran_caf_send): Same. (_gfortran_caf_sendget): Same. (copy_data): Same. (get_for_ref): Same. (_gfortran_caf_get_by_ref): Same. (send_by_ref): Same. (_gfortran_caf_send_by_ref): Same. (_gfortran_caf_sendget_by_ref): Same.
2025-02-20Fortran: Add transfer_between_remotes [PR107635]Andre Vehreschild2-0/+81
Add the last missing coarray data manipulation routine using remote accessors. gcc/fortran/ChangeLog: PR fortran/107635 * coarray.cc (rewrite_caf_send): Rewrite to transfer_between_remotes when both sides of the assignment have a coarray. (coindexed_code_callback): Prevent duplicate rewrite. * gfortran.texi: Add documentation for transfer_between_remotes. * intrinsic.cc (add_subroutines): Add intrinsic symbol for caf_sendget to allow easy rewrite to transfer_between_remotes. * trans-decl.cc (gfc_build_builtin_function_decls): Add prototype for transfer_between_remotes. * trans-intrinsic.cc (conv_caf_vector_subscript_elem): Mark as deprecated. (conv_caf_vector_subscript): Same. (compute_component_offset): Same. (conv_expr_ref_to_caf_ref): Same. (conv_stat_and_team): Extract stat and team from expr. (gfc_conv_intrinsic_caf_get): Use conv_stat_and_team. (conv_caf_send_to_remote): Same. (has_ref_after_cafref): Mark as deprecated. (conv_caf_sendget): Translate to transfer_between_remotes. * trans.h: Add prototype for transfer_between_remotes. libgfortran/ChangeLog: * caf/libcaf.h: Add prototype for transfer_between_remotes. * caf/single.c: Implement transfer_between_remotes. gcc/testsuite/ChangeLog: * gfortran.dg/coarray_lib_comm_1.f90: Fix up scan_trees.
2025-02-20Fortran: Add send_to_remote [PR107635]Andre Vehreschild2-15/+54
Refactor to use send_to_remote instead of the slow send_by_ref. gcc/fortran/ChangeLog: PR fortran/107635 * coarray.cc (move_coarray_ref): Move the coarray reference out of the given one. Especially when there is a regular array ref. (fixup_comp_refs): Move components refs to a derived type where the codim has been removed, aka a new type. (split_expr_at_caf_ref): Correctly split the reference chain. (remove_caf_ref): Simplify. (create_get_callback): Fix some deficiencies. (create_allocated_callback): Adapt to new signature of split. (create_send_callback): New function. (rewrite_caf_send): Rewrite a call to caf_send to caf_send_to_remote. (coindexed_code_callback): Treat caf_send and caf_sendget correctly. * gfortran.h (enum gfc_isym_id): Add SENDGET-isym. * gfortran.texi: Add documentation for send_to_remote. * resolve.cc (gfc_resolve_code): No longer generate send_by_ref when allocatable coarray (component) is on the lhs. * trans-decl.cc (gfc_build_builtin_function_decls): Add caf_send_to_remote decl. * trans-intrinsic.cc (conv_caf_func_index): Ensure the static variables created are not in a block-scope. (conv_caf_send_to_remote): Translate caf_send_to_remote calls. (conv_caf_send): Renamed to conv_caf_sendget. (conv_caf_sendget): Renamed from conv_caf_send. (gfc_conv_intrinsic_subroutine): Branch correctly for conv_caf_send and sendget. * trans.h: Correct decl. libgfortran/ChangeLog: * caf/libcaf.h: Add/Correct prototypes for caf_get_from_remote, caf_send_to_remote. * caf/single.c (struct accessor_hash_t): Rename accessor_t to getter_t. (_gfortran_caf_register_accessor): Use new name of getter_t. (_gfortran_caf_send_to_remote): New function for sending data to coarray on a remote image. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/send_char_array_1.f90: Extend test to catch more cases. * gfortran.dg/coarray_42.f90: Invert tests use, because no longer a send is needed when local memory in a coarray is allocated.
2025-02-20Fortran: Add caf_is_present_on_remote. [PR107635]Andre Vehreschild2-102/+29
Replace caf_is_present by caf_is_present_on_remote which is using a dedicated callback for each object to test on the remote image. gcc/fortran/ChangeLog: PR fortran/107635 * coarray.cc (create_allocated_callback): Add creating remote side procedure for checking allocation status of coarray. (rewrite_caf_allocated): Rewrite ALLOCATED on coarray to use caf routine. (coindexed_expr_callback): Exempt caf_is_present_on_remote from being rewritten again. * gfortran.h (enum gfc_isym_id): Add caf_is_present_on_remote id. * gfortran.texi: Add documentation for caf_is_present_on_remote. * intrinsic.cc (add_functions): Add caf_is_present_on_remote symbol. * trans-decl.cc (gfc_build_builtin_function_decls): Define interface of caf_is_present_on_remote. * trans-intrinsic.cc (gfc_conv_intrinsic_caf_is_present_remote): Translate caf_is_present_on_remote. (trans_caf_is_present): Remove. (caf_this_image_ref): Remove. (gfc_conv_allocated): Take out coarray treatment, because that is rewritten to caf_is_present_on_remote now. (gfc_conv_intrinsic_function): Handle caf_is_present_on_remote calls. * trans.h: Add symbol for caf_is_present_on_remote and remove old one. libgfortran/ChangeLog: * caf/libcaf.h (_gfortran_caf_is_present_on_remote): Add new function. (_gfortran_caf_is_present): Remove deprecated one. * caf/single.c (struct accessor_hash_t): Add function ptr access for remote side call. (_gfortran_caf_is_present_on_remote): Added. (_gfortran_caf_is_present): Removed. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/coarray_allocated.f90: Adapt to new method of checking on remote image. * gfortran.dg/coarray_lib_alloc_4.f90: Same.
2025-02-20Fortran: Allow to use non-pure/non-elemental functions in coarray indexes ↵Andre Vehreschild2-9/+19
[PR107635] Extract calls to non-pure or non-elemental functions from index expressions on a coarray. gcc/fortran/ChangeLog: PR fortran/107635 * coarray.cc (get_arrayspec_from_expr): Treat array result of function calls correctly. (remove_coarray_from_derived_type): Prevent memory loss. (add_caf_get_from_remote): Correct locus. (find_comp): New function to find or create a new component in a derived type. (check_add_new_comp_handle_array): Handle allocatable arrays or non-pure/non-elemental functions in indexes of coarrays. (check_add_new_component): Use above function. (create_get_parameter_type): Rename to create_caf_add_data_parameter_type. (create_caf_add_data_parameter_type): Renaming of variable and make the additional data a coarray. (remove_caf_ref): Factor out to reuse in other caf-functions. (create_get_callback): Use function factored out, set locus correctly and ensure a kind is set for parameters. (add_caf_get_intrinsic): Rename to add_caf_get_from_remote and rename some variables. (coindexed_expr_callback): Skip over function created by the rewriter. (coindexed_code_callback): Filter some intrinsics not to process. (gfc_coarray_rewrite): Rewrite also contained functions. * trans-intrinsic.cc (gfc_conv_intrinsic_caf_get): Reflect changed order on caf_get_from_remote (). libgfortran/ChangeLog: * caf/libcaf.h (_gfortran_caf_register_accessor): Reflect changed parameter order. * caf/single.c (struct accessor_hash_t): Same. (_gfortran_caf_register_accessor): Call accessor using a token for accessing arrays with a descriptor on the source side. gcc/testsuite/ChangeLog: * gfortran.dg/coarray_lib_comm_1.f90: Adapt scan expression. * gfortran.dg/coarray/get_with_fn_parameter.f90: New test. * gfortran.dg/coarray/get_with_scalar_fn.f90: New test.
2025-02-20Fortran: Prepare for more caf-rework. [PR107635]Andre Vehreschild2-16/+13
Factor out generation of code to get remote function index and to create the additional data structure. Rename caf_get_by_ct to caf_get_from_remote. gcc/fortran/ChangeLog: PR fortran/107635 * gfortran.texi: Rename caf_get_by_ct to caf_get_from_remote. * trans-decl.cc (gfc_build_builtin_function_decls): Rename intrinsic. * trans-intrinsic.cc (conv_caf_func_index): Factor out functionality to be reused by other caf-functions. (conv_caf_add_call_data): Same. (gfc_conv_intrinsic_caf_get): Use functions factored out. * trans.h: Rename intrinsic symbol. libgfortran/ChangeLog: * caf/libcaf.h (_gfortran_caf_get_by_ref): Remove from ABI. This function is replaced by caf_get_from_remote (). (_gfortran_caf_get_remote_function_index): Use better name. * caf/single.c (_gfortran_caf_finalize): Free internal data. (_gfortran_caf_get_by_ref): Remove from public interface, but keep it, because it is still used by sendget (). gcc/testsuite/ChangeLog: * gfortran.dg/coarray_lib_comm_1.f90: Adapt to renamed ABI function. * gfortran.dg/coarray_stat_function.f90: Same. * gfortran.dg/coindexed_1.f90: Same.
2025-02-20Fortran: Move caf_get-rewrite to coarray.cc [PR107635]Andre Vehreschild2-9/+8
Add a rewriter to keep all expression tree that is not optimization together. At the moment this is just a move from resolve.cc, but will be extended to handle more cases where rewriting the expression tree may be easier. The first use case is to extract accessors for coarray remote image data access. gcc/fortran/ChangeLog: PR fortran/107635 * Make-lang.in: Add coarray.cc. * coarray.cc: New file. * gfortran.h (gfc_coarray_rewrite): New procedure. * parse.cc (rewrite_expr_tree): Add entrypoint for rewriting expression trees. * resolve.cc (gfc_resolve_ref): Remove caf_lhs handling. (get_arrayspec_from_expr): Moved to rewrite.cc. (remove_coarray_from_derived_type): Same. (convert_coarray_class_to_derived_type): Same. (split_expr_at_caf_ref): Same. (check_add_new_component): Same. (create_get_parameter_type): Same. (create_get_callback): Same. (add_caf_get_intrinsic): Same. (resolve_variable): Remove caf_lhs handling. libgfortran/ChangeLog: * caf/single.c (_gfortran_caf_finalize): Free memory preventing leaks. (_gfortran_caf_get_by_ct): Fix constness. * caf/libcaf.h (_gfortran_caf_register_accessor): Fix constness.