Bug Summary

File:lib/CodeGen/MachineLoopInfo.cpp
Warning:line 132, column 31
Called C++ object pointer is null

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 MachineLoopInfo.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~svn337490/build-llvm/lib/CodeGen -I /build/llvm-toolchain-snapshot-7~svn337490/lib/CodeGen -I /build/llvm-toolchain-snapshot-7~svn337490/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn337490/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-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn337490/build-llvm/lib/CodeGen -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-20-043646-20380-1 -x c++ /build/llvm-toolchain-snapshot-7~svn337490/lib/CodeGen/MachineLoopInfo.cpp -faddrsig
1//===- MachineLoopInfo.cpp - Natural Loop Calculator ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the MachineLoopInfo class that is used to identify natural
11// loops and determine the loop depth of various nodes of the CFG. Note that
12// the loops identified may actually be several natural loops that share the
13// same header node... not just a single natural loop.
14//
15//===----------------------------------------------------------------------===//
16
17#include "llvm/CodeGen/MachineLoopInfo.h"
18#include "llvm/Analysis/LoopInfoImpl.h"
19#include "llvm/CodeGen/MachineDominators.h"
20#include "llvm/CodeGen/Passes.h"
21#include "llvm/Config/llvm-config.h"
22#include "llvm/Support/Debug.h"
23#include "llvm/Support/raw_ostream.h"
24using namespace llvm;
25
26// Explicitly instantiate methods in LoopInfoImpl.h for MI-level Loops.
27template class llvm::LoopBase<MachineBasicBlock, MachineLoop>;
28template class llvm::LoopInfoBase<MachineBasicBlock, MachineLoop>;
29
30char MachineLoopInfo::ID = 0;
31INITIALIZE_PASS_BEGIN(MachineLoopInfo, "machine-loops",static void *initializeMachineLoopInfoPassOnce(PassRegistry &
Registry) {
32 "Machine Natural Loop Construction", true, true)static void *initializeMachineLoopInfoPassOnce(PassRegistry &
Registry) {
33INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)initializeMachineDominatorTreePass(Registry);
34INITIALIZE_PASS_END(MachineLoopInfo, "machine-loops",PassInfo *PI = new PassInfo( "Machine Natural Loop Construction"
, "machine-loops", &MachineLoopInfo::ID, PassInfo::NormalCtor_t
(callDefaultCtor<MachineLoopInfo>), true, true); Registry
.registerPass(*PI, true); return PI; } static llvm::once_flag
InitializeMachineLoopInfoPassFlag; void llvm::initializeMachineLoopInfoPass
(PassRegistry &Registry) { llvm::call_once(InitializeMachineLoopInfoPassFlag
, initializeMachineLoopInfoPassOnce, std::ref(Registry)); }
35 "Machine Natural Loop Construction", true, true)PassInfo *PI = new PassInfo( "Machine Natural Loop Construction"
, "machine-loops", &MachineLoopInfo::ID, PassInfo::NormalCtor_t
(callDefaultCtor<MachineLoopInfo>), true, true); Registry
.registerPass(*PI, true); return PI; } static llvm::once_flag
InitializeMachineLoopInfoPassFlag; void llvm::initializeMachineLoopInfoPass
(PassRegistry &Registry) { llvm::call_once(InitializeMachineLoopInfoPassFlag
, initializeMachineLoopInfoPassOnce, std::ref(Registry)); }
36
37char &llvm::MachineLoopInfoID = MachineLoopInfo::ID;
38
39bool MachineLoopInfo::runOnMachineFunction(MachineFunction &) {
40 releaseMemory();
41 LI.analyze(getAnalysis<MachineDominatorTree>().getBase());
42 return false;
43}
44
45void MachineLoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
46 AU.setPreservesAll();
47 AU.addRequired<MachineDominatorTree>();
48 MachineFunctionPass::getAnalysisUsage(AU);
49}
50
51MachineBasicBlock *MachineLoop::getTopBlock() {
52 MachineBasicBlock *TopMBB = getHeader();
53 MachineFunction::iterator Begin = TopMBB->getParent()->begin();
54 if (TopMBB->getIterator() != Begin) {
55 MachineBasicBlock *PriorMBB = &*std::prev(TopMBB->getIterator());
56 while (contains(PriorMBB)) {
57 TopMBB = PriorMBB;
58 if (TopMBB->getIterator() == Begin)
59 break;
60 PriorMBB = &*std::prev(TopMBB->getIterator());
61 }
62 }
63 return TopMBB;
64}
65
66MachineBasicBlock *MachineLoop::getBottomBlock() {
67 MachineBasicBlock *BotMBB = getHeader();
68 MachineFunction::iterator End = BotMBB->getParent()->end();
69 if (BotMBB->getIterator() != std::prev(End)) {
70 MachineBasicBlock *NextMBB = &*std::next(BotMBB->getIterator());
71 while (contains(NextMBB)) {
72 BotMBB = NextMBB;
73 if (BotMBB == &*std::next(BotMBB->getIterator()))
74 break;
75 NextMBB = &*std::next(BotMBB->getIterator());
76 }
77 }
78 return BotMBB;
79}
80
81MachineBasicBlock *MachineLoop::findLoopControlBlock() {
82 if (MachineBasicBlock *Latch = getLoopLatch()) {
83 if (isLoopExiting(Latch))
84 return Latch;
85 else
86 return getExitingBlock();
87 }
88 return nullptr;
89}
90
91DebugLoc MachineLoop::getStartLoc() const {
92 // Try the pre-header first.
93 if (MachineBasicBlock *PHeadMBB = getLoopPreheader())
94 if (const BasicBlock *PHeadBB = PHeadMBB->getBasicBlock())
95 if (DebugLoc DL = PHeadBB->getTerminator()->getDebugLoc())
96 return DL;
97
98 // If we have no pre-header or there are no instructions with debug
99 // info in it, try the header.
100 if (MachineBasicBlock *HeadMBB = getHeader())
101 if (const BasicBlock *HeadBB = HeadMBB->getBasicBlock())
102 return HeadBB->getTerminator()->getDebugLoc();
103
104 return DebugLoc();
105}
106
107MachineBasicBlock *
108MachineLoopInfo::findLoopPreheader(MachineLoop *L,
109 bool SpeculativePreheader) const {
110 if (MachineBasicBlock *PB = L->getLoopPreheader())
1
Assuming 'PB' is null
2
Taking false branch
111 return PB;
112
113 if (!SpeculativePreheader)
3
Assuming 'SpeculativePreheader' is not equal to 0
4
Taking false branch
114 return nullptr;
115
116 MachineBasicBlock *HB = L->getHeader(), *LB = L->getLoopLatch();
117 if (HB->pred_size() != 2 || HB->hasAddressTaken())
5
Assuming the condition is false
6
Assuming the condition is false
7
Taking false branch
118 return nullptr;
119 // Find the predecessor of the header that is not the latch block.
120 MachineBasicBlock *Preheader = nullptr;
8
'Preheader' initialized to a null pointer value
121 for (MachineBasicBlock *P : HB->predecessors()) {
122 if (P == LB)
123 continue;
124 // Sanity.
125 if (Preheader)
126 return nullptr;
127 Preheader = P;
128 }
129
130 // Check if the preheader candidate is a successor of any other loop
131 // headers. We want to avoid having two loop setups in the same block.
132 for (MachineBasicBlock *S : Preheader->successors()) {
9
Called C++ object pointer is null
133 if (S == HB)
134 continue;
135 MachineLoop *T = getLoopFor(S);
136 if (T && T->getHeader() == S)
137 return nullptr;
138 }
139 return Preheader;
140}
141
142#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
143LLVM_DUMP_METHOD__attribute__((noinline)) __attribute__((__used__)) void MachineLoop::dump() const {
144 print(dbgs());
145}
146#endif