From 92e93ec122310827fef1032df1d05ef8e1b343f7 Mon Sep 17 00:00:00 2001 From: Devajith Valaparambil Sreeramaswamy Date: Wed, 11 Sep 2024 15:48:45 +0200 Subject: [PATCH] Migrate to `FileEntryRef` and `DirectoryEntryRef` Fix the deprecation warning when compiling cling standalone --- lib/Interpreter/ClangInternalState.cpp | 11 ++++++++--- lib/Interpreter/NullDerefProtectionTransformer.cpp | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Interpreter/ClangInternalState.cpp b/lib/Interpreter/ClangInternalState.cpp index c33e9057f7..91c9f3a760 100644 --- a/lib/Interpreter/ClangInternalState.cpp +++ b/lib/Interpreter/ClangInternalState.cpp @@ -256,21 +256,26 @@ namespace cling { std::vector ParsedOpen, Parsed, AST; for (clang::SourceManager::fileinfo_iterator I = SM.fileinfo_begin(), E = SM.fileinfo_end(); I != E; ++I) { - const clang::FileEntry *FE = I->first; + const clang::FileEntryRef FE = I->first; // Our error recovery purges the cache of the FileEntry, but keeps // the FileEntry's pointer so that if it was used by smb (like the // SourceManager) it wouldn't be dangling. In that case we shouldn't // print the FileName, because semantically it is not there. if (!I->second) continue; - std::string fileName(FE->getName()); + std::string fileName(FE.getName()); if (!(fileName.compare(0, 5, "/usr/") == 0 && fileName.find("/bits/") != std::string::npos) && fileName.compare("-")) { if (I->second->getBufferDataIfLoaded()) { // There is content - a memory buffer or a file. // We know it's a file because we started off the FileEntry. - if (FE->isOpen()) + + // FIXME: LLVM will completely migrate to FileEntryRef. + // We added `isOpen()` in our commit: + // `Accessor to "is file opened"; this is crucial info for us.` + // Move this logic to FileEntryRef or have a workaround. + if (FE.getFileEntry().isOpen()) ParsedOpen.emplace_back(std::move(fileName)); else Parsed.emplace_back(std::move(fileName)); diff --git a/lib/Interpreter/NullDerefProtectionTransformer.cpp b/lib/Interpreter/NullDerefProtectionTransformer.cpp index f212614bdc..5b2a836cff 100644 --- a/lib/Interpreter/NullDerefProtectionTransformer.cpp +++ b/lib/Interpreter/NullDerefProtectionTransformer.cpp @@ -284,7 +284,7 @@ namespace cling { if (FID.isInvalid()) return false; - auto FE = SM.getFileEntryForID(FID); + auto FE = SM.getFileEntryRefForID(FID); if (!FE) return false; @@ -296,7 +296,7 @@ namespace cling { if (IterAndInserted.second == false) return IterAndInserted.first->second; - if (llvm::sys::fs::can_write(Dir->getName())) + if (llvm::sys::fs::can_write(Dir.getName())) return true; // `true` is already emplaced above. // Remember that this dir is not writable and should not be visited.