Bug Summary

File:tools/lldb/source/DataFormatters/VectorType.cpp
Warning:line 85, column 12
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 VectorType.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 HAVE_ROUND -D LLDB_CONFIGURATION_RELEASE -D LLDB_USE_BUILTIN_DEMANGLER -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/source/DataFormatters -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/DataFormatters -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn329677/include -I /usr/include/python2.7 -I /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/../clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/. -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/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/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 -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/source/DataFormatters -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-04-11-031539-24776-1 -x c++ /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/DataFormatters/VectorType.cpp
1//===-- VectorType.cpp ------------------------------------------*- C++ -*-===//
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// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
14#include "lldb/DataFormatters/VectorType.h"
15
16#include "lldb/Core/ValueObject.h"
17#include "lldb/DataFormatters/FormattersHelpers.h"
18#include "lldb/Symbol/CompilerType.h"
19#include "lldb/Symbol/TypeSystem.h"
20#include "lldb/Target/Target.h"
21
22#include "lldb/Utility/LLDBAssert.h"
23
24using namespace lldb;
25using namespace lldb_private;
26using namespace lldb_private::formatters;
27
28static CompilerType GetCompilerTypeForFormat(lldb::Format format,
29 CompilerType element_type,
30 TypeSystem *type_system) {
31 lldbassert(type_system && "type_system needs to be not NULL")lldb_private::lldb_assert(type_system && "type_system needs to be not NULL"
, "type_system && \"type_system needs to be not NULL\""
, __FUNCTION__, "/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/DataFormatters/VectorType.cpp"
, 31)
;
32
33 switch (format) {
6
Control jumps to 'case eFormatVectorOfSInt16:' at line 84
34 case lldb::eFormatAddressInfo:
35 case lldb::eFormatPointer:
36 return type_system->GetBuiltinTypeForEncodingAndBitSize(
37 eEncodingUint, 8 * type_system->GetPointerByteSize());
38
39 case lldb::eFormatBoolean:
40 return type_system->GetBasicTypeFromAST(lldb::eBasicTypeBool);
41
42 case lldb::eFormatBytes:
43 case lldb::eFormatBytesWithASCII:
44 case lldb::eFormatChar:
45 case lldb::eFormatCharArray:
46 case lldb::eFormatCharPrintable:
47 return type_system->GetBasicTypeFromAST(lldb::eBasicTypeChar);
48
49 case lldb::eFormatComplex /* lldb::eFormatComplexFloat */:
50 return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloatComplex);
51
52 case lldb::eFormatCString:
53 return type_system->GetBasicTypeFromAST(lldb::eBasicTypeChar)
54 .GetPointerType();
55
56 case lldb::eFormatFloat:
57 return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloat);
58
59 case lldb::eFormatHex:
60 case lldb::eFormatHexUppercase:
61 case lldb::eFormatOctal:
62 return type_system->GetBasicTypeFromAST(lldb::eBasicTypeInt);
63
64 case lldb::eFormatHexFloat:
65 return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloat);
66
67 case lldb::eFormatUnicode16:
68 case lldb::eFormatUnicode32:
69
70 case lldb::eFormatUnsigned:
71 return type_system->GetBasicTypeFromAST(lldb::eBasicTypeUnsignedInt);
72
73 case lldb::eFormatVectorOfChar:
74 return type_system->GetBasicTypeFromAST(lldb::eBasicTypeChar);
75
76 case lldb::eFormatVectorOfFloat32:
77 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingIEEE754,
78 32);
79
80 case lldb::eFormatVectorOfFloat64:
81 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingIEEE754,
82 64);
83
84 case lldb::eFormatVectorOfSInt16:
85 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 16);
7
Called C++ object pointer is null
86
87 case lldb::eFormatVectorOfSInt32:
88 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 32);
89
90 case lldb::eFormatVectorOfSInt64:
91 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 64);
92
93 case lldb::eFormatVectorOfSInt8:
94 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 8);
95
96 case lldb::eFormatVectorOfUInt128:
97 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 128);
98
99 case lldb::eFormatVectorOfUInt16:
100 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 16);
101
102 case lldb::eFormatVectorOfUInt32:
103 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32);
104
105 case lldb::eFormatVectorOfUInt64:
106 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 64);
107
108 case lldb::eFormatVectorOfUInt8:
109 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 8);
110
111 case lldb::eFormatDefault:
112 return element_type;
113
114 case lldb::eFormatBinary:
115 case lldb::eFormatComplexInteger:
116 case lldb::eFormatDecimal:
117 case lldb::eFormatEnum:
118 case lldb::eFormatInstruction:
119 case lldb::eFormatOSType:
120 case lldb::eFormatVoid:
121 default:
122 return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 8);
123 }
124}
125
126static lldb::Format GetItemFormatForFormat(lldb::Format format,
127 CompilerType element_type) {
128 switch (format) {
129 case lldb::eFormatVectorOfChar:
130 return lldb::eFormatChar;
131
132 case lldb::eFormatVectorOfFloat32:
133 case lldb::eFormatVectorOfFloat64:
134 return lldb::eFormatFloat;
135
136 case lldb::eFormatVectorOfSInt16:
137 case lldb::eFormatVectorOfSInt32:
138 case lldb::eFormatVectorOfSInt64:
139 case lldb::eFormatVectorOfSInt8:
140 return lldb::eFormatDecimal;
141
142 case lldb::eFormatVectorOfUInt128:
143 case lldb::eFormatVectorOfUInt16:
144 case lldb::eFormatVectorOfUInt32:
145 case lldb::eFormatVectorOfUInt64:
146 case lldb::eFormatVectorOfUInt8:
147 return lldb::eFormatUnsigned;
148
149 case lldb::eFormatBinary:
150 case lldb::eFormatComplexInteger:
151 case lldb::eFormatDecimal:
152 case lldb::eFormatEnum:
153 case lldb::eFormatInstruction:
154 case lldb::eFormatOSType:
155 case lldb::eFormatVoid:
156 return eFormatHex;
157
158 case lldb::eFormatDefault: {
159 // special case the (default, char) combination to actually display as an
160 // integer value
161 // most often, you won't want to see the ASCII characters... (and if you do,
162 // eFormatChar is a keystroke away)
163 bool is_char = element_type.IsCharType();
164 bool is_signed = false;
165 element_type.IsIntegerType(is_signed);
166 return is_char ? (is_signed ? lldb::eFormatDecimal : eFormatHex) : format;
167 } break;
168
169 default:
170 return format;
171 }
172}
173
174static size_t CalculateNumChildren(
175 CompilerType container_type, CompilerType element_type,
176 lldb_private::ExecutionContextScope *exe_scope =
177 nullptr // does not matter here because all we trade in are basic types
178 ) {
179 auto container_size = container_type.GetByteSize(exe_scope);
180 auto element_size = element_type.GetByteSize(exe_scope);
181
182 if (element_size) {
183 if (container_size % element_size)
184 return 0;
185 return container_size / element_size;
186 }
187 return 0;
188}
189
190namespace lldb_private {
191namespace formatters {
192
193class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
194public:
195 VectorTypeSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
196 : SyntheticChildrenFrontEnd(*valobj_sp), m_parent_format(eFormatInvalid),
197 m_item_format(eFormatInvalid), m_child_type(), m_num_children(0) {}
198
199 ~VectorTypeSyntheticFrontEnd() override = default;
200
201 size_t CalculateNumChildren() override { return m_num_children; }
202
203 lldb::ValueObjectSP GetChildAtIndex(size_t idx) override {
204 if (idx >= CalculateNumChildren())
205 return lldb::ValueObjectSP();
206 auto offset = idx * m_child_type.GetByteSize(nullptr);
207 StreamString idx_name;
208 idx_name.Printf("[%" PRIu64"l" "u" "]", (uint64_t)idx);
209 ValueObjectSP child_sp(m_backend.GetSyntheticChildAtOffset(
210 offset, m_child_type, true, ConstString(idx_name.GetString())));
211 if (!child_sp)
212 return child_sp;
213
214 child_sp->SetFormat(m_item_format);
215
216 return child_sp;
217 }
218
219 bool Update() override {
220 m_parent_format = m_backend.GetFormat();
221 CompilerType parent_type(m_backend.GetCompilerType());
222 CompilerType element_type;
223 parent_type.IsVectorType(&element_type, nullptr);
224 TargetSP target_sp(m_backend.GetTargetSP());
225 m_child_type = ::GetCompilerTypeForFormat(
5
Calling 'GetCompilerTypeForFormat'
226 m_parent_format, element_type,
227 target_sp
3
'?' condition is false
4
Passing null pointer value via 3rd parameter 'type_system'
228 ? target_sp->GetScratchTypeSystemForLanguage(nullptr,
229 lldb::eLanguageTypeC)
230 : nullptr);
231 m_num_children = ::CalculateNumChildren(parent_type, m_child_type);
232 m_item_format = GetItemFormatForFormat(m_parent_format, m_child_type);
233 return false;
234 }
235
236 bool MightHaveChildren() override { return true; }
237
238 size_t GetIndexOfChildWithName(const ConstString &name) override {
239 const char *item_name = name.GetCString();
240 uint32_t idx = ExtractIndexFromString(item_name);
241 if (idx < UINT32_MAX(4294967295U) && idx >= CalculateNumChildren())
242 return UINT32_MAX(4294967295U);
243 return idx;
244 }
245
246private:
247 lldb::Format m_parent_format;
248 lldb::Format m_item_format;
249 CompilerType m_child_type;
250 size_t m_num_children;
251};
252
253} // namespace formatters
254} // namespace lldb_private
255
256bool lldb_private::formatters::VectorTypeSummaryProvider(
257 ValueObject &valobj, Stream &s, const TypeSummaryOptions &) {
258 auto synthetic_children =
259 VectorTypeSyntheticFrontEndCreator(nullptr, valobj.GetSP());
260 if (!synthetic_children)
1
Taking false branch
261 return false;
262
263 synthetic_children->Update();
2
Calling 'VectorTypeSyntheticFrontEnd::Update'
264
265 s.PutChar('(');
266 bool first = true;
267
268 size_t idx = 0, len = synthetic_children->CalculateNumChildren();
269
270 for (; idx < len; idx++) {
271 auto child_sp = synthetic_children->GetChildAtIndex(idx);
272 if (!child_sp)
273 continue;
274 child_sp = child_sp->GetQualifiedRepresentationIfAvailable(
275 lldb::eDynamicDontRunTarget, true);
276
277 const char *child_value = child_sp->GetValueAsCString();
278 if (child_value && *child_value) {
279 if (first) {
280 s.Printf("%s", child_value);
281 first = false;
282 } else {
283 s.Printf(", %s", child_value);
284 }
285 }
286 }
287
288 s.PutChar(')');
289
290 return true;
291}
292
293lldb_private::SyntheticChildrenFrontEnd *
294lldb_private::formatters::VectorTypeSyntheticFrontEndCreator(
295 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
296 if (!valobj_sp)
297 return nullptr;
298 return new VectorTypeSyntheticFrontEnd(valobj_sp);
299}