This is the mail archive of the gcc@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] Do not warn with warn_unused_result for alloca(0).


On Wed, Jun 12, 2019 at 01:30:14PM +0200, Martin Liška wrote:
> @@ -9447,10 +9448,19 @@ 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);
> +		{
> +		  /* Some C libraries use alloca(0) in order to free previously
> +		     allocated memory by alloca calls.  */
> +		  if (gimple_maybe_alloca_call_p (g)
> +		      && gimple_call_num_args (g) == 1
> +		      && integer_zerop (gimple_call_arg (g, 0)))
> +		    ;
> +		  else

Wouldn't it be easier to negate the condition and avoid the weird ; else ?
I.e. if (!gimple_maybe... || gimple_call_num != 1 || !integer_zerop?

> +		    warning_at (loc, OPT_Wunused_result,
> +				"ignoring return value of %qD declared "
> +				"with attribute %<warn_unused_result%>",
> +				fdecl);
> +		}
>  	      else
>  		warning_at (loc, OPT_Wunused_result,
>  			    "ignoring return value of function "

Otherwise LGTM as the patch, but I'd like to hear from others whether
it is kosher to add such a special case to the warn_unused_result attribute
warning.  And if the agreement is yes, I think it should be documented
somewhere that alloca (0) will not warn even when the call has such an
attribute (probably in the description of warn_unused_result attribute).

	Jakub


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