public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/100183] New: Segmentation fault at runtime when passing an internal procedure as argument
@ 2021-04-21 14:33 jellby at yahoo dot com
  2021-04-21 21:12 ` [Bug fortran/100183] " anlauf at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jellby at yahoo dot com @ 2021-04-21 14:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100183
           Summary: Segmentation fault at runtime when passing an internal
                    procedure as argument
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jellby at yahoo dot com
  Target Milestone: ---

I've only been able to reproduce it with:

$ uname -a
Darwin minimac.moose.housegordon.com 20.3.0 Darwin Kernel Version 20.3.0: Thu
Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 arm64

$ gfortran -version
GNU Fortran (Homebrew GCC 10.2.0_4) 10.2.1 20201220


Compiling and running the following code works fine, but with -O1 it gives a
segmentation fault. Alternatively, undefining INTERNAL_PROC_ARG works with -O1.


$ cat test.F90
#define INTERNAL_PROC_ARG                                                      
                                                                               
          [45/90681]

module sorting
    implicit none
    private
    public :: argsort
    real, pointer :: mod_rV(:)

    interface
        logical pure function compare_int_t(a, b)
            integer, intent(in) :: a, b
        end function
    end interface

contains

    logical pure function my_compare_rV(x, y)
        integer, intent(in) :: x, y
        my_compare_rV = mod_rV(x) <= mod_rV(y)
    end function

    function argsort(V) result(idx)
        real, target, intent(inout) :: V(:)
        integer :: idx(lbound(V, 1):ubound(V, 1)), i

        idx = [(i, i = lbound(V, 1), ubound(V, 1))]

#       ifdef INTERNAL_PROC_ARG
        call sort(idx, my_compare)
#       else
        mod_rV => V
        call sort(idx, my_compare_rV)
#       endif

    contains
        logical pure function my_compare(x, y)
            integer, intent(in) :: x, y
            my_compare = V(x) <= V(y)
        end function
    end function argsort

    subroutine sort(A, compare)
        integer, intent(inout) :: A(:)
        procedure(compare_int_t) :: compare
        integer :: i, j, t
        do i = lbound(A, 1), ubound(A, 1)
          do j = i + 1, ubound(A, 1)
            if (.not. compare(A(i), A(j))) then
                t = A(i)
                A(i) = A(j)
                A(j) = t
            end if
          end do
        end do
    end subroutine sort
end module sorting

program test
    use sorting, only: argsort

    implicit none
    integer :: i
    integer, parameter :: seed(50) = [(i, i = 1, size(seed))]
    real :: lambdas(5)
    integer :: idx(size(lambdas))

    call random_seed(put=seed)
    call random_number(lambdas)

    write(6,*) 'Before sorting:'
    write(6,*) lambdas(:)
    idx(:) = argsort(lambdas)
    write(6,*) 'Argsort:'
    write(6,*) idx(:)
    write(6,*) 'Sorted:'
    write(6,*) lambdas(idx(:))
end program test


$ gfortran -O1 test.F90 -o test ; ./test       
 Before sorting:
  0.471070886      0.117344737      0.357547939      0.318134785     
0.696753800    
zsh: segmentation fault  ./test


$ gfortran -O0 test.F90 -o test ; ./test
 Before sorting:
  0.471070886      0.117344737      0.357547939      0.318134785     
0.696753800    
 Argsort:
           2           4           3           1           5
 Sorted:
  0.117344737      0.318134785      0.357547939      0.471070886     
0.696753800

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

* [Bug fortran/100183] Segmentation fault at runtime when passing an internal procedure as argument
  2021-04-21 14:33 [Bug fortran/100183] New: Segmentation fault at runtime when passing an internal procedure as argument jellby at yahoo dot com
@ 2021-04-21 21:12 ` anlauf at gcc dot gnu.org
  2021-04-22  7:25 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-04-21 21:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from anlauf at gcc dot gnu.org ---
Cannot reproduce either with

GNU Fortran (SUSE Linux) 10.2.1 20200825 [revision
c0746a1beb1ba073c7981eb09f55b3d993b32e5c]

nor with

GNU Fortran (GCC) 10.3.1 20210420

May need narrowing down to affected versions.

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

* [Bug fortran/100183] Segmentation fault at runtime when passing an internal procedure as argument
  2021-04-21 14:33 [Bug fortran/100183] New: Segmentation fault at runtime when passing an internal procedure as argument jellby at yahoo dot com
  2021-04-21 21:12 ` [Bug fortran/100183] " anlauf at gcc dot gnu.org
@ 2021-04-22  7:25 ` rguenth at gcc dot gnu.org
  2021-04-22  7:26 ` jellby at yahoo dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-22  7:25 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |iains at gcc dot gnu.org
             Target|                            |aarch64-darwin

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Cannot reproduce on x86_64.

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

* [Bug fortran/100183] Segmentation fault at runtime when passing an internal procedure as argument
  2021-04-21 14:33 [Bug fortran/100183] New: Segmentation fault at runtime when passing an internal procedure as argument jellby at yahoo dot com
  2021-04-21 21:12 ` [Bug fortran/100183] " anlauf at gcc dot gnu.org
  2021-04-22  7:25 ` rguenth at gcc dot gnu.org
@ 2021-04-22  7:26 ` jellby at yahoo dot com
  2021-04-22  7:32 ` iains at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jellby at yahoo dot com @ 2021-04-22  7:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Ignacio Fernández Galván <jellby at yahoo dot com> ---
If it helps, this happens in gcc304 from
https://cfarm.tetaneutral.net/machines/list/, but not in gcc80

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

* [Bug fortran/100183] Segmentation fault at runtime when passing an internal procedure as argument
  2021-04-21 14:33 [Bug fortran/100183] New: Segmentation fault at runtime when passing an internal procedure as argument jellby at yahoo dot com
                   ` (2 preceding siblings ...)
  2021-04-22  7:26 ` jellby at yahoo dot com
@ 2021-04-22  7:32 ` iains at gcc dot gnu.org
  2021-04-29 21:02 ` anlauf at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: iains at gcc dot gnu.org @ 2021-04-22  7:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Iain Sandoe <iains at gcc dot gnu.org> ---
(In reply to Ignacio Fernández Galván from comment #3)
> If it helps, this happens in gcc304 from
> https://cfarm.tetaneutral.net/machines/list/, but not in gcc80

gcc304 is the Apple M1 machine.  The GCC support there is highly experimental
and not in master -- please note that there are known issues with the
implementation.

see : https://github.com/iains/gcc-darwin-arm64/issues

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

* [Bug fortran/100183] Segmentation fault at runtime when passing an internal procedure as argument
  2021-04-21 14:33 [Bug fortran/100183] New: Segmentation fault at runtime when passing an internal procedure as argument jellby at yahoo dot com
                   ` (3 preceding siblings ...)
  2021-04-22  7:32 ` iains at gcc dot gnu.org
@ 2021-04-29 21:02 ` anlauf at gcc dot gnu.org
  2021-04-29 21:30 ` iains at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-04-29 21:02 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-04-29

--- Comment #5 from anlauf at gcc dot gnu.org ---
(In reply to Iain Sandoe from comment #4)
> gcc304 is the Apple M1 machine.  The GCC support there is highly
> experimental and not in master -- please note that there are known issues
> with the implementation.
> 
> see : https://github.com/iains/gcc-darwin-arm64/issues

So rather a target than a fortran issue?

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

* [Bug fortran/100183] Segmentation fault at runtime when passing an internal procedure as argument
  2021-04-21 14:33 [Bug fortran/100183] New: Segmentation fault at runtime when passing an internal procedure as argument jellby at yahoo dot com
                   ` (4 preceding siblings ...)
  2021-04-29 21:02 ` anlauf at gcc dot gnu.org
@ 2021-04-29 21:30 ` iains at gcc dot gnu.org
  2022-01-01  8:57 ` pinskia at gcc dot gnu.org
  2022-01-01  9:01 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: iains at gcc dot gnu.org @ 2021-04-29 21:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Iain Sandoe <iains at gcc dot gnu.org> ---
(In reply to anlauf from comment #5)
> (In reply to Iain Sandoe from comment #4)
> > gcc304 is the Apple M1 machine.  The GCC support there is highly
> > experimental and not in master -- please note that there are known issues
> > with the implementation.
> > 
> > see : https://github.com/iains/gcc-darwin-arm64/issues
> 
> So rather a target than a fortran issue?

The fortran folks have fixed a number of cases recently where the FE was
providing bad information to the ME .. which doesn't cause problems to most
targets, but did to aarch64-darwin.  I cannot rule out that this is another
case in that category (but not had a chance to analyse it yet).

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

* [Bug fortran/100183] Segmentation fault at runtime when passing an internal procedure as argument
  2021-04-21 14:33 [Bug fortran/100183] New: Segmentation fault at runtime when passing an internal procedure as argument jellby at yahoo dot com
                   ` (5 preceding siblings ...)
  2021-04-29 21:30 ` iains at gcc dot gnu.org
@ 2022-01-01  8:57 ` pinskia at gcc dot gnu.org
  2022-01-01  9:01 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-01  8:57 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
           See Also|                            |https://github.com/iains/gc
                   |                            |c-darwin-arm64/issues/26

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

* [Bug fortran/100183] Segmentation fault at runtime when passing an internal procedure as argument
  2021-04-21 14:33 [Bug fortran/100183] New: Segmentation fault at runtime when passing an internal procedure as argument jellby at yahoo dot com
                   ` (6 preceding siblings ...)
  2022-01-01  8:57 ` pinskia at gcc dot gnu.org
@ 2022-01-01  9:01 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-01  9:01 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes this was a the nested functions being passed to another function issue
where executable stack was needed for aarch64-darwin, there is no executable
stack.
Anyways this was tracked as https://github.com/iains/gcc-darwin-arm64/issues/26
and was just fixed so closing as moved as aarch64-darwin is not supported yet
in the FSF sources (Ians and FX are planning on merging it upstream sometime
this year).

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

end of thread, other threads:[~2022-01-01  9:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 14:33 [Bug fortran/100183] New: Segmentation fault at runtime when passing an internal procedure as argument jellby at yahoo dot com
2021-04-21 21:12 ` [Bug fortran/100183] " anlauf at gcc dot gnu.org
2021-04-22  7:25 ` rguenth at gcc dot gnu.org
2021-04-22  7:26 ` jellby at yahoo dot com
2021-04-22  7:32 ` iains at gcc dot gnu.org
2021-04-29 21:02 ` anlauf at gcc dot gnu.org
2021-04-29 21:30 ` iains at gcc dot gnu.org
2022-01-01  8:57 ` pinskia at gcc dot gnu.org
2022-01-01  9:01 ` pinskia 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).