15526 – [3.4 Regression] -ftrapv aborts on 0 * (-1) (original) (raw)

Description Erik Schnetter 2004-05-18 20:43:37 UTC

My version of gcc

$ ~/gcc/bin/gcc --version gcc (GCC) 3.5.0 20040517 (experimental)

produces code that aborts when it encounters the expression "0 * (-1)" when compiled with -ftrapv. The failing programme is

int test (int a) { return a * (a-1); }

int main (int argc, char ** argv) { test (0); return 0; }

which I compile with

$ ~/gcc/bin/gcc -o mul-trapv mul-trapv.c -ftrapv

Comment 1 Falk Hueffner 2004-05-18 21:13:22 UTC

Can't reproduce on alphaev68-linux 3.5.0 20040513. Probably platform specific.

Comment 2 Drea Pinski 2004-05-18 21:33:12 UTC

Confirmed this caused by the following patch: 2003-06-30 Bruno Haible <bruno@clisp.org>

    [PR middle-end/6578](show%5Fbug.cgi?id=6578 "RESOLVED FIXED - -ftrapv doesn't catch multiplication overflow")
    * libgcc2.c (__subvsi3): Remove simplification that would not work
    when subtracting -0x80000000.
    (__subvdi3): Remove simplification that would return a wrong result.
    (__mulvsi3): Fix overflow check.
    (__absvdi2): Fix simplification that would return a wrong result.
    (__mulvdi3): Fix overflow check.

Comment 3 Falk Hueffner 2004-05-18 22:24:36 UTC

This should fix it (but I don't have the proper platform to test it):

diff -u -p -r1.170 libgcc2.c --- libgcc2.c 14 Nov 2003 02:23:13 -0000 1.170 +++ libgcc2.c 18 May 2004 22:21:45 -0000 @@ -130,9 +130,7 @@ __mulvsi3 (Wtype a, Wtype b) { const DWtype w = (DWtype) a * (DWtype) b;

Comment 4 Bruno Haible 2004-05-19 12:24:58 UTC

Yes, Falk Hueffner's patch will fix it. Sorry for the bug: during my testing of the patch I tried various arguments but not multiplying with 0 :-(

Comment 6 Falk Hueffner 2004-05-19 23:45:53 UTC

Fixed.

Comment 7 Drea Pinski 2004-09-25 16:31:50 UTC

Reopening because this is not fixed for 3.4.x, only in 4.0.0.

Comment 9 Drea Pinski 2004-09-26 20:49:27 UTC

Fixed.