Fix for PR5707: make sure implicit copy constructors initialize the vtable
pointer.
llvm-svn: 90840
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp
index 0b77584..bd166d0 100644
--- a/clang/lib/CodeGen/CGCXX.cpp
+++ b/clang/lib/CodeGen/CGCXX.cpp
@@ -1572,6 +1572,8 @@
EmitAggregateCopy(LHS.getAddress(), RHS.getAddress(), Field->getType());
}
}
+
+ InitializeVtablePtrs(ClassDecl);
FinishFunction();
}
@@ -1812,6 +1814,10 @@
PopCXXTemporary();
}
+ InitializeVtablePtr(ClassDecl);
+}
+
+void CodeGenFunction::InitializeVtablePtrs(const CXXRecordDecl *ClassDecl) {
if (!ClassDecl->isDynamicClass())
return;
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index ead2b5d..854eb53 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -468,6 +468,8 @@
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/clang/test/CodeGenCXX/copy-constructor-synthesis-2.cpp b/clang/test/CodeGenCXX/copy-constructor-synthesis-2.cpp
new file mode 100644
index 0000000..b4add46
--- /dev/null
+++ b/clang/test/CodeGenCXX/copy-constructor-synthesis-2.cpp
@@ -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)