[Bug libfortran/53148] New: [gcc/gfortran-4.7.0 Regression] Incorrect intrinsic function parsing on labeled statements when compiled w/optimization
jpsinthemix at verizon dot net
gcc-bugzilla@gcc.gnu.org
Fri Apr 27 23:30:00 GMT 2012
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
More information about the Gcc-bugs
mailing list