public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Qing Zhao <qing.zhao@oracle.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "rguenther@suse.de" <rguenther@suse.de>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fixing PR107411
Date: Mon, 20 Feb 2023 15:04:51 +0000	[thread overview]
Message-ID: <AF2B089C-E35F-4465-84B1-78EBE6715AC5@oracle.com> (raw)
In-Reply-To: <Y/ABKvWRVJzcELvj@tucnak>



> On Feb 17, 2023, at 5:35 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> 
> On Fri, Feb 17, 2023 at 10:26:03PM +0000, Qing Zhao via Gcc-patches wrote:
>> +	      else if (!DECL_NAME (lhs_var))
>> +		{
>> +		  char *lhs_var_name_str
>> +		    = xasprintf ("D.%u", DECL_UID (lhs_var));
> 
> Why xasprintf?

Just emulated the code in “gimple_add_init_for_auto_var” without thinking too much. -:)
>  D.%u can be sprintfed into a fixed size automatic buffer,
> say 3 + (HOST_BITS_PER_INT + 2) / 3 would be a good upper bound for the size
> of the buffer.  Then you don't need to free it...

xasprintf is "like a sprintf but provided a pointer to malloc’d storage (without fail)”. If free the pointer properly, then it should be okay, right?
In addition to “no need to free”, what other benefit to use sprintf other than xasprintf?

Qing
> 
>> +		  if (strcmp (lhs_var_name_str, var_name_str) == 0)
>> +		    {
>> +		      free (lhs_var_name_str);
>> +		      return;
>> +		    }
>> +		  free (lhs_var_name_str);
>> +		}
>> +	    }
>> 	  gcc_assert (var_name_str && var_def_stmt);
>> 	}
>>     }
>> -- 
>> 2.31.1
> 
> 	Jakub


  reply	other threads:[~2023-02-20 15:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17 22:26 Qing Zhao
2023-02-17 22:35 ` Jakub Jelinek
2023-02-20 15:04   ` Qing Zhao [this message]
2023-02-20 15:17     ` Jakub Jelinek
2023-02-20 17:45       ` Qing Zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AF2B089C-E35F-4465-84B1-78EBE6715AC5@oracle.com \
    --to=qing.zhao@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).