Index: cfe/trunk/lib/CodeGen/CodeGenModule.h =================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.h +++ cfe/trunk/lib/CodeGen/CodeGenModule.h @@ -483,6 +483,12 @@ llvm::DenseMap DeferredEmptyCoverageMappingDecls; std::unique_ptr CoverageMapping; + + /// Mapping from canonical types to their metadata identifiers. We need to + /// maintain this mapping because identifiers may be formed from distinct + /// MDNodes. + llvm::DenseMap MetadataIdMap; + public: CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts, const PreprocessorOptions &ppopts, @@ -1112,6 +1118,11 @@ void EmitVTableBitSetEntries(llvm::GlobalVariable *VTable, const VTableLayout &VTLayout); + /// Create a metadata identifier for the given type. This may either be an + /// MDString (for external identifiers) or a distinct unnamed MDNode (for + /// internal identifiers). + llvm::Metadata *CreateMetadataIdentifierForType(QualType T); + /// Create a bitset entry for the given vtable. llvm::MDTuple *CreateVTableBitSetEntry(llvm::GlobalVariable *VTable, CharUnits Offset, Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp @@ -3803,6 +3803,25 @@ } } +llvm::Metadata *CodeGenModule::CreateMetadataIdentifierForType(QualType T) { + llvm::Metadata *&InternalId = MetadataIdMap[T.getCanonicalType()]; + if (InternalId) + return InternalId; + + if (isExternallyVisible(T->getLinkage())) { + std::string OutName; + llvm::raw_string_ostream Out(OutName); + getCXXABI().getMangleContext().mangleTypeName(T, Out); + + InternalId = llvm::MDString::get(getLLVMContext(), Out.str()); + } else { + InternalId = llvm::MDNode::getDistinct(getLLVMContext(), + llvm::ArrayRef()); + } + + return InternalId; +} + llvm::MDTuple *CodeGenModule::CreateVTableBitSetEntry( llvm::GlobalVariable *VTable, CharUnits Offset, const CXXRecordDecl *RD) { std::string OutName;