summaryrefslogtreecommitdiffstats
path: root/llvm/lib/AsmParser/LLParser.cpp
diff options
context:
space:
mode:
authorScott Linder <scott@scottlinder.com>2018-02-12 19:45:54 +0000
committerScott Linder <scott@scottlinder.com>2018-02-12 19:45:54 +0000
commit7160384d40ac5025c5ab23cd898b5370749c66a1 (patch)
treea917fb3bd760c42467541559e913a5b09de8094c /llvm/lib/AsmParser/LLParser.cpp
parent4a4f35f32411abb73360247e53d59e1fea1ca7c8 (diff)
downloadbcm5719-llvm-7160384d40ac5025c5ab23cd898b5370749c66a1.tar.gz
bcm5719-llvm-7160384d40ac5025c5ab23cd898b5370749c66a1.zip
[DebugInfo] Unify ChecksumKind and Checksum value in DIFile
Rather than encode the absence of a checksum with a Kind variant, instead put both the kind and value in a struct and wrap it in an Optional. Differential Revision: http://reviews.llvm.org/D43043 llvm-svn: 324928
Diffstat (limited to 'llvm/lib/AsmParser/LLParser.cpp')
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 209a834fed1..d5714ea1885 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -3612,7 +3612,6 @@ struct MDFieldList : public MDFieldImpl<SmallVector<Metadata *, 4>> {
};
struct ChecksumKindField : public MDFieldImpl<DIFile::ChecksumKind> {
- ChecksumKindField() : ImplTy(DIFile::CSK_None) {}
ChecksumKindField(DIFile::ChecksumKind CSKind) : ImplTy(CSKind) {}
};
@@ -3976,13 +3975,14 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDFieldList &Result) {
template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
ChecksumKindField &Result) {
- if (Lex.getKind() != lltok::ChecksumKind)
+ Optional<DIFile::ChecksumKind> CSKind =
+ DIFile::getChecksumKind(Lex.getStrVal());
+
+ if (Lex.getKind() != lltok::ChecksumKind || !CSKind)
return TokError(
"invalid checksum kind" + Twine(" '") + Lex.getStrVal() + "'");
- DIFile::ChecksumKind CSKind = DIFile::getChecksumKind(Lex.getStrVal());
-
- Result.assign(CSKind);
+ Result.assign(*CSKind);
Lex.Lex();
return false;
}
@@ -4247,16 +4247,25 @@ bool LLParser::ParseDISubroutineType(MDNode *&Result, bool IsDistinct) {
/// checksumkind: CSK_MD5,
/// checksum: "000102030405060708090a0b0c0d0e0f")
bool LLParser::ParseDIFile(MDNode *&Result, bool IsDistinct) {
+ // The default constructed value for checksumkind is required, but will never
+ // be used, as the parser checks if the field was actually Seen before using
+ // the Val.
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
REQUIRED(filename, MDStringField, ); \
REQUIRED(directory, MDStringField, ); \
- OPTIONAL(checksumkind, ChecksumKindField, ); \
+ OPTIONAL(checksumkind, ChecksumKindField, (DIFile::CSK_MD5)); \
OPTIONAL(checksum, MDStringField, );
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS
+ Optional<DIFile::ChecksumInfo<MDString *>> OptChecksum;
+ if (checksumkind.Seen && checksum.Seen)
+ OptChecksum.emplace(checksumkind.Val, checksum.Val);
+ else if (checksumkind.Seen || checksum.Seen)
+ return Lex.Error("'checksumkind' and 'checksum' must be provided together");
+
Result = GET_OR_DISTINCT(DIFile, (Context, filename.Val, directory.Val,
- checksumkind.Val, checksum.Val));
+ OptChecksum));
return false;
}
OpenPOWER on IntegriCloud