[clang] 0c41681 - [clang] NFCI: Use `FileEntryRef` in `VerifyDiagnosticConsumer`
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 8 20:12:16 PDT 2023
Author: Jan Svoboda
Date: 2023-09-08T20:12:08-07:00
New Revision: 0c41681a0ce3ab8c4f145b30e586d25a33b75bbf
URL: https://github.com/llvm/llvm-project/commit/0c41681a0ce3ab8c4f145b30e586d25a33b75bbf
DIFF: https://github.com/llvm/llvm-project/commit/0c41681a0ce3ab8c4f145b30e586d25a33b75bbf.diff
LOG: [clang] NFCI: Use `FileEntryRef` in `VerifyDiagnosticConsumer`
Added:
Modified:
clang/include/clang/Basic/FileEntry.h
clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h
index 50110b8572ef48e..1fcca4c6dfc3da8 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -249,6 +249,23 @@ template <> struct PointerLikeTypeTraits<clang::FileEntryRef> {
const clang::FileEntryRef::MapEntry *>::NumLowBitsAvailable;
};
+template <> struct PointerLikeTypeTraits<clang::OptionalFileEntryRef> {
+ static inline void *getAsVoidPointer(clang::OptionalFileEntryRef File) {
+ if (!File)
+ return nullptr;
+ return PointerLikeTypeTraits<clang::FileEntryRef>::getAsVoidPointer(*File);
+ }
+
+ static inline clang::OptionalFileEntryRef getFromVoidPointer(void *Ptr) {
+ if (!Ptr)
+ return std::nullopt;
+ return PointerLikeTypeTraits<clang::FileEntryRef>::getFromVoidPointer(Ptr);
+ }
+
+ static constexpr int NumLowBitsAvailable =
+ PointerLikeTypeTraits<clang::FileEntryRef>::NumLowBitsAvailable;
+};
+
/// Specialisation of DenseMapInfo for FileEntryRef.
template <> struct DenseMapInfo<clang::FileEntryRef> {
static inline clang::FileEntryRef getEmptyKey() {
diff --git a/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h b/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
index a97cd138d159617..e0f3570e5b2bc6e 100644
--- a/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
+++ b/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
@@ -278,13 +278,13 @@ class VerifyDiagnosticConsumer: public DiagnosticConsumer,
// These facilities are used for validation in debug builds.
class UnparsedFileStatus {
- llvm::PointerIntPair<const FileEntry *, 1, bool> Data;
+ llvm::PointerIntPair<OptionalFileEntryRef, 1, bool> Data;
public:
- UnparsedFileStatus(const FileEntry *File, bool FoundDirectives)
+ UnparsedFileStatus(OptionalFileEntryRef File, bool FoundDirectives)
: Data(File, FoundDirectives) {}
- const FileEntry *getFile() const { return Data.getPointer(); }
+ OptionalFileEntryRef getFile() const { return Data.getPointer(); }
bool foundDirectives() const { return Data.getInt(); }
};
diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index d70f2a90a629ce1..ab8174f4f4db921 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -1030,12 +1030,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.
@@ -1076,17 +1076,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)"));
}
}
More information about the cfe-commits
mailing list