Also posted to the GCC mailing list:
http://gcc.gnu.org/ml/gcc/2005-10/msg00932.html
http://gcc.gnu.org/ml/gcc/2005-10/msg00938.html
While working with GCC's language hooks, we found that
certain places in GCC test for a null value of
lang_hooks.callgraph.expand_function, but
cgraph_expand_function() calls the hook directly:
In cgraphunit.c:
/* Expand function specified by NODE. */
static void
cgraph_expand_function (struct cgraph_node *node)
{
tree decl = node->decl;
/* We ought to not compile any inline clones. */
gcc_assert (!node->global.inlined_to);
if (flag_unit_at_a_time)
announce_function (decl);
cgraph_lower_function (node);
/* Generate RTL for the body of DECL. */
lang_hooks.callgraph.expand_function (decl);
------------
In toplev.c:
/* Disable unit-at-a-time mode for frontends not supporting callgraph
interface. */
if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
flag_unit_at_a_time = 0;
------------
In function.c:
/* Possibly warn about unused parameters.
When frontend does unit-at-a-time, the warning is already
issued at finalization time. */
if (warn_unused_parameter
&& !lang_hooks.callgraph.expand_function)
do_warn_unused_parameter (current_function_decl);
------------
We tried setting lang_hooks.callgraph.expand_function to NULL:
/* For now, disable unit-at-a-time by setting expand_function to NULL */
#undef LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION
#define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION NULL
which has the desired effect of disabling unit-at-a-time, but
runs aground in cgraph_expand_function() with a segfault,
when it attempts to call lang_hooks.callgraph.expand_function().
It seems that GCC is handling lang_hooks.callgraph.expand_function
in an inconsistent fashion. Is a null value for expand_function
meaningful? If it is, then what is the fix for cgraph_expand_function()?
----
In a follow-up note on the GCC list, Dueway Qi notes:
I have found another similar case.
lang_hooks.callgraph.analyze_expr in gcc/gcc/cgraphunit.c
490 if (lang_hooks.callgraph.analyze_expr)
491 return lang_hooks.callgraph.analyze_expr (tp,
walk_subtrees,
492 data);
but in another part of this file
517 if ((unsigned int) TREE_CODE (t) >= LAST_AND_UNUSED_TREE_CODE)
518 return lang_hooks.callgraph.analyze_expr (tp,
walk_subtrees, data);
--
Summary: inconsistent handling of null-valued language hooks in
GCC
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gary at intrepid dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24540