public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jpsinthemix at verizon dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libfortran/53148] New: [gcc/gfortran-4.7.0 Regression] Incorrect intrinsic function parsing on labeled statements when compiled w/optimization
Date: Fri, 27 Apr 2012 23:30:00 -0000	[thread overview]
Message-ID: <bug-53148-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             Bug #: 53148
           Summary: [gcc/gfortran-4.7.0 Regression] Incorrect intrinsic
                    function parsing on labeled statements when compiled
                    w/optimization
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jpsinthemix@verizon.net


Created attachment 27256
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27256
Compilation and .s files for -O0 and -O2 optimizations

Hi,
There appears to be a gcc/gfortran-4.7.0 regression occurring for -O
optimizations greater than -O0 related to the parsing of labeled statements
containing expressions with repeated function calls. For example, a statement
like:

   10 x = dble(y)*dble(y)

will generate a compiler warning, similar to

label_opt_issue.f:38:0: warning: '__var_1' is used uninitialized in this
function [-Wuninitialized]

and at runtime, the expression dble(y)*dble(y) will always evaluate to 0,
regardless of the value of y.

Expected results are obtained when the code is compiled with default/no
optimization, but failure occurs when compiling with -O1 and above. There is
nothing special about the use of intrinsic DBLE here, the same behavior occurs
for other intrinsic functions (user-defined functions work as expected). In
addition, if a more complicated expression is used, for example,

   10 x = (1.d0 + exp(y)*exp(y))/z

then the same compilation warning occurs, and the value of x is evaluated as

      x = (1 + 0)/z = 1/z

that is, exp(y)*exp(y) evaluates to 0, regardless of y.


This issue is not present in gcc/gfortran-4.6.3. The following program
demonstrates the issue:

C label_opt_issue.f

      program main
          real x
          double precision xsq
          double precision test_func
          double precision work_around

          x = 5.

          xsq = test_func(x)
          write(*,*) "function   x: ", x, "    x*x: ", xsq

          call test_subr(x,xsq)
          write(*,*) "subroutine x: ", x, "    x*x: ", xsq

          xsq = work_around(x)
          write(*,*) "expected   x: ", x, "    x*x: ", xsq
          end program

      subroutine test_subr(x,xsq)
          real x
          double precision xsq
          intrinsic dble

          goto 10

   10     xsq = dble(x)*dble(x)
          return
          end subroutine

      double precision function test_func(x)
          real x
          intrinsic dble

          goto 10

   10     test_func = dble(x)*dble(x)
          return
          end function

      double precision function work_around(x)
          real x
          intrinsic dble

          goto 10

   10     continue
          work_around = dble(x)*dble(x)
          return
          end function

Demonstration code output:

With -O1 to -O3 optimization:

$ ./label_opt_issue
 function   x:    5.00000000         x*x:    0.0000000000000000
 subroutine x:    5.00000000         x*x:    0.0000000000000000
 expected   x:    5.00000000         x*x:    25.000000000000000

With default optimization:

$ ./label_opt_issue
 function   x:    5.00000000         x*x:    25.000000000000000
 subroutine x:    5.00000000         x*x:    25.000000000000000
 expected   x:    5.00000000         x*x:    25.000000000000000


I have attached the label_opt_issue.f compilation logs and temp *.s files for
for two cases: default optimization and -O2 optimization. 

I came across this issue building and testing SCIPY; one test failed which
really should not have, and that lead me to a fortran routine using DBLE in the
manner above which always evaluated to 0.

System info:

=== gcc/gfortran version/options/system type:
$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-linux-gnu/4.7.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: /home/bld/gcc-4.7.0-jps_src/gcc-4.7.0/configure --prefix=/usr
--libexecdir=/usr/lib --with-gmp=/usr --with-mpfr=/usr --with-system-zlib
--enable-shared --enable-checking=release --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu --disable-bootstrap
--enable-languages=c,c++,fortran --infodir=/usr/share/info
--mandir=/usr/share/man
Thread model: posix
gcc version 4.7.0 (GCC)

system: Linux b-movie 3.3.3 #1 Sun Apr 22 21:11:23 EDT 2012 i686 GNU/Linux
glibc:  2.15

thanks for your time,
John


             reply	other threads:[~2012-04-27 23:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-27 23:30 jpsinthemix at verizon dot net [this message]
2012-04-28 20:42 ` [Bug fortran/53148] [4.7/4.8 Regression] Incorrect intrinsic function parsing on labeled statements when compiled w/ -ffrontend-optimize burnus at gcc dot gnu.org
2012-04-29  7:04 ` tkoenig at gcc dot gnu.org
2012-04-29  7:12 ` tkoenig at gcc dot gnu.org
2012-04-30 19:32 ` [Bug fortran/53148] [4.7 " tkoenig at gcc dot gnu.org
2012-04-30 19:35 ` tkoenig at gcc dot gnu.org
2012-04-30 23:47 ` jpsinthemix at verizon dot net
2012-05-21 15:13 ` jsm28 at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-53148-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).