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 /libgfortran | |
parent | a3b350f1799a1c0f9e2ece5b817a537fe42f0d2d (diff) | |
download | gcc-b4a9bc7856ee1d3ff98b04402334a362540af2cf.tar.gz |
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 'libgfortran')
-rw-r--r-- | libgfortran/runtime/ISO_Fortran_binding.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c index b1e51612e2b..2830c4575fe 100644 --- a/libgfortran/runtime/ISO_Fortran_binding.c +++ b/libgfortran/runtime/ISO_Fortran_binding.c @@ -689,29 +689,22 @@ int CFI_section (CFI_cdesc_t *result, const CFI_cdesc_t *source, } } + /* Set the base address. We have to compute this first in the case + where source == result, before we overwrite the dimension data. */ + result->base_addr = CFI_address (source, lower); + /* Set the appropriate dimension information that gives us access to the * data. */ - int aux = 0; - for (int i = 0; i < source->rank; i++) + for (int i = 0, o = 0; i < source->rank; i++) { if (stride[i] == 0) - { - aux++; - /* Adjust 'lower' for the base address offset. */ - lower[i] = lower[i] - source->dim[i].lower_bound; - continue; - } - int idx = i - aux; - result->dim[idx].lower_bound = lower[i]; - result->dim[idx].extent = 1 + (upper[i] - lower[i])/stride[i]; - result->dim[idx].sm = stride[i] * source->dim[i].sm; - /* Adjust 'lower' for the base address offset. */ - lower[idx] = lower[idx] - source->dim[i].lower_bound; + continue; + result->dim[o].lower_bound = 0; + result->dim[o].extent = 1 + (upper[i] - lower[i])/stride[i]; + result->dim[o].sm = stride[i] * source->dim[i].sm; + o++; } - /* Set the base address. */ - result->base_addr = CFI_address (source, lower); - return CFI_SUCCESS; } |