public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/60965] New: IPA: Devirtualization versus placement new
@ 2014-04-25 13:35 aph at gcc dot gnu.org
  2014-04-25 14:24 ` [Bug ipa/60965] " aph at gcc dot gnu.org
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: aph at gcc dot gnu.org @ 2014-04-25 13:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 60965
           Summary: IPA: Devirtualization versus placement new
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aph at gcc dot gnu.org

Created attachment 32683
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32683&action=edit
Reproducer here:

Summary: Devirtualization uses type information to determine if a
virtual method is reachable from a call site.  If type information
indicates that it is not, devirt marks the site as unreachable.  I
think this is wrong, and it breaks some programs.

Consider this class:

class Container {
  void *buffer[5];
public:
  EmbeddedObject *obj() { return (EmbeddedObject*)buffer; }
  Container() { new (buffer) EmbeddedObject(); }
};

Placement new is used to embed an object in a buffer inside another
object.  Its address can be retrieved.  This usage of placement new is
common, and it even appears as the canonical use of placement new in
the in the C++ FAQ at
http://www.parashift.com/c++-faq/placement-new.html.  (I am aware that
this may not be strictly legal.  For one thing, the memory at buffer
may not be suitably aligned.  Please bear with me.)

The embedded object is an instance of:

class EmbeddedObject {
public:
  virtual int val() { return 2; }
};

And it is called like this:

extern Container o;
int main() {

  cout << o.obj()->val() << endl;
}

The devirtualization pass looks into the call to val() and the type of
o, decides that there is no type inside o that is compatible with
EmbeddedObject, and inserts a call to __builtin_unreachanble().  As a
result, instead of printing 2, the program does nothing.


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2014-05-05 23:28 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-25 13:35 [Bug c++/60965] New: IPA: Devirtualization versus placement new aph at gcc dot gnu.org
2014-04-25 14:24 ` [Bug ipa/60965] " aph at gcc dot gnu.org
2014-04-25 14:59 ` [Bug ipa/60965] [4.10 Regression] " redi at gcc dot gnu.org
2014-04-25 15:51 ` jamborm at gcc dot gnu.org
2014-04-25 16:28 ` hubicka at gcc dot gnu.org
2014-04-28  9:53 ` rguenth at gcc dot gnu.org
2014-04-30  7:51 ` aph at gcc dot gnu.org
2014-05-01  9:40 ` hubicka at gcc dot gnu.org
2014-05-02 19:18 ` jason at gcc dot gnu.org
2014-05-03  9:42 ` aph at gcc dot gnu.org
2014-05-03 13:21 ` jason at gcc dot gnu.org
2014-05-03 18:05 ` harald at gigawatt dot nl
2014-05-04 10:01 ` aph at gcc dot gnu.org
2014-05-04 12:13 ` hubicka at ucw dot cz
2014-05-04 12:17 ` hubicka at ucw dot cz
2014-05-05 19:41 ` hubicka at gcc dot gnu.org
2014-05-05 23:28 ` hubicka at gcc dot gnu.org

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).