From 2f1686ff70b25fceb04ca2ffc0a450fb682913ef Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Sat, 5 Jun 2021 19:03:06 -0700 Subject: [PATCH] Disallow pointer and offset types on some gimple 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(+) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 4c32f83..f126d2a 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.7.4