This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/34234] New: Incorrect code generated by gfortran (missing code)


It is many years since I last tried to use FORTRAN.  I am now trying to use
gfortran to work through some examples from a book.  Unfortunately I am being
hampered by a bug in gfortran.  It usually causes SIGSEGV.

I couldn't spot this bug in a search, but this is probably due to my
inexperience.

$ gfortran --version
GNU Fortran (GCC) 4.2.1 (Ubuntu 4.2.1-5ubuntu4)
Copyright (C) 2007 Free Software Foundation, Inc.

If I compile the following (using only -Wall), all appears to be o.k.:

      Subroutine fn(f, b, y, m)
      dimension f(m,m)
      y = b / f(1,1)
      return
      end

However, change it to this:

      Subroutine fn(f, b, y, m)
      dimension f(m,m), b(m), y(m)
      y(l) = b(1) / f(1,1)
      return
      end

and the generated code is wrong.

The key point is the treatment of the index of y(1).  It appears that it is
intended to be copied to the local stack frame and used later.  In the (second)
version above, the copying to the local stack frame is skipped in the generated
code.

The following assembler code is generated from the second version by
    $ gfortran -S subs2.f
The instruction which references an uninitialised part of the stack is
indicated by "*******".  It appears that the code would be correct if $1 (i.e.
the index of y(1)) had been previously stored in -4(%ebp).

        .file   "subs2.f"
        .text
.globl fn_
        .type   fn_, @function
fn_:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        movl    20(%ebp), %eax
        movl    (%eax), %eax
        testl   %eax, %eax
        js      .L2
        jmp     .L4
.L2:
.L4:
        movl    20(%ebp), %eax
        movl    (%eax), %eax
        testl   %eax, %eax
        js      .L5
        jmp     .L7
.L5:
.L7:
        movl    20(%ebp), %eax
        movl    (%eax), %eax
        movl    %eax, -20(%ebp)
        cmpl    $0, -20(%ebp)
        js      .L8
        movl    -20(%ebp), %eax
        movl    %eax, -24(%ebp)
        jmp     .L10
.L8:
        movl    $0, -24(%ebp)
.L10:
        movl    -24(%ebp), %eax
        movl    %eax, -20(%ebp)
        movl    20(%ebp), %eax
        movl    (%eax), %eax
        imull   -20(%ebp), %eax
        testl   %eax, %eax
        js      .L11
        jmp     .L13
.L11:
.L13:
        movl    -20(%ebp), %edx
        notl    %edx
        movl    -4(%ebp), %ecx     *******
        subl    $1, %ecx
        movl    12(%ebp), %eax
        flds    (%eax)
        movl    -20(%ebp), %eax
        addl    $1, %eax
        leal    (%eax,%edx), %edx
        movl    8(%ebp), %eax
        flds    (%eax,%edx,4)
        fdivrp  %st, %st(1)
        movl    16(%ebp), %eax
        fstps   (%eax,%ecx,4)
        leave
        ret
        .size   fn_, .-fn_
        .ident  "GCC: (GNU) 4.2.1 (Ubuntu 4.2.1-5ubuntu4)"
        .section        .note.GNU-stack,"",@progbits


-- 
           Summary: Incorrect code generated by gfortran (missing code)
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: billm at melbpc dot org dot au
 GCC build triplet: 4.2.1-5ubuntu4
  GCC host triplet: Linux Ubuntu
GCC target triplet: ix86


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]