public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/96564] [11/12/13/14 Regression] New maybe use of uninitialized variable warning since r11-959
Date: Mon, 11 Mar 2024 10:23:37 +0000	[thread overview]
Message-ID: <bug-96564-4-Ok7SvAsytw@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-96564-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96564

--- Comment #13 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jeffrey A. Law from comment #12)
> So I think we could solve this with a bit of help from the alias oracle.  We
> have  the routine ptrs_compare_unequal, but points-to-null is going to get
> in the way.
> 
> I think VRP and DOM have enough information to rule out NULL for both
> objects in question.  So if we could query the points-to information,
> ignoring NULL then we could likely solve this particular bug.
> 
> Essentially VRP or DOM would prove NULL isn't in the set of possible values
> at the comparison point.  Then we query the alias information ignoring NULL.
> Voila we compute a static result for the comparison of the two pointers and
> the problematical block becomes unreachable and the bogus warning goes away.
> 
> Richi, any thoughts in viability of such an API?

We now treat pt.null conservatively and track non-null-ness derived from
range-info in it.  That means when VRP/DOM can prove a pointer is always
not NULL they can do set_ptr_nonnull (p) on it.

This means the

  /* ???  We'd like to handle ptr1 != NULL and ptr1 != ptr2
     but those require pt.null to be conservatively correct.  */

is no longer true and we could finally implement it, like with

diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index e7c1c1aa624..5b6d9e0aa6a 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -479,9 +479,25 @@ ptrs_compare_unequal (tree ptr1, tree ptr2)
        }
       return !pt_solution_includes (&pi->pt, obj1);
     }
-
-  /* ???  We'd like to handle ptr1 != NULL and ptr1 != ptr2
-     but those require pt.null to be conservatively correct.  */
+  else if (TREE_CODE (ptr1) == SSA_NAME)
+    {
+      struct ptr_info_def *pi1 = SSA_NAME_PTR_INFO (ptr1);
+      if (!pi1
+         || pi1->pt.vars_contains_restrict
+         || pi1->pt.vars_contains_interposable)
+       return false;
+      if (integer_zerop (ptr2) && !pi1->pt.null)
+       return true;
+      if (TREE_CODE (ptr2) == SSA_NAME)
+       {
+         struct ptr_info_def *pi2 = SSA_NAME_PTR_INFO (ptr2);
+         if (!pi2
+             || pi2->pt.vars_contains_restrict
+             || pi2->pt.vars_contains_interposable)
+         if (!pi1->pt.null || !pi2->pt.null)
+           return !pt_solutions_intersect (&pi1->pt, &pi2->pt);
+       }
+    }

   return false;
 }


but the testcase shows the non-null-ness is only conditional which means
we'd have to use a range query above which necessarily falls back to
the global ranges given we don't have any context available here.  The
old EVRP adjusted global ranges during the walk but this is no longer done.

Note it's enough that one pointer is nonnull, so for your idea the
API could be extended with a bool one_ptr_nonnull parameter.

  parent reply	other threads:[~2024-03-11 10:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-11  7:30 [Bug middle-end/96564] New: New maybe use of uninitialized variable warning since GCC >10 stefansf at linux dot ibm.com
2020-08-11  9:27 ` [Bug middle-end/96564] " glisse at gcc dot gnu.org
2020-08-11  9:47 ` [Bug middle-end/96564] [11 Regression] New maybe use of uninitialized variable warning since r11-959 jakub at gcc dot gnu.org
2020-08-11 17:10 ` msebor at gcc dot gnu.org
2020-08-11 17:24 ` msebor at gcc dot gnu.org
2020-08-25  8:20 ` rguenth at gcc dot gnu.org
2021-01-14  9:19 ` rguenth at gcc dot gnu.org
2021-02-11 10:48 ` jakub at gcc dot gnu.org
2021-04-27 11:39 ` [Bug middle-end/96564] [11/12 " jakub at gcc dot gnu.org
2021-07-28  7:05 ` rguenth at gcc dot gnu.org
2022-04-21  7:48 ` rguenth at gcc dot gnu.org
2023-03-14  5:00 ` [Bug middle-end/96564] [11/12/13 " pinskia at gcc dot gnu.org
2023-05-29 10:03 ` [Bug middle-end/96564] [11/12/13/14 " jakub at gcc dot gnu.org
2024-03-10 22:49 ` law at gcc dot gnu.org
2024-03-11 10:23 ` rguenth at gcc dot gnu.org [this message]
2024-03-11 13:26 ` rguenth at gcc dot gnu.org
2024-03-11 15:20 ` amacleod at redhat dot com
2024-03-12  7:37 ` rguenth at gcc dot gnu.org
2024-05-16 11:23 ` [Bug middle-end/96564] [11/12/13/14/15 " rguenth at gcc dot gnu.org
2024-05-16 12:44 ` cvs-commit at gcc dot gnu.org
2024-05-16 14:27 ` aldyh at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-96564-4-Ok7SvAsytw@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).