public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "amacleod at redhat dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/109238] [13 Regression] tst-realloc.i:42:19: error: pointer ‘p’ may be used after ‘realloc’ [-Werror=use-after-free] in glibc tests
Date: Thu, 23 Mar 2023 17:46:07 +0000	[thread overview]
Message-ID: <bug-109238-4-KKfUQCELua@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109238-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #6 from Andrew Macleod <amacleod at redhat dot com> ---
Created attachment 54738
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54738&action=edit
Patch to fix the issue

Ah, sorry I missed that.

OK, I traced it through. The problem turns out to be in the dom_resolve code.
when we are trying to pick up a value via dominators, we walk the dominator
chain looking for outgoing edges which change the value and/or existing values.
 As we find these values, will fill the on-entry cache so that future queries
will be faster.

When we encounter a dominator node that has multiple incoming edges, as BB 33
does, we separately ask for a "quick" read-only fill and accumulate each
incoming edges values.  this allows us to pick up things where ranges are
adjusted on edges from non-dominator block ie

bb2:
   if (foo)
     if (a < 10) goto A: else goto B;
   else
     if (a >= 10) goto C:  else goto A:
   <more code>
   goto D:
A:

Block A's dominator is bb2.  It has 2 predecessors however, and on each of
those incoming edges, a has a range of [0, 10].

So by querying the outgoing range of a on each predecessor we come up with
[0,10] for a range of A, which would not be possible simply by examining the
dominator itself.

This query is done in a read-only mode so we dont go polluting the cache with a
bunch of things we may not need.  Anyway, it all works swimmingly.  usually.

What happened in this case is BB 33 has 2 predecessors. BB 28 and BB 32.
The edge from BB28 correctly picked up the range of ~[0,0], but the query for
BB32 went wrong.  BB32 is a back edge, and the query leads back to BB 33, and
in read only mode, we do not deal with these multiple incoming edges.. (and it
avoids an infinite loop).. so that query bails, and we end up with VARYING. 
that is what was generating the confusing output:

CACHE: BB 32 DOM query for c_24, found [irange] unsigned char * VARYING at BB28
CACHE: Range for DOM returns : [irange] unsigned char * VARYING
CACHE: Range for DOM returns : [irange] unsigned char * VARYING

When we are doing this inferior DOM query in read-only like this like this, we
do not need to incorporate anything from a back edge. Its intended to be
pulling a value from dominators, and there is no additional information on that
edge.  Any values from that edge can only be subsets of what the other incoming
edges have, and with the results being unioned... its pointless.

I have not yet managed to produce a reduced testcase.

  parent reply	other threads:[~2023-03-23 17:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21 18:56 [Bug tree-optimization/109238] New: " marxin at gcc dot gnu.org
2023-03-21 18:57 ` [Bug tree-optimization/109238] " marxin at gcc dot gnu.org
2023-03-21 19:05 ` pinskia at gcc dot gnu.org
2023-03-22  7:37 ` rguenth at gcc dot gnu.org
2023-03-22 13:52 ` rguenth at gcc dot gnu.org
2023-03-22 15:42 ` amacleod at redhat dot com
2023-03-23  8:50 ` rguenth at gcc dot gnu.org
2023-03-23 17:46 ` amacleod at redhat dot com [this message]
2023-03-23 19:07 ` jakub at gcc dot gnu.org
2023-03-24 13:12 ` cvs-commit at gcc dot gnu.org
2023-03-24 13:36 ` amacleod at redhat dot com

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-109238-4-KKfUQCELua@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).