[llvm] r357736 - NFC: Move API uses of MD5::MD5Result to Optional rather than a pointer.
Eric Christopher via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 4 16:34:38 PDT 2019
Author: echristo
Date: Thu Apr 4 16:34:38 2019
New Revision: 357736
URL: http://llvm.org/viewvc/llvm-project?rev=357736&view=rev
Log:
NFC: Move API uses of MD5::MD5Result to Optional rather than a pointer.
Differential Revision: https://reviews.llvm.org/D60290
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/include/llvm/MC/MCDwarf.h
llvm/trunk/include/llvm/MC/MCStreamer.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/MC/MCDwarf.cpp
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/lib/MC/MCStreamer.cpp
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Thu Apr 4 16:34:38 2019
@@ -511,7 +511,7 @@ namespace llvm {
/// Creates an entry in the dwarf file and directory tables.
Expected<unsigned> getDwarfFile(StringRef Directory, StringRef FileName,
unsigned FileNumber,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source, unsigned CUID);
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0);
@@ -554,7 +554,8 @@ namespace llvm {
/// 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<MD5::MD5Result> Checksum,
Optional<StringRef> Source) {
getMCDwarfLineTable(CUID).setRootFile(CompilationDir, Filename, Checksum,
Source);
Modified: llvm/trunk/include/llvm/MC/MCDwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCDwarf.h (original)
+++ llvm/trunk/include/llvm/MC/MCDwarf.h Thu Apr 4 16:34:38 2019
@@ -55,7 +55,7 @@ struct MCDwarfFile {
/// The MD5 checksum, if there is one. Non-owning pointer to data allocated
/// in MCContext.
- MD5::MD5Result *Checksum = nullptr;
+ Optional<MD5::MD5Result> Checksum;
/// The source code of the file. Non-owning reference to data allocated in
/// MCContext.
@@ -223,7 +223,7 @@ public:
MCDwarfLineTableHeader() = default;
Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> &Source,
unsigned FileNumber = 0);
std::pair<MCSymbol *, MCSymbol *>
@@ -256,7 +256,7 @@ class MCDwarfDwoLineTable {
public:
void maybeSetRootFile(StringRef Directory, StringRef FileName,
- MD5::MD5Result *Checksum, Optional<StringRef> Source) {
+ Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source) {
if (!Header.RootFile.Name.empty())
return;
Header.CompilationDir = Directory;
@@ -264,12 +264,12 @@ public:
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<StringRef> Source) {
+ Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source) {
return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source));
}
@@ -290,24 +290,24 @@ public:
Optional<MCDwarfLineStr> &LineStr) const;
Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
unsigned FileNumber = 0);
unsigned getFile(StringRef &Directory, StringRef &FileName,
- MD5::MD5Result *Checksum, Optional<StringRef> &Source,
+ Optional<MD5::MD5Result> Checksum, Optional<StringRef> &Source,
unsigned FileNumber = 0) {
return cantFail(tryGetFile(Directory, FileName, Checksum, Source,
FileNumber));
}
void setRootFile(StringRef Directory, StringRef FileName,
- MD5::MD5Result *Checksum, Optional<StringRef> Source) {
+ Optional<MD5::MD5Result> Checksum, Optional<StringRef> 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();
}
Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Thu Apr 4 16:34:38 2019
@@ -781,7 +781,7 @@ public:
/// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
StringRef Filename,
- MD5::MD5Result *Checksum = nullptr,
+ Optional<MD5::MD5Result> Checksum = None,
Optional<StringRef> Source = None,
unsigned CUID = 0) {
return cantFail(
@@ -796,12 +796,12 @@ public:
/// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive.
virtual Expected<unsigned> tryEmitDwarfFileDirective(
unsigned FileNo, StringRef Directory, StringRef Filename,
- MD5::MD5Result *Checksum = nullptr, Optional<StringRef> Source = None,
+ Optional<MD5::MD5Result> Checksum = None, Optional<StringRef> 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<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
unsigned CUID = 0);
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Thu Apr 4 16:34:38 2019
@@ -104,7 +104,7 @@ unsigned DwarfCompileUnit::getOrCreateSo
// 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);
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Thu Apr 4 16:34:38 2019
@@ -289,21 +289,21 @@ void DwarfUnit::addSectionOffset(DIE &Di
addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);
}
-MD5::MD5Result *DwarfUnit::getMD5AsBytes(const DIFile *File) const {
+Optional<MD5::MD5Result> DwarfUnit::getMD5AsBytes(const DIFile *File) const {
assert(File);
if (DD->getDwarfVersion() < 5)
- return nullptr;
+ return None;
Optional<DIFile::ChecksumInfo<StringRef>> 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<MD5::MD5Result *>(CKMem);
+ MD5::MD5Result CKMem;
+ std::copy(ChecksumString.begin(), ChecksumString.end(), CKMem.Bytes.data());
+ return CKMem;
}
unsigned DwarfTypeUnit::getOrCreateSourceID(const DIFile *File) {
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h Thu Apr 4 16:34:38 2019
@@ -296,7 +296,7 @@ public:
/// 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<MD5::MD5Result> getMD5AsBytes(const DIFile *File) const;
protected:
~DwarfUnit();
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Thu Apr 4 16:34:38 2019
@@ -223,11 +223,11 @@ public:
Expected<unsigned> tryEmitDwarfFileDirective(unsigned FileNo,
StringRef Directory,
StringRef Filename,
- MD5::MD5Result *Checksum = 0,
+ Optional<MD5::MD5Result> Checksum = None,
Optional<StringRef> Source = None,
unsigned CUID = 0) override;
void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
unsigned CUID = 0) override;
void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
@@ -1151,7 +1151,7 @@ void MCAsmStreamer::EmitFileDirective(St
static void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
StringRef Filename,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
bool UseDwarfDirectory,
raw_svector_ostream &OS) {
@@ -1184,7 +1184,7 @@ static void printDwarfFileDirective(unsi
Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
unsigned FileNo, StringRef Directory, StringRef Filename,
- MD5::MD5Result *Checksum, Optional<StringRef> Source, unsigned CUID) {
+ Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source, unsigned CUID) {
assert(CUID == 0 && "multiple CUs not supported by MCAsmStreamer");
MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
@@ -1212,7 +1212,7 @@ Expected<unsigned> MCAsmStreamer::tryEmi
void MCAsmStreamer::emitDwarfFile0Directive(StringRef Directory,
StringRef Filename,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
unsigned CUID) {
assert(CUID == 0);
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Thu Apr 4 16:34:38 2019
@@ -572,12 +572,13 @@ void MCContext::RemapDebugPaths() {
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<MD5::MD5Result> 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 @@ void MCContext::setGenDwarfRootFile(Stri
Expected<unsigned> MCContext::getDwarfFile(StringRef Directory,
StringRef FileName,
unsigned FileNumber,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
unsigned CUID) {
MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Thu Apr 4 16:34:38 2019
@@ -361,10 +361,10 @@ static void emitOneV5FileEntry(MCStreame
}
MCOS->EmitULEB128IntValue(DwarfFile.DirIndex); // Directory number.
if (EmitMD5) {
- MD5::MD5Result *Cksum = DwarfFile.Checksum;
+ const MD5::MD5Result &Cksum = *DwarfFile.Checksum;
MCOS->EmitBinaryData(
- StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()),
- Cksum->Bytes.size()));
+ StringRef(reinterpret_cast<const char *>(Cksum.Bytes.data()),
+ Cksum.Bytes.size()));
}
if (HasSource) {
if (LineStr)
@@ -536,7 +536,7 @@ void MCDwarfLineTable::EmitCU(MCObjectSt
Expected<unsigned> MCDwarfLineTable::tryGetFile(StringRef &Directory,
StringRef &FileName,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
unsigned FileNumber) {
return Header.tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
@@ -545,7 +545,7 @@ Expected<unsigned> MCDwarfLineTable::try
Expected<unsigned>
MCDwarfLineTableHeader::tryGetFile(StringRef &Directory,
StringRef &FileName,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> &Source,
unsigned FileNumber) {
if (Directory == CompilationDir)
@@ -558,7 +558,7 @@ MCDwarfLineTableHeader::tryGetFile(Strin
// 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 @@ MCDwarfLineTableHeader::tryGetFile(Strin
File.Name = FileName;
File.DirIndex = DirIndex;
File.Checksum = Checksum;
- trackMD5Usage(Checksum);
+ trackMD5Usage(Checksum.hasValue());
File.Source = Source;
if (Source)
HasSource = true;
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Thu Apr 4 16:34:38 2019
@@ -3388,13 +3388,14 @@ bool AsmParser::parseDirectiveFile(SMLoc
Ctx.setGenDwarfForAssembly(false);
}
- MD5::MD5Result *CKMem = nullptr;
+ Optional<MD5::MD5Result> 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<char *>(Ctx.allocate(SourceString.size()));
Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=357736&r1=357735&r2=357736&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Thu Apr 4 16:34:38 2019
@@ -204,7 +204,7 @@ void MCStreamer::EmitZeros(uint64_t NumB
Expected<unsigned>
MCStreamer::tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
StringRef Filename,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
unsigned CUID) {
return getContext().getDwarfFile(Directory, Filename, FileNo, Checksum,
@@ -213,7 +213,7 @@ MCStreamer::tryEmitDwarfFileDirective(un
void MCStreamer::emitDwarfFile0Directive(StringRef Directory,
StringRef Filename,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
unsigned CUID) {
getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,
More information about the llvm-commits
mailing list