On 21.06.21 08:05, Sandra Loosemore wrote:
I ran into this bug in CFI_allocate while testing something else and
then realized there was already a PR open for it. It seems like an
easy fix, and I've used Tobias's test case from the issue more or less
verbatim.
There were some other bugs added on to this issue but I think they
have all been fixed already except for this one.
OK to check in?
OK – but see some comments below.
libgfortran/
PR fortran/93524
* runtime/ISO_Fortran_binding.c (CFI_allocate): Fix
sm computation.
gcc/testsuite/
PR fortran/93524
* gfortran.dg/pr93524.c, gfortran.dg/pr93524.f90: New.
It is new to me that we use this syntax. I think you want to have one
line per file, each starting with "<tab>*"
+++ b/gcc/testsuite/gfortran.dg/pr93524.c
@@ -0,0 +1,33 @@
+/* Test the fix for PR93524, in which CFI_allocate was computing
+ sm incorrectly for dimensions > 2. */
+
+#include <stdlib.h> // For size_t
+#include <ISO_Fortran_binding.h>
I keep making this mistake myself: The last line works if you
use the installed compiler for testing; if you run the testsuite
via the build directory, it will either fail or take the wrong
version of the file (the one under /usr/include). Solution: Use
#include "../../../libgfortran/ISO_Fortran_binding.h"
as we do in the other tests which use that file.
+++ b/gcc/testsuite/gfortran.dg/pr93524.f90
...
+! Test the fix for PR93524. The main program is in pr93524.c.
+
+subroutine my_fortran_sub_1 (A) bind(C)
+ real :: A(:, :,:)
+ print *, 'Lower bounds: ', lbound(A) ! Lower bounds: 1 1 1
+ print *, 'Upper bounds: ', ubound(A) ! Upper bounds: 21 6 8
+end
+subroutine my_fortran_sub_2 (A) bind(C)
+ real, ALLOCATABLE :: A(:, :,:)
+ print *, 'Lower bounds: ', lbound(A)
+ print *, 'Upper bounds: ', ubound(A)
I think the 'print' should be replaced (or commented + augmented) by 'if
(any (lbound(A) /= 1) stop 1'; 'if (any (ubound(A) /= [21,6,8])) stop 2'
etc.
Actually, it probably does not work for the second function due to
PR92189 (lbounds are wrong). If so, you could use 'if (any (shape(A) /=
[21,6,8])) stop 4' instead.
Can you also add 'if (.not. is_contiguous (A)) stop 3' to both
functions? That issue was mentioned in the PR and is probably fixed by
your change.
Otherwise, it looks fine :-)
Thanks for the patch.
Tobias
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank
Thürauf