[LLVMbugs] [Bug 18917] New: MS ABI: Pointers to virtual member functions in non-primary vftables need to include offset to vfptr
    bugzilla-daemon at llvm.org 
    bugzilla-daemon at llvm.org
       
    Thu Feb 20 18:02:38 PST 2014
    
    
  
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: unassignedclangbugs at nondot.org
          Reporter: rnk at google.com
                CC: llvmbugs at cs.uiuc.edu
            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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140221/73db6ec0/attachment.html>
    
    
More information about the llvm-bugs
mailing list