On 11/18/24 6:58 PM, Richard Sandiford wrote:
Tejas Belagod <tejas.bela...@arm.com> writes:
Handle variable-sized vectors for BIT_FIELD_REF canonicalization.
gcc/ChangeLog:
* gimple-fold.cc (maybe_canonicalize_mem_ref_addr): Handle variable
sized vector types in BIT_FIELD_REF canonicalization.
* tree-cfg.cc (verify_types_in_gimple_reference): Change object-size-
checking for BIT_FIELD_REF to error offsets that are known_gt to be
outside object-size. Out-of-range offsets can happen in the case of
indices that reference VLA SVE vector elements that may be outside the
minimum vector size range and therefore maybe_gt is not appropirate
here.
---
gcc/gimple-fold.cc | 3 ++-
gcc/tree-cfg.cc | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index c19dac0dbfd..97ac6f5379f 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -6294,7 +6294,8 @@ maybe_canonicalize_mem_ref_addr (tree *t, bool is_debug =
false)
(TYPE_SIZE (TREE_TYPE (*t))));
widest_int ext
= wi::add (idx, wi::to_widest (TYPE_SIZE (TREE_TYPE (*t))));
- if (wi::les_p (ext, wi::to_widest (TYPE_SIZE (vtype))))
+ if (known_le (ext, wi::to_poly_widest (TYPE_SIZE (vtype)))
+ || !wi::to_poly_widest (TYPE_SIZE (vtype)).is_constant ())
Did you consider using:
if (maybe_le (ext, wi::to_poly_widest (TYPE_SIZE (vtype))))
here, without the is_constant definition? That seems to match the
tree-cfg.cc code more closely.
Ah, that's more apt here. I hadn't considered that - my brain is still
wired to think VLS and VLA is terms of known_* and is_constant ().
Thanks for this suggestion - I'll fix it.
Thanks,
Tejas.
Thanks,
Richard
{
*t = build3_loc (EXPR_LOCATION (*t), BIT_FIELD_REF,
TREE_TYPE (*t),
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 3eede0d61cd..5a44b89907e 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -3176,7 +3176,7 @@ verify_types_in_gimple_reference (tree expr, bool
require_lvalue)
return true;
}
if (!AGGREGATE_TYPE_P (TREE_TYPE (op))
- && maybe_gt (size + bitpos,
+ && known_gt (size + bitpos,
tree_to_poly_uint64 (TYPE_SIZE (TREE_TYPE (op)))))
{
error ("position plus size exceeds size of referenced object in "