[Bug fortran/20538] compiling -finline-functions -O2 and we crash at runtime

tobi at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Sat Mar 19 00:54:00 GMT 2005


------- Additional Comments From tobi at gcc dot gnu dot org  2005-03-19 00:54 -------
Slightly reduced testcase, segfaults at -O2, runs with lower optimization. 
Removing any single statement leads to either illegal floating pointn numbers or
makes the segfault disappear:

  character(len=8) argv
  real*8, parameter :: tstep = 0.01d0
  real*8 :: e
  type body
     real*8 x, y,z,vx,vy,vz, mass
  end type body
  type(body), parameter :: jupiter = body(1d0, 1d0, 1d0, 1d0, 1d0, 1d0, 1d0 )
  type(body), parameter :: sun = body(0.0d0, 0.0d0, 0.0d0, 0.0d0, 0.0d0, 0.0d0,1d0)

  type(body), dimension(2) :: bodies
  bodies = (/ sun, jupiter/)
  argv = "1"
  read (argv,*) num

  call offsetMomentum(1,bodies)
  do i=1,num
     call advance(tstep, bodies)
  end do
  e = 0.
  print *, e

contains

  subroutine offsetMomentum(k, bodies)
    integer, intent(in) :: k
    type(body), dimension(:), intent(inout) :: bodies
    real*8 :: px, py, pz
    do i=1,size(bodies)
       px =  bodies(i)%vx * bodies(i)%mass;
    end do
    bodies(k)%vx = -px
  end subroutine offsetMomentum


  subroutine advance(tstep, bodies)
  real*8, intent(in) :: tstep
  type(body), dimension(:), intent(inout) :: bodies

  real*8 dx, dy, dz, distance, mag
  integer i, j

  i = 1; j = 2; mag = 1.
        dx = bodies(i)%x - bodies(j)%x
        bodies(i)%vx = bodies(i)%vx - dx * bodies(j)%mass * mag

        bodies(j)%vx = bodies(j)%vx + dx * bodies(i)%mass * mag
        bodies(j)%vy = bodies(j)%vy + dy * bodies(i)%mass * mag
        bodies(j)%vz = bodies(j)%vz + dz * bodies(i)%mass * mag

  do i=1,size(bodies)
     bodies(i)%x = bodies(i)%x + tstep * bodies(i)%vx
     bodies(i)%y = bodies(i)%y + tstep * bodies(i)%vy
     bodies(i)%z = bodies(i)%z + tstep * bodies(i)%vz
  end do

  end subroutine advance

  real*8 function energy(bodies)
    type(body), dimension(:), intent(in) :: bodies
    real*8 dx, dy, dz, distance
    integer i, j

    energy = 0.0d0
  end function energy

end

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-03-19 00:54:17
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20538



More information about the Gcc-bugs mailing list