r202331 - [MS ABI] Error instead of generating bad vftables for certain virtual hierarchies (PR18967)
Hans Wennborg
hans at hanshq.net
Wed Feb 26 17:14:32 PST 2014
Author: hans
Date: Wed Feb 26 19:14:31 2014
New Revision: 202331
URL: http://llvm.org/viewvc/llvm-project?rev=202331&view=rev
Log:
[MS ABI] Error instead of generating bad vftables for certain virtual hierarchies (PR18967)
Erroring out until we fix the bug means we don't have to keep chasing down
this same miscompile in a bunch of different places.
Differential Revision: http://llvm-reviews.chandlerc.com/D2890
Added:
cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-pr18967.cpp
Modified:
cfe/trunk/lib/AST/VTableBuilder.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
Modified: cfe/trunk/lib/AST/VTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTableBuilder.cpp?rev=202331&r1=202330&r2=202331&view=diff
==============================================================================
--- cfe/trunk/lib/AST/VTableBuilder.cpp (original)
+++ cfe/trunk/lib/AST/VTableBuilder.cpp Wed Feb 26 19:14:31 2014
@@ -2560,10 +2560,47 @@ private:
const CXXRecordDecl *LastVBase,
BasesSetVectorTy &VisitedBases);
+ void CheckBadVirtualInheritanceHierarchy() {
+ // We fail at this-adjustment for virtual methods inherited from
+ // non-virtual bases that overrides a method in a virtual base.
+ if (Context.getLangOpts().DumpVTableLayouts)
+ return;
+ for (CXXRecordDecl::base_class_const_iterator BI =
+ MostDerivedClass->bases_begin(), BE = MostDerivedClass->bases_end();
+ BI != BE; ++BI) {
+ const CXXRecordDecl *Base = BI->getType()->getAsCXXRecordDecl();
+ if (BI->isVirtual())
+ continue;
+ for (CXXRecordDecl::method_iterator I = Base->method_begin(),
+ E = Base->method_end(); I != E; ++I) {
+ const CXXMethodDecl *Method = *I;
+ if (!Method->isVirtual())
+ continue;
+ if (isa<CXXDestructorDecl>(Method))
+ continue;
+ OverriddenMethodsSetTy OverriddenMethods;
+ ComputeAllOverriddenMethods(Method, OverriddenMethods);
+ for (OverriddenMethodsSetTy::const_iterator I =
+ OverriddenMethods.begin(),
+ E = OverriddenMethods.end(); I != E; ++I) {
+ const CXXMethodDecl *Overridden = *I;
+ if (Base->isVirtuallyDerivedFrom(Overridden->getParent())) {
+ ErrorUnsupported("classes with non-virtual base "
+ "classes that override methods in virtual bases",
+ BI->getLocStart());
+ return;
+ }
+ }
+ }
+ }
+ }
+
void LayoutVFTable() {
// FIXME: add support for RTTI when we have proper LLVM support for symbols
// pointing to the middle of a section.
+ CheckBadVirtualInheritanceHierarchy();
+
BasesSetVectorTy VisitedBases;
AddMethods(BaseSubobject(MostDerivedClass, CharUnits::Zero()), 0, 0,
VisitedBases);
Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp?rev=202331&r1=202330&r2=202331&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp Wed Feb 26 19:14:31 2014
@@ -217,7 +217,12 @@ void call_complete_dtor() {
// CHECK: ret
}
-struct C : B {
+struct X : virtual VBase {
+ int x;
+};
+
+
+struct C : X {
C();
// has an implicit vdtor.
};
Added: cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-pr18967.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-pr18967.cpp?rev=202331&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-pr18967.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-pr18967.cpp Wed Feb 26 19:14:31 2014
@@ -0,0 +1,27 @@
+// RUN: not %clang_cc1 -triple i686-pc-win32 -emit-llvm -fno-rtti %s 2>&1 | FileCheck %s
+
+// CHECK: error: v-table layout for classes with non-virtual base classes that override methods in virtual bases is not supported yet
+
+struct A {
+ virtual int foo() { return a; }
+ int a;
+};
+struct B : virtual A {
+ B() : b(1) {}
+ virtual int bar() { return b; }
+ int b;
+};
+struct C : virtual A {
+ C() : c(2) {}
+ virtual int foo() { return c; }
+ int c;
+};
+struct D : B, C {
+ D() : d(3) {}
+ virtual int bar() { return d; }
+ int d;
+};
+int main() {
+ D d;
+ return d.foo();
+}
More information about the cfe-commits
mailing list