Bug Summary

File:lib/Target/Hexagon/HexagonMCInstLower.cpp
Warning:line 108, column 3
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 HexagonMCInstLower.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 -analyzer-config-compatibility-mode=true -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-9/lib/clang/9.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/lib/Target/Hexagon -I /build/llvm-toolchain-snapshot-9~svn362543/lib/Target/Hexagon -I /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/include -I /build/llvm-toolchain-snapshot-9~svn362543/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/9.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-9/lib/clang/9.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-9~svn362543/build-llvm/lib/Target/Hexagon -fdebug-prefix-map=/build/llvm-toolchain-snapshot-9~svn362543=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2019-06-05-060531-1271-1 -x c++ /build/llvm-toolchain-snapshot-9~svn362543/lib/Target/Hexagon/HexagonMCInstLower.cpp -faddrsig
1//===- HexagonMCInstLower.cpp - Convert Hexagon MachineInstr to an MCInst -===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains code to lower Hexagon MachineInstrs to their corresponding
10// MCInst records.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Hexagon.h"
15#include "HexagonAsmPrinter.h"
16#include "MCTargetDesc/HexagonMCExpr.h"
17#include "MCTargetDesc/HexagonMCInstrInfo.h"
18#include "MCTargetDesc/HexagonMCTargetDesc.h"
19#include "llvm/ADT/APFloat.h"
20#include "llvm/ADT/APInt.h"
21#include "llvm/CodeGen/MachineBasicBlock.h"
22#include "llvm/CodeGen/MachineInstr.h"
23#include "llvm/CodeGen/MachineOperand.h"
24#include "llvm/IR/Constants.h"
25#include "llvm/MC/MCContext.h"
26#include "llvm/MC/MCExpr.h"
27#include "llvm/MC/MCInst.h"
28#include "llvm/Support/ErrorHandling.h"
29#include "llvm/Support/raw_ostream.h"
30#include <cassert>
31
32using namespace llvm;
33
34namespace llvm {
35
36void HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI,
37 MCInst &MCB, HexagonAsmPrinter &AP);
38
39} // end namespace llvm
40
41static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
42 HexagonAsmPrinter &Printer, bool MustExtend) {
43 MCContext &MC = Printer.OutContext;
44 const MCExpr *ME;
45
46 // Populate the relocation type based on Hexagon target flags
47 // set on an operand
48 MCSymbolRefExpr::VariantKind RelocationType;
49 switch (MO.getTargetFlags() & ~HexagonII::HMOTF_ConstExtended) {
50 default:
51 RelocationType = MCSymbolRefExpr::VK_None;
52 break;
53 case HexagonII::MO_PCREL:
54 RelocationType = MCSymbolRefExpr::VK_Hexagon_PCREL;
55 break;
56 case HexagonII::MO_GOT:
57 RelocationType = MCSymbolRefExpr::VK_GOT;
58 break;
59 case HexagonII::MO_LO16:
60 RelocationType = MCSymbolRefExpr::VK_Hexagon_LO16;
61 break;
62 case HexagonII::MO_HI16:
63 RelocationType = MCSymbolRefExpr::VK_Hexagon_HI16;
64 break;
65 case HexagonII::MO_GPREL:
66 RelocationType = MCSymbolRefExpr::VK_Hexagon_GPREL;
67 break;
68 case HexagonII::MO_GDGOT:
69 RelocationType = MCSymbolRefExpr::VK_Hexagon_GD_GOT;
70 break;
71 case HexagonII::MO_GDPLT:
72 RelocationType = MCSymbolRefExpr::VK_Hexagon_GD_PLT;
73 break;
74 case HexagonII::MO_IE:
75 RelocationType = MCSymbolRefExpr::VK_Hexagon_IE;
76 break;
77 case HexagonII::MO_IEGOT:
78 RelocationType = MCSymbolRefExpr::VK_Hexagon_IE_GOT;
79 break;
80 case HexagonII::MO_TPREL:
81 RelocationType = MCSymbolRefExpr::VK_TPREL;
82 break;
83 }
84
85 ME = MCSymbolRefExpr::create(Symbol, RelocationType, MC);
86
87 if (!MO.isJTI() && MO.getOffset())
88 ME = MCBinaryExpr::createAdd(ME, MCConstantExpr::create(MO.getOffset(), MC),
89 MC);
90
91 ME = HexagonMCExpr::create(ME, MC);
92 HexagonMCInstrInfo::setMustExtend(*ME, MustExtend);
93 return MCOperand::createExpr(ME);
94}
95
96// Create an MCInst from a MachineInstr
97void llvm::HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI,
98 MCInst &MCB, HexagonAsmPrinter &AP) {
99 if (MI->getOpcode() == Hexagon::ENDLOOP0) {
1
Assuming the condition is false
2
Taking false branch
100 HexagonMCInstrInfo::setInnerLoop(MCB);
101 return;
102 }
103 if (MI->getOpcode() == Hexagon::ENDLOOP1) {
3
Assuming the condition is false
4
Taking false branch
104 HexagonMCInstrInfo::setOuterLoop(MCB);
105 return;
106 }
107 MCInst *MCI = new (AP.OutContext) MCInst;
5
'MCI' initialized to a null pointer value
108 MCI->setOpcode(MI->getOpcode());
6
Called C++ object pointer is null
109 assert(MCI->getOpcode() == static_cast<unsigned>(MI->getOpcode()) &&((MCI->getOpcode() == static_cast<unsigned>(MI->getOpcode
()) && "MCI opcode should have been set on construction"
) ? static_cast<void> (0) : __assert_fail ("MCI->getOpcode() == static_cast<unsigned>(MI->getOpcode()) && \"MCI opcode should have been set on construction\""
, "/build/llvm-toolchain-snapshot-9~svn362543/lib/Target/Hexagon/HexagonMCInstLower.cpp"
, 110, __PRETTY_FUNCTION__))
110 "MCI opcode should have been set on construction")((MCI->getOpcode() == static_cast<unsigned>(MI->getOpcode
()) && "MCI opcode should have been set on construction"
) ? static_cast<void> (0) : __assert_fail ("MCI->getOpcode() == static_cast<unsigned>(MI->getOpcode()) && \"MCI opcode should have been set on construction\""
, "/build/llvm-toolchain-snapshot-9~svn362543/lib/Target/Hexagon/HexagonMCInstLower.cpp"
, 110, __PRETTY_FUNCTION__))
;
111
112 for (unsigned i = 0, e = MI->getNumOperands(); i < e; i++) {
113 const MachineOperand &MO = MI->getOperand(i);
114 MCOperand MCO;
115 bool MustExtend = MO.getTargetFlags() & HexagonII::HMOTF_ConstExtended;
116
117 switch (MO.getType()) {
118 default:
119 MI->print(errs());
120 llvm_unreachable("unknown operand type")::llvm::llvm_unreachable_internal("unknown operand type", "/build/llvm-toolchain-snapshot-9~svn362543/lib/Target/Hexagon/HexagonMCInstLower.cpp"
, 120)
;
121 case MachineOperand::MO_RegisterMask:
122 continue;
123 case MachineOperand::MO_Register:
124 // Ignore all implicit register operands.
125 if (MO.isImplicit())
126 continue;
127 MCO = MCOperand::createReg(MO.getReg());
128 break;
129 case MachineOperand::MO_FPImmediate: {
130 APFloat Val = MO.getFPImm()->getValueAPF();
131 // FP immediates are used only when setting GPRs, so they may be dealt
132 // with like regular immediates from this point on.
133 auto Expr = HexagonMCExpr::create(
134 MCConstantExpr::create(*Val.bitcastToAPInt().getRawData(),
135 AP.OutContext),
136 AP.OutContext);
137 HexagonMCInstrInfo::setMustExtend(*Expr, MustExtend);
138 MCO = MCOperand::createExpr(Expr);
139 break;
140 }
141 case MachineOperand::MO_Immediate: {
142 auto Expr = HexagonMCExpr::create(
143 MCConstantExpr::create(MO.getImm(), AP.OutContext), AP.OutContext);
144 HexagonMCInstrInfo::setMustExtend(*Expr, MustExtend);
145 MCO = MCOperand::createExpr(Expr);
146 break;
147 }
148 case MachineOperand::MO_MachineBasicBlock: {
149 MCExpr const *Expr = MCSymbolRefExpr::create(MO.getMBB()->getSymbol(),
150 AP.OutContext);
151 Expr = HexagonMCExpr::create(Expr, AP.OutContext);
152 HexagonMCInstrInfo::setMustExtend(*Expr, MustExtend);
153 MCO = MCOperand::createExpr(Expr);
154 break;
155 }
156 case MachineOperand::MO_GlobalAddress:
157 MCO = GetSymbolRef(MO, AP.getSymbol(MO.getGlobal()), AP, MustExtend);
158 break;
159 case MachineOperand::MO_ExternalSymbol:
160 MCO = GetSymbolRef(MO, AP.GetExternalSymbolSymbol(MO.getSymbolName()),
161 AP, MustExtend);
162 break;
163 case MachineOperand::MO_JumpTableIndex:
164 MCO = GetSymbolRef(MO, AP.GetJTISymbol(MO.getIndex()), AP, MustExtend);
165 break;
166 case MachineOperand::MO_ConstantPoolIndex:
167 MCO = GetSymbolRef(MO, AP.GetCPISymbol(MO.getIndex()), AP, MustExtend);
168 break;
169 case MachineOperand::MO_BlockAddress:
170 MCO = GetSymbolRef(MO, AP.GetBlockAddressSymbol(MO.getBlockAddress()), AP,
171 MustExtend);
172 break;
173 }
174
175 MCI->addOperand(MCO);
176 }
177 AP.HexagonProcessInstruction(*MCI, *MI);
178 HexagonMCInstrInfo::extendIfNeeded(AP.OutContext, MCII, MCB, *MCI);
179 MCB.addOperand(MCOperand::createInst(MCI));
180}