[PATCH] Do not warn with warn_unused_result for alloca(0).

Martin Liška mliska@suse.cz
Wed Jun 12 11:30:00 GMT 2019


On 6/12/19 1:22 PM, Jakub Jelinek wrote:
> On Wed, Jun 12, 2019 at 01:11:09PM +0200, Martin Liška wrote:
>> 2019-06-12  Martin Liska  <mliska@suse.cz>
>>
>> 	* calls.c (special_function_p): Make it global.
>> 	* calls.h (special_function_p): Declare.
> 
> Why?

Not needed any longer.

> 
>> 	* tree-cfg.c (do_warn_unused_result): Do not
>> 	warn for alloca(0).
>> --- a/gcc/tree-cfg.c
>> +++ b/gcc/tree-cfg.c
>> @@ -63,6 +63,7 @@ along with GCC; see the file COPYING3.  If not see
>>  #include "opts.h"
>>  #include "asan.h"
>>  #include "profile.h"
>> +#include "calls.h"
>>  
>>  /* This file contains functions for building the Control Flow Graph (CFG)
>>     for a function tree.  */
>> @@ -9447,10 +9448,17 @@ do_warn_unused_result (gimple_seq seq)
>>  	      location_t loc = gimple_location (g);
>>  
>>  	      if (fdecl)
>> -		warning_at (loc, OPT_Wunused_result,
>> -			    "ignoring return value of %qD "
>> -			    "declared with attribute %<warn_unused_result%>",
>> -			    fdecl);
>> +		{
>> +		  if ((special_function_p (fdecl, 0) & ECF_MAY_BE_ALLOCA)
> 
> Why not instead gimple_maybe_alloca_call_p (g) ?

Because I was not aware of the function ;)

> On the other side, you want && gimple_call_num_args (g) == 1,

Sure.

> if some alloca call had wrong declaration, you might ICE otherwise.
> 
>> +		      && TREE_CODE (gimple_call_arg (g, 0)) == INTEGER_CST
>> +		      && wi::to_wide (gimple_call_arg (g, 0)) == 0)
> 
> && integer_zerop (gimple_call_arg (g, 0))
> 
> instead?

Yep.

> 
> Plus you need a comment explaining why we don't warn about alloca with
> constant 0 argument.

Also done.

Is it fine now?
Martin

> 
> 	Jakub
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Do-not-warn-with-warn_unused_result-for-alloca-0.patch
Type: text/x-patch
Size: 3571 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190612/d4cb7696/attachment.bin>


More information about the Gcc-patches mailing list