Fixup key function calculations.

llvm-svn: 89412
This commit is contained in:
Mike Stump 2009-11-20 00:02:19 +00:00
parent 772f922acb
commit a7a1b7e780
4 changed files with 58 additions and 59 deletions

View File

@ -345,12 +345,8 @@ static const CXXMethodDecl *GetKeyFunction(const RecordDecl *D) {
if (MD->isPure())
continue;
// FIXME: This doesn't work. If we have an out of line body, that body will
// set the MD to have a body, what we want to know is, was the body present
// inside the declaration of the class. For now, we just avoid the problem
// by pretending there is no key function.
return 0;
if (MD->getBody())
const FunctionDecl *fn;
if (MD->getBody(fn) && !fn->isOutOfLine())
continue;
// We found it.

View File

@ -623,7 +623,9 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) {
const CGRecordLayout &CGLayout = Types.getCGRecordLayout(RD);
// A definition of a KeyFunction, generates all the class data, such
// as vtable, rtti and the VTT.
if (CGLayout.getKeyFunction() == MD)
if (CGLayout.getKeyFunction()
&& (CGLayout.getKeyFunction()->getCanonicalDecl()
== MD->getCanonicalDecl()))
getVtableInfo().GenerateClassData(RD);
}
if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(D))

View File

@ -97,7 +97,7 @@ void test1() {
// CHECK-LL-NEXT: br i1 %4, label %5, label %9
// CHECK-LL: ; <label>:5
// CHECK-LL-NEXT: %6 = bitcast %class.test1_A* %tmp to i8*
// CHECK-LL-NEXT: %7 = call i8* @__dynamic_cast(i8* %6, i8* bitcast (i8** @_ZTI7test1_B to i8*), i8* bitcast (i8** @_ZTI7test1_D to i8*), i64 -1)
// CHECK-LL-NEXT: %7 = call i8* @__dynamic_cast(i8* %6, i8* bitcast ({{.*}} @_ZTI7test1_B to i8*), i8* bitcast (i8** @_ZTI7test1_D to i8*), i64 -1)
// CHECK-LL-NEXT: %8 = bitcast i8* %7 to %class.test1_D*
// CHECK-LL-NEXT: br label %10
// CHECK-LL: ; <label>:9
@ -120,7 +120,7 @@ void test1() {
// CHECK-LL-NEXT: br i1 %12, label %13, label %17
// CHECK-LL: ; <label>:13
// CHECK-LL-NEXT: %14 = bitcast %class.test1_A* %tmp6 to i8*
// CHECK-LL-NEXT: %15 = call i8* @__dynamic_cast(i8* %14, i8* bitcast (i8** @_ZTI7test1_B to i8*), i8* bitcast (i8** @_ZTI7test1_A to i8*), i64 -1)
// CHECK-LL-NEXT: %15 = call i8* @__dynamic_cast(i8* %14, i8* bitcast ({{.*}} @_ZTI7test1_B to i8*), i8* bitcast ({{.*}} @_ZTI7test1_A to i8*), i64 -1)
// CHECK-LL-NEXT: %16 = bitcast i8* %15 to %class.test1_A*
// CHECK-LL-NEXT: br label %18
// CHECK-LL: ; <label>:17
@ -143,7 +143,7 @@ void test1() {
// CHECK-LL-NEXT: br i1 %20, label %21, label %25
// CHECK-LL: ; <label>:21
// CHECK-LL-NEXT: %22 = bitcast %class.test1_A* %tmp14 to i8*
// CHECK-LL-NEXT: %23 = call i8* @__dynamic_cast(i8* %22, i8* bitcast (i8** @_ZTI7test1_A to i8*), i8* bitcast (i8** @_ZTI7test1_B to i8*), i64 -1)
// CHECK-LL-NEXT: %23 = call i8* @__dynamic_cast({{.*}} %22, i8* bitcast ({{.*}} @_ZTI7test1_A to i8*), i8* bitcast ({{.*}} @_ZTI7test1_B to i8*), i64 -1)
// CHECK-LL-NEXT: %24 = bitcast i8* %23 to %class.test1_A*
// CHECK-LL-NEXT: br label %26
// CHECK-LL: ; <label>:25
@ -214,7 +214,7 @@ void test1() {
// CHECK-LL-NEXT: br i1 %34, label %35, label %39
// CHECK-LL: ; <label>:35
// CHECK-LL-NEXT: %36 = bitcast %class.test1_A* %tmp54 to i8*
// CHECK-LL-NEXT: %37 = call i8* @__dynamic_cast(i8* %36, i8* bitcast (i8** @_ZTI7test1_A to i8*), i8* bitcast (i8** @_ZTI7test1_D to i8*), i64 -1)
// CHECK-LL-NEXT: %37 = call i8* @__dynamic_cast(i8* %36, i8* bitcast ({{.*}} @_ZTI7test1_A to i8*), i8* bitcast ({{.*}} @_ZTI7test1_D to i8*), i64 -1)
// CHECK-LL-NEXT: %38 = bitcast i8* %37 to %class.test1_D*
// CHECK-LL-NEXT: br label %40
// CHECK-LL: ; <label>:39
@ -237,7 +237,7 @@ void test1() {
// CHECK-LL-NEXT: br i1 %42, label %43, label %47
// CHECK-LL: ; <label>:43
// CHECK-LL-NEXT: %44 = bitcast %class.test1_A* %tmp63 to i8*
// CHECK-LL-NEXT: %45 = call i8* @__dynamic_cast(i8* %44, i8* bitcast (i8** @_ZTI7test1_A to i8*), i8* bitcast (i8** @_ZTI7test1_E to i8*), i64 -1)
// CHECK-LL-NEXT: %45 = call i8* @__dynamic_cast(i8* %44, i8* bitcast ({{.*}} @_ZTI7test1_A to i8*), i8* bitcast ({{.*}} @_ZTI7test1_E to i8*), i64 -1)
// CHECK-LL-NEXT: %46 = bitcast i8* %45 to %class.test1_E*
// CHECK-LL-NEXT: br label %48
// CHECK-LL: ; <label>:47
@ -279,7 +279,7 @@ void test1() {
// CHECK-LL: if.end85:
// CHECK-LL-NEXT: br i1 false, label %50, label %53
// CHECK-LL: ; <label>:50
// CHECK-LL-NEXT: %51 = call i8* @__dynamic_cast(i8* null, i8* bitcast (i8** @_ZTI7test1_A to i8*), i8* bitcast (i8** @_ZTI7test1_D to i8*), i64 -1)
// CHECK-LL-NEXT: %51 = call i8* @__dynamic_cast(i8* null, i8* bitcast ({{.*}}* @_ZTI7test1_A to i8*), i8* bitcast ({{.*}} @_ZTI7test1_D to i8*), i64 -1)
// CHECK-LL-NEXT: %52 = bitcast i8* %51 to %class.test1_D*
// CHECK-LL-NEXT: br label %54
// CHECK-LL: ; <label>:53

View File

@ -4,6 +4,11 @@
// RUN: clang-cc -triple x86_64-apple-darwin -std=c++0x -emit-llvm %s -o %t-64.ll
// RUN: FileCheck -check-prefix LPLL64 --input-file=%t-64.ll %s
// CHECK-LP64: main:
// CHECK-LP64: movl $1, 12(%rax)
// CHECK-LP64: movl $2, 8(%rax)
struct B {
virtual void bar1();
virtual void bar2();
@ -12,6 +17,12 @@ struct B {
void B::bar1() { }
void B::bar2() { }
// CHECK-LP64: __ZTV1B:
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .quad __ZTI1B
// CHECK-LP64-NEXT: .quad __ZN1B4bar1Ev
// CHECK-LP64-NEXT: .quad __ZN1B4bar2Ev
struct C {
virtual void bee1();
virtual void bee2();
@ -41,6 +52,28 @@ public:
};
void F::foo() { }
// CHECK-LP64: __ZTV1F:
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .quad 16
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .quad __ZTI1F
// CHECK-LP64-NEXT: .quad __ZN1D3booEv
// CHECK-LP64-NEXT: .quad __ZN1F3fooEv
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .quad 18446744073709551600
// CHECK-LP64-NEXT: .quad __ZTI1F
// CHECK-LP64-NEXT: .quad __ZN2D13barEv
// CHECK-LP64-NEXT: .quad __ZN2D14bar2Ev
// CHECK-LP64-NEXT: .quad __ZN2D14bar3Ev
// CHECK-LP64-NEXT: .quad __ZN2D14bar4Ev
// CHECK-LP64-NEXT: .quad __ZN2D14bar5Ev
int j;
void *vp;
void test2() {
@ -79,9 +112,18 @@ int main() {
ap->b = 2;
}
// CHECK-LP64: main:
// CHECK-LP64: movl $1, 12(%rax)
// CHECK-LP64: movl $2, 8(%rax)
// CHECK-LP64: __ZTV1A:
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .quad __ZTI1A
// CHECK-LP64-NEXT: .quad __ZN1B4bar1Ev
// CHECK-LP64-NEXT: .quad __ZN1B4bar2Ev
// CHECK-LP64-NEXT: .quad __ZN1A4foo1Ev
// CHECK-LP64-NEXT: .quad __ZN1A4foo2Ev
// CHECK-LP64-NEXT: .quad 18446744073709551600
// CHECK-LP64-NEXT: .quad __ZTI1A
// CHECK-LP64-NEXT: .quad __ZN1C4bee1Ev
// CHECK-LP64-NEXT: .quad __ZN1C4bee2Ev
struct test12_A {
virtual void foo0() { }
@ -675,12 +717,10 @@ virtual void foo_B2() { }
};
struct test16_D : test16_NV1, virtual test16_B2 {
virtual void bar();
virtual test16_D *foo1();
virtual void bar() { }
virtual test16_D *foo1() { return 0; }
};
void test16_D::bar() { }
// CHECK-LP64: __ZTV8test16_D:
// CHECK-LP64-NEXT: .quad 32
// CHECK-LP64-NEXT: .quad 16
@ -1040,45 +1080,6 @@ class test21_D : public test21_B, public test21_B1 {
// CHECK-LP64: __ZTV1B:
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .quad __ZTI1B
// CHECK-LP64-NEXT: .quad __ZN1B4bar1Ev
// CHECK-LP64-NEXT: .quad __ZN1B4bar2Ev
// CHECK-LP64: __ZTV1A:
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .quad __ZTI1A
// CHECK-LP64-NEXT: .quad __ZN1B4bar1Ev
// CHECK-LP64-NEXT: .quad __ZN1B4bar2Ev
// CHECK-LP64-NEXT: .quad __ZN1A4foo1Ev
// CHECK-LP64-NEXT: .quad __ZN1A4foo2Ev
// CHECK-LP64-NEXT: .quad 18446744073709551600
// CHECK-LP64-NEXT: .quad __ZTI1A
// CHECK-LP64-NEXT: .quad __ZN1C4bee1Ev
// CHECK-LP64-NEXT: .quad __ZN1C4bee2Ev
// CHECK-LP64: __ZTV1F:
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .quad 16
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .quad __ZTI1F
// CHECK-LP64-NEXT: .quad __ZN1D3booEv
// CHECK-LP64-NEXT: .quad __ZN1F3fooEv
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .space 8
// CHECK-LP64-NEXT: .quad 18446744073709551600
// CHECK-LP64-NEXT: .quad __ZTI1F
// CHECK-LP64-NEXT: .quad __ZN2D13barEv
// CHECK-LP64-NEXT: .quad __ZN2D14bar2Ev
// CHECK-LP64-NEXT: .quad __ZN2D14bar3Ev
// CHECK-LP64-NEXT: .quad __ZN2D14bar4Ev
// CHECK-LP64-NEXT: .quad __ZN2D14bar5Ev
test21_D d21;
test20_D d20;
test19_D d19;