Bug 49235 - [4.7 Regression] ICE: in int_mode_for_mode, at stor-layout.c:424 with -O -fno-delete-null-pointer-checks -fno-tree-scev-cprop -ftree-vectorize -fno-vect-cost-model
Summary: [4.7 Regression] ICE: in int_mode_for_mode, at stor-layout.c:424 with -O -fno...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Jakub Jelinek
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 48702
  Show dependency treegraph
 
Reported: 2011-05-30 18:33 UTC by Zdenek Sojka
Modified: 2016-03-24 17:20 UTC (History)
1 user (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build:
Known to work: 4.6.1
Known to fail: 4.7.0
Last reconfirmed: 2011-05-31 06:40:33


Attachments
reduced testcase (the same as gcc.c-torture/compile/pr36817.c) (78 bytes, text/plain)
2011-05-30 18:33 UTC, Zdenek Sojka
Details
gcc47-pr49235.patch (687 bytes, patch)
2011-05-31 07:46 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2011-05-30 18:33:08 UTC
Created attachment 24398 [details]
reduced testcase (the same as gcc.c-torture/compile/pr36817.c)

Compiler output:
$ gcc -O -fno-delete-null-pointer-checks -fno-tree-scev-cprop -ftree-vectorize -fno-vect-cost-model testcase.c 
testcase.c: In function 'foo':
testcase.c:9:10: internal compiler error: in int_mode_for_mode, at stor-layout.c:424
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

(gdb) bt
#0  fancy_abort (file=0x11c8af0 "/mnt/svn/gcc-trunk/gcc/stor-layout.c", line=424, function=0x11c8ee0 "int_mode_for_mode")
    at /mnt/svn/gcc-trunk/gcc/diagnostic.c:892
#1  0x0000000000939533 in int_mode_for_mode (mode=Unhandled dwarf expression opcode 0xf3
) at /mnt/svn/gcc-trunk/gcc/stor-layout.c:424
#2  0x00000000006bdae2 in emit_move_via_integer (mode=VOIDmode, x=0x7ffff5c345e0, y=0x7ffff7ecc470, force=0 '\000')
    at /mnt/svn/gcc-trunk/gcc/expr.c:2921
#3  0x00000000006cb8ea in emit_move_insn_1 (x=0x7ffff5c345e0, y=0x7ffff7ecc470) at /mnt/svn/gcc-trunk/gcc/expr.c:3296
#4  0x00000000006cbc53 in emit_move_insn (x=0x7ffff5c345e0, y=0x7ffff7ecc470) at /mnt/svn/gcc-trunk/gcc/expr.c:3359
#5  0x00000000006ad0bb in copy_to_reg (x=0x7ffff7ecc470) at /mnt/svn/gcc-trunk/gcc/explow.c:608
#6  0x00000000006ae10f in memory_address_addr_space (mode=V4SImode, x=0x7ffff5c36438, as=0 '\000') at /mnt/svn/gcc-trunk/gcc/explow.c:480
#7  0x00000000006c49f1 in expand_expr_real_1 (exp=0x7ffff5c319d8, target=0x0, tmode=VOIDmode, modifier=EXPAND_WRITE, alt_rtl=0x0)
    at /mnt/svn/gcc-trunk/gcc/expr.c:8690
#8  0x00000000006d9cf8 in expand_expr (to=0x7ffff5c319d8, from=0x7ffff5c1fcd8, nontemporal=0 '\000') at /mnt/svn/gcc-trunk/gcc/expr.h:419
#9  expand_assignment (to=0x7ffff5c319d8, from=0x7ffff5c1fcd8, nontemporal=0 '\000') at /mnt/svn/gcc-trunk/gcc/expr.c:4406
#10 expand_assignment (to=0x7ffff5c319d8, from=0x7ffff5c1fcd8, nontemporal=0 '\000') at /mnt/svn/gcc-trunk/gcc/expr.c:4106
#11 0x00000000005e6ce6 in expand_gimple_stmt_1 (stmt=0x7ffff5c37910) at /mnt/svn/gcc-trunk/gcc/cfgexpand.c:1953
#12 expand_gimple_stmt (stmt=0x7ffff5c37910) at /mnt/svn/gcc-trunk/gcc/cfgexpand.c:2050
#13 0x00000000005e86ba in expand_gimple_basic_block (bb=0x7ffff5bb41a0) at /mnt/svn/gcc-trunk/gcc/cfgexpand.c:3633
#14 0x00000000005eec67 in gimple_expand_cfg () at /mnt/svn/gcc-trunk/gcc/cfgexpand.c:4116
#15 0x000000000085e876 in execute_one_pass (pass=0x16adae0) at /mnt/svn/gcc-trunk/gcc/passes.c:1876
#16 0x000000000085eb65 in execute_pass_list (pass=0x16adae0) at /mnt/svn/gcc-trunk/gcc/passes.c:1930
#17 0x00000000009b398d in tree_rest_of_compilation (fndecl=0x7ffff5bcf000) at /mnt/svn/gcc-trunk/gcc/tree-optimize.c:417
#18 0x0000000000614cf5 in cgraph_expand_function (node=0x7ffff5bd4000) at /mnt/svn/gcc-trunk/gcc/cgraphunit.c:1630
#19 0x000000000061697c in cgraph_expand_all_functions () at /mnt/svn/gcc-trunk/gcc/cgraphunit.c:1689
#20 cgraph_optimize () at /mnt/svn/gcc-trunk/gcc/cgraphunit.c:1952
#21 0x0000000000616faa in cgraph_finalize_compilation_unit () at /mnt/svn/gcc-trunk/gcc/cgraphunit.c:1126
#22 0x00000000004fe148 in c_write_global_declarations () at /mnt/svn/gcc-trunk/gcc/c-decl.c:9844
#23 0x0000000000948a74 in compile_file (argc=17, argv=0x7fffffffdb88) at /mnt/svn/gcc-trunk/gcc/toplev.c:586
#24 do_compile (argc=17, argv=0x7fffffffdb88) at /mnt/svn/gcc-trunk/gcc/toplev.c:1923
#25 toplev_main (argc=17, argv=0x7fffffffdb88) at /mnt/svn/gcc-trunk/gcc/toplev.c:1995
#26 0x00007ffff6477cec in __libc_start_main () from /lib64/libc.so.6
#27 0x00000000004e22ed in _start ()

Tested revisions:
r174424 - crash
4.6 r173059 - OK
Comment 1 Jakub Jelinek 2011-05-31 06:40:33 UTC
Confirmed, TARGET_MEM_REF expansion needs fixing.
This started with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174282
Comment 2 Jakub Jelinek 2011-05-31 07:46:22 UTC
Created attachment 24401 [details]
gcc47-pr49235.patch

Untested fix.  base might be const0_rtx (seems other constants are moved into
offset and base stays const0_rtx), and if there is also offset and nothing else,
we end up with (plus:DI (const_int 0) (const_int 16)) and similar.
Comment 3 Richard Biener 2011-05-31 09:23:53 UTC
Need to make sure to also backport this then.
Comment 4 Richard Biener 2011-05-31 09:26:59 UTC
(In reply to comment #2)
> Created attachment 24401 [details]
> gcc47-pr49235.patch
> 
> Untested fix.  base might be const0_rtx (seems other constants are moved into
> offset and base stays const0_rtx), and if there is also offset and nothing
> else,
> we end up with (plus:DI (const_int 0) (const_int 16)) and similar.

Yes, base has to be of pointer type.  But I thought get_address_description
would "untangle" this again ... if not it's probably latent pre-MEM_REF
as well.
Comment 5 Jakub Jelinek 2011-05-31 09:34:04 UTC
get_address_description only does that if TMR_INDEX2 is present:
      addr->symbol = NULL_TREE;
      if (TMR_INDEX2 (op))
        {
          gcc_assert (integer_zerop (TMR_BASE (op)));
          addr->base = TMR_INDEX2 (op);
        }
      else
        addr->base = TMR_BASE (op);

In this case TMR_BASE (op) is (void *) 0 and TMR_OFFSET is INTEGER_CST, the rest is all NULL.
Comment 6 Richard Biener 2011-05-31 09:44:55 UTC
Index: gcc/tree-ssa-address.c
===================================================================
--- gcc/tree-ssa-address.c      (revision 174469)
+++ gcc/tree-ssa-address.c      (working copy)
@@ -365,7 +365,7 @@ create_mem_ref_raw (tree type, tree alia
      ???  As IVOPTs does not follow restrictions to where the base
      pointer may point to create a MEM_REF only if we know that
      base is valid.  */
-  if (TREE_CODE (base) == ADDR_EXPR
+  if ((TREE_CODE (base) == ADDR_EXPR || TREE_CODE (base) == INTEGER_CST)
       && (!index2 || integer_zerop (index2))
       && (!addr->index || integer_zerop (addr->index)))
     return fold_build2 (MEM_REF, type, base, addr->offset);

might hide the issue again (still worth fixing IMHO), and also makes
sense.
Comment 7 Jakub Jelinek 2011-05-31 12:34:45 UTC
Author: jakub
Date: Tue May 31 12:34:42 2011
New Revision: 174478

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174478
Log:
	PR rtl-optimization/49235
	* tree-ssa-address.c (gen_addr_rtx): Ignore base if it is const0_rtx.
	(create_mem_ref_raw): Create MEM_REF even if base is INTEGER_CST.

	* gcc.dg/pr49235.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr49235.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-address.c
Comment 8 Jakub Jelinek 2011-05-31 12:39:55 UTC
Fixed.
Comment 9 Richard Biener 2011-06-06 10:13:27 UTC
Author: rguenth
Date: Mon Jun  6 10:13:23 2011
New Revision: 174688

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174688
Log:
2011-06-06  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/48702
	* tree-ssa-address.c (create_mem_ref_raw): Create MEM_REFs
	only when we know the base address is within bounds.
	* tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Do not
	assume the base address of TARGET_MEM_REFs is in bounds.
	(indirect_refs_may_alias_p): Fix TARGET_MEM_REF without index tests.

	* gcc.dg/torture/pr48702.c: New testcase.

	Backport from mainline
	2011-05-31  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/49235
	* tree-ssa-address.c (gen_addr_rtx): Ignore base if it is const0_rtx.
	(create_mem_ref_raw): Create MEM_REF even if base is INTEGER_CST.

	* gcc.dg/pr49235.c: New test.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/pr49235.c
    branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/torture/pr48702.c
Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_6-branch/gcc/tree-ssa-address.c
    branches/gcc-4_6-branch/gcc/tree-ssa-alias.c