Bug Summary

File:tools/lld/lib/Core/LinkingContext.cpp
Warning:line 41, column 3
Forming reference to null pointer

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name LinkingContext.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lld/lib/Core -I /build/llvm-toolchain-snapshot-7~svn338205/tools/lld/lib/Core -I /build/llvm-toolchain-snapshot-7~svn338205/tools/lld/include -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lld/include -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn338205/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/lib/gcc/x86_64-linux-gnu/8/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lld/lib/Core -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-07-29-043837-17923-1 -x c++ /build/llvm-toolchain-snapshot-7~svn338205/tools/lld/lib/Core/LinkingContext.cpp -faddrsig
1//===- lib/Core/LinkingContext.cpp - Linker Context Object Interface ------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lld/Core/LinkingContext.h"
11#include "lld/Core/File.h"
12#include "lld/Core/Node.h"
13#include "lld/Core/Simple.h"
14#include "lld/Core/Writer.h"
15#include <algorithm>
16
17namespace lld {
18
19LinkingContext::LinkingContext() = default;
20
21LinkingContext::~LinkingContext() = default;
22
23bool LinkingContext::validate() {
24 return validateImpl();
25}
26
27llvm::Error LinkingContext::writeFile(const File &linkedFile) const {
28 return this->writer().writeFile(linkedFile, _outputPath);
29}
30
31std::unique_ptr<File> LinkingContext::createEntrySymbolFile() const {
32 return createEntrySymbolFile("<command line option -e>");
2
Calling 'LinkingContext::createEntrySymbolFile'
33}
34
35std::unique_ptr<File>
36LinkingContext::createEntrySymbolFile(StringRef filename) const {
37 if (entrySymbolName().empty())
3
Assuming the condition is false
4
Taking false branch
38 return nullptr;
39 std::unique_ptr<SimpleFile> entryFile(new SimpleFile(filename,
40 File::kindEntryObject));
41 entryFile->addAtom(
5
Forming reference to null pointer
42 *(new (_allocator) SimpleUndefinedAtom(*entryFile, entrySymbolName())));
43 return std::move(entryFile);
44}
45
46std::unique_ptr<File> LinkingContext::createUndefinedSymbolFile() const {
47 return createUndefinedSymbolFile("<command line option -u or --defsym>");
48}
49
50std::unique_ptr<File>
51LinkingContext::createUndefinedSymbolFile(StringRef filename) const {
52 if (_initialUndefinedSymbols.empty())
53 return nullptr;
54 std::unique_ptr<SimpleFile> undefinedSymFile(
55 new SimpleFile(filename, File::kindUndefinedSymsObject));
56 for (StringRef undefSym : _initialUndefinedSymbols)
57 undefinedSymFile->addAtom(*(new (_allocator) SimpleUndefinedAtom(
58 *undefinedSymFile, undefSym)));
59 return std::move(undefinedSymFile);
60}
61
62void LinkingContext::createInternalFiles(
63 std::vector<std::unique_ptr<File>> &result) const {
64 if (std::unique_ptr<File> file = createEntrySymbolFile())
1
Calling 'LinkingContext::createEntrySymbolFile'
65 result.push_back(std::move(file));
66 if (std::unique_ptr<File> file = createUndefinedSymbolFile())
67 result.push_back(std::move(file));
68}
69
70} // end namespace lld