libjava Divide_1 and pr6388 fail on 4.2.0 RC3 for several targets
Ian Lance Taylor
iant@google.com
Tue May 8 00:39:00 GMT 2007
Tom Tromey <tromey@redhat.com> writes:
> >>>>> "Ian" == Ian Lance Taylor <iant@google.com> writes:
>
> Ian> This is a bug in C++ code in libjava.
>
> Thanks. We enabled -fwrapv for the interpreter but, I think, thought
> that perhaps the other C++ code was safe.
> Would the new warning have caught this?
Yes. With -Wstrict-overflow:
../../../trunk/libjava/java/lang/natString.cc: In function ‘jint _Jv_FormatInt(jchar*, jint)’:
../../../trunk/libjava/java/lang/natString.cc:375: warning: assuming signed overflow does not occur when simplifying conditional to constant
It also warns about this sort of code which occurs a few times in that
file:
if (offset < 0 || count < 0 || offset + count < 0
|| offset + count > data_size)
Since if offset < 0 and count < 0, then VRP can assume that offset +
count < 0 is always true. If you want to code to correctly check for
signed overflow of offset + count, you will need to instead write
something along the lines of INT_MAX - offset <= count.
Ian
More information about the Gcc-patches
mailing list