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.

Reply via email to