diff mbox series

expander: Fix ICE in maybe_warn_rdwr_sizes [PR96335]

Message ID 20200728084033.GB2363@tucnak
State New
Headers show
Series expander: Fix ICE in maybe_warn_rdwr_sizes [PR96335] | expand

Commit Message

Jakub Jelinek July 28, 2020, 8:40 a.m. UTC
Hi!

The following testcase ICEs in maybe_warn_rdwr_sizes.  The problem is that
the caller uses its fndecl and fntype variables to fill up rdwr_map, and
the fntype in that case is a prototype with the access attribute and all
the checks needed for that performed.  But the maybe_warn_rdwr_sizes
function tries to rediscover fndecl/fntype itself and does it differently
from how the caller did (for fndecl get_callee_fndecl and fntype from that
FUNCTION_DECL, otherwise sets fntype to CALL_EXPR_FN's type).

On the testcase, get_callee_fndecl does find a FUNCTION_DECL because
it does STRIP_NOPS in between.

Instead of trying to rediscover those, this patch just passes them down,
like is done in several other functions.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/10.3?

2020-07-28  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/96335
	* calls.c (maybe_warn_rdwr_sizes): Add FNDECL and FNTYPE arguments,
	instead of trying to rediscover them in the body.
	(initialize_argument_information): Adjust caller.

	* gcc.dg/pr96335.c: New test.


	Jakub

Comments

Richard Biener July 28, 2020, 8:51 a.m. UTC | #1
On Tue, 28 Jul 2020, Jakub Jelinek wrote:

> Hi!
> 
> The following testcase ICEs in maybe_warn_rdwr_sizes.  The problem is that
> the caller uses its fndecl and fntype variables to fill up rdwr_map, and
> the fntype in that case is a prototype with the access attribute and all
> the checks needed for that performed.  But the maybe_warn_rdwr_sizes
> function tries to rediscover fndecl/fntype itself and does it differently
> from how the caller did (for fndecl get_callee_fndecl and fntype from that
> FUNCTION_DECL, otherwise sets fntype to CALL_EXPR_FN's type).
> 
> On the testcase, get_callee_fndecl does find a FUNCTION_DECL because
> it does STRIP_NOPS in between.
> 
> Instead of trying to rediscover those, this patch just passes them down,
> like is done in several other functions.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/10.3?

OK.

Thanks,
Richard.

> 2020-07-28  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR middle-end/96335
> 	* calls.c (maybe_warn_rdwr_sizes): Add FNDECL and FNTYPE arguments,
> 	instead of trying to rediscover them in the body.
> 	(initialize_argument_information): Adjust caller.
> 
> 	* gcc.dg/pr96335.c: New test.
> 
> --- gcc/calls.c.jj	2020-06-29 14:51:54.000000000 +0200
> +++ gcc/calls.c	2020-07-27 15:51:30.343115830 +0200
> @@ -1920,24 +1920,8 @@ append_attrname (const std::pair<int, at
>     in the function call EXP.  */
>  
>  static void
> -maybe_warn_rdwr_sizes (rdwr_map *rwm, tree exp)
> +maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp)
>  {
> -  tree fndecl = NULL_TREE;
> -  tree fntype = NULL_TREE;
> -  if (tree fnaddr = CALL_EXPR_FN (exp))
> -    {
> -      if (TREE_CODE (fnaddr) == ADDR_EXPR)
> -	{
> -	  fndecl = TREE_OPERAND (fnaddr, 0);
> -	  fntype = TREE_TYPE (fndecl);
> -	}
> -      else
> -	fntype = TREE_TYPE (TREE_TYPE (fnaddr));
> -    }
> -
> -  if (!fntype)
> -    return;
> -
>    auto_diagnostic_group adg;
>  
>    /* A string describing the attributes that the warnings issued by this
> @@ -2501,7 +2485,7 @@ initialize_argument_information (int num
>    maybe_warn_nonstring_arg (fndecl, exp);
>  
>    /* Check attribute access arguments.  */
> -  maybe_warn_rdwr_sizes (&rdwr_idx, exp);
> +  maybe_warn_rdwr_sizes (&rdwr_idx, fndecl, fntype, exp);
>  }
>  
>  /* Update ARGS_SIZE to contain the total size for the argument block.
> --- gcc/testsuite/gcc.dg/pr96335.c.jj	2020-07-27 16:07:22.707766139 +0200
> +++ gcc/testsuite/gcc.dg/pr96335.c	2020-07-27 16:07:47.624416172 +0200
> @@ -0,0 +1,12 @@
> +/* PR middle-end/96335 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +
> +void bar (int, void *) __attribute__((__access__(__read_only__, 2)));
> +
> +void
> +foo (void *x)
> +{
> +  void (*fn) () = bar;
> +  fn (0, x);
> +}
> 
> 	Jakub
> 
>
diff mbox series

Patch

--- gcc/calls.c.jj	2020-06-29 14:51:54.000000000 +0200
+++ gcc/calls.c	2020-07-27 15:51:30.343115830 +0200
@@ -1920,24 +1920,8 @@  append_attrname (const std::pair<int, at
    in the function call EXP.  */
 
 static void
-maybe_warn_rdwr_sizes (rdwr_map *rwm, tree exp)
+maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp)
 {
-  tree fndecl = NULL_TREE;
-  tree fntype = NULL_TREE;
-  if (tree fnaddr = CALL_EXPR_FN (exp))
-    {
-      if (TREE_CODE (fnaddr) == ADDR_EXPR)
-	{
-	  fndecl = TREE_OPERAND (fnaddr, 0);
-	  fntype = TREE_TYPE (fndecl);
-	}
-      else
-	fntype = TREE_TYPE (TREE_TYPE (fnaddr));
-    }
-
-  if (!fntype)
-    return;
-
   auto_diagnostic_group adg;
 
   /* A string describing the attributes that the warnings issued by this
@@ -2501,7 +2485,7 @@  initialize_argument_information (int num
   maybe_warn_nonstring_arg (fndecl, exp);
 
   /* Check attribute access arguments.  */
-  maybe_warn_rdwr_sizes (&rdwr_idx, exp);
+  maybe_warn_rdwr_sizes (&rdwr_idx, fndecl, fntype, exp);
 }
 
 /* Update ARGS_SIZE to contain the total size for the argument block.
--- gcc/testsuite/gcc.dg/pr96335.c.jj	2020-07-27 16:07:22.707766139 +0200
+++ gcc/testsuite/gcc.dg/pr96335.c	2020-07-27 16:07:47.624416172 +0200
@@ -0,0 +1,12 @@ 
+/* PR middle-end/96335 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void bar (int, void *) __attribute__((__access__(__read_only__, 2)));
+
+void
+foo (void *x)
+{
+  void (*fn) () = bar;
+  fn (0, x);
+}