Patchwork PATCH: Correct alloca length in dump_gimple_bb_header

login
register
mail settings
Submitter H.J. Lu
Date Oct. 29, 2012, 12:06 p.m.
Message ID <20121029120601.GA19039@gmail.com>
Download mbox | patch
Permalink /patch/194989/
State New
Headers show

Comments

H.J. Lu - Oct. 29, 2012, 12:06 p.m.
Hi,

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?

Thanks.


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

	* gimple-pretty-print.c (dump_gimple_bb_header): Correct alloca
	length.
Jakub Jelinek - Oct. 29, 2012, 12:18 p.m.
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);
?

	Jakub
H.J. Lu - Oct. 29, 2012, 1:01 p.m.
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.

Patch

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