public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/94110] New: Erroneous code compiling
@ 2020-03-09 20:27 jrfsousa at gmail dot com
  2020-04-13 17:19 ` [Bug fortran/94110] " tkoenig at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jrfsousa at gmail dot com @ 2020-03-09 20:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94110

            Bug ID: 94110
           Summary: Erroneous code compiling
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jrfsousa at gmail dot com
  Target Milestone: ---

Created attachment 48000
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48000&action=edit
Code demonstrating problems.

Hi all!

I am pretty sure this code is erroneous both because you can not pass an
assumed-size to an assumed-shape and because of pointer association rules.

Compiles without any warnings even using -pedantic -Wall -Wextra and others in
both:

GNU Fortran (GCC) 9.2.1 20200307

and

GNU Fortran (GCC) 10.0.1 20200307 (experimental)

Thank you very much.

Best regards,
José Rui

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/94110] Erroneous code compiling
  2020-03-09 20:27 [Bug fortran/94110] New: Erroneous code compiling jrfsousa at gmail dot com
@ 2020-04-13 17:19 ` tkoenig at gcc dot gnu.org
  2020-04-14 15:29 ` jrfsousa at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-04-13 17:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94110

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING
                 CC|                            |tkoenig at gcc dot gnu.org
   Last reconfirmed|                            |2020-04-13

--- Comment #1 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
(In reply to José Rui Faustino de Sousa from comment #0)
> Created attachment 48000 [details]
> Code demonstrating problems.
> 
> Hi all!
> 
> I am pretty sure this code is erroneous both because you can not pass an
> assumed-size to an assumed-shape

This is entirely possible and normal practice, and is often done by
normal code.

(I am, however, willing to be corrected).

> and because of pointer association rules.

Which rules?

Can you specify what the standard says about this case?
(If it is a numbered constraint, then a compiler is required
to diagnose it.  If it is something like "shall" or "shall not",
then it is up to the programmer to get this right; a good
implementation might catch the error, but it is not
required to do so).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/94110] Erroneous code compiling
  2020-03-09 20:27 [Bug fortran/94110] New: Erroneous code compiling jrfsousa at gmail dot com
  2020-04-13 17:19 ` [Bug fortran/94110] " tkoenig at gcc dot gnu.org
@ 2020-04-14 15:29 ` jrfsousa at gmail dot com
  2020-04-14 16:54 ` [Bug fortran/94110] Passing an assumed-size to an assumed-shape argument should be rejected tkoenig at gcc dot gnu.org
  2020-09-01 13:08 ` jrfsousa at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: jrfsousa at gmail dot com @ 2020-04-14 15:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94110

--- Comment #2 from José Rui Faustino de Sousa <jrfsousa at gmail dot com> ---
Hi Thomas!

IIRC assumed-size arrays are implemented has packaged descriptor less arrays.
In order to point to them or to pass them to a procedure expecting an assumed
or deferred-shape array one has to create an array descriptor. To create such
descriptor one must know the array bounds, which one does not for assumed-size
arrays.

Fortran pointers, unlike their C brethren, also carry bound information and
AFAIK one can not have an array, or a pointer to an array, which has undefined
bounds (what would the intrinsics like shape, ubound and size return?).

So in order to point to, or pass, an assumed-size array to a procedure
expecting an assumed or deferred-shape array the user must provide the missing
bound information, which can be done by specifying an array section effectively
creating an explicit-shape array (see PR94022).

So if one has an assumed-size array “arr”, rank 3, and a procedure “sub”, with
either an assumed or deferred-shape array dummy argument, one can do:

a = arr(:,:,1:n)
p => arr(:,:,1:n)
call sub(arr(:,:,1:n))

Assuming appropriate declarations of both “a” and “p”.
But one can not address the whole assumed-size array:

a = arr ! already generates error 
p=> arr ! already generates error
call sub(arr) ! The case here

What IMHO might be relevant and that I could find in the standard:

8.5.8.3 Assumed-shape array (par 1):
“An assumed-shape array is a nonallocatable nonpointer dummy argument array
that takes its shape from its effective argument.”

8.5.8.5 Assumed-size array:

C835:
“An object whose array bounds are specified by an
implied-shape-or-assumed-size-spec shall be a dummy data object or a named
constant.”

(par. 4):
“An assumed-size array shall not appear in a context that requires its shape.”

9.5.2 Whole arrays (par. 2):
“An assumed-size array (8.5.8.5) is permitted to appear as a whole array in an
executable construct or specification expression only as an actual argument in
a procedure reference that does not require the shape.”

10.1.2.2 Primary:
C1002 (R1001) The designator shall not be a whole assumed-size array.

10.2.2.2 Syntax of the pointer assignment statement C1025:
“The expr shall be a designator that designates a variable with either the
TARGET or POINTER attribute and is not an array section with a vector
subscript, or it shall be a reference to a function that returns a data
pointer.”

15.5.2.4 Ordinary dummy variables (par. 16):
“If a dummy argument is an assumed-shape array [...] the actual argument shall
not be an assumed-size array.”

15.5.2.7 Pointer dummy variables (par. 2):
“If the dummy argument does not have INTENT (IN) [...]. Otherwise, the actual
argument shall be a pointer or a valid target for the dummy pointer in a
pointer assignment statement. If the actual argument is not a pointer, the
dummy pointer becomes pointer associated with the actual argument.”

Should the compiler diagnose the error? Well it seems possible to do it and
error reports are always better than surprising results... Is it required to? I
would believe so... But I am interested on having the compiler hand hold me as
much as possible... ;-)

Best regards,
José Rui

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/94110] Passing an assumed-size to an assumed-shape argument should be rejected
  2020-03-09 20:27 [Bug fortran/94110] New: Erroneous code compiling jrfsousa at gmail dot com
  2020-04-13 17:19 ` [Bug fortran/94110] " tkoenig at gcc dot gnu.org
  2020-04-14 15:29 ` jrfsousa at gmail dot com
@ 2020-04-14 16:54 ` tkoenig at gcc dot gnu.org
  2020-09-01 13:08 ` jrfsousa at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-04-14 16:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94110

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
            Summary|Erroneous code compiling    |Passing an assumed-size to
                   |                            |an assumed-shape argument
                   |                            |should be rejected
           Keywords|accepts-invalid             |diagnostic
             Status|WAITING                     |NEW

--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
So, as far as I can see, not something that the compiler is required
to diagnose.

Confirming as an enhancement.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/94110] Passing an assumed-size to an assumed-shape argument should be rejected
  2020-03-09 20:27 [Bug fortran/94110] New: Erroneous code compiling jrfsousa at gmail dot com
                   ` (2 preceding siblings ...)
  2020-04-14 16:54 ` [Bug fortran/94110] Passing an assumed-size to an assumed-shape argument should be rejected tkoenig at gcc dot gnu.org
@ 2020-09-01 13:08 ` jrfsousa at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: jrfsousa at gmail dot com @ 2020-09-01 13:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94110

José Rui Faustino de Sousa <jrfsousa at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #4 from José Rui Faustino de Sousa <jrfsousa at gmail dot com> ---
Fixed by:

https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=8e1be7efcb1c68dd82e2b2c1bcf3e5ace245654d

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-01 13:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-09 20:27 [Bug fortran/94110] New: Erroneous code compiling jrfsousa at gmail dot com
2020-04-13 17:19 ` [Bug fortran/94110] " tkoenig at gcc dot gnu.org
2020-04-14 15:29 ` jrfsousa at gmail dot com
2020-04-14 16:54 ` [Bug fortran/94110] Passing an assumed-size to an assumed-shape argument should be rejected tkoenig at gcc dot gnu.org
2020-09-01 13:08 ` jrfsousa at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).