]> granicus.if.org Git - clang/commitdiff
Fix for PR5707: make sure implicit copy constructors initialize the vtable
authorEli Friedman <eli.friedman@gmail.com>
Tue, 8 Dec 2009 06:46:18 +0000 (06:46 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 8 Dec 2009 06:46:18 +0000 (06:46 +0000)
pointer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90840 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGenCXX/copy-constructor-synthesis-2.cpp [new file with mode: 0644]

index 0b77584dd93c2f96df9c865812d01308eb548090..bd166d08efe0b26bc0aa8c76e3671e167da42719 100644 (file)
@@ -1572,6 +1572,8 @@ CodeGenFunction::SynthesizeCXXCopyConstructor(const CXXConstructorDecl *Ctor,
       EmitAggregateCopy(LHS.getAddress(), RHS.getAddress(), Field->getType());
     }
   }
+
+  InitializeVtablePtrs(ClassDecl);
   FinishFunction();
 }
 
@@ -1812,6 +1814,10 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD,
       PopCXXTemporary();
   }
 
+  InitializeVtablePtr(ClassDecl);
+}
+
+void CodeGenFunction::InitializeVtablePtrs(const CXXRecordDecl *ClassDecl) {
   if (!ClassDecl->isDynamicClass())
     return;
   
index ead2b5df7d36092b419d4b96f62d9e164ffa16bb..854eb53ec29915b36379caf96e599bba831f8b98 100644 (file)
@@ -468,6 +468,8 @@ public:
 
   void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type);
 
+  void InitializeVtablePtrs(const CXXRecordDecl *ClassDecl);
+
   void SynthesizeCXXCopyConstructor(const CXXConstructorDecl *Ctor,
                                     CXXCtorType Type,
                                     llvm::Function *Fn,
diff --git a/test/CodeGenCXX/copy-constructor-synthesis-2.cpp b/test/CodeGenCXX/copy-constructor-synthesis-2.cpp
new file mode 100644 (file)
index 0000000..b4add46
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: clang-cc -emit-llvm -o - %s | FileCheck %s
+
+struct A { virtual void a(); };
+A x(A& y) { return y; }
+
+// CHECK: define linkonce_odr void @_ZN1AC1ERKS_(
+// CHECK: store i8** getelementptr inbounds ([3 x i8*]* @_ZTV1A, i64 0, i64 2)