[2/2] Disallow pointer and offset types on some gimple

Message ID 1623202328-13664-2-git-send-email-apinski@marvell.com
State New
Headers show
Series
  • [1/2] Fix PR 100925: Limit some a?CST1:CST2 optimizations to intergal types only
Related show

Commit Message

Jonathan Wakely via Gcc-patches June 9, 2021, 1:32 a.m.
From: Andrew Pinski <apinski@marvell.com>


While debugging PR 100925, I found that the gimple verifiers
don't reject NEGATE on pointer or offset type.
This patch adds the check on some unary and binary gimple which
should not have operated on pointer/offset types.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

gcc/ChangeLog:

	* tree-cfg.c (verify_gimple_assign_unary): Reject point and offset
	types on NEGATE_EXPR, ABS_EXPR, BIT_NOT_EXPR, PAREN_EXPR and CNONJ_EXPR.
	(verify_gimple_assign_binary): Reject point and offset types on
	MULT_EXPR, MULT_HIGHPART_EXPR, TRUNC_DIV_EXPR, CEIL_DIV_EXPR,
	FLOOR_DIV_EXPR, ROUND_DIV_EXPR, TRUNC_MOD_EXPR, CEIL_MOD_EXPR,
	FLOOR_MOD_EXPR, ROUND_MOD_EXPR, RDIV_EXPR, and EXACT_DIV_EXPR.
---
 gcc/tree-cfg.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

-- 
2.27.0

Comments

Jonathan Wakely via Gcc-patches June 9, 2021, 11:18 a.m. | #1
On Wed, Jun 9, 2021 at 3:33 AM apinski--- via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>

> From: Andrew Pinski <apinski@marvell.com>

>

> While debugging PR 100925, I found that the gimple verifiers

> don't reject NEGATE on pointer or offset type.

> This patch adds the check on some unary and binary gimple which

> should not have operated on pointer/offset types.

>

> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.


Are you sure we don't see sth like EXACT_DIV for OFFSET_TYPE?
(I never remember the contexts where OFFSET_TYPE appears, but
I suppose it's from virtual calls / vtable adjustments or so - but also not
sure why we need to treat it different from integer types at all...)

Thanks,
Richard.

> Thanks,

> Andrew Pinski

>

> gcc/ChangeLog:

>

>         * tree-cfg.c (verify_gimple_assign_unary): Reject point and offset

>         types on NEGATE_EXPR, ABS_EXPR, BIT_NOT_EXPR, PAREN_EXPR and CNONJ_EXPR.

>         (verify_gimple_assign_binary): Reject point and offset types on

>         MULT_EXPR, MULT_HIGHPART_EXPR, TRUNC_DIV_EXPR, CEIL_DIV_EXPR,

>         FLOOR_DIV_EXPR, ROUND_DIV_EXPR, TRUNC_MOD_EXPR, CEIL_MOD_EXPR,

>         FLOOR_MOD_EXPR, ROUND_MOD_EXPR, RDIV_EXPR, and EXACT_DIV_EXPR.

> ---

>  gcc/tree-cfg.c | 22 ++++++++++++++++++++++

>  1 file changed, 22 insertions(+)

>

> diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c

> index 02256580c98..90fe4775405 100644

> --- a/gcc/tree-cfg.c

> +++ b/gcc/tree-cfg.c

> @@ -3752,6 +3752,15 @@ verify_gimple_assign_unary (gassign *stmt)

>      case BIT_NOT_EXPR:

>      case PAREN_EXPR:

>      case CONJ_EXPR:

> +      /* Disallow pointer and offset types for many of the unary gimple. */

> +      if (POINTER_TYPE_P (lhs_type)

> +         || TREE_CODE (lhs_type) == OFFSET_TYPE)

> +       {

> +         error ("invalid types for %qs", code_name);

> +         debug_generic_expr (lhs_type);

> +         debug_generic_expr (rhs1_type);

> +         return true;

> +       }

>        break;

>

>      case ABSU_EXPR:

> @@ -4127,6 +4136,19 @@ verify_gimple_assign_binary (gassign *stmt)

>      case ROUND_MOD_EXPR:

>      case RDIV_EXPR:

>      case EXACT_DIV_EXPR:

> +      /* Disallow pointer and offset types for many of the binary gimple. */

> +      if (POINTER_TYPE_P (lhs_type)

> +         || TREE_CODE (lhs_type) == OFFSET_TYPE)

> +       {

> +         error ("invalid types for %qs", code_name);

> +         debug_generic_expr (lhs_type);

> +         debug_generic_expr (rhs1_type);

> +         debug_generic_expr (rhs2_type);

> +         return true;

> +       }

> +      /* Continue with generic binary expression handling.  */

> +      break;

> +

>      case MIN_EXPR:

>      case MAX_EXPR:

>      case BIT_IOR_EXPR:

> --

> 2.27.0

>

Patch

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 02256580c98..90fe4775405 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -3752,6 +3752,15 @@  verify_gimple_assign_unary (gassign *stmt)
     case BIT_NOT_EXPR:
     case PAREN_EXPR:
     case CONJ_EXPR:
+      /* Disallow pointer and offset types for many of the unary gimple. */
+      if (POINTER_TYPE_P (lhs_type)
+	  || TREE_CODE (lhs_type) == OFFSET_TYPE)
+	{
+	  error ("invalid types for %qs", code_name);
+	  debug_generic_expr (lhs_type);
+	  debug_generic_expr (rhs1_type);
+	  return true;
+	}
       break;
 
     case ABSU_EXPR:
@@ -4127,6 +4136,19 @@  verify_gimple_assign_binary (gassign *stmt)
     case ROUND_MOD_EXPR:
     case RDIV_EXPR:
     case EXACT_DIV_EXPR:
+      /* Disallow pointer and offset types for many of the binary gimple. */
+      if (POINTER_TYPE_P (lhs_type)
+	  || TREE_CODE (lhs_type) == OFFSET_TYPE)
+	{
+	  error ("invalid types for %qs", code_name);
+	  debug_generic_expr (lhs_type);
+	  debug_generic_expr (rhs1_type);
+	  debug_generic_expr (rhs2_type);
+	  return true;
+	}
+      /* Continue with generic binary expression handling.  */
+      break;
+
     case MIN_EXPR:
     case MAX_EXPR:
     case BIT_IOR_EXPR: