[clang] 59a3b1a - clang-format: Assert in-memory file created in createInMemoryFile, NFC
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 16 07:21:18 PDT 2020
Author: Duncan P. N. Exon Smith
Date: 2020-10-16T10:20:32-04:00
New Revision: 59a3b1afb28541d5bf37445b028bfd711e3c556a
URL: https://github.com/llvm/llvm-project/commit/59a3b1afb28541d5bf37445b028bfd711e3c556a
DIFF: https://github.com/llvm/llvm-project/commit/59a3b1afb28541d5bf37445b028bfd711e3c556a.diff
LOG: clang-format: Assert in-memory file created in createInMemoryFile, NFC
`SourceManager::createFileID` asserts that the given `FileEntry` is not
null, so remove the logic that passed in `nullptr`. Since we just added
the file to an in-memory FS via an API that cannot fail, use
`llvm_unreachable` on the error path. Didn't use an `assert` since it
seems cleaner semantically to check the error (and better,
hypothetically, for updating the API to use `Expected` instead of
`ErrorOr`).
I noticed this incidentally while auditing calls to `createFileID`.
Added:
Modified:
clang/tools/clang-format/ClangFormat.cpp
Removed:
################################################################################
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index 8dd55d99e2a0..3a7247deab46 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -179,8 +179,8 @@ static FileID createInMemoryFile(StringRef FileName, MemoryBuffer *Source,
llvm::vfs::InMemoryFileSystem *MemFS) {
MemFS->addFileNoOwn(FileName, 0, Source);
auto File = Files.getFile(FileName);
- return Sources.createFileID(File ? *File : nullptr, SourceLocation(),
- SrcMgr::C_User);
+ assert(File && "File not added to MemFS?");
+ return Sources.createFileID(*File, SourceLocation(), SrcMgr::C_User);
}
// Parses <start line>:<end line> input to a pair of line numbers.
More information about the cfe-commits
mailing list