Bug 30744 - [4.2/4.3 Regression] ICE in compare_values, at tree-vrp.c:466
Summary: [4.2/4.3 Regression] ICE in compare_values, at tree-vrp.c:466
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P1 normal
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 22368
  Show dependency treegraph
 
Reported: 2007-02-09 11:22 UTC by George Katsirelos
Modified: 2007-03-06 16:32 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.1 4.2.0 4.3.0
Known to fail:
Last reconfirmed: 2007-02-09 13:21:38


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description George Katsirelos 2007-02-09 11:22:22 UTC
The following causes an ICE
$ gcc -v
Using built-in specs.
Target: i386-apple-darwin8.8.1
Configured with: ../configure --prefix=/Users/gkatsi/pkgs/gcc-4.2.pre --enable-languages=c,c++ --enable-__cxa_atexit
Thread model: posix
gcc version 4.2.0 20070209 (prerelease)
$ cat tt2.c
typedef struct {
  unsigned long unique;
} G;

void r(G* n)
{
  unsigned long p;
  if (((G *) ((void *)((~(unsigned long)(p))))) != ((void *)0)) {
    ((G *) ((void *)((~(unsigned long)(p)))))->unique = n->unique;
  }
}
$ gcc -O2 -c tt2.c
tt2.c: In function 'r':
tt2.c:6: internal compiler error: in compare_values, at tree-vrp.c:466
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

It also happens on i686-pc-linux-gnu with gcc version 4.2.0 20070207
Comment 1 Richard Biener 2007-02-09 13:21:38 UTC
Confirmed.  Wrong types in comparison:

#5  0x000000000094f7ff in fold_predicate_in (stmt=0x2b5158e17690)
    at /space/rguenther/src/svn/trunk/gcc/tree-ssa-propagate.c:1106
1106      val = vrp_evaluate_conditional (*pred_p, true);
(gdb) call debug_generic_expr (stmt)
if (p_1(D) != -1B) goto <L0>; else goto <L1>;

(gdb) call debug_tree (cond)
 <ne_expr 0x2b5158e1c200
    type <boolean_type 0x2b5158e219c0 _Bool public unsigned QI
        size <integer_cst 0x2b5158e11810 constant invariant 8>
        unit size <integer_cst 0x2b5158e11840 constant invariant 1>
        align 8 symtab 0 alias set -1 canonical type 0x2b5158e219c0 precision 1 min <integer_cst 0x2b5158e11d20 0> max <integer_cst 0x2b5158e11d80 1>>
   
    arg 0 <ssa_name 0x2b5158f6cde0
        type <integer_type 0x2b5158e21780 long unsigned int sizes-gimplified public unsigned DI
            size <integer_cst 0x2b5158e11ba0 constant invariant 64>
            unit size <integer_cst 0x2b5158e11bd0 constant invariant 8>
            align 64 symtab 0 alias set -1 canonical type 0x2b5158e21780 precision 64 min <integer_cst 0x2b5158e11c00 0> max <integer_cst 0x2b5158e11b70 18446744073709551615>>
        volatile visited var <var_decl 0x2b5158f79000 p> def_stmt <nop_expr 0x2b5158e1c840>
        version 1>
    arg 1 <integer_cst 0x2b5158e2eb40 type <pointer_type 0x2b5158e31300> constant invariant 18446744073709551615>
    t.i:8>

From the beginning:

;; enabled by -tree-original


{
  long unsigned int p;

    long unsigned int p;
  if (p != -1B)
    {
      ((struct G *) (void *) ~p)->unique = n->unique;
    }
}

We fold (void *)~p != (void *)0 to p != (void *)-1 here:

fold_comparison (...
...
  /* Fold ~X op C as X op' ~C, where op' is the swapped comparison.  */
  if (TREE_CODE (arg0) == BIT_NOT_EXPR
      && TREE_CODE (arg1) == INTEGER_CST)
    return fold_build2 (swap_tree_comparison (code), type,
                        TREE_OPERAND (arg0, 0),
                        fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), arg1));

but arg0 has NOPs stripped.
Comment 2 Roger Sayle 2007-03-04 19:03:24 UTC
Subject: Bug 30744

Author: sayle
Date: Sun Mar  4 19:03:13 2007
New Revision: 122531

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122531
Log:

	PR middle-end/30744
	* fold-const.c (fold_comparison): Enforce type consistency when
	transforming ~X op ~Y to Y op X, and ~X op C to X op' ~C.

	* gcc.dg/pr30744-1.c: New test case.


Added:
    trunk/gcc/testsuite/gcc.dg/pr30744-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Roger Sayle 2007-03-06 16:30:32 UTC
Subject: Bug 30744

Author: sayle
Date: Tue Mar  6 16:30:12 2007
New Revision: 122622

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122622
Log:

	PR middle-end/30744
	* fold-const.c (fold_binary) <EQ_EXPR>: Enforce type consistency
	when transforming ~X op C to X op' ~C.

	* gcc.dg/pr30744-1.c: New test case.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/pr30744-1.c
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/fold-const.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 4 roger 2007-03-06 16:32:50 UTC
This should now be fixed on both mainline and the 4.2 release branch.