Bug Summary

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