Delay codegen of vtables when handling implicit instantiations.

This fixes PR6474.

llvm-svn: 98123
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d6a56da..c67948d 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -488,7 +488,15 @@
   // Emit code for any potentially referenced deferred decls.  Since a
   // previously unused static decl may become used during the generation of code
   // for a static function, iterate until no  changes are made.
-  while (!DeferredDeclsToEmit.empty()) {
+
+  while (!DeferredDeclsToEmit.empty() || !DeferredVtables.empty()) {
+    if (!DeferredVtables.empty()) {
+      const CXXRecordDecl *RD = DeferredVtables.back();
+      DeferredVtables.pop_back();
+      getVtableInfo().GenerateClassData(getVtableLinkage(RD), RD);
+      continue;
+    }
+
     GlobalDecl D = DeferredDeclsToEmit.back();
     DeferredDeclsToEmit.pop_back();