This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: Robustify current_function_name()
- From: Nick Clifton <nickc at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 28 Sep 2009 10:55:46 +0100
- Subject: RFA: Robustify current_function_name()
Hi Guys,
I would like to apply the small patch below to prevent
current_function_name from generating a seg-fault if there is no
current function. I ran into this behaviour whilst using GDB to
debug a problem and naively invoking current_function_name when
actually no function was being compiled.
Tested without regressions on an i686-pc-linux-gnu bootstrap.
OK to apply ?
Cheers
Nick
gcc/ChangeLog
2009-09-28 Nick Clifton <nickc@redhat.com>
* function.c (current_function_name): If there is no current
function just return "<none>".
Index: gcc/function.c
===================================================================
--- gcc/function.c (revision 152230)
+++ gcc/function.c (working copy)
@@ -5415,6 +5415,8 @@
const char *
current_function_name (void)
{
+ if (cfun == NULL)
+ return "<none>";
return lang_hooks.decl_printable_name (cfun->decl, 2);
}