[hjl@gnu-psc gcc]$ ./xgcc -B./ -S /tmp/foo.c -O2 /tmp/foo.c:8: internal compiler error: Aborted Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. [hjl@gnu-psc gcc]$ cat /tmp/foo.c extern __inline int foo (const char *__s, char __reject) { return __builtin_strchr (__s, __reject) != ((void *)0); } extern char *bar (__const char *__s, int __c); extern __typeof (bar) strchr __asm__ ("bar"); [hjl@gnu-psc gcc]$ ./xgcc -B./ -S /tmp/foo.c -O2 /tmp/foo.c:8: internal compiler error: Aborted Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Stack backtrace Breakpoint 3, 0xb76cd245 in abort () from /lib/tls/libc.so.6 (gdb) bt #0 0xb76cd245 in abort () from /lib/tls/libc.so.6 #1 0x08384498 in htab_clear_slot (htab=0xb73ed580, slot=0x0) at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/libiberty/hashtab.c:595 During symbol reading, Incomplete CFI data; unspecified registers at 0x08384493.During symbol reading, Incomplete CFI data; unspecified registers at 0x08384493.During symbol reading, Incomplete CFI data; unspecified registers at 0x08384493.During symbol reading, Incomplete CFI data; unspecified registers at 0x08384493.During symbol reading, Incomplete CFI data; unspecified registers at 0x08384493.#2 0x0831c671 in cgraph_remove_node (node=0xb73ef5e8) at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/cgraph.c:245 During symbol reading, Incomplete CFI data; unspecified registers at 0x0831c655.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831c655.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831c655.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831c655.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831c655.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831c655.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831c655.#3 0x0831e5cc in cgraph_remove_unreachable_nodes () at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/cgraphunit.c:876 During symbol reading, Incomplete CFI data; unspecified registers at 0x0831e5a0.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831e5a0.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831e5a0.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831e5a0.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831e5a0.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831e5a0.During symbol reading, Incomplete CFI data; unspecified registers at 0x0831e5a0.#4 0x0831f8c5 in cgraph_decide_inlining () at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/cgraphunit.c:1402 During symbol reading, Incomplete CFI data; unspecified registers at 0x0831f8f4.#5 0x0831fe9e in cgraph_optimize () at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/cgraphunit.c:1595 #6 0x080951c3 in c_objc_common_finish_file () at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/c-objc-common.c:245 #7 0x08050513 in finish_file () at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/c-lang.c:185 #8 0x0808c87f in c_common_parse_file (set_yydebug=0) at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/c-opts.c:1242 #9 0x082d91fb in compile_file () at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/toplev.c:1822 #10 0x082dd833 in do_compile () at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/toplev.c:4650 #11 0x082dd8c8 in toplev_main (argc=13, argv=0xbfffb2f4) at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/toplev.c:4690 ---Type <return> to continue, or q <return> to quit--- #12 0x080a94aa in main (argc=13, argv=0xbfffb2f4) at /net/gnu/export/gnu/src/gcc-3.4-import/gcc/gcc/main.c:35 (gdb)
It looks like this patch http://gcc.gnu.org/ml/gcc-patches/2004-01/msg01854.html may be the cause.
I should note that version.c never was able to compile with 3.4.0 either, see PR 15702 which I can confirm in a released version of 3.4.0.
*** Bug 15702 has been marked as a duplicate of this bug. ***
Oh, I must have messed up when testing it for 3.4.0 because I can confirm this in 3.4.0 so it was is not related to that patch at all.
*** Bug 15728 has been marked as a duplicate of this bug. ***
The real fixes are http://gcc.gnu.org/ml/gcc-patches/2004-05/msg01096.html and the related patches. The problem is stated in Zack's post, "using DECL_ASSEMBLER_NAME for a key in cgraph." It doesn't work with the testcase. Should we backport Zack's patch to 3.4?
Created attachment 6431 [details] A patch to avoid crash If we don't want to backport Zack's patch, this patch will avoid gcc crash.
I will note you will need the following followup patches by me if we go the route of Zack's patch: http://gcc.gnu.org/ml/gcc-patches/2004-05/msg01904.html http://gcc.gnu.org/ml/gcc-patches/2004-05/msg01600.html http://gcc.gnu.org/ml/gcc-patches/2004-05/msg01263.html And one more for i686 which I cannot find at this moment.
Subject: Re: [3.4 regression] [unit-at-a-time] Gcc abort on valid code I do not think it is safe to backport my patches to 3.4. We would have to bring in the entire c-decl.c rewrite for it to work at all, and we haven't finished flushing out all the bugs it exposed. I cannot evaluate the patch attached to this bug. As usual you have forgotten to explain in detail what is going wrong and why the patch helps. Also, embedding a test case in the buggy source file does not help. Put it in the test suite where it belongs, and just mention the PR number in the comments. zw
The problem is "using DECL_ASSEMBLER_NAME for a key in cgraph." DECL_ASSEMBLER_NAME can change after a node is inserted, as it is shown in the testcase. When it happens, htab_find_slot_with_hash is called with a different hash value than the one was used in cgraph_node when the node was added. As the result, htab_find_slot_with_hash returns NULL and htab_clear_slot aborts.
Subject: Re: [3.4 regression] [unit-at-a-time] Gcc abort on valid code Could you please be more specific? zw
Starting program: /export/build/gnu/gcc-3.4/build-pentium4-linux/gcc/cc1 - fpreprocessed foo.i -quiet -dumpbase foo.i -mtune=pentiumpro -auxbase foo -O2 - version -o foo.s GNU C version 3.4.1 20040529 (prerelease) (i686-pc-linux-gnu) compiled by GNU C version 3.4.1 20040529 (prerelease). GGC heuristics: --param ggc-min-expand=63 --param ggc-min-heapsize=62888 Breakpoint 1, cgraph_node (decl=0xb766dd80) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/cgraph.c:101 101 if (TREE_CODE (decl) != FUNCTION_DECL) <function_decl 0xb766dd80 __builtin_strchr type <function_type 0xb766b948 type <pointer_type 0xb76a3ec4 type <integer_type 0xb769c360 char> unsigned SI size <integer_cst 0xb769a7d0 constant 32> unit size <integer_cst 0xb769a820 constant 4> align 32 symtab 0 alias set -1> DI size <integer_cst 0xb769a5a0 constant 64> unit size <integer_cst 0xb769a794 constant 8> align 64 symtab 0 alias set -1 attributes <tree_list 0xb7668c58 purpose <identifier_node 0xb76873c0 nonnull> value <tree_list 0xb768b780 value <integer_cst 0xb768b76c constant 1>>> arg-types <tree_list 0xb7684b18 value <pointer_type 0xb7686bd0> chain <tree_list 0xb7684b04 value <integer_type 0xb769c4a4 int> chain <tree_list 0xb768467c value <void_type 0xb76a3870 void>>>> pointer_to_this <pointer_type 0xb75f057c>> used nothrow public external built-in QI file <internal> line 0 built-in BUILT_IN_NORMAL:BUILT_IN_STRCHR context <translation_unit_decl 0xb769c144> attributes <tree_list 0xb766e0b4> (mem:QI (symbol_ref:SI ("strchr") [flags 0x41] <function_decl 0xb766dd80 __builtin_strchr>) [0 S1 A8]) chain <function_decl 0xb766de58 strchr>> (gdb) bt #0 cgraph_node (decl=0xb766dd80) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/cgraph.c:101 #1 0x082a6d48 in cgraph_rtl_info (decl=0xb766dd80) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/cgraph.c:364 #2 0x080a9468 in flags_from_decl_or_type (exp=0xb766dd80) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/calls.c:706 #3 0x080a94ee in call_expr_flags (t=0xb76a12b8) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/calls.c:763 #4 0x08272012 in build (code=CALL_EXPR, tt=0x1e) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/tree.c:2391 #5 0x0806865a in build_function_call (function=0xb7657e4c, params=0xb7657e24) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/c-typeck.c:1762 #6 0x0804c0b6 in yyparse () at c-parse.y:642 #7 0x0804f9bb in c_parse_file () at c-parse.y:3028 #8 0x0807e969 in c_common_parse_file (set_yydebug=30) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/c-opts.c:1237 #9 0x0826eaad in toplev_main (argc=30, argv=0xbfffdcbc) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/toplev.c:1822 #10 0x0809821e in main (argc=30, argv=0x1e) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/main.c:35 (gdb) call decl_assembler_name (decl) $1 = (union tree_node *) 0xb766c880 (gdb) call debug_tree(0xb766c880) <identifier_node 0xb766c880 strchr symbol <function_decl 0xb766de58 strchr type <function_type 0xb766b948 type <pointer_type 0xb76a3ec4> DI size <integer_cst 0xb769a5a0 constant 64> unit size <integer_cst 0xb769a794 constant 8> align 64 symtab 0 alias set -1 attributes <tree_list 0xb7668c58 purpose <identifier_node 0xb76873c0 nonnull> value <tree_list 0xb768b780 value <integer_cst 0xb768b76c constant 1>>> arg-types <tree_list 0xb7684b18 value <pointer_type 0xb7686bd0> chain <tree_list 0xb7684b04 value <integer_type 0xb769c4a4 int> chain <tree_list 0xb768467c value <void_type 0xb76a3870 void>>>> pointer_to_this <pointer_type 0xb75f057c>> nothrow public external built-in decl_3 QI file <internal> line 0 built-in BUILT_IN_NORMAL:BUILT_IN_STRCHR context <translation_unit_decl 0xb769c144> attributes <tree_list 0xb766e0f0> (mem:QI (symbol_ref:SI ("strchr") [flags 0x41] <function_decl 0xb766de58 strchr>) [0 S1 A8]) chain <function_decl 0xb766df30 __builtin_strcmp type <function_type 0xb767006c> nothrow public external built-in QI file <internal> line 0 built-in BUILT_IN_NORMAL:BUILT_IN_STRCMP context <translation_unit_decl 0xb769c144> attributes <tree_list 0xb766e140> (mem:QI (symbol_ref:SI ("strcmp") [flags 0x41] <function_decl 0xb766df30 __builtin_strcmp>) [0 S1 A8]) chain <function_decl 0xb76700d8 strcmp>>>> (gdb) c Continuing. Breakpoint 2, cgraph_remove_node (node=0xb75f05e8) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/cgraph.c:218 218 cgraph_remove_edge (node->callers->caller, node); <function_decl 0xb766dd80 __builtin_strchr type <function_type 0xb766b948 type <pointer_type 0xb76a3ec4 type <integer_type 0xb769c360 char> unsigned SI size <integer_cst 0xb769a7d0 constant 32> unit size <integer_cst 0xb769a820 constant 4> align 32 symtab 0 alias set -1> DI size <integer_cst 0xb769a5a0 constant 64> unit size <integer_cst 0xb769a794 constant 8> align 64 symtab 0 alias set -1 attributes <tree_list 0xb7668c58 purpose <identifier_node 0xb76873c0 nonnull> value <tree_list 0xb768b780 value <integer_cst 0xb768b76c constant 1>>> arg-types <tree_list 0xb7684b18 value <pointer_type 0xb7686bd0> chain <tree_list 0xb7684b04 value <integer_type 0xb769c4a4 int> chain <tree_list 0xb768467c value <void_type 0xb76a3870 void>>>> pointer_to_this <pointer_type 0xb75f057c>> used nothrow public external built-in QI file <internal> line 0 built-in BUILT_IN_NORMAL:BUILT_IN_STRCHR context <translation_unit_decl 0xb769c144> attributes <tree_list 0xb766e0b4> chain <function_decl 0xb766de58 strchr>> (gdb) bt #0 cgraph_remove_node (node=0xb75f05e8) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/cgraph.c:218 #1 0x082a8f38 in cgraph_optimize () at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/cgraphunit.c:892 #2 0x08086374 in c_objc_common_finish_file () at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/c-objc-common.c:245 #3 0x0826eaad in toplev_main (argc=0, argv=0xbffffcbc) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/toplev.c:1822 #4 0x0809821e in main (argc=0, argv=0x0) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/main.c:35 (gdb) call decl_assembler_name (node->decl) $2 = (union tree_node *) 0xb75ee680 (gdb) call debug_tree(0xb75ee680) <identifier_node 0xb75ee680 *bar> (gdb) next 220 cgraph_remove_edge (node, node->callees->callee); (gdb) 222 cgraph_remove_node (node->nested); (gdb) 223 if (node->origin) (gdb) 231 if (node->previous) (gdb) 234 cgraph_nodes = node->next; (gdb) 235 if (node->next) (gdb) 237 DECL_SAVED_TREE (node->decl) = NULL; (gdb) 238 DECL_SAVED_INSNS (node->decl) = NULL; (gdb) 239 DECL_ARGUMENTS (node->decl) = NULL; (gdb) 240 DECL_INITIAL (node->decl) = error_mark_node; (gdb) 241 slot = (gdb) 245 if (slot == 0) (gdb) p slot $3 = (void **) 0x0 (gdb)
Subject: Re: [3.4 regression] [unit-at-a-time] Gcc abort on valid code That's a nice debugging session; now please explain in detail what it means. Please do not assume that I know anything. zw
IDENTIFIER_HASH_VALUE (DECL_ASSEMBLER_NAME (decl)) is used to compute hash value and DECL_ASSEMBLER_NAME is defined as #define DECL_ASSEMBLER_NAME(NODE) decl_assembler_name (NODE) When DECL 0xb766dd80 is added in cgraph_node, its DECL_ASSEMBLER_NAME is 0xb766c880. But when it is removed in cgraph_remove_node, its DECL_ASSEMBLER_NAME is 0xb75ee680. They have different hash values. It is due to extern __typeof (bar) strchr __asm__ ("bar"); As the result, cgraph_remove_node can't find the slot since the wrong hash value is used.
I see how it's going off the rails now. Next two questions: Why do __builtin_strchr and strchr have the same DECL node? Why does __builtin_strchr have its DECL_ASSEMBLER_NAME instantiated to begin with?
#0 builtin_function (name=0x830cff0 "__builtin_strchr", type=0x282, function_code=-1217995392, class=BUILT_IN_NORMAL, library_name=0x830cffa "strchr", attrs=0xb768b960) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/c-decl.c:2306 #1 0x0806d4ef in builtin_function_2 (builtin_name=0x0, name=0x830cffa "strchr", builtin_type=0xb766dd80, type=0xb766dd80, function_code=297, class=BUILT_IN_NORMAL, library_name_p=1, nonansi_p=0, attrs=0xb768b960) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/c-common.c:3535 #2 0x0807830e in c_common_nodes_and_builtins () at builtins.def:448 #3 0x08056b59 in c_init_decl_processing () at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/c-decl.c:2220 #4 0x080861d9 in c_objc_common_init () at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/c-objc-common.c:164 #5 0x0826e9c9 in toplev_main (argc=3076971904, argv=0x0) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/toplev.c:4527 #6 0x0809821e in main (argc=-1217995392, argv=0xb766dd80) at /net/gnu/export/gnu/src/gcc-3.4/gcc/gcc/main.c:35 /* Return a definition for a builtin function named NAME and whose data type is TYPE. TYPE should be a function type with argument types. FUNCTION_CODE tells later passes how to compile calls to this function. See tree.h for its possible values. If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, the name to be called if we can't opencode the function. If ATTRS is nonzero, use that for the function's attribute list. */ tree builtin_function (const char *name, tree type, int function_code, enum built_in_class class, const char *library_name, tree attrs) { tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type); DECL_EXTERNAL (decl) = 1; TREE_PUBLIC (decl) = 1; if (library_name) SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
*sigh* How many times must I say this? Don't just quote code or debugging sessions at me. Explain. In detail. Don't assume I know anything.
From what I can tell, __builtin_strchr has strchr as its DECL_ASSEMBLER_NAME and it is done on purpose. I don't know why it has to be done that way.
Subject: Re: [3.4 regression] [unit-at-a-time] Gcc abort on valid code Oh, I see now. If the optimization fails, we fall back on a normal call to __builtin_strchr ... which would fail to link if its DECL_ASSEMBLER_NAME weren't "strchr". So based on that I think your patch is correct, but you should move the test case into the testsuite where it belongs. zw
A testcase patch is posted at http://gcc.gnu.org/ml/gcc-patches/2004-05/msg02090.html A patch is posted at http://gcc.gnu.org/ml/gcc-patches/2004-05/msg02091.html
Subject: Re: [3.4 regression] [unit-at-a-time] Gcc abort on valid code "zack at codesourcery dot com" <gcc-bugzilla@gcc.gnu.org> writes: | Oh, I see now. If the optimization fails, we fall back on a normal | call to __builtin_strchr ... which would fail to link if its | DECL_ASSEMBLER_NAME weren't "strchr". Yes, that is the documented behaviour of all "library" built-ins __builtin_xxx, which fall back to xxx. Unrelated to this PR, I'm of the strong opinion that they should fall back to something like __xxx, allowing other front-ends to get around specific namespace requirements. -- Gaby
This patch and associated testcase are OK for 3.4.1 *only*.
Subject: Bug 15666 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: hjl@gcc.gnu.org 2004-05-31 23:42:27 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.c-torture/compile: 20040531-1.c Log message: 2004-05-31 H.J. Lu <hongjiu.lu@intel.com> PR middle-end/15666 * gcc.c-torture/compile/20040531-1.c: New file. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.192&r2=1.3389.2.193 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/20040531-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
Subject: Bug 15666 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: hjl@gcc.gnu.org 2004-05-31 23:43:54 Modified files: gcc : ChangeLog cgraph.c Log message: 2004-05-31 H.J. Lu <hongjiu.lu@intel.com> PR middle-end/15666 * cgraph.c (cgraph_remove_node): Don't call htab_clear_slot if we can't find the slot. Abort if we can't find slot and the node isn't for a builtin function. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.460&r2=2.2326.2.461 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cgraph.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.41.2.4&r2=1.41.2.5
Created attachment 6443 [details] Actual fix for the problem. This patch actually fixes the problem, as opposed to papering over it. I suppose it would be fine to keep the abort() for slot == 0, but I don't think we should just disregard the error for builtins. If we can't find the node, it means we have an entry in the hash table that shouldn't be there, and that's a bug.
*** Bug 15762 has been marked as a duplicate of this bug. ***
Subject: Re: [3.4 regression] [unit-at-a-time] Gcc abort on valid code aoliva at gcc dot gnu dot org wrote: > ------- Additional Comments From aoliva at gcc dot gnu dot org 2004-06-01 04:06 ------- > Created an attachment (id=6443) > --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=6443&action=view) > Actual fix for the problem. I think we can live with the papering-over patch for 3.4 -- but thank you for preparing a cleaner alternative.
Fixed.
*** Bug 15691 has been marked as a duplicate of this bug. ***
Subject: Bug 15666 CVSROOT: /cvs/gcc Module name: gcc Changes by: aoliva@gcc.gnu.org 2004-06-07 19:06:33 Modified files: gcc : ChangeLog c-decl.c Log message: PR middle-end/15666 * c-decl.c (finish_decl): Use change_decl_assembler_name for the builtin decl as well. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3864&r2=2.3865 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.505&r2=1.506