[PATCH] libfortran: Readd 15 accidentally removed libgfortran symbols [PR120152]

2025-05-07 Thread Jakub Jelinek
Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk
and 15.2?

2025-05-07  Jakub Jelinek  

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.

--- libgfortran/Makefile.am.jj  2025-04-08 14:10:04.882256861 +0200
+++ libgfortran/Makefile.am 2025-05-07 10:44:54.534238786 +0200
@@ -400,6 +400,12 @@ generated/maxloc1_16_i2.c \
 generated/maxloc1_4_i4.c \
 generated/maxloc1_8_i4.c \
 generated/maxloc1_16_i4.c \
+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 \
+generated/maxloc1_16_i16.c \
 generated/maxloc1_4_m1.c \
 generated/maxloc1_8_m1.c \
 generated/maxloc1_16_m1.c \
@@ -414,7 +420,6 @@ generated/maxloc1_8_m8.c \
 generated/maxloc1_16_m8.c \
 generated/maxloc1_4_m16.c \
 generated/maxloc1_8_m16.c \
-generated/maxloc1_16_i16.c \
 generated/maxloc1_4_r4.c \
 generated/maxloc1_8_r4.c \
 generated/maxloc1_16_r4.c \
--- libgfortran/Makefile.in.jj  2025-05-07 10:47:40.361973724 +0200
+++ libgfortran/Makefile.in 2025-05-07 10:46:41.288779475 +0200
@@ -265,22 +265,24 @@ am__objects_8 = generated/maxloc1_4_i1.l
generated/maxloc1_16_i1.lo generated/maxloc1_4_i2.lo \
generated/maxloc1_8_i2.lo generated/maxloc1_16_i2.lo \
generated/maxloc1_4_i4.lo generated/maxloc1_8_i4.lo \
-   generated/maxloc1_16_i4.lo generated/maxloc1_4_m1.lo \
+   generated/maxloc1_16_i4.lo generated/maxloc1_4_i8.lo \
+   generated/maxloc1_8_i8.lo generated/maxloc1_16_i8.lo \
+   generated/maxloc1_4_i16.lo generated/maxloc1_8_i16.lo \
+   generated/maxloc1_16_i16.lo generated/maxloc1_4_m1.lo \
generated/maxloc1_8_m1.lo generated/maxloc1_16_m1.lo \
generated/maxloc1_4_m2.lo generated/maxloc1_8_m2.lo \
generated/maxloc1_16_m2.lo generated/maxloc1_4_m4.lo \
generated/maxloc1_8_m4.lo generated/maxloc1_16_m4.lo \
generated/maxloc1_4_m8.lo generated/maxloc1_8_m8.lo \
generated/maxloc1_16_m8.lo generated/maxloc1_4_m16.lo \
-   generated/maxloc1_8_m16.lo generated/maxloc1_16_i16.lo \
-   generated/maxloc1_4_r4.lo generated/maxloc1_8_r4.lo \
-   generated/maxloc1_16_r4.lo generated/maxloc1_4_r8.lo \
-   generated/maxloc1_8_r8.lo generated/maxloc1_16_r8.lo \
-   generated/maxloc1_4_r10.lo generated/maxloc1_8_r10.lo \
-   generated/maxloc1_16_r10.lo generated/maxloc1_4_r16.lo \
-   generated/maxloc1_8_r16.lo generated/maxloc1_16_r16.lo \
-   generated/maxloc1_4_r17.lo generated/maxloc1_8_r17.lo \
-   generated/maxloc1_16_r17.lo
+   generated/maxloc1_8_m16.lo generated/maxloc1_4_r4.lo \
+   generated/maxloc1_8_r4.lo generated/maxloc1_16_r4.lo \
+   generated/maxloc1_4_r8.lo generated/maxloc1_8_r8.lo \
+   generated/maxloc1_16_r8.lo generated/maxloc1_4_r10.lo \
+   generated/maxloc1_8_r10.lo generated/maxloc1_16_r10.lo \
+   generated/maxloc1_4_r16.lo generated/maxloc1_8_r16.lo \
+   generated/maxloc1_16_r16.lo generated/maxloc1_4_r17.lo \
+   generated/maxloc1_8_r17.lo generated/maxloc1_16_r17.lo
 am__objects_9 = generated/maxval_i1.lo generated/maxval_i2.lo \
generated/maxval_i4.lo generated/maxval_i8.lo \
generated/maxval_i16.lo generated/maxval_m1.lo \
@@ -1205,6 +1207,12 @@ generated/maxloc1_16_i2.c \
 generated/maxloc1_4_i4.c \
 generated/maxloc1_8_i4.c \
 generated/maxloc1_16_i4.c \
+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 \
+generated/maxloc1_16_i16.c \
 generated/maxloc1_4_m1.c \
 generated/maxloc1_8_m1.c \
 generated/maxloc1_16_m1.c \
@@ -1219,7 +1227,6 @@ generated/maxloc1_8_m8.c \
 generated/maxloc1_16_m8.c \
 generated/maxloc1_4_m16.c \
 generated/maxloc1_8_m16.c \
-generated/maxloc1_16_i16.c \
 generated/maxloc1_4_r4.c \
 generated/maxloc1_8_r4.c \
 generated/maxloc1_16_r4.c \
@@ -2311,6 +2318,18 @@ generated/maxloc1_8_i4.lo: generated/$(a
generated/$(DEPDIR)/$(am__dirstamp)
 generated/maxloc1_16_i4.lo: generated/$(am__dirstamp) \
generated/$(DEPDIR)/$(am__dirstamp)
+generated/maxloc1_4_i8.lo: generated/$(am__dirstamp) \
+   generated/$(DEPDIR)/$(am__dirstamp)
+generated/maxloc1_8_i8.lo: generated/$(am__dirstamp) \
+   generated/$(DEPDIR)/$(am__dirstamp)
+generated/maxloc1_16_i8.lo: generated/$(am__dirstamp) \
+   generated/$(DEPDIR)/$(am__dirstamp)
+generated/maxloc1_4_i16.lo: genera

[PATCH] libfortran: Add 5 missing UNSIGNED symbols [PR120153]

2025-05-07 Thread Jakub Jelinek
Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and 15.2?

2025-05-07  Jakub Jelinek  

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.

--- libgfortran/Makefile.am.jj  2025-05-07 10:56:25.857806018 +0200
+++ libgfortran/Makefile.am 2025-05-07 11:25:33.819973194 +0200
@@ -420,6 +420,7 @@ generated/maxloc1_8_m8.c \
 generated/maxloc1_16_m8.c \
 generated/maxloc1_4_m16.c \
 generated/maxloc1_8_m16.c \
+generated/maxloc1_16_m16.c \
 generated/maxloc1_4_r4.c \
 generated/maxloc1_8_r4.c \
 generated/maxloc1_16_r4.c \
--- libgfortran/intrinsics/random.c.jj  2025-01-02 20:54:32.790120772 +0100
+++ libgfortran/intrinsics/random.c 2025-05-07 11:26:13.451431511 +0200
@@ -1215,7 +1215,7 @@ arandom_m8 (gfc_array_m8 *x)
 }
 }
 
-#ifdef GFC_HAVE_GFC_UINTEGER_16
+#ifdef HAVE_GFC_UINTEGER_16
 
 /* Fill an unsigned array with random bytes.  */
 
--- libgfortran/gfortran.map.jj 2025-03-21 22:40:04.748803949 +0100
+++ libgfortran/gfortran.map2025-05-07 11:31:26.706149955 +0200
@@ -1786,7 +1786,6 @@ GFORTRAN_15 {
 _gfortran_arandom_m2;
 _gfortran_arandom_m4;
 _gfortran_arandom_m8;
-_gfortran_arandom_m16;
 _gfortran_minval_m16;
 _gfortran_minval_m1;
 _gfortran_minval_m2;
@@ -1832,7 +1831,6 @@ GFORTRAN_15 {
 _gfortran_maxloc0_8_m2;
 _gfortran_maxloc0_8_m4;
 _gfortran_maxloc0_8_m8;
-_gfortran_maxloc1_16_m16;
 _gfortran_maxloc1_16_m1;
 _gfortran_maxloc1_16_m2;
 _gfortran_maxloc1_16_m4;
@@ -1862,7 +1860,6 @@ GFORTRAN_15 {
 _gfortran_mmaxloc0_8_m2;
 _gfortran_mmaxloc0_8_m4;
 _gfortran_mmaxloc0_8_m8;
-_gfortran_mmaxloc1_16_m16;
 _gfortran_mmaxloc1_16_m1;
 _gfortran_mmaxloc1_16_m2;
 _gfortran_mmaxloc1_16_m4;
@@ -1892,7 +1889,6 @@ GFORTRAN_15 {
 _gfortran_smaxloc0_8_m2;
 _gfortran_smaxloc0_8_m4;
 _gfortran_smaxloc0_8_m8;
-_gfortran_smaxloc1_16_m16;
 _gfortran_smaxloc1_16_m1;
 _gfortran_smaxloc1_16_m2;
 _gfortran_smaxloc1_16_m4;
@@ -2028,3 +2024,11 @@ GFORTRAN_15 {
 _gfortran_reduce_c;
 _gfortran_reduce_scalar_c;
 } GFORTRAN_14;
+
+GFORTRAN_15.2 {
+  global:
+_gfortran_arandom_m16;
+_gfortran_maxloc1_16_m16;
+_gfortran_mmaxloc1_16_m16;
+_gfortran_smaxloc1_16_m16;
+} GFORTRAN_15;
--- libgfortran/generated/maxloc1_16_m16.c.jj   2025-05-07 11:35:20.094959988 
+0200
+++ libgfortran/generated/maxloc1_16_m16.c  2025-05-07 11:34:17.131820570 
+0200
@@ -0,0 +1,591 @@
+/* Implementation of the MAXLOC intrinsic
+   Copyright (C) 2002-2025 Free Software Foundation, Inc.
+   Contributed by Paul Brook 
+
+This file is part of the GNU Fortran runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 3 of the License, or (at your option) any later version.
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+.  */
+
+#include "libgfortran.h"
+#include 
+
+
+#if defined (HAVE_GFC_UINTEGER_16) && defined (HAVE_GFC_INTEGER_16)
+
+#define HAVE_BACK_ARG 1
+
+
+extern void maxloc1_16_m16 (gfc_array_i16 * const restrict,
+   gfc_array_m16 * cons

Re: [PATCH] libfortran: Readd 15 accidentally removed libgfortran symbols [PR120152]

2025-05-07 Thread Thomas Koenig

Hi Jakub,


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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk
and 15.2?


OK. Thanks a lot for for fixing this!

Best regards

Thomas



Re: [PATCH] libfortran: Add 5 missing UNSIGNED symbols [PR120153]

2025-05-07 Thread Thomas Koenig

Hi Jakub,


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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and 15.2?


OK. And thanks, again!

Best regards

Thomas



Re: [PATCH] libfortran: Fix up maxval/maxloc for UNSIGNED [PR120158]

2025-05-07 Thread Thomas Koenig

Hi Jakub,


Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and
15.2?


OK. Thanks for catching and fixing this!

Best regards

Thomas König



[PATCH] libfortran: Fix up maxval/maxloc for UNSIGNED [PR120158]

2025-05-07 Thread Jakub Jelinek
Hi!

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
-0xU 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*.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and
15.2?

2025-05-07  Jakub Jelinek  

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.

--- libgfortran/m4/iparm.m4.jj  2024-09-25 17:25:07.201360961 +0200
+++ libgfortran/m4/iparm.m4 2025-05-07 16:45:48.674397766 +0200
@@ -28,7 +28,7 @@ define_type(rtype, rtype_tmp)dnl
 define(rtype_qual,`_'rtype_kind)dnl
 ')dnl
 define(atype_max, atype_name`_HUGE')dnl
-define(atype_min,ifelse(regexp(file, `_\(.\)[0-9]*\.c$', 
`\1'),`i',`(-'atype_max`-1)',`-'atype_max))dnl
+define(atype_min,ifelse(index(atype_name,`GFC_UINTEGER'),0,`0',ifelse(regexp(file,
 `_\(.\)[0-9]*\.c$', `\1'),`i',`(-'atype_max`-1)',`-'atype_max)))dnl
 define(atype_inf, atype_name`_INFINITY')dnl
 define(atype_nan, atype_name`_QUIET_NAN')dnl
 define(name, regexp(regexp(file, `[^/]*$', `\&'), `^\([^_]*\)_', `\1'))dnl
--- libgfortran/generated/maxloc0_16_m1.c.jj2025-01-02 20:54:32.768121076 
+0100
+++ libgfortran/generated/maxloc0_16_m1.c   2025-05-07 16:47:35.422000527 
+0200
@@ -96,7 +96,7 @@ maxloc0_16_m1 (gfc_array_i16 * const res
 #if defined(GFC_UINTEGER_1_INFINITY)
 maxval = -GFC_UINTEGER_1_INFINITY;
 #else
-maxval = -GFC_UINTEGER_1_HUGE;
+maxval = 0;
 #endif
   while (base)
 {
@@ -271,7 +271,7 @@ mmaxloc0_16_m1 (gfc_array_i16 * const re
 #if defined(GFC_UINTEGER_1_INFINITY)
 maxval = -GFC_UINTEGER_1_INFINITY;
 #else
-maxval = -GFC_UINTEGER_1_HUGE;
+maxval = 0;
 #endif
   while (base)
 {
--- libgfortran/generated/maxloc0_16_m2.c.jj2025-01-02 20:54:32.768121076 
+0100
+++ libgfortran/generated/maxloc0_16_m2.c   2025-05-07 16:47:35.423000514 
+0200
@@ -96,7 +96,7 @@ maxloc0_16_m2 (gfc_array_i16 * const res
 #if defined(GFC_UINTEGER_2_INFINITY)
 maxval = -GFC_UINTEGER_2_INFINITY;
 #else
-maxval = -GFC_UINTEGER_2_HUGE;
+maxval = 0;
 #endif
   while (base)
 {
@@ -271,7 +271,7 @@ mmaxloc0_16_m2 (gfc_array_i16 * const re
 #if defined(GFC_UINTEGER_2_INFINITY)
 maxval = -GFC_UINT