From d3a7ef9aacb50cbcd85a34966da10304f048a576 Mon Sep 17 00:00:00 2001 From: Falk Hueffner Date: Thu, 20 May 2004 01:43:20 +0200 Subject: [PATCH] re PR other/15526 (-ftrapv aborts on 0 * (-1)) PR other/15526 * libgcc2.c (__mulvsi3): Fix overflow test. * gcc.dg/ftrapv-1.c: New test case. From-SVN: r82042 --- gcc/ChangeLog | 5 +++++ gcc/libgcc2.c | 4 +--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/ftrapv-1.c | 25 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ftrapv-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 54e328a560e..6cc921fc091 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-05-20 Falk Hueffner + + PR other/15526 + * libgcc2.c (__mulvsi3): Fix overflow test. + 2004-05-19 Andrew Pinski PR c/14171 diff --git a/gcc/libgcc2.c b/gcc/libgcc2.c index 34171ad9002..8a953ea8b76 100644 --- a/gcc/libgcc2.c +++ b/gcc/libgcc2.c @@ -130,9 +130,7 @@ __mulvsi3 (Wtype a, Wtype b) { const DWtype w = (DWtype) a * (DWtype) b; - if (((a >= 0) == (b >= 0)) - ? (UDWtype) w > (UDWtype) (((DWtype) 1 << (WORD_SIZE - 1)) - 1) - : (UDWtype) w < (UDWtype) ((DWtype) -1 << (WORD_SIZE - 1))) + if ((Wtype) (w >> WORD_SIZE) != (Wtype) w >> (WORD_SIZE - 1)) abort (); return w; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 92437ffdcc2..c716a323162 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-05-20 Falk Hueffner + + PR other/15526 + * gcc.dg/ftrapv-1.c: New test case. + 2004-05-18 Feng Wang * gfortran.fortran-torture/execute/power.f90: Test constant integers. diff --git a/gcc/testsuite/gcc.dg/ftrapv-1.c b/gcc/testsuite/gcc.dg/ftrapv-1.c new file mode 100644 index 00000000000..44eb176b50d --- /dev/null +++ b/gcc/testsuite/gcc.dg/ftrapv-1.c @@ -0,0 +1,25 @@ +/* Copyright (C) 2004 Free Software Foundation. + + PR other/15526 + Verify correct overflow checking with -ftrapv. + + Written by Falk Hueffner, 20th May 2004. */ + +/* { dg-do run } */ +/* { dg-options "-ftrapv" } */ + +__attribute__((noinline)) int +mulv(int a, int b) +{ + return a * b; +} + +int +main() +{ + mulv( 0, 0); + mulv( 0, -1); + mulv(-1, 0); + mulv(-1, -1); + return 0; +} -- 2.30.2