From: Mike Stump Date: Tue, 10 Nov 2009 02:30:51 +0000 (+0000) Subject: Be sure to clear out VCall when we clear out VCalls. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fbfb52d4cf10b4fd1ac19d1445fe2ffcb9c2bbf1;p=clang 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 5c3c9a573e..e65c213b76 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -433,6 +433,7 @@ public: 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 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) { // 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 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) { AddressPoint*LLVMPointerWidth/8)); return vtable; } + +class VTTBuilder { + /// Inits - The list of values built for the VTT. + std::vector &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 &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 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 f2901beca4..fdbab245d0 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -384,6 +384,9 @@ public: /// 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.