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.

Reply via email to