aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp76
1 files changed, 41 insertions, 35 deletions
diff --git a/contrib/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/contrib/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index 0503ae46a15f..f508408ba706 100644
--- a/contrib/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/contrib/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -99,9 +99,7 @@ public:
return true;
}
- bool match(StringRef S) override {
- return S.find(Text) != StringRef::npos;
- }
+ bool match(StringRef S) override { return S.contains(Text); }
};
/// RegexDirective - Directive with regular-expression matching.
@@ -228,10 +226,10 @@ public:
P = C;
while (P < End) {
StringRef S(P, End - P);
- if (S.startswith(OpenBrace)) {
+ if (S.starts_with(OpenBrace)) {
++Depth;
P += OpenBrace.size();
- } else if (S.startswith(CloseBrace)) {
+ } else if (S.starts_with(CloseBrace)) {
--Depth;
if (Depth == 0) {
PEnd = P + CloseBrace.size();
@@ -447,7 +445,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
// others.
// Regex in initial directive token: -re
- if (DToken.endswith("-re")) {
+ if (DToken.ends_with("-re")) {
D.RegexKind = true;
KindStr = "regex";
DToken = DToken.substr(0, DToken.size()-3);
@@ -456,20 +454,19 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
// Type in initial directive token: -{error|warning|note|no-diagnostics}
bool NoDiag = false;
StringRef DType;
- if (DToken.endswith(DType="-error"))
+ if (DToken.ends_with(DType = "-error"))
D.DL = ED ? &ED->Errors : nullptr;
- else if (DToken.endswith(DType="-warning"))
+ else if (DToken.ends_with(DType = "-warning"))
D.DL = ED ? &ED->Warnings : nullptr;
- else if (DToken.endswith(DType="-remark"))
+ else if (DToken.ends_with(DType = "-remark"))
D.DL = ED ? &ED->Remarks : nullptr;
- else if (DToken.endswith(DType="-note"))
+ else if (DToken.ends_with(DType = "-note"))
D.DL = ED ? &ED->Notes : nullptr;
- else if (DToken.endswith(DType="-no-diagnostics")) {
+ else if (DToken.ends_with(DType = "-no-diagnostics")) {
NoDiag = true;
if (D.RegexKind)
continue;
- }
- else
+ } else
continue;
DToken = DToken.substr(0, DToken.size()-DType.size());
@@ -543,9 +540,8 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
ExpectedLoc = SourceLocation();
} else {
// Lookup file via Preprocessor, like a #include.
- const DirectoryLookup *CurDir;
- Optional<FileEntryRef> File =
- PP->LookupFile(Pos, Filename, false, nullptr, nullptr, CurDir,
+ OptionalFileEntryRef File =
+ PP->LookupFile(Pos, Filename, false, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr);
if (!File) {
Diags.Report(Pos.getLocWithOffset(PH.C - PH.Begin),
@@ -615,12 +611,19 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
diag::err_verify_missing_start) << KindStr;
continue;
}
+ llvm::SmallString<8> CloseBrace("}}");
+ const char *const DelimBegin = PH.C;
PH.Advance();
+ // Count the number of opening braces for `string` kinds
+ for (; !D.RegexKind && PH.Next("{"); PH.Advance())
+ CloseBrace += '}';
const char* const ContentBegin = PH.C; // mark content begin
- // Search for token: }}
- if (!PH.SearchClosingBrace("{{", "}}")) {
- Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin),
- diag::err_verify_missing_end) << KindStr;
+ // Search for closing brace
+ StringRef OpenBrace(DelimBegin, ContentBegin - DelimBegin);
+ if (!PH.SearchClosingBrace(OpenBrace, CloseBrace)) {
+ Diags.Report(Pos.getLocWithOffset(PH.C - PH.Begin),
+ diag::err_verify_missing_end)
+ << KindStr << CloseBrace;
continue;
}
const char* const ContentEnd = PH.P; // mark content end
@@ -740,12 +743,12 @@ void VerifyDiagnosticConsumer::HandleDiagnostic(
Loc = SrcManager->getExpansionLoc(Loc);
FileID FID = SrcManager->getFileID(Loc);
- const FileEntry *FE = SrcManager->getFileEntryForID(FID);
+ auto FE = SrcManager->getFileEntryRefForID(FID);
if (FE && CurrentPreprocessor && SrcManager->isLoadedFileID(FID)) {
// If the file is a modules header file it shall not be parsed
// for expected-* directives.
HeaderSearch &HS = CurrentPreprocessor->getHeaderSearchInfo();
- if (HS.findModuleForHeader(FE))
+ if (HS.findModuleForHeader(*FE))
PS = IsUnparsedNoDirectives;
}
@@ -871,16 +874,18 @@ static unsigned PrintUnexpected(DiagnosticsEngine &Diags, SourceManager *SourceM
OS << "\n (frontend)";
else {
OS << "\n ";
- if (const FileEntry *File = SourceMgr->getFileEntryForID(
- SourceMgr->getFileID(I->first)))
+ if (OptionalFileEntryRef File =
+ SourceMgr->getFileEntryRefForID(SourceMgr->getFileID(I->first)))
OS << " File " << File->getName();
OS << " Line " << SourceMgr->getPresumedLineNumber(I->first);
}
OS << ": " << I->second;
}
+ std::string Prefix = *Diags.getDiagnosticOptions().VerifyPrefixes.begin();
+ std::string KindStr = Prefix + "-" + Kind;
Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit()
- << Kind << /*Unexpected=*/true << OS.str();
+ << KindStr << /*Unexpected=*/true << OS.str();
return std::distance(diag_begin, diag_end);
}
@@ -910,8 +915,10 @@ static unsigned PrintExpected(DiagnosticsEngine &Diags,
OS << ": " << D->Text;
}
+ std::string Prefix = *Diags.getDiagnosticOptions().VerifyPrefixes.begin();
+ std::string KindStr = Prefix + "-" + Kind;
Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit()
- << Kind << /*Unexpected=*/false << OS.str();
+ << KindStr << /*Unexpected=*/false << OS.str();
return DL.size();
}
@@ -1029,12 +1036,12 @@ void VerifyDiagnosticConsumer::UpdateParsedFileStatus(SourceManager &SM,
if (FID.isInvalid())
return;
- const FileEntry *FE = SM.getFileEntryForID(FID);
+ OptionalFileEntryRef FE = SM.getFileEntryRefForID(FID);
if (PS == IsParsed) {
// Move the FileID from the unparsed set to the parsed set.
UnparsedFiles.erase(FID);
- ParsedFiles.insert(std::make_pair(FID, FE));
+ ParsedFiles.insert(std::make_pair(FID, FE ? &FE->getFileEntry() : nullptr));
} else if (!ParsedFiles.count(FID) && !UnparsedFiles.count(FID)) {
// Add the FileID to the unparsed set if we haven't seen it before.
@@ -1075,17 +1082,17 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
// Iterate through list of unparsed files.
for (const auto &I : UnparsedFiles) {
const UnparsedFileStatus &Status = I.second;
- const FileEntry *FE = Status.getFile();
+ OptionalFileEntryRef FE = Status.getFile();
// Skip files that have been parsed via an alias.
- if (FE && ParsedFileCache.count(FE))
+ if (FE && ParsedFileCache.count(*FE))
continue;
// Report a fatal error if this file contained directives.
if (Status.foundDirectives()) {
- llvm::report_fatal_error(Twine("-verify directives found after rather"
- " than during normal parsing of ",
- StringRef(FE ? FE->getName() : "(unknown)")));
+ llvm::report_fatal_error("-verify directives found after rather"
+ " than during normal parsing of " +
+ (FE ? FE->getName() : "(unknown)"));
}
}
@@ -1144,8 +1151,7 @@ std::unique_ptr<Directive> Directive::create(bool RegexKind,
std::string RegexStr;
StringRef S = Text;
while (!S.empty()) {
- if (S.startswith("{{")) {
- S = S.drop_front(2);
+ if (S.consume_front("{{")) {
size_t RegexMatchLength = S.find("}}");
assert(RegexMatchLength != StringRef::npos);
// Append the regex, enclosed in parentheses.