Bug 13066 - [tree-ssa] ICE in in invert_truthvalue, at fold-const.c:2554
Summary: [tree-ssa] ICE in in invert_truthvalue, at fold-const.c:2554
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: tree-ssa
: P2 critical
Target Milestone: tree-ssa
Assignee: Andrew Pinski
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2003-11-16 04:33 UTC by Brian Ryner
Modified: 2004-03-01 19:21 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-02-05 01:25:15


Attachments
preprocessed source (119.34 KB, text/plain)
2003-11-16 04:35 UTC, Brian Ryner
Details
reduced testcase (132 bytes, text/plain)
2003-11-16 05:24 UTC, Brian Ryner
Details
second reduced testcase (87 bytes, text/plain)
2004-01-20 09:35 UTC, Brian Ryner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Ryner 2003-11-16 04:33:58 UTC
I pulled a tree from tree-ssa-20020619-branch today and got the following ICE
when compiling some Mozilla code:

$ c++ -Os -o nsScriptSecurityManager.o nsScriptSecurityManager.i
../../../../mozilla/caps/src/nsScriptSecurityManager.cpp: In member function
`nsresult nsScriptSecurityManager::CheckSameOriginPrincipalInternal(nsIPrincipal*,
nsIPrincipal*, PRBool)':
../../../../mozilla/caps/src/nsScriptSecurityManager.cpp:807: internal compiler
error: in invert_truthvalue, at fold-const.c:2554

The ICE occurs with -O1,-Os,-O2, but not -O0.
Comment 1 Brian Ryner 2003-11-16 04:35:07 UTC
Created attachment 5145 [details]
preprocessed source
Comment 2 Brian Ryner 2003-11-16 05:24:15 UTC
Created attachment 5146 [details]
reduced testcase
Comment 3 Andrew Pinski 2003-11-16 08:41:55 UTC
I can confirm this on the tree-ssa (20031115).
Comment 4 Andrew Pinski 2003-11-16 18:51:13 UTC
Here is the backtrace:
(gdb) bt
#0  fancy_abort (file=0x881b7c "/Volumes/UFS_Partition/pinskia/src/gccssa/src/gcc/fold-
const.c", line=2554, function=0x881d38 "invert_truthvalue") at /Volumes/UFS_Partition/pinskia/
src/gccssa/src/gcc/diagnostic.c:584
#1  0x002c693c in invert_truthvalue (arg=0x4176aae0) at /Volumes/UFS_Partition/pinskia/src/
gccssa/src/gcc/fold-const.c:2554
#2  0x002c56e0 in invert_truthvalue (arg=0x4172f988) at /Volumes/UFS_Partition/pinskia/src/
gccssa/src/gcc/fold-const.c:2496
#3  0x0072bc9c in cfg_remove_useless_stmts_bb.385 (bb=0x4181b8b4) at /Volumes/
UFS_Partition/pinskia/src/gccssa/src/gcc/tree-cfg.c:1299
#4  0x0072d18c in cfg_remove_useless_stmts () at /Volumes/UFS_Partition/pinskia/src/gccssa/
src/gcc/tree-cfg.c:1443
#5  0x0048c67c in rewrite_out_of_ssa (fndecl=0x4176a6cc, phase=TDI_optimized) at /Volumes/
UFS_Partition/pinskia/src/gccssa/src/gcc/tree-ssa.c:2484
#6  0x005276e0 in optimize_function_tree.347 (fndecl=0x4176a6cc, chain=0xbffff5a4) at /
Volumes/UFS_Partition/pinskia/src/gccssa/src/gcc/tree-optimize.c:173
#7  0x00527f7c in tree_rest_of_compilation (fndecl=0x4176a6cc, nested_p=false) at /Volumes/
UFS_Partition/pinskia/src/gccssa/src/gcc/tree-optimize.c:316
#8  0x001a3724 in expand_body (fn=0x4176a6cc) at /Volumes/UFS_Partition/pinskia/src/gccssa/
src/gcc/cp/semantics.c:2874
#9  0x0050f078 in cgraph_expand_function.293 (node=0x4176acb0) at /Volumes/UFS_Partition/
pinskia/src/gccssa/src/gcc/cgraphunit.c:496
#10 0x0050ddc0 in cgraph_assemble_pending_functions () at /Volumes/UFS_Partition/pinskia/src/
gccssa/src/gcc/cgraphunit.c:142
#11 0x0050dfcc in cgraph_finalize_function (decl=0x4176a6cc, nested=false) at /Volumes/
UFS_Partition/pinskia/src/gccssa/src/gcc/cgraphunit.c:221
#12 0x001a3ed0 in expand_or_defer_fn (fn=0x4176a6cc) at /Volumes/UFS_Partition/pinskia/src/
gccssa/src/gcc/cp/semantics.c:2966
#13 0x001372b8 in cp_parser_function_definition_after_declarator.522 (parser=0x41765ae0, 
inline_p=false) at /Volumes/UFS_Partition/pinskia/src/gccssa/src/gcc/cp/parser.c:13606
#14 0x0013713c in cp_parser_function_definition_from_specifiers_and_declarator.487 
(parser=0x41765ae0, decl_specifiers=0x417693f0, attributes=0x0, declarator=0x4172f5c8) at /
Volumes/UFS_Partition/pinskia/src/gccssa/src/gcc/cp/parser.c:13545
#15 0x0012e4a0 in cp_parser_init_declarator.448 (parser=0x41765ae0, 
decl_specifiers=0x417693f0, prefix_attributes=0x0, function_definition_allowed_p=true, 
member_p=false, declares_class_or_enum=0, function_definition_p=0xbffff974) at /Volumes/
UFS_Partition/pinskia/src/gccssa/src/gcc/cp/parser.c:9357
#16 0x001292c0 in cp_parser_simple_declaration.433 (parser=0x41765ae0, 
function_definition_allowed_p=true) at /Volumes/UFS_Partition/pinskia/src/gccssa/src/gcc/cp/
parser.c:6156
#17 0x001291b8 in cp_parser_block_declaration.434 (parser=0x41765ae0, statement_p=false) at 
/Volumes/UFS_Partition/pinskia/src/gccssa/src/gcc/cp/parser.c:6072
#18 0x00129020 in cp_parser_declaration.435 (parser=0x41765ae0) at /Volumes/UFS_Partition/
pinskia/src/gccssa/src/gcc/cp/parser.c:5992
#19 0x00128d98 in cp_parser_declaration_seq_opt.342 (parser=0x41765ae0) at /Volumes/
UFS_Partition/pinskia/src/gccssa/src/gcc/cp/parser.c:5901
#20 0x001231d0 in cp_parser_translation_unit.341 (parser=0x41765ae0) at /Volumes/
UFS_Partition/pinskia/src/gccssa/src/gcc/cp/parser.c:2163
#21 0x001397a4 in c_parse_file () at /Volumes/UFS_Partition/pinskia/src/gccssa/src/gcc/cp/
parser.c:14522
#22 0x0024f1bc in c_common_parse_file (set_yydebug=0) at /Volumes/UFS_Partition/pinskia/src/
gccssa/src/gcc/c-opts.c:1222
#23 0x002a9530 in compile_file.306 () at /Volumes/UFS_Partition/pinskia/src/gccssa/src/gcc/
toplev.c:1880
#24 0x002b0030 in do_compile.349 () at /Volumes/UFS_Partition/pinskia/src/gccssa/src/gcc/
toplev.c:4751
#25 0x002b0114 in toplev_main (argc=3, argv=0xbffffdec) at /Volumes/UFS_Partition/pinskia/
src/gccssa/src/gcc/toplev.c:4791
#26 0x0026566c in main (argc=3, argv=0xbffffdec) at /Volumes/UFS_Partition/pinskia/src/
gccssa/src/gcc/main.c:35
Comment 5 Andrew Pinski 2003-11-16 18:53:55 UTC
It is failing on this bb:
(gdb) p debug_tree_bb_n(2)
;; basic block 2, loop depth 0, count 0
;; prev block 1, next block 3
;; pred:       1 (fallthru,exec)
;; succ:       4 (false,exec) 3 (true,exec)
<Uaf68>:;
if (T.2 ^ <Uae0c> == 0B)
  {
    (void)0;
  }
else
  {
    goto <U915c>;
  }
Comment 6 Andrew Pinski 2003-12-01 04:29:36 UTC
This is caused by -ftree-tre, assigning it to the writter.
Comment 7 Steven Bosscher 2004-01-10 00:52:38 UTC
Starting program: /home/steven/devel/ssabuild/gcc/cc1plus -O testcase_ice.cpp 
 nsCOMPtr::operator nsIURI*() const 
 void func() 
 
Breakpoint 1, fancy_abort (file=0x85184e0 "../../tree-ssa/gcc/fold-const.c", 
line=9, 
    function=0x85184e0 "../../tree-ssa/gcc/fold-const.c") at ../../tree-ssa/
gcc/diagnostic.c:584 
584       internal_error ("in %s, at %s:%d", function, trim_filename (file), 
line); 
(gdb) up 
#1  0x0828f518 in invert_truthvalue (arg=0x40237bc8) at ../../tree-ssa/gcc/
fold-const.c:2553 
2553        abort (); 
(gdb) l 
2548 
2549        default: 
2550          break; 
2551        } 
2552      if (TREE_CODE (TREE_TYPE (arg)) != BOOLEAN_TYPE) 
2553        abort (); 
2554      return build1 (TRUTH_NOT_EXPR, type, arg); 
2555    } 
2556 
2557    /* Given a bit-wise operation CODE applied to ARG0 and ARG1, see if 
both 
(gdb) p debug_tree (arg) 
 <var_decl 0x40237bc8 T.2 
    type <integer_type 0x40023658 int SI 
        size <integer_cst 0x40021288 constant invariant 32> 
        unit size <integer_cst 0x40021330 constant invariant 4> 
        align 32 symtab 0 alias set -1 precision 32 min <integer_cst 
0x40021300 -2147483648> max <integer_cst 0x40021318 2147483647> 
        pointer_to_this <pointer_type 0x401612b8>> 
    used ignored SI file testcase_ice.cpp line 17 size <integer_cst 0x40021288 
32> unit size <integer_cst 0x40021330 4> 
    align 32 context <function_decl 0x402377b4 func> chain <var_decl 
0x40237c3c T.3>> 
$4 = void 
(gdb) up 
#2  0x0828f070 in invert_truthvalue (arg=0x400227e0) at ../../tree-ssa/gcc/
fold-const.c:2494 
2494            return build (TRUTH_XOR_EXPR, type, 
(gdb) 
#3  0x08184e98 in cfg_remove_useless_stmts () at ../../tree-ssa/gcc/
tree-cfg.c:1251 
1251        cond = invert_truthvalue (cond); 
(gdb) l 
1246          || !(bb->pred->flags & (EDGE_TRUE_VALUE | EDGE_FALSE_VALUE))) 
1247        return; 
1248 
1249      cond = COND_EXPR_COND (last_stmt (bb->pred->src)); 
1250      if (bb->pred->flags & EDGE_FALSE_VALUE) 
1251        cond = invert_truthvalue (cond); 
1252 
1253      if (TREE_CODE (cond) == VAR_DECL 
1254          || TREE_CODE (cond) == PARM_DECL) 
1255        { 
(gdb) p print_generic_stmt (stderr,last_stmt (bb->pred->src),0) 
if (T.2 ^ SR.9 == 0B) goto <L2>; else goto <L3>; 
$1 = void 
(gdb) p debug_tree (last_stmt (bb->pred->src)->exp.operands[0]) 
 <truth_xor_expr 0x400227e0 
    type <boolean_type 0x40023910 bool unsigned QI 
        size <integer_cst 0x40021138 constant invariant 8> 
        unit size <integer_cst 0x40021150 constant invariant 1> 
        align 8 symtab 0 alias set -1 precision 1 min <integer_cst 0x40021510 
0> max <integer_cst 0x40021558 1>> 
 
    arg 0 <var_decl 0x40237bc8 T.2 
        type <integer_type 0x40023658 int SI 
            size <integer_cst 0x40021288 constant invariant 32> 
            unit size <integer_cst 0x40021330 constant invariant 4> 
            align 32 symtab 0 alias set -1 precision 32 min <integer_cst 
0x40021300 -2147483648> max <integer_cst 0x40021318 2147483647> 
            pointer_to_this <pointer_type 0x401612b8>> 
        used ignored SI file testcase_ice.cpp line 17 size <integer_cst 
0x40021288 32> unit size <integer_cst 0x40021330 4> 
        align 32 context <function_decl 0x402377b4 func> 
        chain <var_decl 0x40237c3c T.3 type <pointer_type 0x40233d24> 
            unsigned used ignored SI file testcase_ice.cpp line 17 
            size <integer_cst 0x40021b58 constant invariant 32> 
            unit size <integer_cst 0x40021bb8 constant invariant 4> 
            align 32 context <function_decl 0x402377b4 func> chain <var_decl 
0x40237cb0 T.4>>> 
    arg 1 <eq_expr 0x40022750 type <integer_type 0x40023658 int> 
 
        arg 0 <var_decl 0x4023fef4 SR.9 type <pointer_type 0x40233d24> 
            unsigned used ignored SI file testcase_ice.cpp line 15 
            size <integer_cst 0x40232c00 constant invariant 32> 
            unit size <integer_cst 0x40232c18 constant invariant 4> 
            align 32 context <function_decl 0x402377b4 func>> 
        arg 1 <integer_cst 0x40232978 constant invariant 0>>> 
$3 = void 
 
This seems to fail already when genericizing (testcase_ice.cpp.t04.generic): 
 
;; Function void func() (_Z4funcv) 
 
void func() () 
{ 
  struct nsIURI * T.1; 
  int T.2; 
  struct nsIURI * T.3; 
  int T.4; 
  bool T.5; 
 
  { 
    struct nsCOMPtr u1; 
 
    { 
      T.1 = operator 1 (&u1); 
      T.2 = T.1 != 0B; 
      T.3 = operator 1 (&u1); 
      T.4 = T.3 == 0B; 
      T.5 = T.2 ^ T.4; 
      if (T.5) 
        { 
          { 
            return; 
          } 
        } 
      else 
        { 
 
        } 
    } 
  } 
} 
 
Note how T.2 is declared as an int, but used in a boolean expr.  I would say 
it should have been declared as a bool from the start... 
 
Comment 8 Brian Ryner 2004-01-20 08:51:17 UTC
This testcase no longer fails for me with a build from 20040120.  Can someone
else confirm this?
Comment 9 Brian Ryner 2004-01-20 09:32:52 UTC
However, I believe I've found a new way to demonstrate this same crash.
Comment 10 Brian Ryner 2004-01-20 09:35:46 UTC
Created attachment 5530 [details]
second reduced testcase

$ c++ -v
Reading specs from /usr/gcc-ssa/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/specs
Configured with: ../gcc/configure --prefix=/usr/gcc-ssa --enable-shared
--enable-threads=posix --disable-checking --with-system-zlib
--enable-__cxa_atexit --enable-languages=c,c++ --host=i686-pc-linux-gnu
Thread model: posix
gcc version 3.5-tree-ssa 20040120 (merged 20040102)

$ c++ -Os -c -o testcase_equal_ice.o testcase_equal_ice.cpp
testcase_equal_ice.cpp: In function `int f()':
testcase_equal_ice.cpp:5: internal compiler error: in invert_truthvalue, at
fold-const.c:2553

Note that this happens only with optimization enabled, as before, and also only
happens when the source file is compiled as C++ (it is fine as C).
Comment 11 Andrew Pinski 2004-01-20 15:55:05 UTC
Reconfirmed with the new test case.
Comment 12 Andrew Pinski 2004-02-29 01:25:27 UTC
Actually it is fold which is causing this bug.
fold is changing:
<ne_expr 0x4169a5c4
    type <boolean_type 0x4169bba0 bool unsigned SI
        size <integer_cst 0x41698360 constant invariant 32>
        unit size <integer_cst 0x41698400 constant invariant 4>
        align 32 symtab 0 alias set -1 precision 1 min <integer_cst 0x416985c0 0> max <
integer_cst 0x41698600 1>>
   
    arg 0 <eq_expr 0x4169a534
        type <integer_type 0x4169b8b8 int SI size <integer_cst 0x41698360 32> unit size <
integer_cst 0x41698400 4>
            align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0x416983c0 -
2147483648> max <integer_cst 0x416983e0 2147483647>
            pointer_to_this <pointer_type 0x416a77c0>>
       
        arg 0 <var_decl 0x4176083c a type <integer_type 0x4169b8b8 int>
            asm_written used public static tree_1 SI file pr13066.cc line 3 size <integer_cst 
0x41698360 32> unit size <integer_cst 0x41698400 4>
            align 32
            (mem/f:SI (symbol_ref:SI ("!D__a") [flags 0x2] <var_decl 0x4176083c a>) [0 a+0 
S4 A32]) chain <var_decl 0x417607c0 c>>
        arg 1 <integer_cst 0x416adc60 constant invariant 0>>
    arg 1 <truth_orif_expr 0x4169a558 type <integer_type 0x4169b8b8 int>
       
        arg 0 <ne_expr 0x4169a57c type <integer_type 0x4169b8b8 int>
            arg 0 <var_decl 0x417608b8 b>
            arg 1 <integer_cst 0x41698ae0 constant invariant 0>>
        arg 1 <eq_expr 0x4169a5a0 type <integer_type 0x4169b8b8 int>
            arg 0 <var_decl 0x41760744 g> arg 1 <var_decl 0x417607c0 c>>>>
into the expression invoving the TRUTH_XOR_EXPR which is wrong as the type of arg1 
is an integer_type at this point.
Comment 13 Andrew Pinski 2004-02-29 01:39:13 UTC
Mine, I have a fix.
Comment 14 Andrew Pinski 2004-02-29 02:11:24 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-02/msg02731.html>.
Comment 15 GCC Commits 2004-03-01 19:18:50 UTC
Subject: Bug 13066

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	tree-ssa-20020619-branch
Changes by:	pinskia@gcc.gnu.org	2004-03-01 19:18:47

Modified files:
	gcc            : ChangeLog.tree-ssa fold-const.c 

Log message:
	2004-03-01  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR middle-end/13066
	* fold-const (fold): Call fold_convert when building
	a TRUTH_*_EXPR tree.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.tree-ssa.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.1.2.1244&r2=1.1.2.1245
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.213.2.75&r2=1.213.2.76

Comment 16 Andrew Pinski 2004-03-01 19:21:02 UTC
Fixed by my patch.