Hi,

the test case g++.old-deja/g++.mike/p4736b.C is mis-compiled with with all
optimization levels, except -O0 and -Og. This probably started with gcc 4.7.x.

The constructor Main::Main() is first inlined and then completely optimized
away in the dce1 pass. But the thunk is still using the vtable, and therefore
crashes.

Well, the problem seems to be, that the thunk code is
not emitted in the normal way using gimple code,
but instead by the i386 back-end with a callback.

This makes the thunk invisible to the ipa-pure-const pass,
which assumes that all values just flow straight thu the thunk.

See ipa-pure-const.c (analyze_function):

  if (fn->thunk.thunk_p || fn->alias)
    {
      /* Thunk gets propagated through, so nothing interesting happens.  */
      gcc_assert (ipa);
      return l;
    }

But this is not true for a virtual base class:
The thunk itself references the vtable, so if nothing else might need
the vtable, the optimizer may remove the initalization of the vtable,
which happened in this example.

The most simple work around would be the attached patch, which
simply falls back to emitting gimple code, if virtual base classes
are used.

Boot-Strapped and Regression-Tested on x86_64-linux-gnu.
Ok for trunk?


Thanks
Bernd.
                                          
2014-06-02  Bernd Edlinger  <bernd.edlin...@hotmail.de>

        PR ipa/61190
        * cgraphunit.c (expand_thunk): Don't try to output the thunk for
        a virtual base class via targetm.asm_out.output_mi_thunk. 

testsuite/ChangeLog:
2014-06-02  Bernd Edlinger  <bernd.edlin...@hotmail.de>

        PR ipa/61190
        * g++.old-deja/g++.mike/p4736b.C: Use -O2.

Attachment: patch-pr61190.diff
Description: Binary data

Reply via email to