Bug 41182 - [4.5 Regression] Revision 145254 caused ICE: tree check: expected integer_cst, have nop_expr in tree_int_cst_lt, at tree.c:5259
Summary: [4.5 Regression] Revision 145254 caused ICE: tree check: expected integer_cst...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.5.0
: P1 normal
Target Milestone: 4.5.0
Assignee: Joseph S. Myers
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2009-08-28 09:07 UTC by Tobias Burnus
Modified: 2009-10-08 00:34 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-*-*
Build:
Known to work: 4.5.0
Known to fail:
Last reconfirmed: 2009-10-07 22:36:15


Attachments
test.i (18.55 KB, application/x-gzip)
2009-08-28 09:08 UTC, Tobias Burnus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2009-08-28 09:07:16 UTC
$ gcc asnlib.i
../../libu/util/asnlib.c: In function '_lae_process_opts':
../../libu/util/asnlib.c:1103:4: internal compiler error: tree check: expected integer_cst, have nop_expr in tree_int_cst_lt, at tree.c:5259
Please submit a full bug report,


That's with:
gcc version 4.5.0 20090828 (experimental) [trunk revision 151156] (GCC)
Target: x86_64-unknown-linux-gnu

(Complete source code is "hg clone http://hg.osunix.org/path64", cf. http://www.path64.com/)
Comment 1 Tobias Burnus 2009-08-28 09:08:34 UTC
Created attachment 18443 [details]
test.i
Comment 2 Richard Biener 2009-08-28 13:00:29 UTC
Confirmed.  ICEs in folding a minmax comparison.

typedef long unsigned int size_t;
int _lae_process_opts(char *pr, char *pe)
{ 
  return (strlen ("on") < ((size_t) ((pe-&pr[2])>(strlen("on"))                                                      ? (pe-&pr[2]) : (strlen("on")))));
}

requires unprototyped strlen.
Comment 3 Andrew Pinski 2009-09-20 20:29:22 UTC
6148	  comp_const = fold_convert_loc (loc, TREE_TYPE (arg0), op1);

op1 is already not folded:
(gdb) p debug_tree(op1)
 <nop_expr 0x7ffff6fcc040
    type <integer_type 0x7ffff7ed8780 long unsigned int public unsigned DI
        size <integer_cst 0x7ffff7ec7bd0 constant 64>
        unit size <integer_cst 0x7ffff7ec7c00 constant 8>
        align 64 symtab 0 alias set -1 canonical type 0x7ffff7ed8780 precision 64 min <integer_cst 0x7ffff7ec7c30 0> max <integer_cst 0x7ffff7ec7ba0 18446744073709551615>>
    constant
    arg 0 <integer_cst 0x7ffff6fc6990 type <integer_type 0x7ffff7ed8780 long unsigned int> constant 2>>
$5 = void

Comment 4 Andrew Pinski 2009-09-20 20:32:50 UTC
op1 comes from the front-end which means this is most likely caused by the constant expression patch.  Trying to figure out how to fix it ...
Comment 5 Andrew Pinski 2009-09-20 20:39:00 UTC
orig_op0 in c-common.c:
(gdb) p debug_tree(orig_op0)
 <c_maybe_const_expr 0x7ffff7ff8f80
    type <integer_type 0x7ffff7ed8780 long unsigned int public unsigned DI
        size <integer_cst 0x7ffff7ec7bd0 constant 64>
        unit size <integer_cst 0x7ffff7ec7c00 constant 8>
        align 64 symtab 0 alias set -1 canonical type 0x7ffff7ed8780 precision 64 min <integer_cst 0x7ffff7ec7c30 0> max <integer_cst 0x7ffff7ec7ba0 18446744073709551615>>
    tree_1
    arg 1 <nop_expr 0x7ffff7ff8b00 type <integer_type 0x7ffff7ed8780 long unsigned int>
        constant
        arg 0 <integer_cst 0x7ffff6fc6990 constant 2>
        t.c:4:18>>

Hmm, actually I don't understand how c_maybe_const_expr are suposed to work.
Comment 6 jsm-csl@polyomino.org.uk 2009-09-20 21:08:17 UTC
Subject: Re:  [4.5 Regression] ICE: tree check: expected
 integer_cst, have nop_expr in tree_int_cst_lt, at tree.c:5259

There is no backtrace in this bug or any statement of the point in such a 
backtrace at which you think an invalid argument has been passed to a 
function that should not have been passed there.  C_MAYBE_CONST_EXPRs are 
created at various stages in the front end and are lowered by 
c_fully_fold, so none should exist by gimplification.  If the 
C_MAYBE_CONST_EXPR is being seen during gimplification, that's a front end 
bug.  Otherwise, non-front-end code dealing with trees needs to accept 
them just like any other front-end-specific trees.

Comment 7 Andrew Pinski 2009-09-20 21:11:06 UTC
sorry for not adding a backtrace:
#2  0x0000000000b86862 in tree_int_cst_lt (t1=0x7ffff6fc6990, t2=0x7ffff6fcc040)
    at /home/pinskia/src/local/gcc/gcc/tree.c:6087
#3  0x0000000000710ea0 in optimize_minmax_comparison (loc=482, code=GT_EXPR, type=0x7ffff7ed8540, 
    op0=0x7ffff7ff8c80, op1=0x7ffff6fcc040) at /home/pinskia/src/local/gcc/gcc/fold-const.c:6150
#4  0x000000000072e64c in fold_comparison (loc=482, code=GT_EXPR, type=0x7ffff7ed8540, 
    op0=0x7ffff7ff8c80, op1=0x7ffff6fcc040) at /home/pinskia/src/local/gcc/gcc/fold-const.c:9616
#5  0x000000000076ba81 in fold_binary_loc (loc=482, code=GT_EXPR, type=0x7ffff7ed8540, 
    op0=0x7ffff7ff8c80, op1=0x7ffff6fcc040) at /home/pinskia/src/local/gcc/gcc/fold-const.c:13105
#6  0x000000000077752a in fold_build2_stat_loc (loc=482, code=GT_EXPR, type=0x7ffff7ed8540, 
    op0=0x7ffff7ff8c80, op1=0x7ffff6fcc040) at /home/pinskia/src/local/gcc/gcc/fold-const.c:14374
#7  0x0000000000728e28 in fold_comparison (loc=482, code=LT_EXPR, type=0x7ffff7ed8540, 
    op0=0x7ffff6fcc040, op1=0x7ffff7ff8c80) at /home/pinskia/src/local/gcc/gcc/fold-const.c:9159
#8  0x000000000076ba81 in fold_binary_loc (loc=482, code=LT_EXPR, type=0x7ffff7ed8540, 
    op0=0x7ffff6fcc040, op1=0x7ffff7ff8c80) at /home/pinskia/src/local/gcc/gcc/fold-const.c:13105
#9  0x000000000077752a in fold_build2_stat_loc (loc=482, code=LT_EXPR, type=0x7ffff7ed8540, 
    op0=0x7ffff6fcc040, op1=0x7ffff7ff8c80) at /home/pinskia/src/local/gcc/gcc/fold-const.c:14374
#10 0x00000000004fd2a6 in c_fully_fold_internal (expr=0x7ffff6fcc000, in_init=0 '\0', 
    maybe_const_operands=0x7fffffffe0af "", maybe_const_itself=0x7fffffffe0ae "\001")
    at /home/pinskia/src/local/gcc/gcc/c-common.c:1308
#11 0x00000000004fbf28 in c_fully_fold (expr=0x7ffff6fcc000, in_init=0 '\0', 
    maybe_const=0x7fffffffe0af "") at /home/pinskia/src/local/gcc/gcc/c-common.c:1108
#12 0x00000000004eee23 in c_finish_return (loc=460, retval=0x7ffff6fcc000, origtype=0x0)
    at /home/pinskia/src/local/gcc/gcc/c-typeck.c:8078

The op0 of the call to fold_build2_stat_loc is not fully folded which causes the ICE.
Comment 8 Andrew Pinski 2009-09-20 21:12:37 UTC
>The op0 of the call to fold_build2_stat_loc is not fully folded which causes
the ICE.

And op0 of the call to fold_build2_stat_loc does not contain c_maybe_const_expr but just the NOP_EXPR<INT_CST>.
Comment 9 Richard Biener 2009-09-20 21:16:52 UTC
We likely should recursively fold all trees during gimplification.  That also
would prepare us to no longer fold in the frontends.  Didn't we do this at
some point in the past?
Comment 10 jsm-csl@polyomino.org.uk 2009-09-20 21:23:56 UTC
Subject: Re:  [4.5 Regression] ICE: tree check: expected
 integer_cst, have nop_expr in tree_int_cst_lt, at tree.c:5259

Where (backtrace) did the C_MAYBE_CONST_EXPR get created?  Where 
(backtrace) did the NOP_EXPR get created?  The tree going inside a 
C_MAYBE_CONST_EXPR should have been folded at the point the 
C_MAYBE_CONST_EXPR was created, though that is meant to be an efficiency 
issue (avoiding multiple folding of the same trees) rather than required 
to avoid ICEs.

Comment 11 H.J. Lu 2009-09-20 23:31:38 UTC
It is caused by revision 145254:

http://gcc.gnu.org/ml/gcc-cvs/2009-03/msg00761.html
Comment 12 Joseph S. Myers 2009-10-07 22:36:15 UTC
Testing a patch.
Comment 13 Joseph S. Myers 2009-10-08 00:33:03 UTC
Subject: Bug 41182

Author: jsm28
Date: Thu Oct  8 00:32:51 2009
New Revision: 152548

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=152548
Log:
	PR c/41182
	* c-common.c (c_fully_fold_internal): Strip nops from the result
	of recursive calls to c_fully_fold_internal.
	(c_wrap_maybe_const): New.
	(c_save_expr): Use c_wrap_maybe_const.
	* c-common.h (c_wrap_maybe_const): Declare.
	* c-typeck.c (build_conditional_expr, c_finish_stmt_expr,
	build_binary_op): Use c_wrap_maybe_const.

testsuite:
	* gcc.c-torture/compile/pr41182-1.c: New.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/pr41182-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/c-common.h
    trunk/gcc/c-typeck.c
    trunk/gcc/testsuite/ChangeLog

Comment 14 Joseph S. Myers 2009-10-08 00:34:49 UTC
Fixed for 4.5.
Comment 15 hjl@gcc.gnu.org 2009-10-15 21:18:19 UTC
Subject: Bug 41182

Author: hjl
Date: Thu Oct 15 21:17:36 2009
New Revision: 152870

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=152870
Log:
2009-10-15  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:
	2009-10-13  Martin Jambor  <mjambor@suse.cz>

	* gcc.c-torture/compile/pr41661.c: New test.

	2009-10-12  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/41683
	* gfortran.dg/fmt_error_9.f: Add check for repeat count after P.

	2009-10-12  Dodji Seketeli  <dodji@redhat.com>

	PR c++/41570
	* g++.dg/debug/dwarf2/template-params-7.C: New test.

	2009-10-11  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/41555
	* gcc.dg/torture/pr41555.c: New testcase.

	2009-10-09  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/41634
	* gcc.c-torture/compile/pr41634.c: New testcase.

	2009-10-08  Michael Matz  <matz@suse.de>

	PR middle-end/41573
	* gcc.dg/pr41573.c: New test.

	2009-10-07  Joseph Myers  <joseph@codesourcery.com>

	PR c/41182
	* gcc.c-torture/compile/pr41182-1.c: New.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/debug/dwarf2/template-params-7.C
      - copied unchanged from r152869, trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-params-7.C
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr41182-1.c
      - copied unchanged from r152869, trunk/gcc/testsuite/gcc.c-torture/compile/pr41182-1.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr41634.c
      - copied unchanged from r152869, trunk/gcc/testsuite/gcc.c-torture/compile/pr41634.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr41661.c
      - copied unchanged from r152868, trunk/gcc/testsuite/gcc.c-torture/compile/pr41661.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/pr41573.c
      - copied unchanged from r152869, trunk/gcc/testsuite/gcc.dg/pr41573.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/torture/pr41555.c
      - copied unchanged from r152869, trunk/gcc/testsuite/gcc.dg/torture/pr41555.c
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/fmt_error_9.f
      - copied unchanged from r152869, trunk/gcc/testsuite/gfortran.dg/fmt_error_9.f
Modified:
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog