diff options
author | Sandra Loosemore <sandra@codesourcery.com> | 2021-07-17 16:12:18 -0700 |
---|---|---|
committer | Sandra Loosemore <sandra@codesourcery.com> | 2021-07-27 21:24:25 -0700 |
commit | b4a9bc7856ee1d3ff98b04402334a362540af2cf (patch) | |
tree | deee059989f7a38c1199a3d63cfa3c1bb4530055 /gcc | |
parent | a3b350f1799a1c0f9e2ece5b817a537fe42f0d2d (diff) | |
download | gcc-b4a9bc7856ee1d3ff98b04402334a362540af2cf.zip gcc-b4a9bc7856ee1d3ff98b04402334a362540af2cf.tar.gz gcc-b4a9bc7856ee1d3ff98b04402334a362540af2cf.tar.bz2 |
Bind(c): Fix bugs in CFI_section
CFI_section was incorrectly adjusting the base pointer for the result
array twice in different ways. It was also overwriting the array
dimension info in the result descriptor before computing the base
address offset from the source descriptor, which caused problems if
the two descriptors are the same. This patch fixes both problems and
makes the code simpler, too.
A consequence of this patch is that the result array is now 0-based in
all dimensions instead of starting at the numbering to match the first
element of the source array. The Fortran standard only specifies the
shape of the result array, not its lower bounds, so this is permitted
and probably less confusing for users as well as implementors.
2021-07-17 Sandra Loosemore <sandra@codesourcery.com>
PR libfortran/101310
libgfortran/
* runtime/ISO_Fortran_binding.c (CFI_section): Fix the base
address computation and simplify the code.
gcc/testsuite/
* gfortran.dg/ISO_Fortran_binding_1.c (section_c): Remove
incorrect assertions.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c index 9da5d85..bb56ca0 100644 --- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c +++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c @@ -142,11 +142,12 @@ float section_c(int *std_case, CFI_cdesc_t * source, int *low, int *str) CFI_type_float, 0, 1, NULL); if (ind) return -1.0; ind = CFI_section((CFI_cdesc_t *)§ion, source, lower, NULL, strides); - assert (section.dim[0].lower_bound == lower[0]); if (ind) return -2.0; /* Sum over the section */ - for (idx[0] = lower[0]; idx[0] < section.dim[0].extent + lower[0]; idx[0]++) + for (idx[0] = section.dim[0].lower_bound; + idx[0] < section.dim[0].extent + section.dim[0].lower_bound; + idx[0]++) ans += *(float*)CFI_address ((CFI_cdesc_t*)§ion, idx); return ans; } @@ -164,11 +165,12 @@ float section_c(int *std_case, CFI_cdesc_t * source, int *low, int *str) ind = CFI_section((CFI_cdesc_t *)§ion, source, lower, upper, strides); assert (section.rank == 1); - assert (section.dim[0].lower_bound == lower[0]); if (ind) return -2.0; /* Sum over the section */ - for (idx[0] = lower[0]; idx[0] < section.dim[0].extent + lower[0]; idx[0]++) + for (idx[0] = section.dim[0].lower_bound; + idx[0] < section.dim[0].extent + section.dim[0].lower_bound; + idx[0]++) ans += *(float*)CFI_address ((CFI_cdesc_t*)§ion, idx); return ans; } |