Disallow pointer and offset types on some gimple
authorAndrew Pinski <apinski@marvell.com>
Sun, 6 Jun 2021 02:03:06 +0000 (19:03 -0700)
committerAndrew Pinski <apinski@marvell.com>
Fri, 18 Jun 2021 07:58:18 +0000 (00:58 -0700)
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

index 4c32f83..f126d2a 100644 (file)
@@ -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: