Bug 29439 - [4.2 regression] ICE in fold-const.c:1385 with -O1 -fwrapv -ftree-vrp
Summary: [4.2 regression] ICE in fold-const.c:1385 with -O1 -fwrapv -ftree-vrp
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.2.0
: P5 normal
Target Milestone: 4.2.0
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2006-10-12 13:00 UTC by Pawel Sikora
Modified: 2006-11-13 14:46 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.2
Known to fail: 4.2.0
Last reconfirmed: 2006-10-15 18:39:21


Attachments
reduced testcase (112 bytes, text/x-adasrc)
2006-10-15 18:02 UTC, Pawel Sikora
Details
reduced testcase (227 bytes, text/x-adasrc)
2006-10-15 18:02 UTC, Pawel Sikora
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Sikora 2006-10-12 13:00:23 UTC
after closing the PR28230 the bootstrap ICEs on ada.

(...)
/home/users/pluto/rpm/BUILD/trunk/builddir/./gcc/xgcc -B/home/users/pluto/rpm/BUILD/trunk/builddir/./gcc/ -B/usr/x86_64-pld-linux/bin/ -B/usr/x86_64-pld-linux/lib/ -isystem /usr/x86_64-pld-linux/include -isystem /usr/x86_64-pld-linux/sys-include -c -O2 -fwrapv -march=x86-64 -gdwarf-2 -g2  -fPIC      -W -Wall -gnatpg  a-stwifi.adb -o a-stwifi.o
+===========================GNAT BUG DETECTED==============================+
| 4.2.0 20061012 (experimental) (PLD-Linux) (x86_64-pld-linux-gnu) GCC error:|
| tree check: expected integer_cst, have var_decl in int_const_binop,      |
|    at fold-const.c:1385                                                  |
| Error detected at a-stwifi.adb:677:1
Comment 1 Richard Biener 2006-10-12 14:30:01 UTC
I had ada included in the set of languages for the bootstrap & regtest for PR28230.  So you need to find another one ;)

Or are you complaining about the next failure with a -fwrapv bootstrap?
Comment 2 Pawel Sikora 2006-10-12 14:38:12 UTC
(In reply to comment #1)
> I had ada included in the set of languages for the bootstrap & regtest for
> PR28230.  So you need to find another one ;)

try to bootstrap C+ADA with CFLAGS='-O2 -fwrapv' ;)

> Or are you complaining about the next failure with a -fwrapv bootstrap?

exactly.
Comment 3 Pawel Sikora 2006-10-12 19:45:53 UTC
cwd: ada/rts:
$ ../../gnat1 -quiet -dumpbase a-stwifi.adb -O1 -fwrapv -ftree-vrp \
              -gnatpg a-stwifi.adb -o a-stwifi.s

(gdb) bt
#0  int_const_binop (code=PLUS_EXPR, arg1=0x2b8302f027b0, arg2=0x2b8302f02810,
                     notrunc=0) at ../../gcc/fold-const.c:1385
#1  0x000000000077c1e0 in round_up (value=0x2b8302f027b0, divisor=8)
                          at ../../gcc/fold-const.c:12841
#2  0x000000000090a7ea in finalize_type_size (type=0x2b8302f0f160)
                          at ../../gcc/stor-layout.c:1431
#3  0x000000000090e2a4 in layout_type (type=0x2b8302f0f160)
                          at ../../gcc/stor-layout.c:1861
#4  0x000000000090ee38 in make_signed_type (precision=<value optimized out>)
                          at ../../gcc/stor-layout.c:1881
#5  0x000000000092433e in build_common_tree_nodes (signed_char=1 '\001',
                          signed_sizetype=<value optimized out>)
                          at ../../gcc/tree.c:6460
#6  0x0000000000423e00 in gnat_init_decl_processing ()
                          at ../../gcc/ada/utils.c:405
#7  0x000000000041bc9e in gnat_init () at ../../gcc/ada/misc.c:421
#8  0x0000000000912d1a in toplev_main (argc=<value optimized out>,
                          argv=<value optimized out>)
                          at ../../gcc/toplev.c:1900
#9  0x00002b8302cf0134 in __libc_start_main () from /lib64/libc.so.6
#10 0x00000000004030e9 in _start ()

(gdb) c debug_tree(arg1)
 <integer_cst 0x2b3a2e1c47b0 type <integer_type 0x2b3a2e1d10b0>
    constant invariant 8>
Value can't be converted to integer.

(gdb) c debug_tree(arg2)
 <integer_cst 0x2b3a2e1c4810 type <integer_type 0x2b3a2e1d10b0>
    constant invariant 7>
Comment 4 Pawel Sikora 2006-10-15 18:02:24 UTC
Created attachment 12440 [details]
reduced testcase
Comment 5 Pawel Sikora 2006-10-15 18:02:40 UTC
Created attachment 12441 [details]
reduced testcase
Comment 6 Andrew Pinski 2006-10-15 18:35:01 UTC
This worked in 4.2.0 20061002 but failed in 4.2.0 20061014
Comment 7 Andrew Pinski 2006-10-15 18:39:20 UTC
Here is the backtrace which I get:
#0  internal_error (gmsgid=0x8b072fc "tree check: %s, have %s in %s, at %s:%d")
    at /src/gcc/local/gcc/gcc/diagnostic.c:586
#1  0x08798869 in tree_check_failed (node=Could not find the frame base for "tree_check_failed".
) at /src/gcc/local/gcc/gcc/tree.c:6161
#2  0x08519d50 in int_const_binop (code=TRUNC_DIV_EXPR, arg1=0x76ef20, arg2=0x7b4300, notrunc=0)
    at /src/gcc/local/gcc/gcc/fold-const.c:1385
#3  0x087d60cb in vrp_int_const_binop (code=MULT_EXPR, val1=0x7b4300, val2=0x7b42d0)
    at /src/gcc/local/gcc/gcc/tree-vrp.c:1181
#4  0x087d5931 in extract_range_from_binary_expr (vr=0xbffd1210, expr=0x7b3e7c)
    at /src/gcc/local/gcc/gcc/tree-vrp.c:1472
#5  0x087d7875 in extract_range_from_expr (vr=0xbffd1210, expr=0x7b3e7c) at /src/gcc/local/gcc/gcc/tree-vrp.c:1903
#6  0x087de4b8 in vrp_visit_assignment (stmt=0x7c12f4, output_p=0xbffd1378) at /src/gcc/local/gcc/gcc/tree-vrp.c:3397
#7  0x087dff88 in vrp_visit_stmt (stmt=0x7c12f4, taken_edge_p=0xbffd137c, output_p=0xbffd1378)
    at /src/gcc/local/gcc/gcc/tree-vrp.c:3812

1172          /* Checking for multiplication overflow is done by dividing the
1173             output of the multiplication by the first input of the
1174             multiplication.  If the result of that division operation is
1175             not equal to the second input of the multiplication, then the
(gdb) l
1176             multiplication overflowed.  */
1177          else if (code == MULT_EXPR && !integer_zerop (val1))
1178            {
1179              tree tmp = int_const_binop (TRUNC_DIV_EXPR,
1180                                          TYPE_MAX_VALUE (TREE_TYPE (val1)),
1181                                          val1, 0);
1182              int check = compare_values (tmp, val2);

YPE_MAX_VALUE (TREE_TYPE (val1)) is a DECL right here so we fail because of that.

Comment 8 Andrew Pinski 2006-10-15 18:56:43 UTC
The call int_const_binop to seems to be wrong, if the comment is correct the following is more correct:
	  tree tmp = int_const_binop (TRUNC_DIV_EXPR,
				      res,
				      val1, 0);

Comment 9 Mark Mitchell 2006-10-15 21:27:30 UTC
Is there a C/C++ equivalent?
Comment 10 Andrew Pinski 2006-10-15 21:30:38 UTC
(In reply to comment #9)
> Is there a C/C++ equivalent?
No because it depends on non constant subtypes.
But that does not mean we could get the wrong answer from VRP because overflow is incorrectly set.
Comment 11 Andrew Pinski 2006-10-16 00:15:26 UTC
Mine.
Comment 12 Mark Mitchell 2006-10-17 07:35:27 UTC
Until we can demonstrate a C/C++ failure: P5.
Comment 13 Pawel Sikora 2006-10-18 09:34:36 UTC
(In reply to comment #8)
> The call int_const_binop to seems to be wrong, if the comment is correct the
> following is more correct:
>           tree tmp = int_const_binop (TRUNC_DIV_EXPR,
>                                       res,
>                                       val1, 0);
> 

with -fwrapv + this change, the a-stwifi.adb compiles,
but other failure occurs later:

a-stwiun.adb:34:06: warning: cannot depend on "Wide_Fixed" (wrong categorization)
a-stwiun.adb:34:06: warning: preelaborated unit cannot depend on non-preelaborated unit
a-stwiun.adb:34:17: warning: no entities of "Wide_Fixed" are referenced
a-stwiun.adb:450:22: "Delete" not declared in "Wide_Fixed"
a-stwiun.adb:555:20: "Head" not declared in "Wide_Fixed"
a-stwiun.adb:567:22: "Head" not declared in "Wide_Fixed"
a-stwiun.adb:695:22: "Insert" not declared in "Wide_Fixed"
a-stwiun.adb:740:22: "Overwrite" not declared in "Wide_Fixed"
a-stwiun.adb:758:26: "Overwrite" not declared in "Wide_Fixed"
a-stwiun.adb:840:20: "Replace_Slice" not declared in "Wide_Fixed"
a-stwiun.adb:853:20: "Replace_Slice" not declared in "Wide_Fixed"
a-stwiun.adb:902:20: "Tail" not declared in "Wide_Fixed"
a-stwiun.adb:913:20: "Tail" not declared in "Wide_Fixed"
a-stwiun.adb:968:22: "Translate" not declared in "Wide_Fixed"
a-stwiun.adb:977:17: "Translate" not declared in "Wide_Fixed"
a-stwiun.adb:988:22: "Translate" not declared in "Wide_Fixed"
a-stwiun.adb:997:17: "Translate" not declared in "Wide_Fixed"
a-stwiun.adb:1011:22: "Trim" not declared in "Wide_Fixed"
a-stwiun.adb:1022:22: "Trim" not declared in "Wide_Fixed"
a-stwiun.adb:1036:22: "Trim" not declared in "Wide_Fixed"
a-stwiun.adb:1049:22: "Trim" not declared in "Wide_Fixed"
make[7]: *** [a-stwiun.o] Error 1

without this change and without -fwrapv bootstrap passes.
Comment 14 Richard Biener 2006-10-18 10:00:06 UTC
Well, this looks like a miscompilation somewhere then.
Comment 15 Andrew Pinski 2006-11-06 23:25:32 UTC
Subject: Bug 29439

Author: pinskia
Date: Mon Nov  6 23:25:19 2006
New Revision: 118530

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118530
Log:
2006-11-06  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR tree-opt/29439
        * tree-vrp.c (vrp_int_const_binop): Use the correct tree when
        checking for overflow.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-vrp.c

Comment 16 Andrew Pinski 2006-11-06 23:25:44 UTC
Fixed on the mainline, will fix later on the 4.2 branch.
Comment 17 Andrew Pinski 2006-11-12 01:57:12 UTC
I am testing the fix for the 4.2 branch right now.
Comment 18 Andrew Pinski 2006-11-13 14:46:15 UTC
Subject: Bug 29439

Author: pinskia
Date: Mon Nov 13 14:46:05 2006
New Revision: 118763

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118763
Log:
2006-11-13  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR tree-opt/29439
        * tree-vrp.c (vrp_int_const_binop): Use the correct tree when
        checking for overflow.



Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/tree-vrp.c

Comment 19 Andrew Pinski 2006-11-13 14:46:37 UTC
Fixed.