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]

Re: PATCH: Correct alloca length in dump_gimple_bb_header


On Mon, Oct 29, 2012 at 6:01 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Oct 29, 2012 at 5:18 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>> On Mon, Oct 29, 2012 at 05:06:01AM -0700, H.J. Lu wrote:
>>> When indent == 0, we call alloca with -1 bytes.  This patch changes
>>> it to indent + 1.  This is a trunk only regression.  OK to install?
>>
>>> 2012-10-29  H.J. Lu  <hongjiu.lu@intel.com>
>>>
>>>       * gimple-pretty-print.c (dump_gimple_bb_header): Correct alloca
>>>       length.
>>>
>>> diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
>>> index 4b3235e..62c315e 100644
>>> --- a/gcc/gimple-pretty-print.c
>>> +++ b/gcc/gimple-pretty-print.c
>>> @@ -2093,7 +2093,7 @@ dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
>>>        gimple stmt = first_stmt (bb);
>>>        if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
>>>       {
>>> -       char *s_indent = (char *) alloca ((size_t) indent - 2 + 1);
>>> +       char *s_indent = (char *) alloca ((size_t) indent + 1);
>>>         memset (s_indent, ' ', (size_t) indent);
>>>         s_indent[indent] = '\0';
>>>         fprintf (outf, "%s<bb %d>:\n", s_indent, bb->index);
>>
>> Can't you instead of all this just do
>>   fprintf (outf, "%*s<bb %d>:\n", indent, "", bb->index);
>> ?
>>
>
> The whole function has another:
>
>          char *s_indent = (char *) alloca ((size_t) indent + 1);
>           memset (s_indent, ' ', (size_t) indent);
>           s_indent[indent] = '\0';
>
> We should make the same switch for both.

Tested on Lnux/x8-64.  OK to install?

-- 
H.J.
---2012-10-30  H.J. Lu  <hongjiu.lu@intel.com>

	* gimple-pretty-print.c (dump_gimple_bb_header): Avoid alloca.

diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index 4b3235e..a5a493a 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -2068,9 +2068,6 @@ dump_gimple_bb_header (FILE *outf, basic_block
bb, int indent, int flags)
       if (flags & TDF_LINENO)
 	{
 	  gimple_stmt_iterator gsi;
-	  char *s_indent = (char *) alloca ((size_t) indent + 1);
-	  memset (s_indent, ' ', (size_t) indent);
-	  s_indent[indent] = '\0';

 	  if (flags & TDF_COMMENT)
 	    fputs (";; ", outf);
@@ -2079,8 +2076,8 @@ dump_gimple_bb_header (FILE *outf, basic_block
bb, int indent, int flags)
 	    if (!is_gimple_debug (gsi_stmt (gsi))
 		&& get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
 	      {
-		fprintf (outf, "%sstarting at line %d",
-			 s_indent, get_lineno (gsi_stmt (gsi)));
+		fprintf (outf, "%*sstarting at line %d",
+			 indent, "", get_lineno (gsi_stmt (gsi)));
 		break;
 	      }
 	  if (bb->discriminator)
@@ -2092,12 +2089,7 @@ dump_gimple_bb_header (FILE *outf, basic_block
bb, int indent, int flags)
     {
       gimple stmt = first_stmt (bb);
       if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
-	{
-	  char *s_indent = (char *) alloca ((size_t) indent - 2 + 1);
-	  memset (s_indent, ' ', (size_t) indent);
-	  s_indent[indent] = '\0';
-	  fprintf (outf, "%s<bb %d>:\n", s_indent, bb->index);
-	}
+	fprintf (outf, "%*s<bb %d>:\n", indent, "", bb->index);
     }
 }


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