Be sure to clear out VCall when we clear out VCalls.

Start implementing VTTs.  WIP.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86650 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp
index 5c3c9a5..e65c213 100644
--- a/lib/CodeGen/CGVtable.cpp
+++ b/lib/CodeGen/CGVtable.cpp
@@ -433,6 +433,7 @@
          i != e; ++i)
       methods[InsertionPoint++] = wrap((0?600:0) + *i);
     VCalls.clear();
+    VCall.clear();
   }
 
   Index_t end(const CXXRecordDecl *RD, const ASTRecordLayout &Layout,
@@ -700,6 +701,8 @@
   // then the vtables for all the virtual bases.
   b.GenerateVtableForVBases(RD);
 
+  //GenerateVTT(RD);
+
   llvm::Constant *C;
   llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, methods.size());
   C = llvm::ConstantArray::get(type, methods);
@@ -711,3 +714,39 @@
                                               AddressPoint*LLVMPointerWidth/8));
   return vtable;
 }
+
+class VTTBuilder {
+  /// Inits - The list of values built for the VTT.
+  std::vector<llvm::Constant *> &Inits;
+  /// Class - The most derived class that this vtable is being built for.
+  const CXXRecordDecl *Class;
+  CodeGenModule &CGM;  // Per-module state.
+
+public:
+  VTTBuilder(std::vector<llvm::Constant *> &inits, const CXXRecordDecl *c,
+             CodeGenModule &cgm) : Inits(inits), Class(c), CGM(cgm) {
+  }
+};
+
+llvm::Value *CodeGenFunction::GenerateVTT(const CXXRecordDecl *RD) {
+  llvm::SmallString<256> OutName;
+  llvm::raw_svector_ostream Out(OutName);
+  mangleCXXVTT(CGM.getMangleContext(), RD, Out);
+
+  llvm::GlobalVariable::LinkageTypes linktype;
+  linktype = llvm::GlobalValue::LinkOnceODRLinkage;
+  std::vector<llvm::Constant *> inits;
+  llvm::Type *Ptr8Ty=llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext),0);
+
+  VTTBuilder b(inits, RD, CGM);
+
+  D1(printf("vtt %s\n", RD->getNameAsCString()));
+
+  llvm::Constant *C;
+  llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, inits.size());
+  C = llvm::ConstantArray::get(type, inits);
+  llvm::Value *vtt = new llvm::GlobalVariable(CGM.getModule(), type, true,
+                                              linktype, C, Out.str());
+  vtt = Builder.CreateBitCast(vtt, Ptr8Ty);
+  return vtt;
+}
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index f2901be..fdbab24 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -384,6 +384,9 @@
   /// GenerateVtable - Generate the vtable for the given type.
   llvm::Value *GenerateVtable(const CXXRecordDecl *RD);
 
+  /// GenerateVTT - Generate the VTT for the given type.
+  llvm::Value *GenerateVTT(const CXXRecordDecl *RD);
+
   /// DynamicTypeAdjust - Do the non-virtual and virtual adjustments on an
   /// object pointer to alter the dynamic type of the pointer.  Used by
   /// GenerateCovariantThunk for building thunks.