]> git.ipfire.org Git - thirdparty/gcc.git/commit
ranger: Improve nonnull_if_nonzero attribute [PR117023]
authorJakub Jelinek <jakub@redhat.com>
Fri, 2 May 2025 17:40:55 +0000 (19:40 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 2 May 2025 17:40:55 +0000 (19:40 +0200)
commit1e27e9a3184c948b499a21ff20181611514ed720
tree7ed6e477c0ccdebb28414bdf8cfe796c9afd2a62
parentc77d04506e6abdc45969d0ff146204be7485244a
ranger: Improve nonnull_if_nonzero attribute [PR117023]

On Mon, Mar 31, 2025 at 11:30:20AM -0400, Andrew MacLeod wrote:
> Infer range processing was adjusted to allow a query to be specified,
> but during VRP folding, ranger w3as not providing a query.  This results
> in contextual ranges being missed.   Pass the cache in as the query
> which provide a read-only query of the current state.

Now that this patch is in, I've retested my patch and it works fine.
If we can determine a range for the arg2 argument and prove that it
doesn't include zero, we can imply nonzero for the arg1 argument.

2025-05-02  Jakub Jelinek  <jakub@redhat.com>
    Andrew MacLeod  <amacleod@redhat.com>

PR c/117023
* gimple-range-infer.cc (gimple_infer_range::gimple_infer_range):
For nonnull_if_nonzero attribute check also arg2 range if it doesn't
include zero and in that case call add_nonzero too.

* gcc.dg/tree-ssa/pr78154-2.c: New test.
gcc/gimple-range-infer.cc
gcc/testsuite/gcc.dg/tree-ssa/pr78154-2.c [new file with mode: 0644]