Bug Summary

File:tools/lldb/include/lldb/Core/FormatEntity.h
Warning:line 113, column 12
Excessive padding in 'struct lldb_private::FormatEntity::Entry::Definition' (11 padding bytes, where 3 is optimal). Optimal fields order: name, string, data, children, type, format_type, num_children, keep_separator, consider reordering the fields or adding explicit padding members

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 FormatEntity.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/Core -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Core -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/Core -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/Core/FormatEntity.cpp
1//===-- FormatEntity.h ------------------------------------------*- 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#ifndef liblldb_FormatEntity_h_
11#define liblldb_FormatEntity_h_
12
13#include "lldb/Utility/FileSpec.h" // for FileSpec
14#include "lldb/Utility/Status.h"
15#include "lldb/lldb-enumerations.h" // for Format::eFormatDefault, Format
16#include "lldb/lldb-types.h" // for addr_t
17#include <algorithm> // for min
18#include <stddef.h> // for size_t
19#include <stdint.h> // for uint32_t, uint64_t
20
21#include <string>
22#include <vector>
23
24namespace lldb_private {
25class Address;
26}
27namespace lldb_private {
28class ExecutionContext;
29}
30namespace lldb_private {
31class Stream;
32}
33namespace lldb_private {
34class StringList;
35}
36namespace lldb_private {
37class SymbolContext;
38}
39namespace lldb_private {
40class ValueObject;
41}
42namespace llvm {
43class StringRef;
44}
45
46namespace lldb_private {
47class FormatEntity {
48public:
49 struct Entry {
50 enum class Type {
51 Invalid,
52 ParentNumber,
53 ParentString,
54 InsertString,
55 Root,
56 String,
57 Scope,
58 Variable,
59 VariableSynthetic,
60 ScriptVariable,
61 ScriptVariableSynthetic,
62 AddressLoad,
63 AddressFile,
64 AddressLoadOrFile,
65 ProcessID,
66 ProcessFile,
67 ScriptProcess,
68 ThreadID,
69 ThreadProtocolID,
70 ThreadIndexID,
71 ThreadName,
72 ThreadQueue,
73 ThreadStopReason,
74 ThreadReturnValue,
75 ThreadCompletedExpression,
76 ScriptThread,
77 ThreadInfo,
78 TargetArch,
79 ScriptTarget,
80 ModuleFile,
81 File,
82 Lang,
83 FrameIndex,
84 FrameNoDebug,
85 FrameRegisterPC,
86 FrameRegisterSP,
87 FrameRegisterFP,
88 FrameRegisterFlags,
89 FrameRegisterByName,
90 ScriptFrame,
91 FunctionID,
92 FunctionDidChange,
93 FunctionInitialFunction,
94 FunctionName,
95 FunctionNameWithArgs,
96 FunctionNameNoArgs,
97 FunctionAddrOffset,
98 FunctionAddrOffsetConcrete,
99 FunctionLineOffset,
100 FunctionPCOffset,
101 FunctionInitial,
102 FunctionChanged,
103 FunctionIsOptimized,
104 LineEntryFile,
105 LineEntryLineNumber,
106 LineEntryStartAddress,
107 LineEntryEndAddress,
108 CurrentPCArrow
109 };
110
111 enum FormatType { None, UInt32, UInt64, CString };
112
113 struct Definition {
Excessive padding in 'struct lldb_private::FormatEntity::Entry::Definition' (11 padding bytes, where 3 is optimal). Optimal fields order: name, string, data, children, type, format_type, num_children, keep_separator, consider reordering the fields or adding explicit padding members
114 const char *name;
115 const char *string; // Insert this exact string into the output
116 Entry::Type type;
117 FormatType format_type; // uint32_t, uint64_t, cstr, or anything that can
118 // be formatted by printf or lldb::Format
119 uint64_t data;
120 uint32_t num_children;
121 Definition *children; // An array of "num_children" Definition entries,
122 bool keep_separator;
123 };
124
125 Entry(Type t = Type::Invalid, const char *s = nullptr,
126 const char *f = nullptr)
127 : string(s ? s : ""), printf_format(f ? f : ""), children(),
128 definition(nullptr), type(t), fmt(lldb::eFormatDefault), number(0),
129 deref(false) {}
130
131 Entry(llvm::StringRef s);
132 Entry(char ch);
133
134 void AppendChar(char ch);
135
136 void AppendText(const llvm::StringRef &s);
137
138 void AppendText(const char *cstr);
139
140 void AppendEntry(const Entry &&entry) { children.push_back(entry); }
141
142 void Clear() {
143 string.clear();
144 printf_format.clear();
145 children.clear();
146 definition = nullptr;
147 type = Type::Invalid;
148 fmt = lldb::eFormatDefault;
149 number = 0;
150 deref = false;
151 }
152
153 static const char *TypeToCString(Type t);
154
155 void Dump(Stream &s, int depth = 0) const;
156
157 bool operator==(const Entry &rhs) const {
158 if (string != rhs.string)
159 return false;
160 if (printf_format != rhs.printf_format)
161 return false;
162 const size_t n = children.size();
163 const size_t m = rhs.children.size();
164 for (size_t i = 0; i < std::min<size_t>(n, m); ++i) {
165 if (!(children[i] == rhs.children[i]))
166 return false;
167 }
168 if (children != rhs.children)
169 return false;
170 if (definition != rhs.definition)
171 return false;
172 if (type != rhs.type)
173 return false;
174 if (fmt != rhs.fmt)
175 return false;
176 if (deref != rhs.deref)
177 return false;
178 return true;
179 }
180
181 std::string string;
182 std::string printf_format;
183 std::vector<Entry> children;
184 Definition *definition;
185 Type type;
186 lldb::Format fmt;
187 lldb::addr_t number;
188 bool deref;
189 };
190
191 static bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
192 const ExecutionContext *exe_ctx, const Address *addr,
193 ValueObject *valobj, bool function_changed,
194 bool initial_function);
195
196 static bool FormatStringRef(const llvm::StringRef &format, Stream &s,
197 const SymbolContext *sc,
198 const ExecutionContext *exe_ctx,
199 const Address *addr, ValueObject *valobj,
200 bool function_changed, bool initial_function);
201
202 static bool FormatCString(const char *format, Stream &s,
203 const SymbolContext *sc,
204 const ExecutionContext *exe_ctx,
205 const Address *addr, ValueObject *valobj,
206 bool function_changed, bool initial_function);
207
208 static Status Parse(const llvm::StringRef &format, Entry &entry);
209
210 static Status ExtractVariableInfo(llvm::StringRef &format_str,
211 llvm::StringRef &variable_name,
212 llvm::StringRef &variable_format);
213
214 static size_t AutoComplete(llvm::StringRef s, int match_start_point,
215 int max_return_elements, bool &word_complete,
216 StringList &matches);
217
218 //----------------------------------------------------------------------
219 // Format the current elements into the stream \a s.
220 //
221 // The root element will be stripped off and the format str passed in
222 // will be either an empty string (print a description of this object),
223 // or contain a . separated series like a domain name that identifies
224 // further sub elements to display.
225 //----------------------------------------------------------------------
226 static bool FormatFileSpec(const FileSpec &file, Stream &s,
227 llvm::StringRef elements,
228 llvm::StringRef element_format);
229
230protected:
231 static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
232 uint32_t depth);
233};
234} // namespace lldb_private
235
236#endif // liblldb_FormatEntity_h_