[PATCH] D97258: [llvm] Add assertions for the smart pointers with the possibility to be null in ModuleLazyLoaderCache::operator()

Ella Ma via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 22 22:37:20 PST 2021


OikawaKirie created this revision.
OikawaKirie added a reviewer: tejohnson.
OikawaKirie added a project: LLVM.
OikawaKirie requested review of this revision.
Herald added a subscriber: llvm-commits.

Split from D91844 <https://reviews.llvm.org/D91844>.

The return value of function `ModuleLazyLoaderCache::operator()` in file llvm/tools/llvm-link/llvm-link.cpp. According to the bug report of my static analyzer, the std::function variable `ModuleLazyLoaderCache::createLazyModule` points to function `loadFile`, which may return `nullptr` when error. And the pointer is dereferenced without a check.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97258

Files:
  llvm/tools/llvm-link/llvm-link.cpp


Index: llvm/tools/llvm-link/llvm-link.cpp
===================================================================
--- llvm/tools/llvm-link/llvm-link.cpp
+++ llvm/tools/llvm-link/llvm-link.cpp
@@ -246,8 +246,10 @@
 Module &ModuleLazyLoaderCache::operator()(const char *argv0,
                                           const std::string &Identifier) {
   auto &Module = ModuleMap[Identifier];
-  if (!Module)
+  if (!Module) {
     Module = createLazyModule(argv0, Identifier);
+    assert(Module && "Failed to create lazy module!");
+  }
   return *Module;
 }
 } // anonymous namespace


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97258.325678.patch
Type: text/x-patch
Size: 582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210223/b6ead74f/attachment.bin>


More information about the llvm-commits mailing list