public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy
@ 2022-03-07 13:24 burnus at gcc dot gnu.org
  2022-03-08  7:31 ` [Bug fortran/104819] " burnus at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: burnus at gcc dot gnu.org @ 2022-03-07 13:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104819
           Summary: Reject NULL without MOLD as actual to an assumed-rank
                    dummy
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

[Found when looking at PR 104126]
Cf. https://mailman.j3-fortran.org/pipermail/j3/2022-March/013584.html

   call foo(null())
contains
   subroutine foo(x)
     integer, pointer, intent(in) :: x(..)
     print *, rank(x)
   end subroutine
end

I believe this should be rejected as the rank is not known without a MOLD.

 * * *

The following is also invalid because of
  "If any type parameters of the contextual entity are assumed, MOLD shall be
present."
("16.9.155 NULL ([MOLD])"):

call foo(null())
contains
   subroutine foo(x)
     character(len=*), pointer, intent(in) :: x
   end subroutine
end

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
@ 2022-03-08  7:31 ` burnus at gcc dot gnu.org
  2023-11-06 20:32 ` anlauf at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: burnus at gcc dot gnu.org @ 2022-03-08  7:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to Tobias Burnus from comment #0)
> I believe this should be rejected as the rank is not known without a MOLD.

That's now an interpretation request:
https://j3-fortran.org/doc/year/22/22-146.txt

(Note: might see updates, such as 22-146r1.txt or ...)

 * * *

In the email thread, also an issue related to C_SIZEOF was mentioned:
https://j3-fortran.org/doc/year/22/22-101r1.txt

Example from the IR, see IR for details about the validity.

program p
 use iso_c_binding
 implicit none
 integer(c_int), pointer :: int_s
 integer(c_int), pointer :: int_a(:)
 print *, c_sizeof (c_null_ptr) ! (A)
 print *, c_sizeof (null ())    ! (B)
 print *, c_sizeof (null (int_s)) ! (C)
 print *, c_sizeof (null (int_a)) ! (D)
end

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
  2022-03-08  7:31 ` [Bug fortran/104819] " burnus at gcc dot gnu.org
@ 2023-11-06 20:32 ` anlauf at gcc dot gnu.org
  2023-11-06 20:46 ` anlauf at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-11-06 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-11-06
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #2 from anlauf at gcc dot gnu.org ---
There are also a few cases where null(null()) is erroneously rejected:

program p
  implicit none
  integer, pointer :: x
  call foo (null (x))        ! valid and accepted
  call foo (null ())         ! valid and accepted
  call foo (null (null (x))) ! valid but rejected
  call foo (null (null ()))  ! valid but rejected
contains
  subroutine foo (y)
    integer, pointer :: y
  end subroutine foo
end

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
  2022-03-08  7:31 ` [Bug fortran/104819] " burnus at gcc dot gnu.org
  2023-11-06 20:32 ` anlauf at gcc dot gnu.org
@ 2023-11-06 20:46 ` anlauf at gcc dot gnu.org
  2023-11-09 21:32 ` anlauf at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-11-06 20:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from anlauf at gcc dot gnu.org ---
Created attachment 56519
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56519&action=edit
Partial patch

This patch adjusts the checking so that nested NULL()s are accepted,
tries to implement Interp J3/22-146 when passing NULL() to an
assumed-rank dummy, and catches NULL() passed to an assumed-length dummy.

TODO: fix handling of NULL(mold) in gfc_conv_procedure_call.

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-11-06 20:46 ` anlauf at gcc dot gnu.org
@ 2023-11-09 21:32 ` anlauf at gcc dot gnu.org
  2023-11-12 21:02 ` anlauf at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-11-09 21:32 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #56519|0                           |1
        is obsolete|                            |

--- Comment #4 from anlauf at gcc dot gnu.org ---
Created attachment 56546
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56546&action=edit
Second version of a patch

This patch contains a revised checking of NULL() as actual argument
which should be consistent with F2008+ for allocatables.

It also fixes the cases where NULL(x) is passed to an assumed-rank
dummy, but only for scalar x so far.

I might need some assistance in how to produce a proper descriptor to pass
for rank > 0.  (I added a gfc_internal_error (TODO) for the allocatable case.)

Regtests essentially fine, but requires fixing these invalid testcases:

! gfortran.dg/assumed_rank_8.f90
! gfortran.dg/assumed_rank_9.f90
! gfortran.dg/assumed_rank_10.f90
! gfortran.dg/pr101329.f90

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-11-09 21:32 ` anlauf at gcc dot gnu.org
@ 2023-11-12 21:02 ` anlauf at gcc dot gnu.org
  2023-11-14 21:17 ` anlauf at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-11-12 21:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from anlauf at gcc dot gnu.org ---
Created attachment 56563
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56563&action=edit
Partial testsuite fixes

This patch contains obvious fixes to 3 testcases, except for
assumed_rank_9.f90,
which is more severe, as it violates

! F2018:15.5.2.5  Allocatable and pointer dummy variables
!
! The actual argument shall be polymorphic if and only if the associated
! dummy argument is polymorphic, and either both the actual and dummy
! arguments shall be unlimited polymorphic, or the declared type of the
! actual argument shall be the same as the declared type of the dummy
! argument.
!
! F2023:15.5.2.6  has the same text

which is detected (mostly) by NAG and Intel.

We need to detect and diagnose violations of the above.

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-11-12 21:02 ` anlauf at gcc dot gnu.org
@ 2023-11-14 21:17 ` anlauf at gcc dot gnu.org
  2023-11-16 20:19 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-11-14 21:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #5)
> We need to detect and diagnose violations of the above.

Example:

program main
  implicit none
  type t
    integer :: i
  end type t

  type(t),  allocatable, target :: xa
  type(t),  pointer             :: xp
  class(t), allocatable, target :: ya
  class(t), pointer             :: yp

  call foo_p (xp) ! Invalid
  call foo_p (xa) ! Invalid in F2008, valid in F2018

  call foo_p (yp) ! Valid, OK
  call foo_p (ya) ! Valid, OK

contains

  subroutine foo_p (x)
    class(t), pointer, intent(in) :: x
  end subroutine

end

The lines marked invalid are detected for -std=f2003, but not for >= f2008.

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-11-14 21:17 ` anlauf at gcc dot gnu.org
@ 2023-11-16 20:19 ` anlauf at gcc dot gnu.org
  2023-11-23 18:32 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-11-16 20:19 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #56546|0                           |1
        is obsolete|                            |

--- Comment #7 from anlauf at gcc dot gnu.org ---
Created attachment 56607
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56607&action=edit
Updated patch

This patch adds further checking to handle F2008/F2018 differences.
It is now more in line with NAG (and sort-of Intel) here.
However, regression testing produces further fallout:

gfortran.dg/pointer_intent_7.f90 - harmless, needs adjusted pattern,

but the following appear to be really invalid according to NAG and visual
inspection:

gfortran.dg/class_dummy_4.f03
gfortran.dg/class_optional_2.f90
gfortran.dg/finalize_12.f90
gfortran.dg/select_type_30.f03

This is now getting really messy...

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-11-16 20:19 ` anlauf at gcc dot gnu.org
@ 2023-11-23 18:32 ` cvs-commit at gcc dot gnu.org
  2024-02-29 21:01 ` anlauf at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-23 18:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:7646b5d88056cf269ff555afe95bc361dcf5e5c0

commit r14-5798-g7646b5d88056cf269ff555afe95bc361dcf5e5c0
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Nov 22 21:45:46 2023 +0100

    testsuite: fortran: fix invalid testcases (missing MOLD argument to NULL)

    The Fortran standard requires that NULL() passed to an assumed-rank
    dummy argument has a MOLD argument.

    gcc/testsuite/ChangeLog:

            PR fortran/104819
            * gfortran.dg/assumed_rank_10.f90: Add MOLD argument to NULL().
            * gfortran.dg/assumed_rank_8.f90: Likewise.

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2023-11-23 18:32 ` cvs-commit at gcc dot gnu.org
@ 2024-02-29 21:01 ` anlauf at gcc dot gnu.org
  2024-03-01 18:22 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-29 21:01 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |anlauf at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #9 from anlauf at gcc dot gnu.org ---
First patch:

https://gcc.gnu.org/pipermail/fortran/2024-February/060289.html

(slightly corrected version from comment#3).

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2024-02-29 21:01 ` anlauf at gcc dot gnu.org
@ 2024-03-01 18:22 ` cvs-commit at gcc dot gnu.org
  2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
  2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-01 18:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:db0b6746be075e43c8142585968483e125bb52d0

commit r14-9261-gdb0b6746be075e43c8142585968483e125bb52d0
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Fri Mar 1 19:21:27 2024 +0100

    Fortran: improve checks of NULL without MOLD as actual argument [PR104819]

    gcc/fortran/ChangeLog:

            PR fortran/104819
            * check.cc (gfc_check_null): Handle nested NULL()s.
            (is_c_interoperable): Check for MOLD argument of NULL() as part of
            the interoperability check.
            * interface.cc (gfc_compare_actual_formal): Extend checks for
NULL()
            actual arguments for presence of MOLD argument when required by
            Interp J3/22-146.

    gcc/testsuite/ChangeLog:

            PR fortran/104819
            * gfortran.dg/assumed_rank_9.f90: Adjust testcase use of NULL().
            * gfortran.dg/pr101329.f90: Adjust testcase to conform to interp.
            * gfortran.dg/null_actual_4.f90: New test.

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2024-03-01 18:22 ` cvs-commit at gcc dot gnu.org
@ 2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
  2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-15 21:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:ba4b4b3864d426835ea10e900a4e1dd466d06e51

commit r13-8442-gba4b4b3864d426835ea10e900a4e1dd466d06e51
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Nov 22 21:45:46 2023 +0100

    testsuite: fortran: fix invalid testcases (missing MOLD argument to NULL)

    The Fortran standard requires that NULL() passed to an assumed-rank
    dummy argument has a MOLD argument.

    gcc/testsuite/ChangeLog:

            PR fortran/104819
            * gfortran.dg/assumed_rank_10.f90: Add MOLD argument to NULL().
            * gfortran.dg/assumed_rank_8.f90: Likewise.

    (cherry picked from commit 7646b5d88056cf269ff555afe95bc361dcf5e5c0)

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

* [Bug fortran/104819] Reject NULL without MOLD as actual to an assumed-rank dummy
  2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
@ 2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-15 21:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:90442fb421823153c4f762a2d26a0d700af2e6c3

commit r13-8443-g90442fb421823153c4f762a2d26a0d700af2e6c3
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Fri Mar 1 19:21:27 2024 +0100

    Fortran: improve checks of NULL without MOLD as actual argument [PR104819]

    gcc/fortran/ChangeLog:

            PR fortran/104819
            * check.cc (gfc_check_null): Handle nested NULL()s.
            (is_c_interoperable): Check for MOLD argument of NULL() as part of
            the interoperability check.
            * interface.cc (gfc_compare_actual_formal): Extend checks for
NULL()
            actual arguments for presence of MOLD argument when required by
            Interp J3/22-146.

    gcc/testsuite/ChangeLog:

            PR fortran/104819
            * gfortran.dg/assumed_rank_9.f90: Adjust testcase use of NULL().
            * gfortran.dg/pr101329.f90: Adjust testcase to conform to interp.
            * gfortran.dg/null_actual_4.f90: New test.

    (cherry picked from commit db0b6746be075e43c8142585968483e125bb52d0)

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

end of thread, other threads:[~2024-03-15 21:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 13:24 [Bug fortran/104819] New: Reject NULL without MOLD as actual to an assumed-rank dummy burnus at gcc dot gnu.org
2022-03-08  7:31 ` [Bug fortran/104819] " burnus at gcc dot gnu.org
2023-11-06 20:32 ` anlauf at gcc dot gnu.org
2023-11-06 20:46 ` anlauf at gcc dot gnu.org
2023-11-09 21:32 ` anlauf at gcc dot gnu.org
2023-11-12 21:02 ` anlauf at gcc dot gnu.org
2023-11-14 21:17 ` anlauf at gcc dot gnu.org
2023-11-16 20:19 ` anlauf at gcc dot gnu.org
2023-11-23 18:32 ` cvs-commit at gcc dot gnu.org
2024-02-29 21:01 ` anlauf at gcc dot gnu.org
2024-03-01 18:22 ` cvs-commit at gcc dot gnu.org
2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org

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).