public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix glitch in -fstack-usage output
@ 2013-09-06 15:28 Eric Botcazou
  0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2013-09-06 15:28 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 622 bytes --]

The output of -fstack-usage doesn't use fully qualified names of functions 
(because they can be quite long in Ada) so the code attempts to strip the 
scope prefix.  But this isn't robust enough in presence of suffixes created by 
the compiler, for example by the cloning machinery.

Tested on x86_64-suse-linux, applied on the mainline as obvious.


2013-09-06  Eric Botcazou  <ebotcazou@adacore.com>

	* toplev.c (output_stack_usage): Be prepared for suffixes created by
	the compiler in the function names.


2013-09-06  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/stack_usage2.adb: New test.


-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 1457 bytes --]

Index: toplev.c
===================================================================
--- toplev.c	(revision 202160)
+++ toplev.c	(working copy)
@@ -1017,22 +1017,35 @@ output_stack_usage (void)
     {
       expanded_location loc
 	= expand_location (DECL_SOURCE_LOCATION (current_function_decl));
-      const char *raw_id, *id;
-
-      /* Strip the scope prefix if any.  */
-      raw_id = lang_hooks.decl_printable_name (current_function_decl, 2);
-      id = strrchr (raw_id, '.');
-      if (id)
-	id++;
+      /* We don't want to print the full qualified name because it can be long,
+	 so we strip the scope prefix, but we may need to deal with the suffix
+	 created by the compiler.  */
+      const char *suffix
+	= strchr (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), '.');
+      const char *name
+	= lang_hooks.decl_printable_name (current_function_decl, 2);
+      if (suffix)
+	{
+	  const char *dot = strchr (name, '.');
+	  while (dot && strcasecmp (dot, suffix) != 0)
+	    {
+	      name = dot + 1;
+	      dot = strchr (name, '.');
+	    }
+	}
       else
-	id = raw_id;
+	{
+	  const char *dot = strrchr (name, '.');
+	  if (dot)
+	    name = dot + 1;
+	}
 
       fprintf (stack_usage_file,
 	       "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
 	       lbasename (loc.file),
 	       loc.line,
 	       loc.column,
-	       id,
+	       name,
 	       stack_usage,
 	       stack_usage_kind_str[stack_usage_kind]);
     }

[-- Attachment #3: stack_usage2.adb --]
[-- Type: text/x-adasrc, Size: 526 bytes --]

-- { dg-do compile }
-- { dg-options "-O2 -fstack-usage" }

with System;

procedure Stack_Usage2 is

   Sink : System.Address;
   pragma Import (Ada, Sink);

   procedure Transmit_Data (Branch : Integer) is
      pragma No_Inline (Transmit_Data);
      X : Integer;
   begin
      case Branch is
         when 1 => Sink := X'Address;
         when others => null;
      end case;
   end;

begin
   Transmit_Data (Branch => 1);
end;

-- { dg-final { scan-stack-usage-not ":Constprop" } }
-- { dg-final { cleanup-stack-usage } }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-09-06 15:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-06 15:28 Fix glitch in -fstack-usage output Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).