Skip to content

Commit 0c41681

Browse files
committed
[clang] NFCI: Use FileEntryRef in VerifyDiagnosticConsumer
1 parent 600e0cd commit 0c41681

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

clang/include/clang/Basic/FileEntry.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,23 @@ template <> struct PointerLikeTypeTraits<clang::FileEntryRef> {
249249
const clang::FileEntryRef::MapEntry *>::NumLowBitsAvailable;
250250
};
251251

252+
template <> struct PointerLikeTypeTraits<clang::OptionalFileEntryRef> {
253+
static inline void *getAsVoidPointer(clang::OptionalFileEntryRef File) {
254+
if (!File)
255+
return nullptr;
256+
return PointerLikeTypeTraits<clang::FileEntryRef>::getAsVoidPointer(*File);
257+
}
258+
259+
static inline clang::OptionalFileEntryRef getFromVoidPointer(void *Ptr) {
260+
if (!Ptr)
261+
return std::nullopt;
262+
return PointerLikeTypeTraits<clang::FileEntryRef>::getFromVoidPointer(Ptr);
263+
}
264+
265+
static constexpr int NumLowBitsAvailable =
266+
PointerLikeTypeTraits<clang::FileEntryRef>::NumLowBitsAvailable;
267+
};
268+
252269
/// Specialisation of DenseMapInfo for FileEntryRef.
253270
template <> struct DenseMapInfo<clang::FileEntryRef> {
254271
static inline clang::FileEntryRef getEmptyKey() {

clang/include/clang/Frontend/VerifyDiagnosticConsumer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ class VerifyDiagnosticConsumer: public DiagnosticConsumer,
278278

279279
// These facilities are used for validation in debug builds.
280280
class UnparsedFileStatus {
281-
llvm::PointerIntPair<const FileEntry *, 1, bool> Data;
281+
llvm::PointerIntPair<OptionalFileEntryRef, 1, bool> Data;
282282

283283
public:
284-
UnparsedFileStatus(const FileEntry *File, bool FoundDirectives)
284+
UnparsedFileStatus(OptionalFileEntryRef File, bool FoundDirectives)
285285
: Data(File, FoundDirectives) {}
286286

287-
const FileEntry *getFile() const { return Data.getPointer(); }
287+
OptionalFileEntryRef getFile() const { return Data.getPointer(); }
288288
bool foundDirectives() const { return Data.getInt(); }
289289
};
290290

clang/lib/Frontend/VerifyDiagnosticConsumer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,12 +1030,12 @@ void VerifyDiagnosticConsumer::UpdateParsedFileStatus(SourceManager &SM,
10301030
if (FID.isInvalid())
10311031
return;
10321032

1033-
const FileEntry *FE = SM.getFileEntryForID(FID);
1033+
OptionalFileEntryRef FE = SM.getFileEntryRefForID(FID);
10341034

10351035
if (PS == IsParsed) {
10361036
// Move the FileID from the unparsed set to the parsed set.
10371037
UnparsedFiles.erase(FID);
1038-
ParsedFiles.insert(std::make_pair(FID, FE));
1038+
ParsedFiles.insert(std::make_pair(FID, FE ? &FE->getFileEntry() : nullptr));
10391039
} else if (!ParsedFiles.count(FID) && !UnparsedFiles.count(FID)) {
10401040
// Add the FileID to the unparsed set if we haven't seen it before.
10411041

@@ -1076,17 +1076,17 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
10761076
// Iterate through list of unparsed files.
10771077
for (const auto &I : UnparsedFiles) {
10781078
const UnparsedFileStatus &Status = I.second;
1079-
const FileEntry *FE = Status.getFile();
1079+
OptionalFileEntryRef FE = Status.getFile();
10801080

10811081
// Skip files that have been parsed via an alias.
1082-
if (FE && ParsedFileCache.count(FE))
1082+
if (FE && ParsedFileCache.count(*FE))
10831083
continue;
10841084

10851085
// Report a fatal error if this file contained directives.
10861086
if (Status.foundDirectives()) {
1087-
llvm::report_fatal_error(Twine("-verify directives found after rather"
1088-
" than during normal parsing of ",
1089-
StringRef(FE ? FE->getName() : "(unknown)")));
1087+
llvm::report_fatal_error("-verify directives found after rather"
1088+
" than during normal parsing of " +
1089+
(FE ? FE->getName() : "(unknown)"));
10901090
}
10911091
}
10921092

0 commit comments

Comments
 (0)