From a95e917c48e62209383b5f81097af75f93a7a1c5 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Thu, 22 Jul 2021 16:03:53 +0200 Subject: [PATCH] Allow non-null adjustments for pointers even when there is a known range. Fix non_null_ref::adjust_range so it always adjust ranges, not just varying ranges. This will allow pointers that have a range, but are not necessarily non-null, to be adjusted. gcc/ChangeLog: * gimple-range-cache.cc (non_null_ref::adjust_range): Replace varying_p check for null/non-null check. --- gcc/gimple-range-cache.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 23597ade802..265a64bacca 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -89,12 +89,17 @@ bool non_null_ref::adjust_range (irange &r, tree name, basic_block bb, bool search_dom) { - // Check if pointers have any non-null dereferences. Non-call - // exceptions mean we could throw in the middle of the block, so just - // punt for now on those. - if (!cfun->can_throw_non_call_exceptions - && r.varying_p () - && non_null_deref_p (name, bb, search_dom)) + // Non-call exceptions mean we could throw in the middle of the + // block, so just punt on those for now. + if (cfun->can_throw_non_call_exceptions) + return false; + + // We only care about the null / non-null property of pointers. + if (!POINTER_TYPE_P (TREE_TYPE (name)) || r.zero_p () || r.nonzero_p ()) + return false; + + // Check if pointers have any non-null dereferences. + if (non_null_deref_p (name, bb, search_dom)) { int_range<2> nz; nz.set_nonzero (TREE_TYPE (name)); -- 2.31.1