Author: majnemer Date: Wed Nov 18 18:03:54 2015 New Revision: 253523 URL: http://llvm.org/viewvc/llvm-project?rev=253523&view=rev Log: [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. Modified: cfe/trunk/lib/AST/VTableBuilder.cpp cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp Modified: cfe/trunk/lib/AST/VTableBuilder.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTableBuilder.cpp?rev=253523&r1=253522&r2=253523&view=diff ============================================================================== --- cfe/trunk/lib/AST/VTableBuilder.cpp (original) +++ cfe/trunk/lib/AST/VTableBuilder.cpp Wed Nov 18 18:03:54 2015 @@ -2882,22 +2882,26 @@ static void GroupNewVirtualOverloads( // Put the virtual methods into VirtualMethods in the proper order: // 1) Group overloads by declaration name. New groups are added to the // vftable in the order of their first declarations in this class - // (including overrides and non-virtual methods). + // (including overrides, non-virtual methods and any other named decl that + // might be nested within the class). // 2) In each group, new overloads appear in the reverse order of declaration. typedef SmallVector<const CXXMethodDecl *, 1> MethodGroup; SmallVector<MethodGroup, 10> Groups; typedef llvm::DenseMap<DeclarationName, unsigned> VisitedGroupIndicesTy; VisitedGroupIndicesTy VisitedGroupIndices; - for (const auto *MD : RD->methods()) { - MD = MD->getCanonicalDecl(); + for (const auto *D : RD->decls()) { + const auto *ND = dyn_cast<NamedDecl>(D); + if (!ND) + continue; VisitedGroupIndicesTy::iterator J; bool Inserted; std::tie(J, Inserted) = VisitedGroupIndices.insert( - std::make_pair(MD->getDeclName(), Groups.size())); + std::make_pair(ND->getDeclName(), Groups.size())); if (Inserted) Groups.push_back(MethodGroup()); - if (MD->isVirtual()) - Groups[J->second].push_back(MD); + if (const auto *MD = dyn_cast<CXXMethodDecl>(ND)) + if (MD->isVirtual()) + Groups[J->second].push_back(MD->getCanonicalDecl()); } for (const MethodGroup &Group : Groups) Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp?rev=253523&r1=253522&r2=253523&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp (original) +++ cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp Wed Nov 18 18:03:54 2015 @@ -299,3 +299,18 @@ struct S { }; S::S() {} + +struct T { + struct U {}; +}; +struct V : T { + // CHECK-LABEL: VFTable for 'V' (2 entries). + // CHECK-NEXT: 0 | void V::U() + // CHECK-NEXT: 1 | void V::f() + using T::U; + virtual void f(); + virtual void U(); + V(); +}; + +V::V() {} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits