On 11/21/26 11:41 PM, Thomas Koenig wrote:
Hi Jerry,
See attached patch. Resolution drops a substring of an array section
only when its range is a constant covering the whole string. For
c(:)(1:n), dc(:)(:len(dc)) or a substring of an assumed-length dummy,
the reference stays, gfc_is_not_contiguous treats any reference after
the section as proof, and so IS_CONTIGUOUS folds to .false. and a
CONTIGUOUS pointer assignment is rejected. The run-time path cannot
answer either, because gfc_conv_expr_descriptor builds a temporary for
a substring section. With the patch, a trailing substring is proof
only when substring_is_partial shows it starts after 1 or ends before
the length; otherwise IS_CONTIGUOUS tests the array without the
substring at run time and ANDs that with start == 1 and end == the
string length.
gfc_is_not_contiguous also decides copy-in for a CONTIGUOUS, TARGET
dummy in trans-expr.cc; passing c(:)(1:n) to one still creates a
temporary and copies back correctly.
Regression tested on x86_64.
I think this (and possibly other) cases would conclude that
something with a substring is simply contiguous, which is
excluded by F2023, 9.5.4, subclause 2. Shouldn't this be
conditional on !strict?
(I believe my own recent patch has the same problem, BTW).
Best regards
Thomas
Hi Thomas,
I have to think some on this.
The patch does not make anything with a substring-range simply
contiguous: gfc_is_simply_contiguous is unchanged and still returns
false at the first REF_SUBSTRING, strict or not. What changes is
gfc_is_not_contiguous (provably not contiguous, no strict argument)
and the run-time IS_CONTIGUOUS test. Those are about "contiguous"
(F2023 8.5.7), where item (7)(e) explicitly allows a substring-range
that specifies all the characters of the parent string.
So rank remapping still rejects c(:,:)(1:n), and the -Wextra warning
for a CONTIGUOUS pointer assigned from c(:)(1:n) remains; only the
hard error goes, since 10.2.2.3p6 requires the target to be
contiguous, not simply contiguous.
Your memset patch does have the problem: the new DIMEN_ELEMENT test
in gfc_is_simply_contiguous is not conditional on !strict, so with
real, target :: b(1,2,2)
real, pointer :: q(:)
q(1:4) => b(1,:,:)
the rank-remapping error that gcc 16 gives is gone (9.5.4p1, third
bullet). Adding "!strict &&" to that condition should fix it.
All this being subject to my feeble interpretation.
Jerry