<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Possible Issue with Whole Program Devirtualization"
   href="https://bugs.llvm.org/show_bug.cgi?id=50190">50190</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Possible Issue with Whole Program Devirtualization
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>steplong@quicinc.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>class A {
public:
  virtual int foo() const = 0;
};

class B : public A {
public:
  virtual int foo() const { return 2; }
};

class C : public A {
public:
  virtual int foo() const { return 3; }
};

A *get_A(int num) {
  if (num > 1) {
    printf("returning new B\n");
    return new B; 
  }
  printf("returning new C\n");
  return new C;
}

__attribute__((noinline))
void call_foo(int argc) {
  C *c = (C *)get_A(argc);
  printf("%d\n", c->foo());
}

int main(int argc, char *argv[]) {
  call_foo(argc);
}

trunk clang with -O3 -flto -whole-program-vtables -fvisibility=hidden outputs
./a.out 1
returning new B
3

gcc 10.2 with -O3 -flto -fwhole-program -fvisibility=hidden outputs
./a.out 1
returning new B
2

It looks like the c->foo is being devirtualized to a direct C::foo() call.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>