<html>
    <head>
      <base href="http://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 --- - MS ABI: Pointers to virtual member functions in non-primary vftables need to include offset to vfptr"
   href="http://llvm.org/bugs/show_bug.cgi?id=18917">18917</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>MS ABI: Pointers to virtual member functions in non-primary vftables need to include offset to vfptr
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>rnk@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>12477, 18887
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We currently miscompile this code:

struct A {
  virtual int f() { return a; }
  int a;
};
struct B {
  virtual int g() { return b; }
  int b;
};
struct C : A, B {
  virtual int g() { return c; }
  int c;
};

int call_mp(C &c, int (C::*mp)()) {
  return (c.*mp)();
}

int main() {
  C c;
  c.a = 1;
  c.b = 2;
  c.c = 3;
  int (C::*mp)() = &C::g;
  return call_mp(c, mp);
}

When we take the address of &C::g, we should give a 'this' adjustment of zero
because we assume that the user will supply a C* and that the thunk expects
this to point to the complete object.  MSVC disagrees.

MSVC's thunks expect 'this' to point to the vfptr that holds the virtual method
in question.  The thunk then loads from the vftable and jumps.  Therefore, that
adjustment has to be part of the member pointer, so mp in this example needs a
non-virtual this adjustment of 8.</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>