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]

Re: c langauge optimizer problem, sparc-solaris and debian gnu/linu



Thank you for looking into this problem, however, I still believe that it is a
bug.  None of the computations involved produce an integer overflow --
after looking at the assembly, I think that the optimizer might be producing
the overflow, and as a result optimizing out the test as always
true.  If you assign (2147483647L   * 2UL + 1) to an unsigned long
variable and place that variable in the test expression then the code
works as expected.  Also, if you break the expression out into
sequential, nested ifs it also works.  I have conferred with several
programmers here and on the debian irc and they agree.

If there is an overflow taking place, could you explain where it is
happening so that I may fix the code.

Again, Thank you for your help on this issue.
James M.


Martin v. Loewis writes:
 > > The optimized code in the attached file results in runtime behavior
 > > that is different and incorrect, when compared to the runtime
 > > behavior of the non-optimized code.
 > 
 > Thanks for your bug report. Your program performs the computation
 > 
 >    if ( totalsize > (2147483647L   * 2UL + 1)  || (msize != 0 &&
 >    ((msize - 1) > (2147483647L   * 2UL + 1) ))) 
 > 
 > I believe this computation causes an integer overflow on your
 > platform, which in turn results in undefined behaviour, according to
 > the C standard. Therefore, the compiler is entitled to produce any
 > output it wants, and that is not a bug.
 > 
 > Regards,
 > Martin
 > 

<original message>

The optimized code in the attached file results in runtime behavior
that is different and incorrect, when compared to the runtime behavior
of the non-optimized code.

The command line and command line output follows:

gcc -v --save-temps -O t2.c

Reading specs from /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/cpp -lang-c -v -D__GNUC__=2
-D__GNUC_MINOR__=95 -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__
-D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__OPTIMIZE__
-D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) t2.c t2.i
GNU CPP version 2.95.2 19991024 (release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include

/usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/../../../../sparc-sun-solaris2.5.1/include
 /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/include/g++
End of omitted list.
 /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/cc1 t2.i -quiet -dumpbase t2.c -O
-version -o t2.s
GNU C version 2.95.2 19991024 (release) (sparc-sun-solaris2.5.1) compiled by GNU C version 2.95.2
19991024 (release).
 /usr/ccs/bin/as -V -Qy -s -o t2.o t2.s
/usr/ccs/bin/as: WorkShop Compilers 4.2 dev 13 May 1996
 /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/collect2 -V -Y
P,/usr/ccs/lib:/usr/lib -Qy /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/crt1.o
/usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/crti.o /usr/ccs/lib/values-Xa.o
/usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/crtbegin.o
-L/usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2 -L/usr/ccs/bin -L/usr/ccs/lib
-L/usr/local/gcc-2.95.2/lib t2.o -lgcc -lc -lgcc
/usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/crtend.o
/usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/crtn.o
ld: Software Generation Utilities - Solaris/ELF (3.0)

t2.i.gz


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