Bug Summary

File:lib/Target/AArch64/AArch64CompressJumpTables.cpp
Warning:line 122, column 42
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 AArch64CompressJumpTables.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/lib/Target/AArch64 -I /build/llvm-toolchain-snapshot-8~svn345461/lib/Target/AArch64 -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn345461/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/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-8~svn345461/build-llvm/lib/Target/AArch64 -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-10-27-211344-32123-1 -x c++ /build/llvm-toolchain-snapshot-8~svn345461/lib/Target/AArch64/AArch64CompressJumpTables.cpp -faddrsig
1//==-- AArch64CompressJumpTables.cpp - Compress jump tables for AArch64 --====//
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// This pass looks at the basic blocks each jump-table refers to and works out
9// whether they can be emitted in a compressed form (with 8 or 16-bit
10// entries). If so, it changes the opcode and flags them in the associated
11// AArch64FunctionInfo.
12//
13//===----------------------------------------------------------------------===//
14
15#include "AArch64.h"
16#include "AArch64MachineFunctionInfo.h"
17#include "AArch64Subtarget.h"
18#include "llvm/ADT/Statistic.h"
19#include "llvm/CodeGen/MachineFunctionPass.h"
20#include "llvm/CodeGen/MachineJumpTableInfo.h"
21#include "llvm/CodeGen/TargetInstrInfo.h"
22#include "llvm/CodeGen/TargetSubtargetInfo.h"
23#include "llvm/MC/MCContext.h"
24#include "llvm/Support/Debug.h"
25
26using namespace llvm;
27
28#define DEBUG_TYPE"aarch64-jump-tables" "aarch64-jump-tables"
29
30STATISTIC(NumJT8, "Number of jump-tables with 1-byte entries")static llvm::Statistic NumJT8 = {"aarch64-jump-tables", "NumJT8"
, "Number of jump-tables with 1-byte entries", {0}, {false}}
;
31STATISTIC(NumJT16, "Number of jump-tables with 2-byte entries")static llvm::Statistic NumJT16 = {"aarch64-jump-tables", "NumJT16"
, "Number of jump-tables with 2-byte entries", {0}, {false}}
;
32STATISTIC(NumJT32, "Number of jump-tables with 4-byte entries")static llvm::Statistic NumJT32 = {"aarch64-jump-tables", "NumJT32"
, "Number of jump-tables with 4-byte entries", {0}, {false}}
;
33
34namespace {
35class AArch64CompressJumpTables : public MachineFunctionPass {
36 const TargetInstrInfo *TII;
37 MachineFunction *MF;
38 SmallVector<int, 8> BlockInfo;
39
40 int computeBlockSize(MachineBasicBlock &MBB);
41 void scanFunction();
42
43 bool compressJumpTable(MachineInstr &MI, int Offset);
44
45public:
46 static char ID;
47 AArch64CompressJumpTables() : MachineFunctionPass(ID) {
48 initializeAArch64CompressJumpTablesPass(*PassRegistry::getPassRegistry());
49 }
50
51 bool runOnMachineFunction(MachineFunction &MF) override;
52
53 MachineFunctionProperties getRequiredProperties() const override {
54 return MachineFunctionProperties().set(
55 MachineFunctionProperties::Property::NoVRegs);
56 }
57 StringRef getPassName() const override {
58 return "AArch64 Compress Jump Tables";
59 }
60};
61char AArch64CompressJumpTables::ID = 0;
62}
63
64INITIALIZE_PASS(AArch64CompressJumpTables, DEBUG_TYPE,static void *initializeAArch64CompressJumpTablesPassOnce(PassRegistry
&Registry) { PassInfo *PI = new PassInfo( "AArch64 compress jump tables pass"
, "aarch64-jump-tables", &AArch64CompressJumpTables::ID, PassInfo
::NormalCtor_t(callDefaultCtor<AArch64CompressJumpTables>
), false, false); Registry.registerPass(*PI, true); return PI
; } static llvm::once_flag InitializeAArch64CompressJumpTablesPassFlag
; void llvm::initializeAArch64CompressJumpTablesPass(PassRegistry
&Registry) { llvm::call_once(InitializeAArch64CompressJumpTablesPassFlag
, initializeAArch64CompressJumpTablesPassOnce, std::ref(Registry
)); }
65 "AArch64 compress jump tables pass", false, false)static void *initializeAArch64CompressJumpTablesPassOnce(PassRegistry
&Registry) { PassInfo *PI = new PassInfo( "AArch64 compress jump tables pass"
, "aarch64-jump-tables", &AArch64CompressJumpTables::ID, PassInfo
::NormalCtor_t(callDefaultCtor<AArch64CompressJumpTables>
), false, false); Registry.registerPass(*PI, true); return PI
; } static llvm::once_flag InitializeAArch64CompressJumpTablesPassFlag
; void llvm::initializeAArch64CompressJumpTablesPass(PassRegistry
&Registry) { llvm::call_once(InitializeAArch64CompressJumpTablesPassFlag
, initializeAArch64CompressJumpTablesPassOnce, std::ref(Registry
)); }
66
67int AArch64CompressJumpTables::computeBlockSize(MachineBasicBlock &MBB) {
68 int Size = 0;
69 for (const MachineInstr &MI : MBB)
70 Size += TII->getInstSizeInBytes(MI);
71 return Size;
72}
73
74void AArch64CompressJumpTables::scanFunction() {
75 BlockInfo.clear();
76 BlockInfo.resize(MF->getNumBlockIDs());
77
78 int Offset = 0;
79 for (MachineBasicBlock &MBB : *MF) {
80 BlockInfo[MBB.getNumber()] = Offset;
81 Offset += computeBlockSize(MBB);
82 }
83}
84
85bool AArch64CompressJumpTables::compressJumpTable(MachineInstr &MI,
86 int Offset) {
87 if (MI.getOpcode() != AArch64::JumpTableDest32)
3
Assuming the condition is false
4
Taking false branch
88 return false;
89
90 int JTIdx = MI.getOperand(4).getIndex();
91 auto &JTInfo = *MF->getJumpTableInfo();
92 const MachineJumpTableEntry &JT = JTInfo.getJumpTables()[JTIdx];
93
94 // The jump-table might have been optimized away.
95 if (JT.MBBs.empty())
5
Assuming the condition is false
6
Taking false branch
96 return false;
97
98 int MaxOffset = std::numeric_limits<int>::min(),
99 MinOffset = std::numeric_limits<int>::max();
100 MachineBasicBlock *MinBlock = nullptr;
7
'MinBlock' initialized to a null pointer value
101 for (auto Block : JT.MBBs) {
102 int BlockOffset = BlockInfo[Block->getNumber()];
103 assert(BlockOffset % 4 == 0 && "misaligned basic block")((BlockOffset % 4 == 0 && "misaligned basic block") ?
static_cast<void> (0) : __assert_fail ("BlockOffset % 4 == 0 && \"misaligned basic block\""
, "/build/llvm-toolchain-snapshot-8~svn345461/lib/Target/AArch64/AArch64CompressJumpTables.cpp"
, 103, __PRETTY_FUNCTION__))
;
104
105 MaxOffset = std::max(MaxOffset, BlockOffset);
106 if (BlockOffset <= MinOffset) {
107 MinOffset = BlockOffset;
108 MinBlock = Block;
109 }
110 }
111
112 // The ADR instruction needed to calculate the address of the first reachable
113 // basic block can address +/-1MB.
114 if (!isInt<21>(MinOffset - Offset)) {
8
Taking false branch
115 ++NumJT32;
116 return false;
117 }
118
119 int Span = MaxOffset - MinOffset;
120 auto AFI = MF->getInfo<AArch64FunctionInfo>();
121 if (isUInt<8>(Span / 4)) {
9
Taking true branch
122 AFI->setJumpTableEntryInfo(JTIdx, 1, MinBlock->getSymbol());
10
Called C++ object pointer is null
123 MI.setDesc(TII->get(AArch64::JumpTableDest8));
124 ++NumJT8;
125 return true;
126 } else if (isUInt<16>(Span / 4)) {
127 AFI->setJumpTableEntryInfo(JTIdx, 2, MinBlock->getSymbol());
128 MI.setDesc(TII->get(AArch64::JumpTableDest16));
129 ++NumJT16;
130 return true;
131 }
132
133 ++NumJT32;
134 return false;
135}
136
137bool AArch64CompressJumpTables::runOnMachineFunction(MachineFunction &MFIn) {
138 bool Changed = false;
139 MF = &MFIn;
140
141 const auto &ST = MF->getSubtarget<AArch64Subtarget>();
142 TII = ST.getInstrInfo();
143
144 if (ST.force32BitJumpTables() && !MF->getFunction().optForMinSize())
1
Assuming the condition is false
145 return false;
146
147 scanFunction();
148
149 for (MachineBasicBlock &MBB : *MF) {
150 int Offset = BlockInfo[MBB.getNumber()];
151 for (MachineInstr &MI : MBB) {
152 Changed |= compressJumpTable(MI, Offset);
2
Calling 'AArch64CompressJumpTables::compressJumpTable'
153 Offset += TII->getInstSizeInBytes(MI);
154 }
155 }
156
157 return Changed;
158}
159
160FunctionPass *llvm::createAArch64CompressJumpTablesPass() {
161 return new AArch64CompressJumpTables();
162}