]> granicus.if.org Git - clang/commit
[MS] Fix bug in method vfptr location code
authorReid Kleckner <rnk@google.com>
Wed, 28 Mar 2018 18:23:35 +0000 (18:23 +0000)
committerReid Kleckner <rnk@google.com>
Wed, 28 Mar 2018 18:23:35 +0000 (18:23 +0000)
commite3fdb5e25ac1bd27e735acb69ee659210f30ec21
treea0a7b665ab8f955d1238f5a9b65102b7e3cdd013
parent873ca69ee16edadd1107c6eb36b93e3668ba59dc
[MS] Fix bug in method vfptr location code

We were assuming that vbtable indices were assigned in layout order in
our comparison, which is not the case. When a virtual method, such as
the destructor, appears in multiple vftables, the vftable that appears
first in object layout order is the one that points to the main
implementation of that method. The later vftables use thunks.

In this layout, we adjusted "this" in the main implementation by the
amount that is appropriate for 'B' instead of 'A', even though the main
implementation is found in D's vftable for A:

  struct A {
    virtual ~A() {}
  };
  struct B {
    virtual ~B() {}
  };
  struct C : virtual B {};
  struct D : virtual A, C {};

D's layout looks like:
   0 D subobject (empty)
   0 C base suboject
   8 A base subobject
  16 B base subobject

With this fix, we correctly adjust by -8 in D's deleting destructor
instead of -16.

Fixes PR36921.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328723 91177308-0d34-0410-b5e6-96231b3b80d8
lib/AST/VTableBuilder.cpp
test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp