public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/54046] [4.6/4.7/4.8 Regression] wrong control reaches end of non-void function for switch case with throw and default
Date: Fri, 20 Jul 2012 12:58:00 -0000	[thread overview]
Message-ID: <bug-54046-4-RJ2ADDFWum@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-54046-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54046

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-07-20 12:57:42 UTC ---
Or:
void foo (void) __attribute__((noreturn));
void bar (void);

struct A
{
  ~A () {}
};

bool
check (int x)
{
  A z;
  switch (x)
    {
    case 0:
      return false;
    default:
      foo ();
      bar ();
    }
}

The problem is related to pass ordering.  EH lowering is done before CFG
cleanups, so if there is code after a noreturn spot (whether throw or noreturn
function, endless loop etc. doesn't matter), when trying to lower try ..
finally EH will see gimple_seq_may_fallthru to be true because of the extra
code after it hiding that it in fact can't fall thru.  We end up then with:
  switch (x) <default: <D.2213>, case 0: <D.2212>>
  <D.2212>:
  D.2216 = 0;
  finally_tmp.0 = 0;
  goto <D.2220>;
  <D.2213>:
  foo ();
  bar ();
  finally_tmp.0 = 1;
  <D.2220>:
  A::~A (&z);
  switch (finally_tmp.0) <default: <D.2223>, default: <D.2223>, case 1:
<D.2221>>

where D.2221 falls thru to exit without returning a value, while D.2223
doesn't.
Then cfg cleanup during cfg pass cleans that up to:
  finally_tmp.0 = 0;
  A::~A (&z);
  switch (finally_tmp.0) <default: <L12>, case 1: <L11>>
after finding out that foo is noreturn and can't fallthru.  But there is no
constant propagation and switch optimization pass that would simplify
switch (0) <default: something; case 1: somethingelse> into
goto something; scheduled before the pass_warn_function_return is scheduled.
As we aren't in SSA form at that point, doing it wouldn't be very easy.


  parent reply	other threads:[~2012-07-20 12:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-20 11:49 [Bug c++/54046] New: " plasmahh at gmx dot net
2012-07-20 12:10 ` [Bug c++/54046] " redi at gcc dot gnu.org
2012-07-20 12:15 ` [Bug c++/54046] [4.6/4.7/4.8 Regression] " redi at gcc dot gnu.org
2012-07-20 12:40 ` jakub at gcc dot gnu.org
2012-07-20 12:58 ` jakub at gcc dot gnu.org [this message]
2012-07-20 15:15 ` ebotcazou at gcc dot gnu.org
2012-09-07 10:03 ` rguenth at gcc dot gnu.org
2012-11-20 16:03 ` jakub at gcc dot gnu.org
2012-11-20 17:27 ` jakub at gcc dot gnu.org
2012-11-23 16:04 ` jakub at gcc dot gnu.org
2013-02-01 14:03 ` [Bug c++/54046] [4.6/4.7 " jakub at gcc dot gnu.org
2013-02-01 14:26 ` jakub 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-54046-4-RJ2ADDFWum@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).