Re: [PATCH 2/2] libgfortran: Remove empty array descriptor first dimension overwrite [PR112371]

2023-11-06 Thread Harald Anlauf

Hi Mikael,

Am 06.11.23 um 20:19 schrieb Mikael Morin:


This change to the testcase:

diff --git a/gcc/testsuite/gfortran.dg/bound_11.f90
b/gcc/testsuite/gfortran.dg/bound_11.f90
index 170eba4ddfd..2e96f843476 100644
--- a/gcc/testsuite/gfortran.dg/bound_11.f90
+++ b/gcc/testsuite/gfortran.dg/bound_11.f90
@@ -88,6 +88,7 @@ contains
  m4 = .false.
  i = 1
  r = sum(a, dim=i)
+    if (.not. allocated(r)) stop 210
  if (any(shape(r) /= (/ 3, 0, 7 /))) stop 211
  if (any(ubound(r) /= (/ 3, 0, 7 /))) stop 212
  i = 2
@@ -104,6 +105,7 @@ contains
  if (any(ubound(r) /= (/ 9, 3, 0 /))) stop 218
  i = 1
  r = sum(a, dim=i, mask=m1)
+    if (.not. allocated(r)) stop 220
  if (any(shape(r) /= (/ 3, 0, 7 /))) stop 221
  if (any(ubound(r) /= (/ 3, 0, 7 /))) stop 222
  i = 2
@@ -120,6 +122,7 @@ contains
  if (any(ubound(r) /= (/ 9, 3, 0 /))) stop 228
  i = 1
  r = sum(a, dim=i, mask=m4)
+    if (.not. allocated(r)) stop 230
  if (any(shape(r) /= (/ 3, 0, 7 /))) stop 231
  if (any(ubound(r) /= (/ 3, 0, 7 /))) stop 232
  i = 2

gives me a FAIL with STOP 220 (or STOP 230 if the STOP 220 line is
commented); the first one with STOP 210 passes.
So it is the first snippet with the xmallocarray (which supports zero
values see memory.c) call that is the correct one.
Good catch, I will open a separate PR.


ah, now I see that the case of allocation of zero elements
always allocates one byte, which is needed for r.data to be
non-null.

Go ahead!

Harald



Mikael





Re: [PATCH 2/2] libgfortran: Remove empty array descriptor first dimension overwrite [PR112371]

2023-11-06 Thread Mikael Morin

Le 06/11/2023 à 19:20, Harald Anlauf a écrit :

Hi Mikael,

Am 06.11.23 um 12:43 schrieb Mikael Morin:

Remove the forced overwrite of the first dimension of the result array
descriptor to set it to zero extent, in the function templates for
transformational functions doing an array reduction along a 
dimension.  This

overwrite, which happened before early returning in case the result array
was empty, was wrong because an array may have a non-zero extent in the
first dimension and still be empty if it has a zero extent in a higher
dimension.  Overwriting the dimension was resulting in wrong array result
upper bound for the first dimension in that case.

The offending piece of code was present in several places, and this 
removes

them all.  More precisely, there is only one case to fix for logical
reduction functions, and there are three cases for other reduction
functions, corresponding to non-masked reduction, reduction with array 
mask,

and reduction with scalar mask.  The impacted m4 files are
ifunction_logical.m4 for logical reduction functions, ifunction.m4 for
regular functions and types, ifunction-s.m4 for character minloc and 
maxloc,

ifunction-s2.m4 for character minval and maxval, and ifindloc1.m4 for
findloc.


while your fix seems mechanical and correct, I wonder if you looked
at the following pre-existing irregularity which can be seen in
this snippet:


diff --git a/libgfortran/m4/ifunction.m4 b/libgfortran/m4/ifunction.m4
index 480649cf691..abc15b430ab 100644
--- a/libgfortran/m4/ifunction.m4
+++ b/libgfortran/m4/ifunction.m4
@@ -96,12 +96,7 @@ name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,


    retarray->base_addr = xmallocarray (alloc_size, sizeof 
(rtype_name));

    if (alloc_size == 0)
-    {
-  /* Make sure we have a zero-sized array.  */
-  GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
-  return;
-
-    }
+    return;
  }
    else
  {


This is all enclosed in a block which has
   if (retarray->base_addr == NULL)
but allocates and sets retarray->base_addr, while

@@ -290,11 +285,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,

    retarray->dtype.rank = rank;

    if (alloc_size == 0)
-    {
-  /* Make sure we have a zero-sized array.  */
-  GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
-  return;
-    }
+    return;
    else
  retarray->base_addr = xmallocarray (alloc_size, sizeof 
(rtype_name));




and


@@ -454,11 +445,7 @@ void
    alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * 
extent[rank-1];


    if (alloc_size == 0)
-    {
-  /* Make sure we have a zero-sized array.  */
-  GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
-  return;
-    }
+    return;
    else
  retarray->base_addr = xmallocarray (alloc_size, sizeof 
(rtype_name));

  }


do not set retarray->base_addr to non-NULL for alloc_size == 0.

Do you know if the first snippet can be safely rewritten to avoid
the (hopefully pointless) xmallocarray for alloc_size == 0?



This change to the testcase:

diff --git a/gcc/testsuite/gfortran.dg/bound_11.f90 
b/gcc/testsuite/gfortran.dg/bound_11.f90

index 170eba4ddfd..2e96f843476 100644
--- a/gcc/testsuite/gfortran.dg/bound_11.f90
+++ b/gcc/testsuite/gfortran.dg/bound_11.f90
@@ -88,6 +88,7 @@ contains
 m4 = .false.
 i = 1
 r = sum(a, dim=i)
+if (.not. allocated(r)) stop 210
 if (any(shape(r) /= (/ 3, 0, 7 /))) stop 211
 if (any(ubound(r) /= (/ 3, 0, 7 /))) stop 212
 i = 2
@@ -104,6 +105,7 @@ contains
 if (any(ubound(r) /= (/ 9, 3, 0 /))) stop 218
 i = 1
 r = sum(a, dim=i, mask=m1)
+if (.not. allocated(r)) stop 220
 if (any(shape(r) /= (/ 3, 0, 7 /))) stop 221
 if (any(ubound(r) /= (/ 3, 0, 7 /))) stop 222
 i = 2
@@ -120,6 +122,7 @@ contains
 if (any(ubound(r) /= (/ 9, 3, 0 /))) stop 228
 i = 1
 r = sum(a, dim=i, mask=m4)
+if (.not. allocated(r)) stop 230
 if (any(shape(r) /= (/ 3, 0, 7 /))) stop 231
 if (any(ubound(r) /= (/ 3, 0, 7 /))) stop 232
 i = 2

gives me a FAIL with STOP 220 (or STOP 230 if the STOP 220 line is 
commented); the first one with STOP 210 passes.
So it is the first snippet with the xmallocarray (which supports zero 
values see memory.c) call that is the correct one.

Good catch, I will open a separate PR.

Mikael


Re: [PATCH 1/2] libgfortran: Remove early return if extent is zero [PR112371]

2023-11-06 Thread Mikael Morin

Le 06/11/2023 à 19:12, Harald Anlauf a écrit :

Hi Mikael,

Am 06.11.23 um 12:43 schrieb Mikael Morin:
Remove the early return present in function templates for 
transformational

functions doing a (masked) reduction of an array along a dimension.
This early return, which triggered if the extent in the reduction 
dimension
was zero, was wrong because even if the reduction operation 
degenerates to

a constant value in that case, one has to loop anyway along the other
dimensions to initialize every element of the resulting array with that
constant value.

The offending piece of code was present in several places, and this 
removes

them all.  Namely, the impacted m4 files are ifunction.m4 for regular
functions and types, ifunction-s.m4 for character minloc and maxloc, and
ifunction-s2.m4 for character minval and maxval.


I wonder if the correct fix would be to replace (instead of deleting)


diff --git a/libgfortran/m4/ifunction.m4 b/libgfortran/m4/ifunction.m4
index c64217ec5db..480649cf691 100644
--- a/libgfortran/m4/ifunction.m4
+++ b/libgfortran/m4/ifunction.m4
@@ -232,8 +232,6 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,

  }

    len = GFC_DESCRIPTOR_EXTENT(array,dim);
-  if (len <= 0)
-    return;

    mbase = mask->base_addr;



by the following:

   if (len < 0)
     len = 0;

See ifunction.m4, lines 56ff, which check if the result of

   len = GFC_DESCRIPTOR_EXTENT(array,dim);

is negative.  I haven't tried to create a testcase, though.

Similarly for the other templates.



Yes, you're right.  I think I won't try to create a testcase and will 
just pick your suggestion which seems safer.


Re: [PATCH 2/2] libgfortran: Remove empty array descriptor first dimension overwrite [PR112371]

2023-11-06 Thread Harald Anlauf

Hi Mikael,

Am 06.11.23 um 12:43 schrieb Mikael Morin:

Remove the forced overwrite of the first dimension of the result array
descriptor to set it to zero extent, in the function templates for
transformational functions doing an array reduction along a dimension.  This
overwrite, which happened before early returning in case the result array
was empty, was wrong because an array may have a non-zero extent in the
first dimension and still be empty if it has a zero extent in a higher
dimension.  Overwriting the dimension was resulting in wrong array result
upper bound for the first dimension in that case.

The offending piece of code was present in several places, and this removes
them all.  More precisely, there is only one case to fix for logical
reduction functions, and there are three cases for other reduction
functions, corresponding to non-masked reduction, reduction with array mask,
and reduction with scalar mask.  The impacted m4 files are
ifunction_logical.m4 for logical reduction functions, ifunction.m4 for
regular functions and types, ifunction-s.m4 for character minloc and maxloc,
ifunction-s2.m4 for character minval and maxval, and ifindloc1.m4 for
findloc.


while your fix seems mechanical and correct, I wonder if you looked
at the following pre-existing irregularity which can be seen in
this snippet:


diff --git a/libgfortran/m4/ifunction.m4 b/libgfortran/m4/ifunction.m4
index 480649cf691..abc15b430ab 100644
--- a/libgfortran/m4/ifunction.m4
+++ b/libgfortran/m4/ifunction.m4
@@ -96,12 +96,7 @@ name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,

retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
if (alloc_size == 0)
-   {
- /* Make sure we have a zero-sized array.  */
- GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
- return;
-
-   }
+   return;
  }
else
  {


This is all enclosed in a block which has
  if (retarray->base_addr == NULL)
but allocates and sets retarray->base_addr, while


@@ -290,11 +285,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
retarray->dtype.rank = rank;

if (alloc_size == 0)
-   {
- /* Make sure we have a zero-sized array.  */
- GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
- return;
-   }
+   return;
else
retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));



and


@@ -454,11 +445,7 @@ void
alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];

if (alloc_size == 0)
-   {
- /* Make sure we have a zero-sized array.  */
- GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
- return;
-   }
+   return;
else
retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
  }


do not set retarray->base_addr to non-NULL for alloc_size == 0.

Do you know if the first snippet can be safely rewritten to avoid
the (hopefully pointless) xmallocarray for alloc_size == 0?

Thanks,
Harald



Re: [PATCH 1/2] libgfortran: Remove early return if extent is zero [PR112371]

2023-11-06 Thread Harald Anlauf

Hi Mikael,

Am 06.11.23 um 12:43 schrieb Mikael Morin:

Remove the early return present in function templates for transformational
functions doing a (masked) reduction of an array along a dimension.
This early return, which triggered if the extent in the reduction dimension
was zero, was wrong because even if the reduction operation degenerates to
a constant value in that case, one has to loop anyway along the other
dimensions to initialize every element of the resulting array with that
constant value.

The offending piece of code was present in several places, and this removes
them all.  Namely, the impacted m4 files are ifunction.m4 for regular
functions and types, ifunction-s.m4 for character minloc and maxloc, and
ifunction-s2.m4 for character minval and maxval.


I wonder if the correct fix would be to replace (instead of deleting)


diff --git a/libgfortran/m4/ifunction.m4 b/libgfortran/m4/ifunction.m4
index c64217ec5db..480649cf691 100644
--- a/libgfortran/m4/ifunction.m4
+++ b/libgfortran/m4/ifunction.m4
@@ -232,8 +232,6 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
  }

len = GFC_DESCRIPTOR_EXTENT(array,dim);
-  if (len <= 0)
-return;

mbase = mask->base_addr;



by the following:

  if (len < 0)
len = 0;

See ifunction.m4, lines 56ff, which check if the result of

  len = GFC_DESCRIPTOR_EXTENT(array,dim);

is negative.  I haven't tried to create a testcase, though.

Similarly for the other templates.

Thanks,
Harald



[PATCH 0/2] libgfortran: empty array fixes [PR112371]

2023-11-06 Thread Mikael Morin
Hello,

while preparing a testcase, I encountered a bug which I filed as
PR112371.  Investigating further, I found two different problems which I
propose to fix with the followup patches.

Those have been bootstraped and regression tested on x86_64-pc-linux-gnu.
OK for master?

Mikael


Mikael Morin (2):
  libgfortran: Remove early return if extent is zero [PR112371]
  libgfortran: Remove empty array descriptor first dimension overwrite
[PR112371]

 gcc/testsuite/gfortran.dg/bound_10.f90 | 207 +
 gcc/testsuite/gfortran.dg/bound_11.f90 | 588 +
 libgfortran/generated/all_l1.c |   6 +-
 libgfortran/generated/all_l16.c|   6 +-
 libgfortran/generated/all_l2.c |   6 +-
 libgfortran/generated/all_l4.c |   6 +-
 libgfortran/generated/all_l8.c |   6 +-
 libgfortran/generated/any_l1.c |   6 +-
 libgfortran/generated/any_l16.c|   6 +-
 libgfortran/generated/any_l2.c |   6 +-
 libgfortran/generated/any_l4.c |   6 +-
 libgfortran/generated/any_l8.c |   6 +-
 libgfortran/generated/count_16_l.c |   6 +-
 libgfortran/generated/count_1_l.c  |   6 +-
 libgfortran/generated/count_2_l.c  |   6 +-
 libgfortran/generated/count_4_l.c  |   6 +-
 libgfortran/generated/count_8_l.c  |   6 +-
 libgfortran/generated/findloc1_c10.c   |  18 +-
 libgfortran/generated/findloc1_c16.c   |  18 +-
 libgfortran/generated/findloc1_c17.c   |  18 +-
 libgfortran/generated/findloc1_c4.c|  18 +-
 libgfortran/generated/findloc1_c8.c|  18 +-
 libgfortran/generated/findloc1_i1.c|  18 +-
 libgfortran/generated/findloc1_i16.c   |  18 +-
 libgfortran/generated/findloc1_i2.c|  18 +-
 libgfortran/generated/findloc1_i4.c|  18 +-
 libgfortran/generated/findloc1_i8.c|  18 +-
 libgfortran/generated/findloc1_r10.c   |  18 +-
 libgfortran/generated/findloc1_r16.c   |  18 +-
 libgfortran/generated/findloc1_r17.c   |  18 +-
 libgfortran/generated/findloc1_r4.c|  18 +-
 libgfortran/generated/findloc1_r8.c|  18 +-
 libgfortran/generated/findloc1_s1.c|  18 +-
 libgfortran/generated/findloc1_s4.c|  18 +-
 libgfortran/generated/iall_i1.c|  21 +-
 libgfortran/generated/iall_i16.c   |  21 +-
 libgfortran/generated/iall_i2.c|  21 +-
 libgfortran/generated/iall_i4.c|  21 +-
 libgfortran/generated/iall_i8.c|  21 +-
 libgfortran/generated/iany_i1.c|  21 +-
 libgfortran/generated/iany_i16.c   |  21 +-
 libgfortran/generated/iany_i2.c|  21 +-
 libgfortran/generated/iany_i4.c|  21 +-
 libgfortran/generated/iany_i8.c|  21 +-
 libgfortran/generated/iparity_i1.c |  21 +-
 libgfortran/generated/iparity_i16.c|  21 +-
 libgfortran/generated/iparity_i2.c |  21 +-
 libgfortran/generated/iparity_i4.c |  21 +-
 libgfortran/generated/iparity_i8.c |  21 +-
 libgfortran/generated/maxloc1_16_i1.c  |  21 +-
 libgfortran/generated/maxloc1_16_i16.c |  21 +-
 libgfortran/generated/maxloc1_16_i2.c  |  21 +-
 libgfortran/generated/maxloc1_16_i4.c  |  21 +-
 libgfortran/generated/maxloc1_16_i8.c  |  21 +-
 libgfortran/generated/maxloc1_16_r10.c |  21 +-
 libgfortran/generated/maxloc1_16_r16.c |  21 +-
 libgfortran/generated/maxloc1_16_r17.c |  21 +-
 libgfortran/generated/maxloc1_16_r4.c  |  21 +-
 libgfortran/generated/maxloc1_16_r8.c  |  21 +-
 libgfortran/generated/maxloc1_16_s1.c  |  21 +-
 libgfortran/generated/maxloc1_16_s4.c  |  21 +-
 libgfortran/generated/maxloc1_4_i1.c   |  21 +-
 libgfortran/generated/maxloc1_4_i16.c  |  21 +-
 libgfortran/generated/maxloc1_4_i2.c   |  21 +-
 libgfortran/generated/maxloc1_4_i4.c   |  21 +-
 libgfortran/generated/maxloc1_4_i8.c   |  21 +-
 libgfortran/generated/maxloc1_4_r10.c  |  21 +-
 libgfortran/generated/maxloc1_4_r16.c  |  21 +-
 libgfortran/generated/maxloc1_4_r17.c  |  21 +-
 libgfortran/generated/maxloc1_4_r4.c   |  21 +-
 libgfortran/generated/maxloc1_4_r8.c   |  21 +-
 libgfortran/generated/maxloc1_4_s1.c   |  21 +-
 libgfortran/generated/maxloc1_4_s4.c   |  21 +-
 libgfortran/generated/maxloc1_8_i1.c   |  21 +-
 libgfortran/generated/maxloc1_8_i16.c  |  21 +-
 libgfortran/generated/maxloc1_8_i2.c   |  21 +-
 libgfortran/generated/maxloc1_8_i4.c   |  21 +-
 libgfortran/generated/maxloc1_8_i8.c   |  21 +-
 libgfortran/generated/maxloc1_8_r10.c  |  21 +-
 libgfortran/generated/maxloc1_8_r16.c  |  21 +-
 libgfortran/generated/maxloc1_8_r17.c  |  21 +-
 libgfortran/generated/maxloc1_8_r4.c   |  21 +-
 libgfortran/generated/maxloc1_8_r8.c   |  21 +-
 libgfortran/generated/maxloc1_8_s1.c   |  21 +-
 libgfortran/generated/maxloc1_8_s4.c   |  21 +-
 libgfortran/generated/maxval1_s1.c |  21 +-
 libgfortran/generated/maxval1_s4.c |  21 +-
 libgfortran/generated/maxval_i1.c  |  21 +-
 libgfortran/generated/maxval_i16.c |  21 +-
 libgfortran/generated/maxval_i2.c  |  21 +-
 libgfortran/generated/maxval_i4.c  |  21 +-
 libgfortran/generated/maxval_i8.c  |  21 +-
 

[PATCH 1/2] libgfortran: Remove early return if extent is zero [PR112371]

2023-11-06 Thread Mikael Morin
Remove the early return present in function templates for transformational
functions doing a (masked) reduction of an array along a dimension.
This early return, which triggered if the extent in the reduction dimension
was zero, was wrong because even if the reduction operation degenerates to
a constant value in that case, one has to loop anyway along the other
dimensions to initialize every element of the resulting array with that
constant value.

The offending piece of code was present in several places, and this removes
them all.  Namely, the impacted m4 files are ifunction.m4 for regular
functions and types, ifunction-s.m4 for character minloc and maxloc, and
ifunction-s2.m4 for character minval and maxval.

PR fortran/112371

libgfortran/ChangeLog:

* m4/ifunction.m4 (START_MASKED_ARRAY_FUNCTION): Remove early return if
extent is zero.
* m4/ifunction-s.m4 (START_MASKED_ARRAY_FUNCTION): Ditto.
* m4/ifunction-s2.m4 (START_MASKED_ARRAY_FUNCTION): Ditto.
* 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/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_16_s1.c: Regenerate.
* generated/maxloc1_16_s4.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_4_s1.c: Regenerate.
* generated/maxloc1_4_s4.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/maxloc1_8_s1.c: Regenerate.
* generated/maxloc1_8_s4.c: Regenerate.
* generated/maxval1_s1.c: Regenerate.
* generated/maxval1_s4.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_16_s1.c: Regenerate.
* generated/minloc1_16_s4.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.

[committed] libgfortran: Fix calloc call by swapping arg order [PR112364]

2023-11-06 Thread Tobias Burnus

See PR for a discussion whether this change is required for alignment (or 
other) reasons
(looks as if not) - or"just" to match the indented order (arg names + 
description) and
to silence a -Walloc-size warning.

Committed as r14-5148-g17df6ddcf11aef

(BTW: I don't think that it is worthwhile to backport it - the -Walloc-size 
warning is new
since r14-5059-gd880e093d92084.)

Tobias
-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
commit 17df6ddcf11aef6d200305d35641a7deb2f430e1
Author: Tobias Burnus 
Date:   Mon Nov 6 11:34:31 2023 +0100

libgfortran: Fix calloc call by swapping arg order [PR112364]

The prototype of calloc is
  void *calloc(size_t nmemb, size_t size);
denoting "an array of nmemb objects, each of whose size is size." (C23)

In order to follow the meaning of the argument names and to silence
a -Walloc-size warning, this commit swaps the order of the two args
to read now:  calloc (1, sizeof (transfer_queue));

libgfortran/ChangeLog:

PR libfortran/112364
* io/async.c (enqueue_transfer, enqueue_done_id, enqueue_done,
enqueue_close): Swap 1st and 2nd arg in calloc call.

diff --git a/libgfortran/io/async.c b/libgfortran/io/async.c
index 57097438e89..8fa1f0d4ce0 100644
--- a/libgfortran/io/async.c
+++ b/libgfortran/io/async.c
@@ -262,7 +262,7 @@ init_async_unit (gfc_unit *u)
 void
 enqueue_transfer (async_unit *au, transfer_args *arg, enum aio_do type)
 {
-  transfer_queue *tq = calloc (sizeof (transfer_queue), 1);
+  transfer_queue *tq = calloc (1, sizeof (transfer_queue));
   tq->arg = *arg;
   tq->type = type;
   tq->has_id = 0;
@@ -284,7 +284,7 @@ int
 enqueue_done_id (async_unit *au, enum aio_do type)
 {
   int ret;
-  transfer_queue *tq = calloc (sizeof (transfer_queue), 1);
+  transfer_queue *tq = calloc (1, sizeof (transfer_queue));
 
   tq->type = type;
   tq->has_id = 1;
@@ -308,7 +308,7 @@ enqueue_done_id (async_unit *au, enum aio_do type)
 void
 enqueue_done (async_unit *au, enum aio_do type)
 {
-  transfer_queue *tq = calloc (sizeof (transfer_queue), 1);
+  transfer_queue *tq = calloc (1, sizeof (transfer_queue));
   tq->type = type;
   tq->has_id = 0;
   LOCK (>lock);
@@ -328,7 +328,7 @@ enqueue_done (async_unit *au, enum aio_do type)
 void
 enqueue_close (async_unit *au)
 {
-  transfer_queue *tq = calloc (sizeof (transfer_queue), 1);
+  transfer_queue *tq = calloc (1, sizeof (transfer_queue));
 
   tq->type = AIO_CLOSE;
   LOCK (>lock);