Bug 34030 - [4.1/4.2 Regression] ICE in in compare_values_warnv, at tree-vrp.c:701
Summary: [4.1/4.2 Regression] ICE in in compare_values_warnv, at tree-vrp.c:701
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.2
: P3 normal
Target Milestone: 4.1.4
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2007-11-08 16:56 UTC by christophe.lyon
Modified: 2007-11-16 21:51 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.0.0 4.3.0
Known to fail: 4.1.0 4.1.1 4.1.2 4.2.0 4.2.2
Last reconfirmed: 2007-11-16 18:33:57


Attachments
patch (625 bytes, patch)
2007-11-16 18:48 UTC, Richard Biener
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description christophe.lyon 2007-11-08 16:56:10 UTC
When compiling this sample code
int myvar;

int foo(int mynum)
{
    if ((((void *)0) ==
	 (
	  myvar & ((1U<<0) << mynum)
	 )
	 )
	&& (mynum > 0)
	)
      {
        return 1;
      }
    return 0;
}

with GCC-4.1.1, 4.1.2, 4.2.2, I get:
internal compiler error: in compare_values_warnv, at tree-vrp.c:701

It occurs only when compiling at -O2, -O3 or -Os, not at -O1.

If I remove the (void*) cast, compilation is successful.
Comment 1 Andrew Pinski 2007-11-08 18:37:30 UTC
This might have been already fixed in 4.2.3.
Comment 2 christophe.lyon 2007-11-09 08:39:37 UTC
In any case, I would appreciate a pointer to the patch, such that I can backport it to my local 4.1.x branch.
Comment 3 Richard Biener 2007-11-16 18:17:10 UTC
Confirmed.  Still broken on the 4.1 and 4.2 branches.  Wrong types on the
comparison:

D.1530_7 == 0B
(gdb) call debug_tree (expr)
 <eq_expr 0xb7c0f1d4
    type <boolean_type 0xb7c1a4ac _Bool public unsigned QI
        size <integer_cst 0xb7c081f8 constant invariant 8>
        unit size <integer_cst 0xb7c08210 constant invariant 1>
        align 8 symtab 0 alias set -1 precision 1 min <integer_cst 0xb7c085e8 0> max <integer_cst 0xb7c08618 1>>
   
    arg 0 <ssa_name 0xb7c9a480
        type <integer_type 0xb7c1a2e0 unsigned int public unsigned SI
            size <integer_cst 0xb7c083f0 constant invariant 32>
            unit size <integer_cst 0xb7c08180 constant invariant 4>
            align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0xb7c08468 0> max <integer_cst 0xb7c08450 4294967295>>
        var <var_decl 0xb7c14268 D.1530> def_stmt <modify_expr 0xb7c0f2f4>
        version 7>
    arg 1 <integer_cst 0xb7c08a98 type <pointer_type 0xb7c1a8fc> constant invariant 0>>

  _Bool D.1532;
  _Bool D.1531;
  unsigned int D.1530;
  unsigned int D.1529;
  unsigned int myvar.1;
  int myvar.0;

<bb 2>:
  myvar.0_3 = myvar;
  myvar.1_4 = (unsigned int) myvar.0_3;
  D.1529_6 = myvar.1_4 >> mynum_5;
  D.1530_7 = D.1529_6 & 1;
  D.1531_8 = D.1530_7 == 0B;

probably some fold bug.
Comment 4 Richard Biener 2007-11-16 18:20:46 UTC
Or rather a frontend bug if it doesn't promote either the integer to a pointer
or the pointer to an integer:

./cc1 -quiet -O2 t.i -quiet
t.i: In function ‘foo’:
t.i:9: warning: comparison between pointer and integer
                      ^^^^^^^
t.i:4: internal compiler error: in compare_values_warnv, at tree-vrp.c:701
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

with trunk we get

  if ((void *) (1 << mynum & (unsigned int) myvar) == 0B && mynum > 0)

while with 4.2 we have

  if (((unsigned int) myvar >> mynum & 1) == 0B && mynum > 0)

which hints at a fold bug again.
Comment 5 Richard Biener 2007-11-16 18:33:57 UTC
Mine.  Still wrong on the trunk.
Comment 6 Richard Biener 2007-11-16 18:38:11 UTC
On the trunk this doesn't fail because there STRIP_SIGN_NOPS (as applied to
comparisons) doesn't strip conversions to/from pointers.
Comment 7 Richard Biener 2007-11-16 18:48:35 UTC
Created attachment 14565 [details]
patch

Still needs testing, applies to all branches and trunk.
Comment 8 Richard Biener 2007-11-16 21:35:15 UTC
Subject: Bug 34030

Author: rguenth
Date: Fri Nov 16 21:34:39 2007
New Revision: 130238

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130238
Log:
2007-11-16  Richard Guenther  <rguenther@suse.de>

	PR middle-end/34030
	* fold-const.c (fold_binary): Use correct types for folding
	1 << X & Y to Y >> X & 1.

	* gcc.c-torture/compile/pr34030.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/pr34030.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog

Comment 9 Richard Biener 2007-11-16 21:45:17 UTC
Subject: Bug 34030

Author: rguenth
Date: Fri Nov 16 21:44:58 2007
New Revision: 130240

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130240
Log:
2007-11-16  Richard Guenther  <rguenther@suse.de>

	PR middle-end/34030
	* fold-const.c (fold_binary): Use correct types for folding
	1 << X & Y to Y >> X & 1.

	* gcc.c-torture/compile/pr34030.c: New testcase.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/compile/pr34030.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 10 Richard Biener 2007-11-16 21:50:31 UTC
Subject: Bug 34030

Author: rguenth
Date: Fri Nov 16 21:50:20 2007
New Revision: 130242

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130242
Log:
2007-11-16  Richard Guenther  <rguenther@suse.de>

	PR middle-end/34030
	* fold-const.c (fold_binary): Use correct types for folding
	1 << X & Y to Y >> X & 1.

	* gcc.c-torture/compile/pr34030.c: New testcase.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/compile/pr34030.c
      - copied unchanged from r130238, trunk/gcc/testsuite/gcc.c-torture/compile/pr34030.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/fold-const.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 11 Richard Biener 2007-11-16 21:51:32 UTC
Fixed.