public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/114703] New: Missed devirtualization in rather simple case
@ 2024-04-12 13:57 konstantin.vladimirov at gmail dot com
  2024-04-12 22:01 ` [Bug ipa/114703] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: konstantin.vladimirov at gmail dot com @ 2024-04-12 13:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114703

            Bug ID: 114703
           Summary: Missed devirtualization in rather simple case
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: konstantin.vladimirov at gmail dot com
  Target Milestone: ---

See code here:

https://godbolt.org/z/T9Ma7qe3E

struct A {
  virtual int foo() { return 1; }
};

struct B : A {
  int foo() override { return 2; }
  virtual int foo(int i) { return i + 1; }
};

int use(int, int, int);

int main() {
  B *p = new B;
#if 0
  A* q = p;
#else
  A* q = new B;
#endif  
  int result1 = p->foo(1);
  int result2 = p->foo();
  int result3 = q->foo();
  use(result1, result2, result3);
}

clang devirtualizes just fine, gcc lacks this one.

Interesting that if you flip preprocessor switch, everything works with gcc
either.

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

end of thread, other threads:[~2024-04-15 10:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12 13:57 [Bug ipa/114703] New: Missed devirtualization in rather simple case konstantin.vladimirov at gmail dot com
2024-04-12 22:01 ` [Bug ipa/114703] " pinskia at gcc dot gnu.org
2024-04-12 22:11 ` pinskia at gcc dot gnu.org
2024-04-15  7:53 ` rguenth at gcc dot gnu.org
2024-04-15 10:20 ` hubicka at ucw dot cz

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