[llvm] 0de3d1c - [llvm] Add assertions for the smart pointers with the possibility to be null in ModuleLazyLoaderCache::operator()
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 19 13:54:56 PDT 2021
Author: Ella Ma
Date: 2021-03-19T13:52:34-07:00
New Revision: 0de3d1c81428c2a7a4f9a23a5105aa2243fad778
URL: https://github.com/llvm/llvm-project/commit/0de3d1c81428c2a7a4f9a23a5105aa2243fad778
DIFF: https://github.com/llvm/llvm-project/commit/0de3d1c81428c2a7a4f9a23a5105aa2243fad778.diff
LOG: [llvm] Add assertions for the smart pointers with the possibility to be null in ModuleLazyLoaderCache::operator()
Split from 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.
Reviewed By: tejohnson
Differential Revision: https://reviews.llvm.org/D97258
Added:
Modified:
llvm/tools/llvm-link/llvm-link.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index eed49c438335..b01270de727a 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -246,8 +246,10 @@ class ModuleLazyLoaderCache {
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
More information about the llvm-commits
mailing list