public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "xinliangli at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/60899] New: undef reference generated with -fdevirtualize-speculatively Date: Sun, 20 Apr 2014 05:34:00 -0000 [thread overview] Message-ID: <bug-60899-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60899 Bug ID: 60899 Summary: undef reference generated with -fdevirtualize-speculatively Product: gcc Version: 4.10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: xinliangli at gmail dot com Build the following code with the following command line: g++ -O2 -fdisable-tree-einline a.cc a_m.cc results in: /tmp/cci31j3N.o: In function `D::doit()': a.cc:(.text._ZN1D4doitEv[_ZN1D4doitEv]+0x5): undefined reference to `A::foo()' collect2: error: ld returned 1 exit status It builds fine when devirtualization is disabled: -O2 -fno-devirtualization-speculatively -fdisable-tree-einline The problem is there is no instantiation of any class A instances (final or subclass) in the program, so vtables and A::foo are all eliminated. The reference to A::foo is from D::doit. In a successful build, there are no D instances either, so D::doit won't be emitted. However with speculative devirtualization, D::doit may be speculatively referenced even though there are no D instances. What happens is that during ipa-inline, goo is inlined into D::doit, the virtual call to foo should become an direct call to A::foo, but the new edge is not discovered. Since there is no call edge to A::foo, A::foo gets removed right after ipa-inline (before inline transform). However during inline transform, gimple-fold-call converts the virtual call into a direct call. The test case is extracted from a very large real program. The explicit reference to D::doit in bar is to demonstrate the problem -- in the real program, the reference is from spec-devirt. //a.h struct B { virtual int foo() = 0; int goo() { return foo(); } int i; }; struct A : public B { A() : i(0) {} int foo() { return 1;} int i; }; struct A2 : public B { int foo() { return 2;} }; struct DI { virtual int doit() = 0; }; struct D : public DI { virtual int doit () { return m.goo(); } A m; }; // a.cc #include "a.h" int cond; int bar (DI* ap) { if (cond) return static_cast<D*>(ap)->D::doit(); // Mimic speculative devirtualization return ap->doit(); } // a_m.cc #include "a.h" int cond; int bar (DI* ap) { if (cond) return static_cast<D*>(ap)->D::doit(); // Mimic speculative devirtualization return ap->doit(); }
next reply other threads:[~2014-04-20 5:34 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-04-20 5:34 xinliangli at gmail dot com [this message] 2014-04-20 6:26 ` [Bug tree-optimization/60899] " hubicka at gcc dot gnu.org 2014-04-20 6:26 ` hubicka at ucw dot cz 2014-04-20 6:52 ` xinliangli at gmail dot com 2014-04-20 7:10 ` xinliangli at gmail dot com 2014-04-20 7:23 ` hubicka at gcc dot gnu.org 2014-04-20 15:20 ` ppluzhnikov at google dot com 2014-04-21 3:33 ` xinliangli at gmail dot com 2014-04-21 3:48 ` hubicka at ucw dot cz 2014-04-22 8:51 ` rguenth at gcc dot gnu.org 2014-05-21 6:16 ` hubicka at gcc dot gnu.org 2014-06-27 13:36 ` trippels 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-60899-4@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: linkBe 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).