This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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);
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]