Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 94404b1

Browse files
committed
[MS ABI] Let arbitrary entities participate in vftable ordering
In the Microsoft ABI, the vftable is laid out in the order in the declaration order of the entities defined within it. Obviously, only virtual methods end up in the vftable but they will be placed into the table at the same position as the first entity with the same name. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253523 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f88e4c3 commit 94404b1

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

lib/AST/VTableBuilder.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,22 +2882,26 @@ static void GroupNewVirtualOverloads(
28822882
// Put the virtual methods into VirtualMethods in the proper order:
28832883
// 1) Group overloads by declaration name. New groups are added to the
28842884
// vftable in the order of their first declarations in this class
2885-
// (including overrides and non-virtual methods).
2885+
// (including overrides, non-virtual methods and any other named decl that
2886+
// might be nested within the class).
28862887
// 2) In each group, new overloads appear in the reverse order of declaration.
28872888
typedef SmallVector<const CXXMethodDecl *, 1> MethodGroup;
28882889
SmallVector<MethodGroup, 10> Groups;
28892890
typedef llvm::DenseMap<DeclarationName, unsigned> VisitedGroupIndicesTy;
28902891
VisitedGroupIndicesTy VisitedGroupIndices;
2891-
for (const auto *MD : RD->methods()) {
2892-
MD = MD->getCanonicalDecl();
2892+
for (const auto *D : RD->decls()) {
2893+
const auto *ND = dyn_cast<NamedDecl>(D);
2894+
if (!ND)
2895+
continue;
28932896
VisitedGroupIndicesTy::iterator J;
28942897
bool Inserted;
28952898
std::tie(J, Inserted) = VisitedGroupIndices.insert(
2896-
std::make_pair(MD->getDeclName(), Groups.size()));
2899+
std::make_pair(ND->getDeclName(), Groups.size()));
28972900
if (Inserted)
28982901
Groups.push_back(MethodGroup());
2899-
if (MD->isVirtual())
2900-
Groups[J->second].push_back(MD);
2902+
if (const auto *MD = dyn_cast<CXXMethodDecl>(ND))
2903+
if (MD->isVirtual())
2904+
Groups[J->second].push_back(MD->getCanonicalDecl());
29012905
}
29022906

29032907
for (const MethodGroup &Group : Groups)

test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,18 @@ struct S {
299299
};
300300

301301
S::S() {}
302+
303+
struct T {
304+
struct U {};
305+
};
306+
struct V : T {
307+
// CHECK-LABEL: VFTable for 'V' (2 entries).
308+
// CHECK-NEXT: 0 | void V::U()
309+
// CHECK-NEXT: 1 | void V::f()
310+
using T::U;
311+
virtual void f();
312+
virtual void U();
313+
V();
314+
};
315+
316+
V::V() {}

0 commit comments

Comments
 (0)