template<short S> void foo(void) { const unsigned short m = S ? ((unsigned short) 0 | (unsigned short) 0) : 0; short t = 1 & m; } ICEs in: #0 0x00000000005b136f in operand_equal_p (arg0=0x2aaaae123f60, arg1=0x2aaaae123f90, flags=0) at ../../gcc/fold-const.c:2421 #1 0x00000000005b5792 in fold_binary (code=BIT_IOR_EXPR, type=0x2aaaae004420, op0=0x2aaaae12d540, op1=0x2aaaae12d580) at ../../gcc/fold-const.c:8050 #2 0x00000000005bbde9 in fold_build2_stat (code=2919253024, type=0x0, op0=0x74, op1=0x0) at ../../gcc/fold-const.c:10597 #3 0x00000000005445c6 in convert_to_integer (type=0x2aaaae004420, expr=<value optimized out>) at ../../gcc/convert.c:641 #4 0x0000000000462e4a in ocp_convert (type=0x2aaaae004420, expr=<value optimized out>, convtype=15, flags=35) at ../../gcc/cp/cvt.c:698 #5 0x00000000005445e9 in convert_to_integer (type=0x2aaaae004420, expr=0x2aaaadff8730) at ../../gcc/convert.c:683 #6 0x0000000000462e4a in ocp_convert (type=0x2aaaae004420, expr=<value optimized out>, convtype=15, flags=3) at ../../gcc/cp/cvt.c:698 #7 0x000000000045e349 in default_conversion (exp=0x2aaaae004420) at ../../gcc/cp/typeck.c:1435 as C++ specific trees (cast_expr in <bit_ior_expr 0x2aaaadff8780 type <integer_type 0x2aaaae0044d0 int public type_6 SI size <integer_cst 0x2aaaadff2a20 constant invariant 32> unit size <integer_cst 0x2aaaadff2540 constant invariant 4> align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0x2aaaadff2990 -2147483648> max <integer_cst 0x2aaaadff29c0 2147483647> pointer_to_this <pointer_type 0x2aaaae017790>> side-effects arg 0 <cast_expr 0x2aaaae12d540 type <integer_type 0x2aaaae004420 short unsigned int public unsigned type_6 HI size <integer_cst 0x2aaaadff2840 constant invariant 16> unit size <integer_cst 0x2aaaadff2870 constant invariant 2> align 16 symtab 0 alias set -1 precision 16 min <integer_cst 0x2aaaadff2960 0> max <integer_cst 0x2aaaadff2930 65535>> side-effects arg 0 <tree_list 0x2aaaae123f60 value <integer_cst 0x2aaaae00f660 constant invariant 0>>> arg 1 <cast_expr 0x2aaaae12d580 type <integer_type 0x2aaaae004420 short unsigned int> side-effects arg 0 <tree_list 0x2aaaae123f90 value <integer_cst 0x2aaaae00f660 0>>>> are passed to convert_to_integer/fold. This certainly didn't ICE in 3.2.3, and doesn't ICE in 4.2+ either (I believe PR27506 made the difference here).
I actually think it is more related to PR 28341 than the other one.
Confirmed. The bogus part is actually that we have two TREE_LISTs as arguments to BIT_IOR_EXPR: <<< Unknown tree: cast_expr 0 >>> | <<< Unknown tree: cast_expr 0 >>> Where the CAST_EXPRs with the tree-list are built from #1 0x08195455 in build_c_cast (type=0xb7b64228, expr=0xb7b539d8) at /home/richard/src/gcc-4_1-branch/gcc/cp/typeck.c:5283 5283 tree_cons (NULL_TREE, value, NULL_TREE)); (gdb) l 5278 return error_mark_node; 5279 5280 if (processing_template_decl) 5281 { 5282 tree t = build_min (CAST_EXPR, type, 5283 tree_cons (NULL_TREE, value, NULL_TREE)); 5284 /* We don't know if it will or will not have side effects. */ 5285 TREE_SIDE_EFFECTS (t) = 1; 5286 return convert_from_reference (t); 5287 } Note this happens while executing the convert_to_integer part of return fold_if_not_in_template (convert_to_integer (type, e)); but processing_template_decl is true. This may be a generic (and now latent) problem that the quasi middle-end convert_to_integer does call fold itself.
Closing 4.1 branch.