<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - clang does not devirtualize method pointer calls against final classes when method identity is known at compile time"
   href="https://llvm.org/bugs/show_bug.cgi?id=27096">27096</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang does not devirtualize method pointer calls against final classes when method identity is known at compile time
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Keywords</th>
          <td>code-quality
          </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>hlandau@devever.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>// Example:
struct Foo final {
  virtual int bar();  
};

int a(Foo &f, int (Foo::*fp)()) {
  return (f.*fp)(); 
}

int b(Foo &f) {
  return a(f, &Foo::bar);
}

// Generated assembly:
b(Foo&):                                # @b(Foo&)
        mov     rax, qword ptr [rdi]
        jmp     qword ptr [rax]         # TAILCALL

// Expected assembly:
b(Foo&):                              # @b(Foo&)
        jmp     Foo::bar()            # TAILCALL

// Generates expected assembly:
int c(Foo &f) {
  return f.bar();
}

// This is the assembly for a, which generates a more conservative
// method pointer call, demonstrating that the knowledge about the identity of
// fp when inlining in b is definitely used to generate the code above.
// Yet the devirtualization which could be taken as a further step above does
not occur.
a(Foo&, int (Foo::*)()):                       # @a(Foo&, int (Foo::*)())
        add     rdi, rdx
        test    sil, 1
        je      .LBB0_2
        mov     rax, qword ptr [rdi]
        mov     rsi, qword ptr [rsi + rax - 1]
.LBB0_2:
        jmp     rsi                            # TAILCALL</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>