public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Aldy Hernandez <aldyh@redhat.com>
Cc: Jakub Jelinek <jakub@redhat.com>,
	gcc-patches@gcc.gnu.org, amacleod@redhat.com
Subject: Re: [PATCH] middle-end/114604 - ranger allocates bitmap without initialized obstack
Date: Mon, 8 Apr 2024 18:28:50 +0200	[thread overview]
Message-ID: <34A40EEC-538B-4899-9683-F1B4285F7C4C@suse.de> (raw)
In-Reply-To: <CAGm3qMWm3aUXE_oSr_PfMhei8gqxSk5KkSHigBH+5fwyAJfsuw@mail.gmail.com>



> Am 08.04.2024 um 18:09 schrieb Aldy Hernandez <aldyh@redhat.com>:
> 
> On Mon, Apr 8, 2024 at 5:54 PM Jakub Jelinek <jakub@redhat.com> wrote:
>> 
>> On Mon, Apr 08, 2024 at 05:40:23PM +0200, Aldy Hernandez wrote:
>>>>        PR middle-end/114604
>>>>        * gimple-range.cc (enable_ranger): Initialize the global
>>>>        bitmap obstack.
>>>>        (disable_ranger): Release it.
>>>> ---
>>>> gcc/gimple-range.cc | 4 ++++
>>>> 1 file changed, 4 insertions(+)
>>>> 
>>>> diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
>>>> index c16b776c1e3..4d3b1ce8588 100644
>>>> --- a/gcc/gimple-range.cc
>>>> +++ b/gcc/gimple-range.cc
>>>> @@ -689,6 +689,8 @@ enable_ranger (struct function *fun, bool use_imm_uses)
>>>> {
>>>>   gimple_ranger *r;
>>>> 
>>>> +  bitmap_obstack_initialize (NULL);
>>>> +
>>>>   gcc_checking_assert (!fun->x_range_query);
>>>>   r = new gimple_ranger (use_imm_uses);
>>>>   fun->x_range_query = r;
>>>> @@ -705,6 +707,8 @@ disable_ranger (struct function *fun)
>>>>   gcc_checking_assert (fun->x_range_query);
>>>>   delete fun->x_range_query;
>>>>   fun->x_range_query = NULL;
>>>> +
>>>> +  bitmap_obstack_release (NULL);
>>> 
>>> Are you not allowed to initialize/use obstacks unless
>>> bitmap_obstack_initialize(NULL) is called?
>> 
>> You can use it with some other obstack, just not the default one.
>> 
>>> If so, wouldn't it be
>>> better to lazily initialize it downstream (bitmap_alloc, or whomever
>>> needs it initialized)?
>> 
>> No, you still need to decide where is the safe point to release it.
>> Unlike the non-default bitmap_obstack_initialize/bitmap_obstack_release,
>> the default one can nest (has associated nesting counter).  So, the above
>> patch just says that ranger starts using the default obstack in
>> enable_ranger and stops using it in disable_ranger and anything ranger
>> associated in the obstack can be freed at that point.
> 
> I thought ranger never used the default one:
> 
> $ grep bitmap_obstack_initialize *value* *range*
> value-relation.cc:  bitmap_obstack_initialize (&m_bitmaps);
> value-relation.cc:  bitmap_obstack_initialize (&m_bitmaps);
> gimple-range-cache.cc:  bitmap_obstack_initialize (&m_bitmaps);
> gimple-range-gori.cc:  bitmap_obstack_initialize (&m_bitmaps);
> gimple-range-infer.cc:  bitmap_obstack_initialize (&m_bitmaps);
> gimple-range-phi.cc:  bitmap_obstack_initialize (&m_bitmaps);
> 
> or even:
> 
> $ grep obstack.*NULL *value* *range*
> value-range-storage.cc:    obstack_free (&m_obstack, NULL);
> value-relation.cc:  obstack_free (&m_chain_obstack, NULL);
> value-relation.cc:  obstack_free (&m_chain_obstack, NULL);
> gimple-range-infer.cc:  obstack_free (&m_list_obstack, NULL);
> value-range-storage.cc:    obstack_free (&m_obstack, NULL);
> 
> I'm obviously missing something here.

Look for BITMAP_ALLOC (NULL) in the backtrace in the PR

Richard 


> Aldy
> 

  reply	other threads:[~2024-04-08 16:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240408095018.4853D385841E@sourceware.org>
2024-04-08 15:40 ` Aldy Hernandez
2024-04-08 15:54   ` Jakub Jelinek
2024-04-08 16:08     ` Aldy Hernandez
2024-04-08 16:28       ` Richard Biener [this message]
2024-04-08 16:39         ` Aldy Hernandez
2024-04-08 17:47           ` Richard Biener
2024-04-09  5:43             ` Aldy Hernandez
2024-04-09  6:48               ` Richard Biener
2024-06-20  8:08             ` Aldy Hernandez
2024-06-20  9:31               ` Richard Biener
2024-06-20 14:05                 ` Andrew MacLeod
2024-06-20 14:36                   ` Richard Biener
2024-06-26  8:50                     ` Aldy Hernandez
2024-04-08  9:49 Richard Biener

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=34A40EEC-538B-4899-9683-F1B4285F7C4C@suse.de \
    --to=rguenther@suse.de \
    --cc=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /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).