Bug Summary

File:lib/IR/DebugInfoMetadata.cpp
Warning:line 1059, column 28
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 DebugInfoMetadata.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-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~svn350071/build-llvm/lib/IR -I /build/llvm-toolchain-snapshot-8~svn350071/lib/IR -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn350071/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~svn350071/build-llvm/lib/IR -fdebug-prefix-map=/build/llvm-toolchain-snapshot-8~svn350071=. -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-2018-12-27-042839-1215-1 -x c++ /build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp -faddrsig
1//===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
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 implements the debug info Metadata classes.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/IR/DebugInfoMetadata.h"
15#include "LLVMContextImpl.h"
16#include "MetadataImpl.h"
17#include "llvm/ADT/SmallSet.h"
18#include "llvm/ADT/StringSwitch.h"
19#include "llvm/IR/DIBuilder.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/Instructions.h"
22
23#include <numeric>
24
25using namespace llvm;
26
27DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
28 unsigned Column, ArrayRef<Metadata *> MDs,
29 bool ImplicitCode)
30 : MDNode(C, DILocationKind, Storage, MDs) {
31 assert((MDs.size() == 1 || MDs.size() == 2) &&(((MDs.size() == 1 || MDs.size() == 2) && "Expected a scope and optional inlined-at"
) ? static_cast<void> (0) : __assert_fail ("(MDs.size() == 1 || MDs.size() == 2) && \"Expected a scope and optional inlined-at\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 32, __PRETTY_FUNCTION__))
32 "Expected a scope and optional inlined-at")(((MDs.size() == 1 || MDs.size() == 2) && "Expected a scope and optional inlined-at"
) ? static_cast<void> (0) : __assert_fail ("(MDs.size() == 1 || MDs.size() == 2) && \"Expected a scope and optional inlined-at\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 32, __PRETTY_FUNCTION__))
;
33
34 // Set line and column.
35 assert(Column < (1u << 16) && "Expected 16-bit column")((Column < (1u << 16) && "Expected 16-bit column"
) ? static_cast<void> (0) : __assert_fail ("Column < (1u << 16) && \"Expected 16-bit column\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 35, __PRETTY_FUNCTION__))
;
36
37 SubclassData32 = Line;
38 SubclassData16 = Column;
39
40 setImplicitCode(ImplicitCode);
41}
42
43static void adjustColumn(unsigned &Column) {
44 // Set to unknown on overflow. We only have 16 bits to play with here.
45 if (Column >= (1u << 16))
46 Column = 0;
47}
48
49DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
50 unsigned Column, Metadata *Scope,
51 Metadata *InlinedAt, bool ImplicitCode,
52 StorageType Storage, bool ShouldCreate) {
53 // Fixup column.
54 adjustColumn(Column);
55
56 if (Storage == Uniqued) {
57 if (auto *N = getUniqued(Context.pImpl->DILocations,
58 DILocationInfo::KeyTy(Line, Column, Scope,
59 InlinedAt, ImplicitCode)))
60 return N;
61 if (!ShouldCreate)
62 return nullptr;
63 } else {
64 assert(ShouldCreate && "Expected non-uniqued nodes to always be created")((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 64, __PRETTY_FUNCTION__))
;
65 }
66
67 SmallVector<Metadata *, 2> Ops;
68 Ops.push_back(Scope);
69 if (InlinedAt)
70 Ops.push_back(InlinedAt);
71 return storeImpl(new (Ops.size()) DILocation(Context, Storage, Line, Column,
72 Ops, ImplicitCode),
73 Storage, Context.pImpl->DILocations);
74}
75
76const DILocation *DILocation::getMergedLocation(const DILocation *LocA,
77 const DILocation *LocB) {
78 if (!LocA || !LocB)
79 return nullptr;
80
81 if (LocA == LocB)
82 return LocA;
83
84 SmallPtrSet<DILocation *, 5> InlinedLocationsA;
85 for (DILocation *L = LocA->getInlinedAt(); L; L = L->getInlinedAt())
86 InlinedLocationsA.insert(L);
87 SmallSet<std::pair<DIScope *, DILocation *>, 5> Locations;
88 DIScope *S = LocA->getScope();
89 DILocation *L = LocA->getInlinedAt();
90 while (S) {
91 Locations.insert(std::make_pair(S, L));
92 S = S->getScope().resolve();
93 if (!S && L) {
94 S = L->getScope();
95 L = L->getInlinedAt();
96 }
97 }
98 const DILocation *Result = LocB;
99 S = LocB->getScope();
100 L = LocB->getInlinedAt();
101 while (S) {
102 if (Locations.count(std::make_pair(S, L)))
103 break;
104 S = S->getScope().resolve();
105 if (!S && L) {
106 S = L->getScope();
107 L = L->getInlinedAt();
108 }
109 }
110
111 // If the two locations are irreconsilable, just pick one. This is misleading,
112 // but on the other hand, it's a "line 0" location.
113 if (!S || !isa<DILocalScope>(S))
114 S = LocA->getScope();
115 return DILocation::get(Result->getContext(), 0, 0, S, L);
116}
117
118Optional<unsigned> DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
119 SmallVector<unsigned, 3> Components = {BD, DF, CI};
120 uint64_t RemainingWork = 0U;
121 // We use RemainingWork to figure out if we have no remaining components to
122 // encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
123 // encode anything for the latter 2.
124 // Since any of the input components is at most 32 bits, their sum will be
125 // less than 34 bits, and thus RemainingWork won't overflow.
126 RemainingWork = std::accumulate(Components.begin(), Components.end(), RemainingWork);
127
128 int I = 0;
129 unsigned Ret = 0;
130 unsigned NextBitInsertionIndex = 0;
131 while (RemainingWork > 0) {
132 unsigned C = Components[I++];
133 RemainingWork -= C;
134 unsigned EC = encodeComponent(C);
135 Ret |= (EC << NextBitInsertionIndex);
136 NextBitInsertionIndex += encodingBits(C);
137 }
138
139 // Encoding may be unsuccessful because of overflow. We determine success by
140 // checking equivalence of components before & after encoding. Alternatively,
141 // we could determine Success during encoding, but the current alternative is
142 // simpler.
143 unsigned TBD, TDF, TCI = 0;
144 decodeDiscriminator(Ret, TBD, TDF, TCI);
145 if (TBD == BD && TDF == DF && TCI == CI)
146 return Ret;
147 return None;
148}
149
150void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
151 unsigned &CI) {
152 BD = getUnsignedFromPrefixEncoding(D);
153 DF = getUnsignedFromPrefixEncoding(getNextComponentInDiscriminator(D));
154 CI = getUnsignedFromPrefixEncoding(
155 getNextComponentInDiscriminator(getNextComponentInDiscriminator(D)));
156}
157
158
159DINode::DIFlags DINode::getFlag(StringRef Flag) {
160 return StringSwitch<DIFlags>(Flag)
161#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
162#include "llvm/IR/DebugInfoFlags.def"
163 .Default(DINode::FlagZero);
164}
165
166StringRef DINode::getFlagString(DIFlags Flag) {
167 switch (Flag) {
168#define HANDLE_DI_FLAG(ID, NAME) \
169 case Flag##NAME: \
170 return "DIFlag" #NAME;
171#include "llvm/IR/DebugInfoFlags.def"
172 }
173 return "";
174}
175
176DINode::DIFlags DINode::splitFlags(DIFlags Flags,
177 SmallVectorImpl<DIFlags> &SplitFlags) {
178 // Flags that are packed together need to be specially handled, so
179 // that, for example, we emit "DIFlagPublic" and not
180 // "DIFlagPrivate | DIFlagProtected".
181 if (DIFlags A = Flags & FlagAccessibility) {
182 if (A == FlagPrivate)
183 SplitFlags.push_back(FlagPrivate);
184 else if (A == FlagProtected)
185 SplitFlags.push_back(FlagProtected);
186 else
187 SplitFlags.push_back(FlagPublic);
188 Flags &= ~A;
189 }
190 if (DIFlags R = Flags & FlagPtrToMemberRep) {
191 if (R == FlagSingleInheritance)
192 SplitFlags.push_back(FlagSingleInheritance);
193 else if (R == FlagMultipleInheritance)
194 SplitFlags.push_back(FlagMultipleInheritance);
195 else
196 SplitFlags.push_back(FlagVirtualInheritance);
197 Flags &= ~R;
198 }
199 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
200 Flags &= ~FlagIndirectVirtualBase;
201 SplitFlags.push_back(FlagIndirectVirtualBase);
202 }
203
204#define HANDLE_DI_FLAG(ID, NAME) \
205 if (DIFlags Bit = Flags & Flag##NAME) { \
206 SplitFlags.push_back(Bit); \
207 Flags &= ~Bit; \
208 }
209#include "llvm/IR/DebugInfoFlags.def"
210 return Flags;
211}
212
213DIScopeRef DIScope::getScope() const {
214 if (auto *T = dyn_cast<DIType>(this))
215 return T->getScope();
216
217 if (auto *SP = dyn_cast<DISubprogram>(this))
218 return SP->getScope();
219
220 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
221 return LB->getScope();
222
223 if (auto *NS = dyn_cast<DINamespace>(this))
224 return NS->getScope();
225
226 if (auto *M = dyn_cast<DIModule>(this))
227 return M->getScope();
228
229 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&(((isa<DIFile>(this) || isa<DICompileUnit>(this))
&& "Unhandled type of scope.") ? static_cast<void
> (0) : __assert_fail ("(isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 230, __PRETTY_FUNCTION__))
230 "Unhandled type of scope.")(((isa<DIFile>(this) || isa<DICompileUnit>(this))
&& "Unhandled type of scope.") ? static_cast<void
> (0) : __assert_fail ("(isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 230, __PRETTY_FUNCTION__))
;
231 return nullptr;
232}
233
234StringRef DIScope::getName() const {
235 if (auto *T = dyn_cast<DIType>(this))
236 return T->getName();
237 if (auto *SP = dyn_cast<DISubprogram>(this))
238 return SP->getName();
239 if (auto *NS = dyn_cast<DINamespace>(this))
240 return NS->getName();
241 if (auto *M = dyn_cast<DIModule>(this))
242 return M->getName();
243 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||(((isa<DILexicalBlockBase>(this) || isa<DIFile>(this
) || isa<DICompileUnit>(this)) && "Unhandled type of scope."
) ? static_cast<void> (0) : __assert_fail ("(isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 245, __PRETTY_FUNCTION__))
244 isa<DICompileUnit>(this)) &&(((isa<DILexicalBlockBase>(this) || isa<DIFile>(this
) || isa<DICompileUnit>(this)) && "Unhandled type of scope."
) ? static_cast<void> (0) : __assert_fail ("(isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 245, __PRETTY_FUNCTION__))
245 "Unhandled type of scope.")(((isa<DILexicalBlockBase>(this) || isa<DIFile>(this
) || isa<DICompileUnit>(this)) && "Unhandled type of scope."
) ? static_cast<void> (0) : __assert_fail ("(isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 245, __PRETTY_FUNCTION__))
;
246 return "";
247}
248
249#ifndef NDEBUG
250static bool isCanonical(const MDString *S) {
251 return !S || !S->getString().empty();
252}
253#endif
254
255GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
256 MDString *Header,
257 ArrayRef<Metadata *> DwarfOps,
258 StorageType Storage, bool ShouldCreate) {
259 unsigned Hash = 0;
260 if (Storage == Uniqued) {
261 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
262 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
263 return N;
264 if (!ShouldCreate)
265 return nullptr;
266 Hash = Key.getHash();
267 } else {
268 assert(ShouldCreate && "Expected non-uniqued nodes to always be created")((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 268, __PRETTY_FUNCTION__))
;
269 }
270
271 // Use a nullptr for empty headers.
272 assert(isCanonical(Header) && "Expected canonical MDString")((isCanonical(Header) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(Header) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 272, __PRETTY_FUNCTION__))
;
273 Metadata *PreOps[] = {Header};
274 return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
275 Context, Storage, Hash, Tag, PreOps, DwarfOps),
276 Storage, Context.pImpl->GenericDINodes);
277}
278
279void GenericDINode::recalculateHash() {
280 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
281}
282
283#define UNWRAP_ARGS_IMPL(...)... __VA_ARGS__
284#define UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS UNWRAP_ARGS_IMPL ARGS
285#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS)do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->CLASSs, CLASSInfo::KeyTy(UNWRAP_ARGS_IMPL ARGS))) return
N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 285, __PRETTY_FUNCTION__)); } } while (false)
\
286 do { \
287 if (Storage == Uniqued) { \
288 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
289 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS))) \
290 return N; \
291 if (!ShouldCreate) \
292 return nullptr; \
293 } else { \
294 assert(ShouldCreate && \((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 295, __PRETTY_FUNCTION__))
295 "Expected non-uniqued nodes to always be created")((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 295, __PRETTY_FUNCTION__))
; \
296 } \
297 } while (false)
298#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS)return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage
, UNWRAP_ARGS_IMPL ARGS, OPS), Storage, Context.pImpl->CLASSs
)
\
299 return storeImpl(new (array_lengthof(OPS)) \
300 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS, OPS), \
301 Storage, Context.pImpl->CLASS##s)
302#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS)return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS_IMPL
ARGS), Storage, Context.pImpl->CLASSs)
\
303 return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS), \
304 Storage, Context.pImpl->CLASS##s)
305#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS)return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage
, OPS), Storage, Context.pImpl->CLASSs)
\
306 return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \
307 Storage, Context.pImpl->CLASS##s)
308#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS)return storeImpl(new (NUM_OPS) CLASS(Context, Storage, UNWRAP_ARGS_IMPL
ARGS, OPS), Storage, Context.pImpl->CLASSs)
\
309 return storeImpl(new (NUM_OPS) \
310 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS, OPS), \
311 Storage, Context.pImpl->CLASS##s)
312
313DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
314 StorageType Storage, bool ShouldCreate) {
315 auto *CountNode = ConstantAsMetadata::get(
316 ConstantInt::getSigned(Type::getInt64Ty(Context), Count));
317 return getImpl(Context, CountNode, Lo, Storage, ShouldCreate);
318}
319
320DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
321 int64_t Lo, StorageType Storage,
322 bool ShouldCreate) {
323 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, Lo))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubranges, DISubrangeInfo::KeyTy(CountNode, Lo))
) return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 323, __PRETTY_FUNCTION__)); } } while (false)
;
324 Metadata *Ops[] = { CountNode };
325 DEFINE_GETIMPL_STORE(DISubrange, (CountNode, Lo), Ops)return storeImpl(new (array_lengthof(Ops)) DISubrange(Context
, Storage, CountNode, Lo, Ops), Storage, Context.pImpl->DISubranges
)
;
326}
327
328DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
329 bool IsUnsigned, MDString *Name,
330 StorageType Storage, bool ShouldCreate) {
331 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 331, __PRETTY_FUNCTION__))
;
332 DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, IsUnsigned, Name))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIEnumerators, DIEnumeratorInfo::KeyTy(Value, IsUnsigned
, Name))) return N; if (!ShouldCreate) return nullptr; } else
{ ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 332, __PRETTY_FUNCTION__)); } } while (false)
;
333 Metadata *Ops[] = {Name};
334 DEFINE_GETIMPL_STORE(DIEnumerator, (Value, IsUnsigned), Ops)return storeImpl(new (array_lengthof(Ops)) DIEnumerator(Context
, Storage, Value, IsUnsigned, Ops), Storage, Context.pImpl->
DIEnumerators)
;
335}
336
337DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
338 MDString *Name, uint64_t SizeInBits,
339 uint32_t AlignInBits, unsigned Encoding,
340 DIFlags Flags, StorageType Storage,
341 bool ShouldCreate) {
342 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 342, __PRETTY_FUNCTION__))
;
343 DEFINE_GETIMPL_LOOKUP(DIBasicType,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIBasicTypes, DIBasicTypeInfo::KeyTy(Tag, Name, SizeInBits
, AlignInBits, Encoding, Flags))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 344, __PRETTY_FUNCTION__)); } } while (false)
344 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIBasicTypes, DIBasicTypeInfo::KeyTy(Tag, Name, SizeInBits
, AlignInBits, Encoding, Flags))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 344, __PRETTY_FUNCTION__)); } } while (false)
;
345 Metadata *Ops[] = {nullptr, nullptr, Name};
346 DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding,return storeImpl(new (array_lengthof(Ops)) DIBasicType(Context
, Storage, Tag, SizeInBits, AlignInBits, Encoding, Flags, Ops
), Storage, Context.pImpl->DIBasicTypes)
347 Flags), Ops)return storeImpl(new (array_lengthof(Ops)) DIBasicType(Context
, Storage, Tag, SizeInBits, AlignInBits, Encoding, Flags, Ops
), Storage, Context.pImpl->DIBasicTypes)
;
348}
349
350Optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
351 switch (getEncoding()) {
352 case dwarf::DW_ATE_signed:
353 case dwarf::DW_ATE_signed_char:
354 return Signedness::Signed;
355 case dwarf::DW_ATE_unsigned:
356 case dwarf::DW_ATE_unsigned_char:
357 return Signedness::Unsigned;
358 default:
359 return None;
360 }
361}
362
363DIDerivedType *DIDerivedType::getImpl(
364 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
365 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
366 uint32_t AlignInBits, uint64_t OffsetInBits,
367 Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData,
368 StorageType Storage, bool ShouldCreate) {
369 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 369, __PRETTY_FUNCTION__))
;
370 DEFINE_GETIMPL_LOOKUP(DIDerivedType,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIDerivedTypes, DIDerivedTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, ExtraData))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 373, __PRETTY_FUNCTION__)); } } while (false)
371 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIDerivedTypes, DIDerivedTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, ExtraData))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 373, __PRETTY_FUNCTION__)); } } while (false)
372 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIDerivedTypes, DIDerivedTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, ExtraData))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 373, __PRETTY_FUNCTION__)); } } while (false)
373 ExtraData))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIDerivedTypes, DIDerivedTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, ExtraData))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 373, __PRETTY_FUNCTION__)); } } while (false)
;
374 Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
375 DEFINE_GETIMPL_STORE(return storeImpl(new (array_lengthof(Ops)) DIDerivedType(Context
, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace
, Flags, Ops), Storage, Context.pImpl->DIDerivedTypes)
376 DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,return storeImpl(new (array_lengthof(Ops)) DIDerivedType(Context
, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace
, Flags, Ops), Storage, Context.pImpl->DIDerivedTypes)
377 DWARFAddressSpace, Flags), Ops)return storeImpl(new (array_lengthof(Ops)) DIDerivedType(Context
, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace
, Flags, Ops), Storage, Context.pImpl->DIDerivedTypes)
;
378}
379
380DICompositeType *DICompositeType::getImpl(
381 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
382 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
383 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
384 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
385 Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
386 StorageType Storage, bool ShouldCreate) {
387 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 387, __PRETTY_FUNCTION__))
;
388
389 // Keep this in sync with buildODRType.
390 DEFINE_GETIMPL_LOOKUP(do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DICompositeTypes, DICompositeTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 393, __PRETTY_FUNCTION__)); } } while (false)
391 DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DICompositeTypes, DICompositeTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 393, __PRETTY_FUNCTION__)); } } while (false)
392 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DICompositeTypes, DICompositeTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 393, __PRETTY_FUNCTION__)); } } while (false)
393 VTableHolder, TemplateParams, Identifier, Discriminator))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DICompositeTypes, DICompositeTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 393, __PRETTY_FUNCTION__)); } } while (false)
;
394 Metadata *Ops[] = {File, Scope, Name, BaseType,
395 Elements, VTableHolder, TemplateParams, Identifier,
396 Discriminator};
397 DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,return storeImpl(new (array_lengthof(Ops)) DICompositeType(Context
, Storage, Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits
, Flags, Ops), Storage, Context.pImpl->DICompositeTypes)
398 AlignInBits, OffsetInBits, Flags),return storeImpl(new (array_lengthof(Ops)) DICompositeType(Context
, Storage, Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits
, Flags, Ops), Storage, Context.pImpl->DICompositeTypes)
399 Ops)return storeImpl(new (array_lengthof(Ops)) DICompositeType(Context
, Storage, Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits
, Flags, Ops), Storage, Context.pImpl->DICompositeTypes)
;
400}
401
402DICompositeType *DICompositeType::buildODRType(
403 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
404 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
405 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
406 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
407 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
408 assert(!Identifier.getString().empty() && "Expected valid identifier")((!Identifier.getString().empty() && "Expected valid identifier"
) ? static_cast<void> (0) : __assert_fail ("!Identifier.getString().empty() && \"Expected valid identifier\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 408, __PRETTY_FUNCTION__))
;
409 if (!Context.isODRUniquingDebugTypes())
410 return nullptr;
411 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
412 if (!CT)
413 return CT = DICompositeType::getDistinct(
414 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
415 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
416 VTableHolder, TemplateParams, &Identifier, Discriminator);
417
418 // Only mutate CT if it's a forward declaration and the new operands aren't.
419 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?")((CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?"
) ? static_cast<void> (0) : __assert_fail ("CT->getRawIdentifier() == &Identifier && \"Wrong ODR identifier?\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 419, __PRETTY_FUNCTION__))
;
420 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
421 return CT;
422
423 // Mutate CT in place. Keep this in sync with getImpl.
424 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
425 Flags);
426 Metadata *Ops[] = {File, Scope, Name, BaseType,
427 Elements, VTableHolder, TemplateParams, &Identifier,
428 Discriminator};
429 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&(((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands
() && "Mismatched number of operands") ? static_cast<
void> (0) : __assert_fail ("(std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() && \"Mismatched number of operands\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 430, __PRETTY_FUNCTION__))
430 "Mismatched number of operands")(((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands
() && "Mismatched number of operands") ? static_cast<
void> (0) : __assert_fail ("(std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() && \"Mismatched number of operands\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 430, __PRETTY_FUNCTION__))
;
431 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
432 if (Ops[I] != CT->getOperand(I))
433 CT->setOperand(I, Ops[I]);
434 return CT;
435}
436
437DICompositeType *DICompositeType::getODRType(
438 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
439 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
440 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
441 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
442 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
443 assert(!Identifier.getString().empty() && "Expected valid identifier")((!Identifier.getString().empty() && "Expected valid identifier"
) ? static_cast<void> (0) : __assert_fail ("!Identifier.getString().empty() && \"Expected valid identifier\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 443, __PRETTY_FUNCTION__))
;
444 if (!Context.isODRUniquingDebugTypes())
445 return nullptr;
446 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
447 if (!CT)
448 CT = DICompositeType::getDistinct(
449 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
450 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
451 TemplateParams, &Identifier, Discriminator);
452 return CT;
453}
454
455DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context,
456 MDString &Identifier) {
457 assert(!Identifier.getString().empty() && "Expected valid identifier")((!Identifier.getString().empty() && "Expected valid identifier"
) ? static_cast<void> (0) : __assert_fail ("!Identifier.getString().empty() && \"Expected valid identifier\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 457, __PRETTY_FUNCTION__))
;
458 if (!Context.isODRUniquingDebugTypes())
459 return nullptr;
460 return Context.pImpl->DITypeMap->lookup(&Identifier);
461}
462
463DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
464 uint8_t CC, Metadata *TypeArray,
465 StorageType Storage,
466 bool ShouldCreate) {
467 DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubroutineTypes, DISubroutineTypeInfo::KeyTy(Flags
, CC, TypeArray))) return N; if (!ShouldCreate) return nullptr
; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 467, __PRETTY_FUNCTION__)); } } while (false)
;
468 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
469 DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops)return storeImpl(new (array_lengthof(Ops)) DISubroutineType(Context
, Storage, Flags, CC, Ops), Storage, Context.pImpl->DISubroutineTypes
)
;
470}
471
472// FIXME: Implement this string-enum correspondence with a .def file and macros,
473// so that the association is explicit rather than implied.
474static const char *ChecksumKindName[DIFile::CSK_Last] = {
475 "CSK_MD5",
476 "CSK_SHA1"
477};
478
479StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
480 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind")((CSKind <= DIFile::CSK_Last && "Invalid checksum kind"
) ? static_cast<void> (0) : __assert_fail ("CSKind <= DIFile::CSK_Last && \"Invalid checksum kind\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 480, __PRETTY_FUNCTION__))
;
481 // The first space was originally the CSK_None variant, which is now
482 // obsolete, but the space is still reserved in ChecksumKind, so we account
483 // for it here.
484 return ChecksumKindName[CSKind - 1];
485}
486
487Optional<DIFile::ChecksumKind> DIFile::getChecksumKind(StringRef CSKindStr) {
488 return StringSwitch<Optional<DIFile::ChecksumKind>>(CSKindStr)
489 .Case("CSK_MD5", DIFile::CSK_MD5)
490 .Case("CSK_SHA1", DIFile::CSK_SHA1)
491 .Default(None);
492}
493
494DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
495 MDString *Directory,
496 Optional<DIFile::ChecksumInfo<MDString *>> CS,
497 Optional<MDString *> Source, StorageType Storage,
498 bool ShouldCreate) {
499 assert(isCanonical(Filename) && "Expected canonical MDString")((isCanonical(Filename) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(Filename) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 499, __PRETTY_FUNCTION__))
;
500 assert(isCanonical(Directory) && "Expected canonical MDString")((isCanonical(Directory) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(Directory) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 500, __PRETTY_FUNCTION__))
;
501 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString")(((!CS || isCanonical(CS->Value)) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("(!CS || isCanonical(CS->Value)) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 501, __PRETTY_FUNCTION__))
;
502 assert((!Source || isCanonical(*Source)) && "Expected canonical MDString")(((!Source || isCanonical(*Source)) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("(!Source || isCanonical(*Source)) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 502, __PRETTY_FUNCTION__))
;
503 DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CS, Source))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIFiles, DIFileInfo::KeyTy(Filename, Directory, CS
, Source))) return N; if (!ShouldCreate) return nullptr; } else
{ ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 503, __PRETTY_FUNCTION__)); } } while (false)
;
504 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr,
505 Source.getValueOr(nullptr)};
506 DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops)return storeImpl(new (array_lengthof(Ops)) DIFile(Context, Storage
, CS, Source, Ops), Storage, Context.pImpl->DIFiles)
;
507}
508
509DICompileUnit *DICompileUnit::getImpl(
510 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
511 MDString *Producer, bool IsOptimized, MDString *Flags,
512 unsigned RuntimeVersion, MDString *SplitDebugFilename,
513 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
514 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
515 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
516 unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage,
517 bool ShouldCreate) {
518 assert(Storage != Uniqued && "Cannot unique DICompileUnit")((Storage != Uniqued && "Cannot unique DICompileUnit"
) ? static_cast<void> (0) : __assert_fail ("Storage != Uniqued && \"Cannot unique DICompileUnit\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 518, __PRETTY_FUNCTION__))
;
519 assert(isCanonical(Producer) && "Expected canonical MDString")((isCanonical(Producer) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(Producer) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 519, __PRETTY_FUNCTION__))
;
520 assert(isCanonical(Flags) && "Expected canonical MDString")((isCanonical(Flags) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(Flags) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 520, __PRETTY_FUNCTION__))
;
521 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString")((isCanonical(SplitDebugFilename) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(SplitDebugFilename) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 521, __PRETTY_FUNCTION__))
;
522
523 Metadata *Ops[] = {
524 File, Producer, Flags, SplitDebugFilename,
525 EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
526 Macros};
527 return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
528 Context, Storage, SourceLanguage, IsOptimized,
529 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
530 DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
531 Ops),
532 Storage);
533}
534
535Optional<DICompileUnit::DebugEmissionKind>
536DICompileUnit::getEmissionKind(StringRef Str) {
537 return StringSwitch<Optional<DebugEmissionKind>>(Str)
538 .Case("NoDebug", NoDebug)
539 .Case("FullDebug", FullDebug)
540 .Case("LineTablesOnly", LineTablesOnly)
541 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
542 .Default(None);
543}
544
545Optional<DICompileUnit::DebugNameTableKind>
546DICompileUnit::getNameTableKind(StringRef Str) {
547 return StringSwitch<Optional<DebugNameTableKind>>(Str)
548 .Case("Default", DebugNameTableKind::Default)
549 .Case("GNU", DebugNameTableKind::GNU)
550 .Case("None", DebugNameTableKind::None)
551 .Default(None);
552}
553
554const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
555 switch (EK) {
556 case NoDebug: return "NoDebug";
557 case FullDebug: return "FullDebug";
558 case LineTablesOnly: return "LineTablesOnly";
559 case DebugDirectivesOnly: return "DebugDirectivesOnly";
560 }
561 return nullptr;
562}
563
564const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) {
565 switch (NTK) {
566 case DebugNameTableKind::Default:
567 return nullptr;
568 case DebugNameTableKind::GNU:
569 return "GNU";
570 case DebugNameTableKind::None:
571 return "None";
572 }
573 return nullptr;
574}
575
576DISubprogram *DILocalScope::getSubprogram() const {
577 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
578 return Block->getScope()->getSubprogram();
579 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
580}
581
582DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
583 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
584 return File->getScope()->getNonLexicalBlockFileScope();
585 return const_cast<DILocalScope *>(this);
586}
587
588DISubprogram::DISPFlags DISubprogram::getFlag(StringRef Flag) {
589 return StringSwitch<DISPFlags>(Flag)
590#define HANDLE_DISP_FLAG(ID, NAME) .Case("DISPFlag" #NAME, SPFlag##NAME)
591#include "llvm/IR/DebugInfoFlags.def"
592 .Default(SPFlagZero);
593}
594
595StringRef DISubprogram::getFlagString(DISPFlags Flag) {
596 switch (Flag) {
597 // Appease a warning.
598 case SPFlagVirtuality:
599 return "";
600#define HANDLE_DISP_FLAG(ID, NAME) \
601 case SPFlag##NAME: \
602 return "DISPFlag" #NAME;
603#include "llvm/IR/DebugInfoFlags.def"
604 }
605 return "";
606}
607
608DISubprogram::DISPFlags
609DISubprogram::splitFlags(DISPFlags Flags,
610 SmallVectorImpl<DISPFlags> &SplitFlags) {
611 // Multi-bit fields can require special handling. In our case, however, the
612 // only multi-bit field is virtuality, and all its values happen to be
613 // single-bit values, so the right behavior just falls out.
614#define HANDLE_DISP_FLAG(ID, NAME) \
615 if (DISPFlags Bit = Flags & SPFlag##NAME) { \
616 SplitFlags.push_back(Bit); \
617 Flags &= ~Bit; \
618 }
619#include "llvm/IR/DebugInfoFlags.def"
620 return Flags;
621}
622
623DISubprogram *DISubprogram::getImpl(
624 LLVMContext &Context, Metadata *Scope, MDString *Name,
625 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
626 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
627 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
628 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
629 Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate) {
630 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 630, __PRETTY_FUNCTION__))
;
631 assert(isCanonical(LinkageName) && "Expected canonical MDString")((isCanonical(LinkageName) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(LinkageName) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 631, __PRETTY_FUNCTION__))
;
632 DEFINE_GETIMPL_LOOKUP(DISubprogram,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubprograms, DISubprogramInfo::KeyTy(Scope, Name
, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex
, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration
, RetainedNodes, ThrownTypes))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 636, __PRETTY_FUNCTION__)); } } while (false)
633 (Scope, Name, LinkageName, File, Line, Type, ScopeLine,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubprograms, DISubprogramInfo::KeyTy(Scope, Name
, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex
, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration
, RetainedNodes, ThrownTypes))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 636, __PRETTY_FUNCTION__)); } } while (false)
634 ContainingType, VirtualIndex, ThisAdjustment, Flags,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubprograms, DISubprogramInfo::KeyTy(Scope, Name
, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex
, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration
, RetainedNodes, ThrownTypes))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 636, __PRETTY_FUNCTION__)); } } while (false)
635 SPFlags, Unit, TemplateParams, Declaration,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubprograms, DISubprogramInfo::KeyTy(Scope, Name
, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex
, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration
, RetainedNodes, ThrownTypes))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 636, __PRETTY_FUNCTION__)); } } while (false)
636 RetainedNodes, ThrownTypes))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubprograms, DISubprogramInfo::KeyTy(Scope, Name
, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex
, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration
, RetainedNodes, ThrownTypes))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 636, __PRETTY_FUNCTION__)); } } while (false)
;
637 SmallVector<Metadata *, 11> Ops = {
638 File, Scope, Name, LinkageName, Type, Unit,
639 Declaration, RetainedNodes, ContainingType, TemplateParams, ThrownTypes};
640 if (!ThrownTypes) {
641 Ops.pop_back();
642 if (!TemplateParams) {
643 Ops.pop_back();
644 if (!ContainingType)
645 Ops.pop_back();
646 }
647 }
648 DEFINE_GETIMPL_STORE_N(return storeImpl(new (Ops.size()) DISubprogram(Context, Storage
, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags
, Ops), Storage, Context.pImpl->DISubprograms)
649 DISubprogram,return storeImpl(new (Ops.size()) DISubprogram(Context, Storage
, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags
, Ops), Storage, Context.pImpl->DISubprograms)
650 (Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags), Ops,return storeImpl(new (Ops.size()) DISubprogram(Context, Storage
, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags
, Ops), Storage, Context.pImpl->DISubprograms)
651 Ops.size())return storeImpl(new (Ops.size()) DISubprogram(Context, Storage
, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags
, Ops), Storage, Context.pImpl->DISubprograms)
;
652}
653
654bool DISubprogram::describes(const Function *F) const {
655 assert(F && "Invalid function")((F && "Invalid function") ? static_cast<void> (
0) : __assert_fail ("F && \"Invalid function\"", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 655, __PRETTY_FUNCTION__))
;
656 if (F->getSubprogram() == this)
657 return true;
658 StringRef Name = getLinkageName();
659 if (Name.empty())
660 Name = getName();
661 return F->getName() == Name;
662}
663
664DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
665 Metadata *File, unsigned Line,
666 unsigned Column, StorageType Storage,
667 bool ShouldCreate) {
668 // Fixup column.
669 adjustColumn(Column);
670
671 assert(Scope && "Expected scope")((Scope && "Expected scope") ? static_cast<void>
(0) : __assert_fail ("Scope && \"Expected scope\"", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 671, __PRETTY_FUNCTION__))
;
672 DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILexicalBlocks, DILexicalBlockInfo::KeyTy(Scope, File
, Line, Column))) return N; if (!ShouldCreate) return nullptr
; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 672, __PRETTY_FUNCTION__)); } } while (false)
;
673 Metadata *Ops[] = {File, Scope};
674 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops)return storeImpl(new (array_lengthof(Ops)) DILexicalBlock(Context
, Storage, Line, Column, Ops), Storage, Context.pImpl->DILexicalBlocks
)
;
675}
676
677DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
678 Metadata *Scope, Metadata *File,
679 unsigned Discriminator,
680 StorageType Storage,
681 bool ShouldCreate) {
682 assert(Scope && "Expected scope")((Scope && "Expected scope") ? static_cast<void>
(0) : __assert_fail ("Scope && \"Expected scope\"", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 682, __PRETTY_FUNCTION__))
;
683 DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILexicalBlockFiles, DILexicalBlockFileInfo::KeyTy
(Scope, File, Discriminator))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 683, __PRETTY_FUNCTION__)); } } while (false)
;
684 Metadata *Ops[] = {File, Scope};
685 DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops)return storeImpl(new (array_lengthof(Ops)) DILexicalBlockFile
(Context, Storage, Discriminator, Ops), Storage, Context.pImpl
->DILexicalBlockFiles)
;
686}
687
688DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
689 MDString *Name, bool ExportSymbols,
690 StorageType Storage, bool ShouldCreate) {
691 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 691, __PRETTY_FUNCTION__))
;
692 DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DINamespaces, DINamespaceInfo::KeyTy(Scope, Name, ExportSymbols
))) return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 692, __PRETTY_FUNCTION__)); } } while (false)
;
693 // The nullptr is for DIScope's File operand. This should be refactored.
694 Metadata *Ops[] = {nullptr, Scope, Name};
695 DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops)return storeImpl(new (array_lengthof(Ops)) DINamespace(Context
, Storage, ExportSymbols, Ops), Storage, Context.pImpl->DINamespaces
)
;
696}
697
698DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
699 MDString *Name, MDString *ConfigurationMacros,
700 MDString *IncludePath, MDString *ISysRoot,
701 StorageType Storage, bool ShouldCreate) {
702 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 702, __PRETTY_FUNCTION__))
;
703 DEFINE_GETIMPL_LOOKUP(do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIModules, DIModuleInfo::KeyTy(Scope, Name, ConfigurationMacros
, IncludePath, ISysRoot))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 704, __PRETTY_FUNCTION__)); } } while (false)
704 DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIModules, DIModuleInfo::KeyTy(Scope, Name, ConfigurationMacros
, IncludePath, ISysRoot))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 704, __PRETTY_FUNCTION__)); } } while (false)
;
705 Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
706 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops)return storeImpl(new (array_lengthof(Ops)) DIModule(Context, Storage
, Ops), Storage, Context.pImpl->DIModules)
;
707}
708
709DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
710 MDString *Name,
711 Metadata *Type,
712 StorageType Storage,
713 bool ShouldCreate) {
714 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 714, __PRETTY_FUNCTION__))
;
715 DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DITemplateTypeParameters, DITemplateTypeParameterInfo
::KeyTy(Name, Type))) return N; if (!ShouldCreate) return nullptr
; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 715, __PRETTY_FUNCTION__)); } } while (false)
;
716 Metadata *Ops[] = {Name, Type};
717 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops)return storeImpl(new (array_lengthof(Ops)) DITemplateTypeParameter
(Context, Storage, Ops), Storage, Context.pImpl->DITemplateTypeParameters
)
;
718}
719
720DITemplateValueParameter *DITemplateValueParameter::getImpl(
721 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
722 Metadata *Value, StorageType Storage, bool ShouldCreate) {
723 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 723, __PRETTY_FUNCTION__))
;
724 DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DITemplateValueParameters, DITemplateValueParameterInfo
::KeyTy(Tag, Name, Type, Value))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 724, __PRETTY_FUNCTION__)); } } while (false)
;
725 Metadata *Ops[] = {Name, Type, Value};
726 DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops)return storeImpl(new (array_lengthof(Ops)) DITemplateValueParameter
(Context, Storage, Tag, Ops), Storage, Context.pImpl->DITemplateValueParameters
)
;
727}
728
729DIGlobalVariable *
730DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
731 MDString *LinkageName, Metadata *File, unsigned Line,
732 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
733 Metadata *StaticDataMemberDeclaration,
734 Metadata *TemplateParams, uint32_t AlignInBits,
735 StorageType Storage, bool ShouldCreate) {
736 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 736, __PRETTY_FUNCTION__))
;
737 assert(isCanonical(LinkageName) && "Expected canonical MDString")((isCanonical(LinkageName) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(LinkageName) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 737, __PRETTY_FUNCTION__))
;
738 DEFINE_GETIMPL_LOOKUP(DIGlobalVariable, (Scope, Name, LinkageName, File, Line,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits)))
return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 741, __PRETTY_FUNCTION__)); } } while (false)
739 Type, IsLocalToUnit, IsDefinition,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits)))
return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 741, __PRETTY_FUNCTION__)); } } while (false)
740 StaticDataMemberDeclaration,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits)))
return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 741, __PRETTY_FUNCTION__)); } } while (false)
741 TemplateParams, AlignInBits))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits)))
return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 741, __PRETTY_FUNCTION__)); } } while (false)
;
742 Metadata *Ops[] = {Scope,
743 Name,
744 File,
745 Type,
746 Name,
747 LinkageName,
748 StaticDataMemberDeclaration,
749 TemplateParams};
750 DEFINE_GETIMPL_STORE(DIGlobalVariable,return storeImpl(new (array_lengthof(Ops)) DIGlobalVariable(Context
, Storage, Line, IsLocalToUnit, IsDefinition, AlignInBits, Ops
), Storage, Context.pImpl->DIGlobalVariables)
751 (Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops)return storeImpl(new (array_lengthof(Ops)) DIGlobalVariable(Context
, Storage, Line, IsLocalToUnit, IsDefinition, AlignInBits, Ops
), Storage, Context.pImpl->DIGlobalVariables)
;
752}
753
754DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
755 MDString *Name, Metadata *File,
756 unsigned Line, Metadata *Type,
757 unsigned Arg, DIFlags Flags,
758 uint32_t AlignInBits,
759 StorageType Storage,
760 bool ShouldCreate) {
761 // 64K ought to be enough for any frontend.
762 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits")((Arg <= (65535) && "Expected argument number to fit in 16-bits"
) ? static_cast<void> (0) : __assert_fail ("Arg <= UINT16_MAX && \"Expected argument number to fit in 16-bits\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 762, __PRETTY_FUNCTION__))
;
763
764 assert(Scope && "Expected scope")((Scope && "Expected scope") ? static_cast<void>
(0) : __assert_fail ("Scope && \"Expected scope\"", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 764, __PRETTY_FUNCTION__))
;
765 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 765, __PRETTY_FUNCTION__))
;
766 DEFINE_GETIMPL_LOOKUP(DILocalVariable,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILocalVariables, DILocalVariableInfo::KeyTy(Scope
, Name, File, Line, Type, Arg, Flags, AlignInBits))) return N
; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? static_cast
<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 768, __PRETTY_FUNCTION__)); } } while (false)
767 (Scope, Name, File, Line, Type, Arg, Flags,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILocalVariables, DILocalVariableInfo::KeyTy(Scope
, Name, File, Line, Type, Arg, Flags, AlignInBits))) return N
; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? static_cast
<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 768, __PRETTY_FUNCTION__)); } } while (false)
768 AlignInBits))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILocalVariables, DILocalVariableInfo::KeyTy(Scope
, Name, File, Line, Type, Arg, Flags, AlignInBits))) return N
; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? static_cast
<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 768, __PRETTY_FUNCTION__)); } } while (false)
;
769 Metadata *Ops[] = {Scope, Name, File, Type};
770 DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops)return storeImpl(new (array_lengthof(Ops)) DILocalVariable(Context
, Storage, Line, Arg, Flags, AlignInBits, Ops), Storage, Context
.pImpl->DILocalVariables)
;
771}
772
773Optional<uint64_t> DIVariable::getSizeInBits() const {
774 // This is used by the Verifier so be mindful of broken types.
775 const Metadata *RawType = getRawType();
776 while (RawType) {
777 // Try to get the size directly.
778 if (auto *T = dyn_cast<DIType>(RawType))
779 if (uint64_t Size = T->getSizeInBits())
780 return Size;
781
782 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
783 // Look at the base type.
784 RawType = DT->getRawBaseType();
785 continue;
786 }
787
788 // Missing type or size.
789 break;
790 }
791
792 // Fail gracefully.
793 return None;
794}
795
796DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope,
797 MDString *Name, Metadata *File, unsigned Line,
798 StorageType Storage,
799 bool ShouldCreate) {
800 assert(Scope && "Expected scope")((Scope && "Expected scope") ? static_cast<void>
(0) : __assert_fail ("Scope && \"Expected scope\"", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 800, __PRETTY_FUNCTION__))
;
801 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 801, __PRETTY_FUNCTION__))
;
802 DEFINE_GETIMPL_LOOKUP(DILabel,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILabels, DILabelInfo::KeyTy(Scope, Name, File, Line
))) return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 803, __PRETTY_FUNCTION__)); } } while (false)
803 (Scope, Name, File, Line))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILabels, DILabelInfo::KeyTy(Scope, Name, File, Line
))) return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 803, __PRETTY_FUNCTION__)); } } while (false)
;
804 Metadata *Ops[] = {Scope, Name, File};
805 DEFINE_GETIMPL_STORE(DILabel, (Line), Ops)return storeImpl(new (array_lengthof(Ops)) DILabel(Context, Storage
, Line, Ops), Storage, Context.pImpl->DILabels)
;
806}
807
808DIExpression *DIExpression::getImpl(LLVMContext &Context,
809 ArrayRef<uint64_t> Elements,
810 StorageType Storage, bool ShouldCreate) {
811 DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIExpressions, DIExpressionInfo::KeyTy(Elements)))
return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 811, __PRETTY_FUNCTION__)); } } while (false)
;
812 DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements))return storeImpl(new (0u) DIExpression(Context, Storage, Elements
), Storage, Context.pImpl->DIExpressions)
;
813}
814
815unsigned DIExpression::ExprOperand::getSize() const {
816 switch (getOp()) {
817 case dwarf::DW_OP_LLVM_fragment:
818 return 3;
819 case dwarf::DW_OP_constu:
820 case dwarf::DW_OP_plus_uconst:
821 return 2;
822 default:
823 return 1;
824 }
825}
826
827bool DIExpression::isValid() const {
828 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
829 // Check that there's space for the operand.
830 if (I->get() + I->getSize() > E->get())
831 return false;
832
833 // Check that the operand is valid.
834 switch (I->getOp()) {
835 default:
836 return false;
837 case dwarf::DW_OP_LLVM_fragment:
838 // A fragment operator must appear at the end.
839 return I->get() + I->getSize() == E->get();
840 case dwarf::DW_OP_stack_value: {
841 // Must be the last one or followed by a DW_OP_LLVM_fragment.
842 if (I->get() + I->getSize() == E->get())
843 break;
844 auto J = I;
845 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
846 return false;
847 break;
848 }
849 case dwarf::DW_OP_swap: {
850 // Must be more than one implicit element on the stack.
851
852 // FIXME: A better way to implement this would be to add a local variable
853 // that keeps track of the stack depth and introduce something like a
854 // DW_LLVM_OP_implicit_location as a placeholder for the location this
855 // DIExpression is attached to, or else pass the number of implicit stack
856 // elements into isValid.
857 if (getNumElements() == 1)
858 return false;
859 break;
860 }
861 case dwarf::DW_OP_constu:
862 case dwarf::DW_OP_plus_uconst:
863 case dwarf::DW_OP_plus:
864 case dwarf::DW_OP_minus:
865 case dwarf::DW_OP_mul:
866 case dwarf::DW_OP_div:
867 case dwarf::DW_OP_mod:
868 case dwarf::DW_OP_or:
869 case dwarf::DW_OP_and:
870 case dwarf::DW_OP_xor:
871 case dwarf::DW_OP_shl:
872 case dwarf::DW_OP_shr:
873 case dwarf::DW_OP_shra:
874 case dwarf::DW_OP_deref:
875 case dwarf::DW_OP_xderef:
876 case dwarf::DW_OP_lit0:
877 case dwarf::DW_OP_not:
878 case dwarf::DW_OP_dup:
879 break;
880 }
881 }
882 return true;
883}
884
885Optional<DIExpression::FragmentInfo>
886DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
887 for (auto I = Start; I != End; ++I)
888 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
889 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
890 return Info;
891 }
892 return None;
893}
894
895void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
896 int64_t Offset) {
897 if (Offset > 0) {
898 Ops.push_back(dwarf::DW_OP_plus_uconst);
899 Ops.push_back(Offset);
900 } else if (Offset < 0) {
901 Ops.push_back(dwarf::DW_OP_constu);
902 Ops.push_back(-Offset);
903 Ops.push_back(dwarf::DW_OP_minus);
904 }
905}
906
907bool DIExpression::extractIfOffset(int64_t &Offset) const {
908 if (getNumElements() == 0) {
909 Offset = 0;
910 return true;
911 }
912
913 if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
914 Offset = Elements[1];
915 return true;
916 }
917
918 if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
919 if (Elements[2] == dwarf::DW_OP_plus) {
920 Offset = Elements[1];
921 return true;
922 }
923 if (Elements[2] == dwarf::DW_OP_minus) {
924 Offset = -Elements[1];
925 return true;
926 }
927 }
928
929 return false;
930}
931
932DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore,
933 int64_t Offset, bool DerefAfter,
934 bool StackValue) {
935 SmallVector<uint64_t, 8> Ops;
936 if (DerefBefore)
937 Ops.push_back(dwarf::DW_OP_deref);
938
939 appendOffset(Ops, Offset);
940 if (DerefAfter)
941 Ops.push_back(dwarf::DW_OP_deref);
942
943 return prependOpcodes(Expr, Ops, StackValue);
944}
945
946DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
947 SmallVectorImpl<uint64_t> &Ops,
948 bool StackValue) {
949 assert(Expr && "Can't prepend ops to this expression")((Expr && "Can't prepend ops to this expression") ? static_cast
<void> (0) : __assert_fail ("Expr && \"Can't prepend ops to this expression\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 949, __PRETTY_FUNCTION__))
;
950
951 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
952 if (Ops.empty())
953 StackValue = false;
954 for (auto Op : Expr->expr_ops()) {
955 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
956 if (StackValue) {
957 if (Op.getOp() == dwarf::DW_OP_stack_value)
958 StackValue = false;
959 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
960 Ops.push_back(dwarf::DW_OP_stack_value);
961 StackValue = false;
962 }
963 }
964 Op.appendToVector(Ops);
965 }
966 if (StackValue)
967 Ops.push_back(dwarf::DW_OP_stack_value);
968 return DIExpression::get(Expr->getContext(), Ops);
969}
970
971DIExpression *DIExpression::append(const DIExpression *Expr,
972 ArrayRef<uint64_t> Ops) {
973 assert(Expr && !Ops.empty() && "Can't append ops to this expression")((Expr && !Ops.empty() && "Can't append ops to this expression"
) ? static_cast<void> (0) : __assert_fail ("Expr && !Ops.empty() && \"Can't append ops to this expression\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 973, __PRETTY_FUNCTION__))
;
974
975 // Copy Expr's current op list.
976 SmallVector<uint64_t, 16> NewOps;
977 for (auto Op : Expr->expr_ops()) {
978 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
979 if (Op.getOp() == dwarf::DW_OP_stack_value ||
980 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
981 NewOps.append(Ops.begin(), Ops.end());
982
983 // Ensure that the new opcodes are only appended once.
984 Ops = None;
985 }
986 Op.appendToVector(NewOps);
987 }
988
989 NewOps.append(Ops.begin(), Ops.end());
990 return DIExpression::get(Expr->getContext(), NewOps);
991}
992
993DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
994 ArrayRef<uint64_t> Ops) {
995 assert(Expr && !Ops.empty() && "Can't append ops to this expression")((Expr && !Ops.empty() && "Can't append ops to this expression"
) ? static_cast<void> (0) : __assert_fail ("Expr && !Ops.empty() && \"Can't append ops to this expression\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 995, __PRETTY_FUNCTION__))
;
996 assert(none_of(Ops,((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
997 [](uint64_t Op) {((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
998 return Op == dwarf::DW_OP_stack_value ||((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
999 Op == dwarf::DW_OP_LLVM_fragment;((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
1000 }) &&((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
1001 "Can't append this op")((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
;
1002
1003 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
1004 // has no DW_OP_stack_value.
1005 //
1006 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
1007 Optional<FragmentInfo> FI = Expr->getFragmentInfo();
1008 unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0;
1009 ArrayRef<uint64_t> ExprOpsBeforeFragment =
1010 Expr->getElements().drop_back(DropUntilStackValue);
1011 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
1012 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
1013 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
1014
1015 // Append a DW_OP_deref after Expr's current op list if needed, then append
1016 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
1017 SmallVector<uint64_t, 16> NewOps;
1018 if (NeedsDeref)
1019 NewOps.push_back(dwarf::DW_OP_deref);
1020 NewOps.append(Ops.begin(), Ops.end());
1021 if (NeedsStackValue)
1022 NewOps.push_back(dwarf::DW_OP_stack_value);
1023 return DIExpression::append(Expr, NewOps);
1024}
1025
1026Optional<DIExpression *> DIExpression::createFragmentExpression(
1027 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
1028 SmallVector<uint64_t, 8> Ops;
1029 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
1030 if (Expr) {
1
Assuming 'Expr' is null
2
Taking false branch
1031 for (auto Op : Expr->expr_ops()) {
1032 switch (Op.getOp()) {
1033 default: break;
1034 case dwarf::DW_OP_plus:
1035 case dwarf::DW_OP_minus:
1036 // We can't safely split arithmetic into multiple fragments because we
1037 // can't express carry-over between fragments.
1038 //
1039 // FIXME: We *could* preserve the lowest fragment of a constant offset
1040 // operation if the offset fits into SizeInBits.
1041 return None;
1042 case dwarf::DW_OP_LLVM_fragment: {
1043 // Make the new offset point into the existing fragment.
1044 uint64_t FragmentOffsetInBits = Op.getArg(0);
1045 uint64_t FragmentSizeInBits = Op.getArg(1);
1046 (void)FragmentSizeInBits;
1047 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&(((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
"new fragment outside of original fragment") ? static_cast<
void> (0) : __assert_fail ("(OffsetInBits + SizeInBits <= FragmentSizeInBits) && \"new fragment outside of original fragment\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1048, __PRETTY_FUNCTION__))
1048 "new fragment outside of original fragment")(((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
"new fragment outside of original fragment") ? static_cast<
void> (0) : __assert_fail ("(OffsetInBits + SizeInBits <= FragmentSizeInBits) && \"new fragment outside of original fragment\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1048, __PRETTY_FUNCTION__))
;
1049 OffsetInBits += FragmentOffsetInBits;
1050 continue;
1051 }
1052 }
1053 Op.appendToVector(Ops);
1054 }
1055 }
1056 Ops.push_back(dwarf::DW_OP_LLVM_fragment);
1057 Ops.push_back(OffsetInBits);
1058 Ops.push_back(SizeInBits);
1059 return DIExpression::get(Expr->getContext(), Ops);
3
Called C++ object pointer is null
1060}
1061
1062bool DIExpression::isConstant() const {
1063 // Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
1064 if (getNumElements() != 3 && getNumElements() != 6)
1065 return false;
1066 if (getElement(0) != dwarf::DW_OP_constu ||
1067 getElement(2) != dwarf::DW_OP_stack_value)
1068 return false;
1069 if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment)
1070 return false;
1071 return true;
1072}
1073
1074DIGlobalVariableExpression *
1075DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
1076 Metadata *Expression, StorageType Storage,
1077 bool ShouldCreate) {
1078 DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariableExpressions, DIGlobalVariableExpressionInfo
::KeyTy(Variable, Expression))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1078, __PRETTY_FUNCTION__)); } } while (false)
;
1079 Metadata *Ops[] = {Variable, Expression};
1080 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops)return storeImpl(new (array_lengthof(Ops)) DIGlobalVariableExpression
(Context, Storage, Ops), Storage, Context.pImpl->DIGlobalVariableExpressions
)
;
1081}
1082
1083DIObjCProperty *DIObjCProperty::getImpl(
1084 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1085 MDString *GetterName, MDString *SetterName, unsigned Attributes,
1086 Metadata *Type, StorageType Storage, bool ShouldCreate) {
1087 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1087, __PRETTY_FUNCTION__))
;
1088 assert(isCanonical(GetterName) && "Expected canonical MDString")((isCanonical(GetterName) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(GetterName) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1088, __PRETTY_FUNCTION__))
;
1089 assert(isCanonical(SetterName) && "Expected canonical MDString")((isCanonical(SetterName) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(SetterName) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1089, __PRETTY_FUNCTION__))
;
1090 DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIObjCPropertys, DIObjCPropertyInfo::KeyTy(Name, File
, Line, GetterName, SetterName, Attributes, Type))) return N;
if (!ShouldCreate) return nullptr; } else { ((ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? static_cast
<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1091, __PRETTY_FUNCTION__)); } } while (false)
1091 SetterName, Attributes, Type))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIObjCPropertys, DIObjCPropertyInfo::KeyTy(Name, File
, Line, GetterName, SetterName, Attributes, Type))) return N;
if (!ShouldCreate) return nullptr; } else { ((ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? static_cast
<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1091, __PRETTY_FUNCTION__)); } } while (false)
;
1092 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
1093 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops)return storeImpl(new (array_lengthof(Ops)) DIObjCProperty(Context
, Storage, Line, Attributes, Ops), Storage, Context.pImpl->
DIObjCPropertys)
;
1094}
1095
1096DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
1097 Metadata *Scope, Metadata *Entity,
1098 Metadata *File, unsigned Line,
1099 MDString *Name, StorageType Storage,
1100 bool ShouldCreate) {
1101 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1101, __PRETTY_FUNCTION__))
;
1102 DEFINE_GETIMPL_LOOKUP(DIImportedEntity,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIImportedEntitys, DIImportedEntityInfo::KeyTy(Tag
, Scope, Entity, File, Line, Name))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1103, __PRETTY_FUNCTION__)); } } while (false)
1103 (Tag, Scope, Entity, File, Line, Name))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIImportedEntitys, DIImportedEntityInfo::KeyTy(Tag
, Scope, Entity, File, Line, Name))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1103, __PRETTY_FUNCTION__)); } } while (false)
;
1104 Metadata *Ops[] = {Scope, Entity, Name, File};
1105 DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops)return storeImpl(new (array_lengthof(Ops)) DIImportedEntity(Context
, Storage, Tag, Line, Ops), Storage, Context.pImpl->DIImportedEntitys
)
;
1106}
1107
1108DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
1109 unsigned Line, MDString *Name, MDString *Value,
1110 StorageType Storage, bool ShouldCreate) {
1111 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1111, __PRETTY_FUNCTION__))
;
1112 DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIMacros, DIMacroInfo::KeyTy(MIType, Line, Name, Value
))) return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1112, __PRETTY_FUNCTION__)); } } while (false)
;
1113 Metadata *Ops[] = { Name, Value };
1114 DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops)return storeImpl(new (array_lengthof(Ops)) DIMacro(Context, Storage
, MIType, Line, Ops), Storage, Context.pImpl->DIMacros)
;
1115}
1116
1117DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
1118 unsigned Line, Metadata *File,
1119 Metadata *Elements, StorageType Storage,
1120 bool ShouldCreate) {
1121 DEFINE_GETIMPL_LOOKUP(DIMacroFile,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIMacroFiles, DIMacroFileInfo::KeyTy(MIType, Line,
File, Elements))) return N; if (!ShouldCreate) return nullptr
; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1122, __PRETTY_FUNCTION__)); } } while (false)
1122 (MIType, Line, File, Elements))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIMacroFiles, DIMacroFileInfo::KeyTy(MIType, Line,
File, Elements))) return N; if (!ShouldCreate) return nullptr
; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1122, __PRETTY_FUNCTION__)); } } while (false)
;
1123 Metadata *Ops[] = { File, Elements };
1124 DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops)return storeImpl(new (array_lengthof(Ops)) DIMacroFile(Context
, Storage, MIType, Line, Ops), Storage, Context.pImpl->DIMacroFiles
)
;
1125}