diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-09-14 12:36:36 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-09-14 12:36:36 +0200 |
commit | 645ef01a463f15fc230e2155719c7a12cec89acf (patch) | |
tree | 600f894f2595d530f45314ed9b322dedaa2347b0 /gcc/tree-cfg.cc | |
parent | 05f5c42cb42c5088187d44cc45a5f671d19ad8c5 (diff) | |
download | gcc-645ef01a463f15fc230e2155719c7a12cec89acf.zip gcc-645ef01a463f15fc230e2155719c7a12cec89acf.tar.gz gcc-645ef01a463f15fc230e2155719c7a12cec89acf.tar.bz2 |
Disallow pointer operands for |, ^ and partly & [PR106878]
My change to match.pd (that added the two simplifications this patch
touches) results in more |/^/& assignments with pointer arguments,
but since r12-1608 we reject pointer operands for BIT_NOT_EXPR.
Disallowing them for BIT_NOT_EXPR and allowing for BIT_{IOR,XOR,AND}_EXPR
leads to a match.pd maintainance nightmare (see one of the patches in the
PR), so either we want to allow pointer operand on BIT_NOT_EXPR (but then
we run into issues e.g. with the ranger which expects it can emulate
BIT_NOT_EXPR ~X as - 1 - X which doesn't work for pointers which don't
support MINUS_EXPR), or the following patch disallows pointer arguments
for all of BIT_{IOR,XOR,AND}_EXPR with the exception of BIT_AND_EXPR
with INTEGER_CST last operand (for simpler pointer realignment).
I had to tweak one reassoc optimization and the two match.pd
simplifications.
2022-09-14 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/106878
* tree-cfg.cc (verify_gimple_assign_binary): Disallow pointer,
reference or OFFSET_TYPE BIT_IOR_EXPR, BIT_XOR_EXPR or, unless
the second argument is INTEGER_CST, BIT_AND_EXPR.
* match.pd ((type) X op CST -> (type) (X op ((type-x) CST)),
(type) (((type2) X) op Y) -> (X op (type) Y)): Punt for
POINTER_TYPE_P or OFFSET_TYPE.
* tree-ssa-reassoc.cc (optimize_range_tests_cmp_bitwise): For
pointers cast them to pointer sized integers first.
* gcc.c-torture/compile/pr106878.c: New test.
Diffstat (limited to 'gcc/tree-cfg.cc')
-rw-r--r-- | gcc/tree-cfg.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index e39d947..41ce1b2 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -4167,6 +4167,8 @@ verify_gimple_assign_binary (gassign *stmt) case ROUND_MOD_EXPR: case RDIV_EXPR: case EXACT_DIV_EXPR: + case BIT_IOR_EXPR: + case BIT_XOR_EXPR: /* Disallow pointer and offset types for many of the binary gimple. */ if (POINTER_TYPE_P (lhs_type) || TREE_CODE (lhs_type) == OFFSET_TYPE) @@ -4182,9 +4184,23 @@ verify_gimple_assign_binary (gassign *stmt) case MIN_EXPR: case MAX_EXPR: - case BIT_IOR_EXPR: - case BIT_XOR_EXPR: + /* Continue with generic binary expression handling. */ + break; + case BIT_AND_EXPR: + if (POINTER_TYPE_P (lhs_type) + && TREE_CODE (rhs2) == INTEGER_CST) + break; + /* 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; |