This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Do not warn with warn_unused_result for alloca(0).
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?
> * 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) ?
On the other side, you want && gimple_call_num_args (g) == 1,
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?
Plus you need a comment explaining why we don't warn about alloca with
constant 0 argument.
Jakub