http://llvm.org/bugs/show_bug.cgi?id=18917

            Bug ID: 18917
           Summary: MS ABI: Pointers to virtual member functions in
                    non-primary vftables need to include offset to vfptr
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
            Blocks: 12477, 18887
    Classification: Unclassified

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to