Bug 28915 - [4.1 regression] ICE: tree check: expected class 'constant', have 'declaration' (var_decl) in build_vector, at tree.c:973
Summary: [4.1 regression] ICE: tree check: expected class 'constant', have 'declaratio...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P1 normal
Target Milestone: 4.1.2
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks: 30222
  Show dependency treegraph
 
Reported: 2006-08-31 12:23 UTC by Martin Michlmayr
Modified: 2006-11-14 09:29 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.0.0 4.2.0 4.3.0
Known to fail: 4.1.0
Last reconfirmed: 2006-09-10 00:48:18


Attachments
test case (190 bytes, text/plain)
2006-08-31 12:30 UTC, Martin Michlmayr
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Michlmayr 2006-08-31 12:23:54 UTC
ICE/tree check with ftree-vectorize -O2:

(sid)44:tbm@usurper: ~] x86_64-unknown-linux-gnu-gcc -ftree-vectorize -O2 -c xskat-xdial.c
xskat-xdial.c: In function 'di_eigenertisch':
xskat-xdial.c:9694: internal compiler error: tree check: expected class 'constant', have 'declaration' (var_decl) in build_vector, at tree.c:973
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
zsh: exit 1     x86_64-unknown-linux-gnu-gcc -ftree-vectorize -O2 -c xskat-xdial.c
(sid)45:tbm@usurper: ~] x86_64-unknown-linux-gnu-gcc -ftree-vectorize -O1 -c xskat-xdial.c
(sid)46:tbm@usurper: ~] x86_64-unknown-linux-gnu-gcc -O3 -c xskat-xdial.c
(sid)47:tbm@usurper: ~]
Comment 1 Martin Michlmayr 2006-08-31 12:30:34 UTC
Created attachment 12160 [details]
test case

Testcase from application "xskat".
Comment 2 Andrew Pinski 2006-08-31 16:13:13 UTC
I cannot reproduce this on either a powerpc64-linux-gnu build or a i686-linux-gnu build.
Comment 3 Uroš Bizjak 2006-08-31 19:15:44 UTC
Confirmed on x86_64.

Backtrace:

(gdb) bt
#0  build_vector (type=0x2aaaadb3e6e0, vals=0x2aaaadb37cc0) at ../../gcc-svn/trunk/gcc/tree.c:973
#1  0x00000000007b829d in force_const_mem (mode=V2DImode, x=0x2aaaada089e0) at ../../gcc-svn/trunk/gcc/varasm.c:3229
#2  0x00000000005d496a in emit_move_insn (x=0x2aaaadb309a0, y=0x2aaaada089e0) at ../../gcc-svn/trunk/gcc/expr.c:3288
#3  0x00000000006b2ec6 in gen_vec_initv2di (operand0=0x2aaaadb309a0, operand1=0x2aaaada089d0) at ../../gcc-svn/trunk/gcc/config/i386/sse.md:3678
#4  0x00000000005c9e37 in store_constructor (exp=0x2aaaadb37900, target=0x2aaaadb309a0, cleared=0, size=16) at ../../gcc-svn/trunk/gcc/expr.c:5431
#5  0x00000000005ce327 in expand_expr_real_1 (exp=0x2aaaadb37900, target=0x2aaaadb309a0, tmode=V2DImode, modifier=EXPAND_NORMAL, alt_rtl=0x7fffffcf5800) at ../../gcc-svn/trunk/gcc/expr.c:7142
#6  0x00000000005d40cf in expand_expr_real (exp=0x2aaaadb37900, target=0x2aaaadb309a0, tmode=V2DImode, modifier=EXPAND_NORMAL, alt_rtl=0x7fffffcf5800) at ../../gcc-svn/trunk/gcc/expr.c:6706
#7  0x00000000005c7264 in store_expr (exp=0x2aaaadb37900, target=0x2aaaadb309a0, call_param_p=0) at ../../gcc-svn/trunk/gcc/expr.c:4370
#8  0x00000000005c8397 in expand_assignment (to=0x2aaaadb3e0b0, from=0x2aaaadb37900) at ../../gcc-svn/trunk/gcc/expr.c:4249
#9  0x00000000005cc403 in expand_expr_real_1 (exp=0x2aaaadb3c140, target=0x0, tmode=VOIDmode, modifier=EXPAND_NORMAL, alt_rtl=0x0) at ../../gcc-svn/trunk/gcc/expr.c:8603
#10 0x00000000005d40cf in expand_expr_real (exp=0x2aaaadb3c140, target=0x2aaaad956400, tmode=VOIDmode, modifier=EXPAND_NORMAL, alt_rtl=0x0) at ../../gcc-svn/trunk/gcc/expr.c:6706

At the point of ICE, value dumps to:

<var_decl 0x2aaaadb3ea50 D.1935
    type <vector_type 0x2aaaadb3e6e0
        type <integer_type 0x2aaaad961630 long int public DI
            size <integer_cst 0x2aaaad951db0 constant invariant 64>
            unit size <integer_cst 0x2aaaad951de0 constant invariant 8>
            align 64 symtab 0 alias set -1 precision 64 min <integer_cst 0x2aaaad951d20 -9223372036854775808> max <integer_cst 0x2aaaad951d50 9223372036854775807>
            pointer_to_this <pointer_type 0x2aaaad974a50>>
        V2DI
        size <integer_cst 0x2aaaad96c0f0 constant invariant 128>
        unit size <integer_cst 0x2aaaad96c120 constant invariant 16>
        align 128 symtab 0 alias set -1 nunits 2>
    V2DI file xskat-xdial.c line 16 size <integer_cst 0x2aaaad96c0f0 128> unit size <integer_cst 0x2aaaad96c120 16>
    align 128
    (const:DI (plus:DI (symbol_ref:DI ("lanip") [flags 0x40] <var_decl 0x2aaaadb1cbb0 lanip>)
        (const_int 40 [0x28])))>
Comment 4 Andrew Pinski 2006-08-31 19:21:14 UTC
Can someone add the dump of -fdump-tree-final_cleanup ?
Comment 5 Martin Michlmayr 2006-08-31 19:28:33 UTC
(In reply to comment #4)
> Can someone add the dump of -fdump-tree-final_cleanup ?


;; Function set_names (set_names)

set_names (ob, idx)
{
  char * * vect_ptt1.38;
  vector char * vect_cst_.34;
  static struct tx_typ tt1;

<bb 2>:
  vect_cst_.34 = {&lanip[1][0], &lanip[1][0]};
  vect_ptt1.38 = &tt1;
  *(vector char * *) vect_ptt1.38 = vect_cst_.34;
  return;

}
Comment 6 Andrew Pinski 2006-09-01 06:27:12 UTC
Here is a testcase which ICEs for i686-linux-gnu with -msse:
extern char lanip[3][40];
typedef struct
{
  char *t[4];
}tx_typ;
int set_names (void)
{
  static tx_typ tt1;
  int ln;
  for (ln = 0; ln < 4; ln++)
      tt1.t[ln] = lanip[1];
}

Comment 7 Andrew Pinski 2006-09-04 17:07:14 UTC
Once my current builds are finished, I will look into fixing this.
Comment 8 Andrew Pinski 2006-09-05 04:19:53 UTC
I have a fix for this, it needed a couple of different fixes.
Comment 9 Andrew Pinski 2006-09-06 06:30:12 UTC
And here is a testcase which is reproducible without the vectorizer:
int t[4];

__attribute__((vector_size(16))) int f(void)
{
__attribute__((vector_size(16))) int t1 = {(int)&t[0], (int)&t[1], (int)&t[2], (int)&t[3]};
  return t1;
}
--------------------
That testcase above shows more problems than I actually want to touch right now.

Here was my fix for the x86 crash (but it does not fix the powerpc-linux with -maltivec crash):
Index: tree.c
===================================================================
--- tree.c      (revision 116689)
+++ tree.c      (working copy)
@@ -969,9 +969,11 @@ build_vector (tree type, tree vals)
   for (link = vals; link; link = TREE_CHAIN (link))
     {
       tree value = TREE_VALUE (link);
-
-      over1 |= TREE_OVERFLOW (value);
-      over2 |= TREE_CONSTANT_OVERFLOW (value);
+      if (CONSTANT_CLASS_P (value))
+       {
+         over1 |= TREE_OVERFLOW (value);
+         over2 |= TREE_CONSTANT_OVERFLOW (value);
+       }
     }

   TREE_OVERFLOW (v) = over1;
Index: expmed.c
===================================================================
--- expmed.c    (revision 116689)
+++ expmed.c    (working copy)
@@ -4945,6 +4945,9 @@ make_tree (tree type, rtx x)

   switch (GET_CODE (x))
     {
+    case CONST:
+       return make_tree (type, XEXP (x, 0));
+
     case CONST_INT:
       {
        HOST_WIDE_INT hi = 0;
@@ -4979,6 +4982,7 @@ make_tree (tree type, rtx x)
        int i, units;
        rtx elt;
        tree t = NULL_TREE;
+       tree type1 = TREE_TYPE (type);

        units = CONST_VECTOR_NUNITS (x);

@@ -4986,7 +4990,7 @@ make_tree (tree type, rtx x)
        for (i = units - 1; i >= 0; --i)
          {
            elt = CONST_VECTOR_ELT (x, i);
-           t = tree_cons (NULL_TREE, make_tree (type, elt), t);
+           t = tree_cons (NULL_TREE, make_tree (type1, elt), t);
          }

        return build_vector (type, t);
@@ -5044,6 +5048,14 @@ make_tree (tree type, rtx x)
                                          GET_CODE (x) == ZERO_EXTEND);
       return fold_convert (type, make_tree (t, XEXP (x, 0)));

+    case SYMBOL_REF:
+      if (SYMBOL_REF_DECL (x))
+       {
+         tree pointer;
+         t = SYMBOL_REF_DECL (x);
+         pointer = build_pointer_type (TREE_TYPE (t));
+         return fold_convert (type, fold_build1 (ADDR_EXPR, pointer, t));
+       }
     default:
       t = build_decl (VAR_DECL, NULL_TREE, type);

Comment 10 Andrew Pinski 2006-09-06 06:33:23 UTC
Note I think the PPC-linux-gnu crash is actually caused by:

2006-06-20  Roger Sayle  <roger@eyesopen.com>

        * expr.c (expand_expr_real_1) <VECTOR_CST>: For vector constants with
        integer modes, attempt to directly construct an integer constant.

But I have not checked but the backtrace is:


(gdb)
#8  0x085cda79 in copy_constant (exp=0xb7d40cd8) at ../../gcc/varasm.c:2742
2742                ce->value = copy_constant (value);
(gdb)
#9  0x085ce18b in build_constant_desc (exp=0xb7d40cd8)
    at ../../gcc/varasm.c:2815
2815      desc->value = copy_constant (exp);
(gdb)
#10 0x085ce4be in output_constant_def (exp=0xb7d40cd8, defer=1)
    at ../../gcc/varasm.c:2885
2885          desc = build_constant_desc (exp);
(gdb)
#11 0x0834d3f4 in expand_expr_constant (exp=0xb7d40cd8, defer=1,
    modifier=EXPAND_NORMAL) at ../../gcc/expr.c:6433
6433      mem = output_constant_def (exp, defer);
(gdb) up
#12 0x0835084f in expand_expr_real_1 (exp=0xb7d40cd8, target=0xb7d2b954,
    tmode=V4SImode, modifier=EXPAND_NORMAL, alt_rtl=0xbf977bf8)
    at ../../gcc/expr.c:7119
7119              rtx constructor = expand_expr_constant (exp, 1, modifier);
(gdb)
#13 0x0834df9d in expand_expr_real (exp=0xb7d40cd8, target=0xb7d2b954,
    tmode=V4SImode, modifier=EXPAND_NORMAL, alt_rtl=0xbf977bf8)
    at ../../gcc/expr.c:6706
6706          ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
(gdb)
#14 0x08340493 in store_expr (exp=0xb7d40cd8, target=0xb7d2b954, call_param_p=0)
    at ../../gcc/expr.c:4370
4370          temp = expand_expr_real (exp, target, GET_MODE (target),
(gdb)
#15 0x0833f7dc in expand_assignment (to=0xb7d37660, from=0xb7d40cd8)
    at ../../gcc/expr.c:4249
4249      result = store_expr (from, to_rtx, 0);
(gdb)

And then we go into an infinite loop calling copy_constant on a decl.
Comment 11 roger 2006-09-06 15:27:29 UTC
Hmm, yep I guess it was caused my change, most probably this part of it:

        * tree.c (build_constructor_single): Mark a CONSTRUCTOR as constant,
        if all of its elements/components are constant.
        (build_constructor_from_list): Likewise.

It looks like someplace is changing the contents of this CONSTRUCTOR to a VAR_DECL "t.0", but not reseting the TREE_CONSTANT flag.  Hence on PPC we
end up with a bogus constant constructor during RTL expansion!?
Scalar replacement perhaps??

Grr.  I'll investigate.  Sorry for the inconvenience.
Comment 12 roger 2006-09-06 15:36:54 UTC
Here's the .102t.final_cleanup

;; Function f (f)

f ()
{
  int D.1524;
  int D.1522;
  int D.1520;
  int t.0;

<bb 2>:
  t.0 = (int) &t;
  D.1520 = (int) &t[1];
  D.1522 = (int) &t[2];
  D.1524 = (int) &t[3];
  return {t.0, D.1520, D.1522, D.1524};

}

The CONSTRUCTOR in the return incorrectly has the TREE_CONSTANT flag set.
So the problem is somewhere in tree-ssa.  One workaround/improvement might
be for out-of-ssa to reconstitute the constructor back to a constant.
Comment 13 Jason Merrill 2006-09-09 06:44:05 UTC
I think if we are going to leave the vector initializer as a CONSTANT, we might as well just leave it alone entirely if it has TREE_CONSTANT set.
Comment 14 Richard Sandiford 2006-09-22 04:36:36 UTC
FWIW, this appears to be the same problem as the
compile/20050112-1.c failure on the -mips32 multilibs
of mipsisa64-elf-gcc.
Comment 15 Andrew Pinski 2006-10-01 04:33:07 UTC
With my reduced testcase on the 4.1 branch we get an ICE.
And infinite loop in "4.1.0 20051026" also.
Comment 16 roger 2006-11-11 02:19:17 UTC
A patch was posted by Jason, here
http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00566.html
Comment 17 Jason Merrill 2006-11-13 08:16:28 UTC
Subject: Bug 28915

Author: jason
Date: Mon Nov 13 08:16:11 2006
New Revision: 118747

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118747
Log:
        PR middle-end/28915
        * gimplify.c (gimplify_init_constructor): Don't reduce TREE_CONSTANT
        vector ctors.
        * tree-cfg.c (verify_expr): Don't look into TREE_CONSTANT
        vector ctors.
        * expmed.c (make_tree): Handle CONST, SYMBOL_REF.
        * tree.c (build_vector): Handle non-_CST elements.

Added:
    trunk/gcc/testsuite/gcc.target/i386/vectorize1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/expmed.c
    trunk/gcc/gimplify.c
    trunk/gcc/tree-cfg.c
    trunk/gcc/tree.c

Comment 18 Jason Merrill 2006-11-13 08:18:47 UTC
Subject: Bug 28915

Author: jason
Date: Mon Nov 13 08:18:28 2006
New Revision: 118748

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118748
Log:
        PR middle-end/28915
        * gimplify.c (gimplify_init_constructor): Don't reduce TREE_CONSTANT
        vector ctors.
        * tree-cfg.c (verify_expr): Don't look into TREE_CONSTANT
        vector ctors.
        * expmed.c (make_tree): Handle CONST, SYMBOL_REF.
        * tree.c (build_vector): Handle non-_CST elements.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gcc.target/i386/vectorize1.c
      - copied unchanged from r118747, trunk/gcc/testsuite/gcc.target/i386/vectorize1.c
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/expmed.c
    branches/gcc-4_2-branch/gcc/gimplify.c
    branches/gcc-4_2-branch/gcc/tree-cfg.c
    branches/gcc-4_2-branch/gcc/tree.c

Comment 19 Andrew Pinski 2006-11-13 14:41:00 UTC
Fixed in at least 4.2.0 and the trunk.
Comment 20 hjl@gcc.gnu.org 2006-11-13 18:53:36 UTC
Subject: Bug 28915

Author: hjl
Date: Mon Nov 13 18:53:27 2006
New Revision: 118771

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118771
Log:
2006-11-12  Jason Merrill  <jason@redhat.com>
	    Andrew Pinski <pinskia@physics.uc.edu>

	PR middle-end/28915
	* gcc.target/i386/vectorize1.c: New.

Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 21 hjl@gcc.gnu.org 2006-11-13 18:55:17 UTC
Subject: Bug 28915

Author: hjl
Date: Mon Nov 13 18:55:08 2006
New Revision: 118772

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118772
Log:
2006-11-12  Jason Merrill  <jason@redhat.com>
	    Andrew Pinski <pinskia@physics.uc.edu>

	Backport form mainline:
	PR middle-end/28915
	* gcc.target/i386/vectorize1.c: New.

Modified:
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 22 Jason Merrill 2006-11-13 23:31:28 UTC
Subject: Bug 28915

Author: jason
Date: Mon Nov 13 23:31:16 2006
New Revision: 118786

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118786
Log:
        PR middle-end/28915
        * gimplify.c (gimplify_init_constructor): Don't reduce TREE_CONSTANT
        vector ctors.
        * tree-cfg.c (verify_expr): Don't look into TREE_CONSTANT
        vector ctors.
        * expmed.c (make_tree): Handle CONST, SYMBOL_REF.
        * tree.c (build_vector): Handle non-_CST elements.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.target/i386/vectorize1.c
      - copied unchanged from r118747, trunk/gcc/testsuite/gcc.target/i386/vectorize1.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/expmed.c
    branches/gcc-4_1-branch/gcc/gimplify.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/tree-cfg.c
    branches/gcc-4_1-branch/gcc/tree.c

Comment 23 Jason Merrill 2006-11-13 23:42:07 UTC
fixed.
Comment 24 Jakub Jelinek 2006-11-14 09:29:58 UTC
This change breaks bootstrap on x86_64-linux and i386-linux:
/usr/src/gcc-4.1/obj/./gcc/xgcc -B/usr/src/gcc-4.1/obj/./gcc/ -B/usr/local/x86_64-unknown-linux-gnu/bin/ -B/usr/local/x86_64-unknown-linux-gnu/lib/ -isystem /usr/local/x86_64-unknown-linux-gnu/include -isystem /usr/local/x86_64-unknown-linux-gnu/sys-include -O2  -O2 -g -O2  -DIN_GCC    -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED  -I. -I. -I../../gcc -I../../gcc/. -I../../gcc/../include -I../../gcc/../libcpp/include  -m32 -fexceptions -fvisibility=hidden -DHIDE_EXPORTS -c ../../gcc/unwind-dw2.c -o libgcc/32/unwind-dw2.o
../../gcc/unwind-dw2.c: In function 'uw_install_context_1':
../../gcc/unwind-dw2.c:1334: error: unrecognizable insn:
(insn:HI 159 44 160 4 (set (reg:SI 102)
        (unspec:SI [
                (symbol_ref:SI ("dwarf_reg_size_table") [flags 0x2] <var_decl 0x2aaaab051210 dwarf_reg_size_table>)
            ] 1)) -1 (nil)
    (nil))
../../gcc/unwind-dw2.c:1334: internal compiler error: in extract_insn, at recog.c:2084
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

The problematic part is the make_tree addition.
Comment 25 pinskia@gmail.com 2006-11-14 10:02:48 UTC
Subject: Re:  [4.1 regression] ICE: tree check:
	expected class 'constant', have 'declaration' (var_decl) in build_vector,
	at tree.c:973

On Tue, 2006-11-14 at 09:29 +0000, jakub at gcc dot gnu dot org wrote:
> 
> ------- Comment #24 from jakub at gcc dot gnu dot org  2006-11-14 09:29 -------
> This change breaks bootstrap on x86_64-linux and i386-linux:

This is now PR 29825 and it is an x86 back-end issue about not accepting
the instruction which is valid as far as I can tell as the following asm
instruction is valid:
movl %eax, dwarf_reg_size_table@GOTOFF

-- Pinski