public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom de Vries <Tom_deVries@mentor.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: "gcc-patches@gnu.org" <gcc-patches@gnu.org>
Subject: Re: [PATCH] Check dominator info in compute_dominance_frontiers
Date: Mon, 22 Jun 2015 11:47:00 -0000	[thread overview]
Message-ID: <5587F277.1080401@mentor.com> (raw)
In-Reply-To: <CAFiYyc3dnCZ7+_o8Cy5qX6LinhA0STPWGMwqQgL4sX8LfPgtoQ@mail.gmail.com>

On 22/06/15 12:14, Richard Biener wrote:
> On Mon, Jun 22, 2015 at 10:04 AM, Tom de Vries <Tom_deVries@mentor.com> wrote:
>> Hi,
>>
>> during development of a patch I ran into a case where
>> compute_dominance_frontiers was called with incorrect dominance info.
>>
>> The result was a segmentation violation somewhere in the bitmap code while
>> executing this bitmap_set_bit in compute_dominance_frontiers_1:
>> ...
>>                    if (!bitmap_set_bit (&frontiers[runner->index],
>>                                         b->index))
>>                      break;
>> ...
>>
>> The segmentation violation happens because runner->index is 0, and
>> frontiers[0] is uninitialized.
>>
>> [ The initialization in update_ssa looks like this:
>> ...
>>       dfs = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
>>        FOR_EACH_BB_FN (bb, cfun)
>>          bitmap_initialize (&dfs[bb->index], &bitmap_default_obstack);
>>        compute_dominance_frontiers (dfs);
>> ...
>>
>> FOR_EACH_BB_FN skips over the entry-block and the exit-block, so dfs[0]
>> (frontiers[0] in compute_dominance_frontiers_1) is not initialized.
>>
>> We could add initialization by making the entry/exit-block bitmap_heads
>> empty and setting the obstack to a reserved obstack bitmap_no_obstack for
>> which allocation results in an assert. ]
>>
>> AFAIU, the immediate problem is not that frontiers[0] is uninitialized, but
>> that the loop reaches the state of runner->index == 0, due to the incorrect
>> dominance info.
>>
>> The patch adds an assert to the loop in compute_dominance_frontiers_1, to
>> make the failure mode cleaner and easier to understand.
>>
>> I think we wouldn't catch all errors in dominance info with this assert. So
>> the patch also contains an ENABLE_CHECKING-enabled verify_dominators call at
>> the start of compute_dominance_frontiers. I'm not sure if:
>> - adding the verify_dominators call is too costly in runtime.
>> - the verify_dominators call should be inside or outside the
>>    TV_DOM_FRONTIERS measurement.
>> - there is a level of ENABLE_CHECKING that is more appropriate for the
>>    verify_dominators call.
>>
>> Is this ok for trunk if bootstrap and reg-test on x86_64 succeeds?
>
> I don't think these kind of asserts are good.  A segfault is good by itself
> (so you can just add the comment if you like).
>

The segfault is not guaranteed to trigger, because it works on 
uninitialized data. Instead, we may end up modifying valid memory and 
silently generating wrong code or causing sigsegvs (which will be 
difficult to track back this error). So I don't think doing nothing is 
an option here. If we're not going to add this assert, we should 
initialize the uninitialized data in such a way that we are guaranteed 
to detect the error. The scheme I proposed above would take care of 
that. Should I implement that instead?

> Likewise the verify_dominators call is too expensive and misplaced.
>
> If then the call belongs in the dom_computed[] == DOM_OK early-out
> in calculate_dominance_info

OK, like this:
...
diff --git a/gcc/dominance.c b/gcc/dominance.c
index a9e042e..1827eda9 100644
--- a/gcc/dominance.c
+++ b/gcc/dominance.c
@@ -646,7 +646,12 @@ calculate_dominance_info (enum cdi_direction dir)
    bool reverse = (dir == CDI_POST_DOMINATORS) ? true : false;

    if (dom_computed[dir_index] == DOM_OK)
-    return;
+    {
+#if ENABLE_CHECKING
+      verify_dominators (CDI_DOMINATORS);
+#endif
+      return;
+    }

    timevar_push (TV_DOMINANCE);
    if (!dom_info_available_p (dir))
...

I didn't fully understand your comment, do you want me to test this?

Thanks,
- Tom

> (eventually also for the case where we
> end up only computing the fast-query stuff).

  reply	other threads:[~2015-06-22 11:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-22  8:20 Tom de Vries
2015-06-22 10:38 ` Richard Biener
2015-06-22 11:47   ` Tom de Vries [this message]
2015-06-22 12:39     ` Richard Biener
2015-06-22 16:53       ` Tom de Vries
2015-06-22 17:17       ` Tom de Vries
2015-06-23  9:33         ` Richard Biener
2015-06-25  7:13           ` Tom de Vries

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=5587F277.1080401@mentor.com \
    --to=tom_devries@mentor.com \
    --cc=gcc-patches@gnu.org \
    --cc=richard.guenther@gmail.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).