public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/52478] New: -ftrapv calls the wrong functions in libgcc
@ 2012-03-04 12:59 burnus at gcc dot gnu.org
  2012-03-05 10:19 ` [Bug middle-end/52478] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-03-04 12:59 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52478
           Summary: -ftrapv calls the wrong functions in libgcc
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


As PR 19020 has been closed ("let's ditch antiquated stuff and start afresh") -
open a fresh bug.


Using -ftrapv works with i368-gnu-linux:

$ gcc -m32 -ftrapv hjfff.c && ./a.out
Aborted (core dumped)
$

But not on x86-64-gnu-linux:
$ gcc -m64 -ftrapv hjfff.c && ./a.out
$


In the debugger, one sees:

a) i386:

__addvsi3 (a=2147483647, b=1) at
/home/tob/projects/gcc-trunk-checkout/libgcc/libgcc2.c:79
(gdb) pt a
type = int


b) x86-64:

(gdb)
__addvdi3 (a=2147483647, b=1) at
/home/tob/projects/gcc-trunk-checkout/libgcc/libgcc2.c:82
(gdb) pt a
type = long int

Thus, there is no overflow in that function.


THUS: On i386 it calls the correct function but on x86-64 it should call the SI
not the DI function.

 * * *

For long/LONG_MAX, one has again:

a) -m32

__addvsi3 (a=2147483647, b=1) at
/home/tob/projects/gcc-trunk-checkout/libgcc/libgcc2.c:79
79      {
(gdb) pt a
type = int

b) -m64

__addvdi3 (a=9223372036854775807, b=1) at
/home/tob/projects/gcc-trunk-checkout/libgcc/libgcc2.c:82
82        if (b >= 0 ? w < a : w > a)
(gdb) pt a
type = long int


THUS: x86-64 calls correctly the DI function but i386 wrongly the SI function

 * * *

long long / LLONG_MAX:

a) -m32:

__addvdi3 (a=9223372036854775807, b=1) at
/home/tob/projects/gcc-trunk-checkout/libgcc/libgcc2.c:82
82        if (b >= 0 ? w < a : w > a)
(gdb) pt a
type = long int

b) -m64

__addvdi3 (a=9223372036854775807, b=1) at
/home/tob/projects/gcc-trunk-checkout/libgcc/libgcc2.c:82
82        if (b >= 0 ? w < a : w > a)
(gdb) pt a  
type = long int


THUS: Both x86-64 and i386 call the "long int" instead of the "long long"
function. I had exepected a TI version, which does not seem to exist.

 * * *


#include <limits.h>

int __attribute__((noinline))
iaddv (int a, int b)
{
  return a + b;
}

int main(void)
{
  return iaddv (INT_MAX, 1);
}


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-07-29 11:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-04 12:59 [Bug middle-end/52478] New: -ftrapv calls the wrong functions in libgcc burnus at gcc dot gnu.org
2012-03-05 10:19 ` [Bug middle-end/52478] " rguenth at gcc dot gnu.org
2012-03-05 10:43 ` burnus at gcc dot gnu.org
2012-03-05 12:02 ` rguenth at gcc dot gnu.org
2012-10-07 19:15 ` pinskia at gcc dot gnu.org
2014-07-24  9:17 ` rguenth at gcc dot gnu.org
2014-07-28  8:48 ` rguenth at gcc dot gnu.org
2014-07-28  9:06 ` rguenth at gcc dot gnu.org
2014-07-29 11:11 ` rguenth at gcc dot gnu.org

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).