Index: llvm/trunk/include/llvm/MC/MCContext.h =================================================================== --- llvm/trunk/include/llvm/MC/MCContext.h +++ llvm/trunk/include/llvm/MC/MCContext.h @@ -511,7 +511,7 @@ /// Creates an entry in the dwarf file and directory tables. Expected getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, - MD5::MD5Result *Checksum, + Optional Checksum, Optional Source, unsigned CUID); bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0); @@ -554,7 +554,8 @@ /// Specifies the "root" file and directory of the compilation unit. /// These are "file 0" and "directory 0" in DWARF v5. void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir, - StringRef Filename, MD5::MD5Result *Checksum, + StringRef Filename, + Optional Checksum, Optional Source) { getMCDwarfLineTable(CUID).setRootFile(CompilationDir, Filename, Checksum, Source); Index: llvm/trunk/include/llvm/MC/MCDwarf.h =================================================================== --- llvm/trunk/include/llvm/MC/MCDwarf.h +++ llvm/trunk/include/llvm/MC/MCDwarf.h @@ -55,7 +55,7 @@ /// The MD5 checksum, if there is one. Non-owning pointer to data allocated /// in MCContext. - MD5::MD5Result *Checksum = nullptr; + Optional Checksum; /// The source code of the file. Non-owning reference to data allocated in /// MCContext. @@ -223,7 +223,7 @@ MCDwarfLineTableHeader() = default; Expected tryGetFile(StringRef &Directory, StringRef &FileName, - MD5::MD5Result *Checksum, + Optional Checksum, Optional &Source, unsigned FileNumber = 0); std::pair @@ -256,7 +256,7 @@ public: void maybeSetRootFile(StringRef Directory, StringRef FileName, - MD5::MD5Result *Checksum, Optional Source) { + Optional Checksum, Optional Source) { if (!Header.RootFile.Name.empty()) return; Header.CompilationDir = Directory; @@ -264,12 +264,12 @@ Header.RootFile.DirIndex = 0; Header.RootFile.Checksum = Checksum; Header.RootFile.Source = Source; - Header.trackMD5Usage(Checksum); + Header.trackMD5Usage(Checksum.hasValue()); Header.HasSource = Source.hasValue(); } unsigned getFile(StringRef Directory, StringRef FileName, - MD5::MD5Result *Checksum, Optional Source) { + Optional Checksum, Optional Source) { return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source)); } @@ -290,24 +290,24 @@ Optional &LineStr) const; Expected tryGetFile(StringRef &Directory, StringRef &FileName, - MD5::MD5Result *Checksum, + Optional Checksum, Optional Source, unsigned FileNumber = 0); unsigned getFile(StringRef &Directory, StringRef &FileName, - MD5::MD5Result *Checksum, Optional &Source, + Optional Checksum, Optional &Source, unsigned FileNumber = 0) { return cantFail(tryGetFile(Directory, FileName, Checksum, Source, FileNumber)); } void setRootFile(StringRef Directory, StringRef FileName, - MD5::MD5Result *Checksum, Optional Source) { + Optional Checksum, Optional Source) { Header.CompilationDir = Directory; Header.RootFile.Name = FileName; Header.RootFile.DirIndex = 0; Header.RootFile.Checksum = Checksum; Header.RootFile.Source = Source; - Header.trackMD5Usage(Checksum); + Header.trackMD5Usage(Checksum.hasValue()); Header.HasSource = Source.hasValue(); } Index: llvm/trunk/include/llvm/MC/MCStreamer.h =================================================================== --- llvm/trunk/include/llvm/MC/MCStreamer.h +++ llvm/trunk/include/llvm/MC/MCStreamer.h @@ -781,7 +781,7 @@ /// implements the DWARF2 '.file 4 "foo.c"' assembler directive. unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum = nullptr, + Optional Checksum = None, Optional Source = None, unsigned CUID = 0) { return cantFail( @@ -796,12 +796,12 @@ /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive. virtual Expected tryEmitDwarfFileDirective( unsigned FileNo, StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum = nullptr, Optional Source = None, + Optional Checksum = None, Optional Source = None, unsigned CUID = 0); /// Specify the "root" file of the compilation, using the ".file 0" extension. virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum, + Optional Checksum, Optional Source, unsigned CUID = 0); Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -104,7 +104,7 @@ // extend .file to support this. unsigned CUID = Asm->OutStreamer->hasRawTextSupport() ? 0 : getUniqueID(); if (!File) - return Asm->OutStreamer->EmitDwarfFileDirective(0, "", "", nullptr, None, CUID); + return Asm->OutStreamer->EmitDwarfFileDirective(0, "", "", None, None, CUID); return Asm->OutStreamer->EmitDwarfFileDirective( 0, File->getDirectory(), File->getFilename(), getMD5AsBytes(File), File->getSource(), CUID); Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -296,7 +296,7 @@ /// If the \p File has an MD5 checksum, return it as an MD5Result /// allocated in the MCContext. - MD5::MD5Result *getMD5AsBytes(const DIFile *File) const; + Optional getMD5AsBytes(const DIFile *File) const; protected: ~DwarfUnit(); Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -289,21 +289,21 @@ addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer); } -MD5::MD5Result *DwarfUnit::getMD5AsBytes(const DIFile *File) const { +Optional DwarfUnit::getMD5AsBytes(const DIFile *File) const { assert(File); if (DD->getDwarfVersion() < 5) - return nullptr; + return None; Optional> Checksum = File->getChecksum(); if (!Checksum || Checksum->Kind != DIFile::CSK_MD5) - return nullptr; + return None; // Convert the string checksum to an MD5Result for the streamer. // The verifier validates the checksum so we assume it's okay. // An MD5 checksum is 16 bytes. std::string ChecksumString = fromHex(Checksum->Value); - void *CKMem = Asm->OutStreamer->getContext().allocate(16, 1); - memcpy(CKMem, ChecksumString.data(), 16); - return reinterpret_cast(CKMem); + MD5::MD5Result CKMem; + std::copy(ChecksumString.begin(), ChecksumString.end(), CKMem.Bytes.data()); + return CKMem; } unsigned DwarfTypeUnit::getOrCreateSourceID(const DIFile *File) { Index: llvm/trunk/lib/MC/MCAsmStreamer.cpp =================================================================== --- llvm/trunk/lib/MC/MCAsmStreamer.cpp +++ llvm/trunk/lib/MC/MCAsmStreamer.cpp @@ -223,11 +223,11 @@ Expected tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum = 0, + Optional Checksum = None, Optional Source = None, unsigned CUID = 0) override; void emitDwarfFile0Directive(StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum, + Optional Checksum, Optional Source, unsigned CUID = 0) override; void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, @@ -1151,7 +1151,7 @@ static void printDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum, + Optional Checksum, Optional Source, bool UseDwarfDirectory, raw_svector_ostream &OS) { @@ -1184,7 +1184,7 @@ Expected MCAsmStreamer::tryEmitDwarfFileDirective( unsigned FileNo, StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum, Optional Source, unsigned CUID) { + Optional Checksum, Optional Source, unsigned CUID) { assert(CUID == 0 && "multiple CUs not supported by MCAsmStreamer"); MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID); @@ -1212,7 +1212,7 @@ void MCAsmStreamer::emitDwarfFile0Directive(StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum, + Optional Checksum, Optional Source, unsigned CUID) { assert(CUID == 0); Index: llvm/trunk/lib/MC/MCContext.cpp =================================================================== --- llvm/trunk/lib/MC/MCContext.cpp +++ llvm/trunk/lib/MC/MCContext.cpp @@ -572,12 +572,13 @@ void MCContext::setGenDwarfRootFile(StringRef InputFileName, StringRef Buffer) { // MCDwarf needs the root file as well as the compilation directory. // If we find a '.file 0' directive that will supersede these values. - MD5::MD5Result *Cksum = nullptr; + Optional Cksum; if (getDwarfVersion() >= 5) { MD5 Hash; - Cksum = (MD5::MD5Result *)allocate(sizeof(MD5::MD5Result), 1); + MD5::MD5Result Sum; Hash.update(Buffer); - Hash.final(*Cksum); + Hash.final(Sum); + Cksum = Sum; } // Canonicalize the root filename. It cannot be empty, and should not // repeat the compilation dir. @@ -600,7 +601,7 @@ Expected MCContext::getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, - MD5::MD5Result *Checksum, + Optional Checksum, Optional Source, unsigned CUID) { MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID]; Index: llvm/trunk/lib/MC/MCDwarf.cpp =================================================================== --- llvm/trunk/lib/MC/MCDwarf.cpp +++ llvm/trunk/lib/MC/MCDwarf.cpp @@ -361,10 +361,10 @@ } MCOS->EmitULEB128IntValue(DwarfFile.DirIndex); // Directory number. if (EmitMD5) { - MD5::MD5Result *Cksum = DwarfFile.Checksum; + const MD5::MD5Result &Cksum = *DwarfFile.Checksum; MCOS->EmitBinaryData( - StringRef(reinterpret_cast(Cksum->Bytes.data()), - Cksum->Bytes.size())); + StringRef(reinterpret_cast(Cksum.Bytes.data()), + Cksum.Bytes.size())); } if (HasSource) { if (LineStr) @@ -536,7 +536,7 @@ Expected MCDwarfLineTable::tryGetFile(StringRef &Directory, StringRef &FileName, - MD5::MD5Result *Checksum, + Optional Checksum, Optional Source, unsigned FileNumber) { return Header.tryGetFile(Directory, FileName, Checksum, Source, FileNumber); @@ -545,7 +545,7 @@ Expected MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, StringRef &FileName, - MD5::MD5Result *Checksum, + Optional Checksum, Optional &Source, unsigned FileNumber) { if (Directory == CompilationDir) @@ -558,7 +558,7 @@ // Keep track of whether any or all files have an MD5 checksum. // If any files have embedded source, they all must. if (MCDwarfFiles.empty()) { - trackMD5Usage(Checksum); + trackMD5Usage(Checksum.hasValue()); HasSource = (Source != None); } if (FileNumber == 0) { @@ -623,7 +623,7 @@ File.Name = FileName; File.DirIndex = DirIndex; File.Checksum = Checksum; - trackMD5Usage(Checksum); + trackMD5Usage(Checksum.hasValue()); File.Source = Source; if (Source) HasSource = true; Index: llvm/trunk/lib/MC/MCParser/AsmParser.cpp =================================================================== --- llvm/trunk/lib/MC/MCParser/AsmParser.cpp +++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp @@ -3388,13 +3388,14 @@ Ctx.setGenDwarfForAssembly(false); } - MD5::MD5Result *CKMem = nullptr; + Optional CKMem; if (HasMD5) { - CKMem = (MD5::MD5Result *)Ctx.allocate(sizeof(MD5::MD5Result), 1); + MD5::MD5Result Sum; for (unsigned i = 0; i != 8; ++i) { - CKMem->Bytes[i] = uint8_t(MD5Hi >> ((7 - i) * 8)); - CKMem->Bytes[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8)); + Sum.Bytes[i] = uint8_t(MD5Hi >> ((7 - i) * 8)); + Sum.Bytes[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8)); } + CKMem = Sum; } if (HasSource) { char *SourceBuf = static_cast(Ctx.allocate(SourceString.size())); Index: llvm/trunk/lib/MC/MCStreamer.cpp =================================================================== --- llvm/trunk/lib/MC/MCStreamer.cpp +++ llvm/trunk/lib/MC/MCStreamer.cpp @@ -204,7 +204,7 @@ Expected MCStreamer::tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum, + Optional Checksum, Optional Source, unsigned CUID) { return getContext().getDwarfFile(Directory, Filename, FileNo, Checksum, @@ -213,7 +213,7 @@ void MCStreamer::emitDwarfFile0Directive(StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum, + Optional Checksum, Optional Source, unsigned CUID) { getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,