public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/97592] New: Incorrectly set pointer remapping with array pointer argument to CONTIGUOUS dummy
@ 2020-10-27 14:25 reubendb at gmail dot com
  2020-10-27 19:07 ` [Bug fortran/97592] " anlauf at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: reubendb at gmail dot com @ 2020-10-27 14:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97592
           Summary: Incorrectly set pointer remapping with array pointer
                    argument to CONTIGUOUS dummy
           Product: gcc
           Version: og10 (devel/omp/gcc-10)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: reubendb at gmail dot com
  Target Milestone: ---

Hi, 

The following code produces an incorrect results with GCC 10.1.0, 10.2.0.

The code works as expected with GCC/6.4.0,7.4.0,8.1.0,8.1.1 

program RemappingTest
  implicit none
  real, dimension ( :, : ), pointer :: & 
    B_2D
  real, dimension ( :, :, : ), pointer :: &
    B_3D

  !-- Prepare B_2D
  allocate ( B_2D ( 16, 3 ) )
  B_2D  =  - huge ( 1.0 )

  !-- Point B_3D to Storage
  call SetPointer ( B_2D, 4, 4, 3, B_3D )

  !-- Set B_3D
  B_3D  =  2.0

  !-- See if the result is reflected in Storage
  print*
  print*, "B_2D = ", B_2D  !-- expect 2.0 for all elements

contains

  subroutine SetPointer ( C_2D, n1, n2, n3, C_3D )
    real, dimension ( :, : ), intent ( inout ), target, contiguous :: &
      C_2D
    integer :: &
      n1, n2, n3
    real, dimension ( :, :, : ), intent ( inout ), pointer :: &
      C_3D
    C_3D ( 1 : n1, 1 : n2, 1 : n3 )  =>  C_2D
  end subroutine SetPointer

end program RemappingTest

]$ gfortran --version
GNU Fortran (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

]$ gfortran -Wall -Wextra -fno-strict-aliasing -fwrapv -Warray-temporaries
PointerRemapTest.f90 
PointerRemapTest.f90:13:20:

   13 |   call SetPointer ( B_2D, 4, 4, 3, B_3D )
      |                    1
Warning: Creating array temporary at (1) [-Warray-temporaries]

]$ ./a.out 

 B_2D =   -3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38 
-3.40282347E+38  -3.40282347E+38  -3.40282347E+38  -3.40282347E+38

It seems to be issue is because inside the subroutine SetPointer, a new array
`C_2D` is created. So `C_3D` points to this new array instead. Outside of
subroutine, this pointer (now `B_3D`) actually points to an invalid memory
location. In some cases I can trigger a segfault with the code with GCC-10.2.0

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

end of thread, other threads:[~2023-12-27 19:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 14:25 [Bug fortran/97592] New: Incorrectly set pointer remapping with array pointer argument to CONTIGUOUS dummy reubendb at gmail dot com
2020-10-27 19:07 ` [Bug fortran/97592] " anlauf at gcc dot gnu.org
2021-02-14 18:17 ` dominiq at lps dot ens.fr
2022-03-14 21:39 ` anlauf at gcc dot gnu.org
2023-03-21 19:44 ` [Bug fortran/97592] [10/11/12/13 Regression] " anlauf at gcc dot gnu.org
2023-03-21 19:57 ` anlauf at gcc dot gnu.org
2023-07-07 10:38 ` [Bug fortran/97592] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-12-15 22:31 ` anlauf at gcc dot gnu.org
2023-12-16 18:29 ` anlauf at gcc dot gnu.org
2023-12-17 17:33 ` cvs-commit at gcc dot gnu.org
2023-12-27 19:27 ` cvs-commit at gcc dot gnu.org
2023-12-27 19:33 ` anlauf 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).