This is the mail archive of the gcc@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]

Re: libjava Divide_1 and pr6388 fail on 4.2.0 RC3 for several targets


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


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