> On Feb 17, 2023, at 5:35 PM, Jakub Jelinek <ja...@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 via email to