public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@redhat.com>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: jh@suse.cz, gcc@gcc.gnu.org
Subject: Re: can_throw_internal affected by inlining?
Date: Thu, 16 Jul 2009 17:09:00 -0000	[thread overview]
Message-ID: <4A5F5EC5.9060401@redhat.com> (raw)
In-Reply-To: <20090711125930.GB27815@atrey.karlin.mff.cuni.cz>

[-- Attachment #1: Type: text/plain, Size: 1847 bytes --]

On 07/11/2009 05:59 AM, Jan Hubicka wrote:
>> Re: http://gcc.gnu.org/ml/gcc-patches/2009-03/msg01404.html
>>
>> Do you have test cases for this?
>>
>> Changing can_throw_internal/external to depend on whether or not future
>> inlining is possible looks *very* wrong to me.  Surely the only thing
>> that matters for new code that might appear "below" this position in the
>> tree is whether or not it might throw, and the only thing that changes
>> with inlining is increased knowledge of whether and how it throws.
>
> The problem here is fact that MUST_NOT_THROW region reachable only via
> runtime is handled completely via runtime, however MUST_NOT_THROW region
> reachable via RESX is eventually going to be handled by direct
> std::terminate call, since RESX will eventually get translated as direct
> goto to the MIST_NOT_THROW reciever.

I'm committing the following test case that displays the bug.  It does 
in fact pass with mainline, and does in fact fail with gcc 4.4.0.

I spent two days trying to come up with some cleaner way to fix this bug 
than the inlinable flag you pass around, but to no avail.  The only 
thing better I could think of is some global flag (or state variable) 
that indicates whether or not inlining is complete.  At least then we 
would not have to pass around that flag.  But I wouldn't want to 
introduce yet another boolean state variable; I'd much prefer all of the 
existing state variables we have be consolidated, and I can't justify 
spending the time on that just now.

> Well, we can either teach inlinable_call_p to handle your new indirect
> calls as "for sure uninlinable"

This is the approach I'll take.  I've already hacked on an extra bit in 
the gimple call subcode to indicate whether an indirect call is nothrow; 
I might as well add another bit to say an indirect call is noinline.


r~

[-- Attachment #2: z --]
[-- Type: text/plain, Size: 1092 bytes --]

--- testsuite/g++.dg/opt/eh4.C	(revision 149703)
+++ testsuite/g++.dg/opt/eh4.C	(local)
@@ -0,0 +1,59 @@
+// { dg-do run }
+// { dg-options "-O3" }
+
+// Make sure that the call to terminate within F2 is not eliminated
+// by incorrect MUST_NOT_THROW optimization.  Note that we expect F1
+// to be inlined into F2 in order to expose this case.
+
+#include <cstdlib>
+#include <exception>
+
+static volatile int zero = 0;
+
+// Note that we need F0 to not be marked nothrow, though we don't actually
+// want a throw to happen at runtime here.  The noinline tag is merely to
+// make sure the assembly in F0 is not unnecessarily complex.
+static void __attribute__((noinline)) f0()
+{
+  if (zero != 0)
+    throw 0;
+}
+
+struct S1
+{
+  S1() { }
+  ~S1() { f0(); }
+};
+
+static void f1()
+{
+  S1 s1;
+  throw 1;
+}
+
+struct S2
+{
+  S2() { }
+  ~S2() { f1(); }
+};
+
+static void __attribute__((noinline)) f2()
+{
+  S2 s2;
+  throw 2;
+}
+
+static void pass()
+{
+  exit (0);
+}
+
+int main()
+{
+  std::set_terminate (pass);
+  try {
+    f2();
+  } catch (...) {
+  }
+  abort ();
+}

  parent reply	other threads:[~2009-07-16 17:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-10 22:58 Richard Henderson
2009-07-11 12:59 ` Jan Hubicka
2009-07-11 17:44   ` Richard Henderson
2009-07-11 17:59     ` Jan Hubicka
2009-07-11 18:09       ` Richard Henderson
2009-07-11 18:53         ` Jan Hubicka
2009-07-16 17:09   ` Richard Henderson [this message]
2009-07-17 10:36     ` Jan Hubicka

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=4A5F5EC5.9060401@redhat.com \
    --to=rth@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=jh@suse.cz \
    /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).