[PATCH] D97255: [clang] Add assertions for the smart pointers with the possibility to be null in InMemoryFileSystem::addFile
Ella Ma via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 22 22:09:18 PST 2021
OikawaKirie created this revision.
OikawaKirie added a reviewer: ilya-biryukov.
OikawaKirie added a project: clang.
Herald added subscribers: dexonsmith, hiraditya.
OikawaKirie requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Split from D91844 <https://reviews.llvm.org/D91844>
The parameter variable `Buffer` in function `InMemoryFileSystem::addFile` in file llvm/lib/Support/VirtualFileSystem.cpp. The assertion in this function (`assert(!(HardLinkTarget && Buffer))`) only checks whether these two parameters can both be non-null. But It can be inferred that both pointers can be null together. A null `Buffer` pointer can be dereferenced without a check.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97255
Files:
llvm/lib/Support/VirtualFileSystem.cpp
Index: llvm/lib/Support/VirtualFileSystem.cpp
===================================================================
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -753,6 +753,7 @@
if (HardLinkTarget)
Child.reset(new detail::InMemoryHardLink(P.str(), *HardLinkTarget));
else {
+ assert(Buffer && "Non-HardLink without a buffer?");
// Create a new file or directory.
Status Stat(P.str(), getNextVirtualUniqueID(),
llvm::sys::toTimePoint(ModificationTime), ResolvedUser,
@@ -791,6 +792,7 @@
if (I != E)
return false;
+ assert(Buffer);
// Return false only if the new file is different from the existing one.
if (auto Link = dyn_cast<detail::InMemoryHardLink>(Node)) {
return Link->getResolvedFile().getBuffer()->getBuffer() ==
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97255.325674.patch
Type: text/x-patch
Size: 893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210223/856bc126/attachment.bin>
More information about the llvm-commits
mailing list