[J3] lbound / ubound undefined behaviour?
Robert Corbett
rpcorbett at att.net
Sun Jul 21 06:09:52 UTC 2024
I saw the questions posted to the discourse.Here are my answers.
In the following, references are to 24-007.
In the large example, the array name arr_in1
in the main program is a whole array. The
array name arr_in1 in the subroutine evaluate
is also a whole array. The array arr_n1 in
the main program has the lower bounds 0 and
2. The array arr_in1 in the subroutine
evaluate is an assumed-shape dummy argument.
An assumed-shape dummy argument assumes the
shape of actual argument, but not the bounds.
The lower bounds of the arr_in1 in the
subroutine evaluate are 1 and 1 (see
Subclause 8.5.8.3 "Assumed-shape array",
paragraph 3). Therefore, in the subroutine
evaluate LBOUND(arr_in1) = [1, 1].
More relevant to the large example, the
dummy arguments arr_out1, arr_out2, and
arr_out3 are also assumed-shape arrays,
and by the same reasoning their lower
bounds are also 1's.
In the small example, the reason the
function reference foo() is not a whole
array is that it does not conform to the
definition of a whole array given in
Subclause 3.125. The subclause defines
a whole array as
3.125
whole array
array component or array name.
A function reference is not an array
component or an array name. Therefore,
it is not a whole array. For emphasis,
see Note 2 of Subclause 6.2.2 "Names".
On Thursday, June 27, 2024 at 08:46:28 AM PDT, Nathan Sircombe via J3 <j3 at mailman.j3-fortran.org> wrote:
<!--#yiv3996405629 filtered {}#yiv3996405629 filtered {}#yiv3996405629 p.yiv3996405629MsoNormal, #yiv3996405629 li.yiv3996405629MsoNormal, #yiv3996405629 div.yiv3996405629MsoNormal {margin:0cm;font-size:11.0pt;font-family:"Aptos", sans-serif;}#yiv3996405629 a:link, #yiv3996405629 span.yiv3996405629MsoHyperlink {color:#467886;text-decoration:underline;}#yiv3996405629 span.yiv3996405629EmailStyle17 {font-family:"Aptos", sans-serif;color:windowtext;}#yiv3996405629 .yiv3996405629MsoChpDefault {font-size:11.0pt;}#yiv3996405629 filtered {}#yiv3996405629 div.yiv3996405629WordSection1 {}-->
Hi,
I’ve got a question from one of the engineers in the compiler team here – I’d appreciate the J3 list’s opinion (actually some of the list are on the original fortran-lang thread).
The problem was initially discussed here: https://fortran-lang.discourse.group/t/an-interesting-difference-between-compilers/7131
The initial conclusion seems to be that compilers from group "B” have the wrong end of the stick. But a separate discussion on the Flang github reached a different conclusion:https://github.com/flang-compiler/flang/issues/1435. Claiming that we are facing undefined behaviour and various compilers handle this situation differently.
So, is it actually undefined behaviour and the compilers have liberty in handling it their own way? or it is clearly defined what the compilers should do?
Cheers,
Nathan.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20240721/6f5a5cbe/attachment.htm>
More information about the J3
mailing list