Bug Summary

File:build/source/llvm/lib/IR/DebugInfoMetadata.cpp
Warning:line 1916, column 3
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name DebugInfoMetadata.cpp -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 -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-17/lib/clang/17 -D _DEBUG -D _GLIBCXX_ASSERTIONS -D _GNU_SOURCE -D _LIBCPP_ENABLE_ASSERTIONS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I lib/IR -I /build/source/llvm/lib/IR -I include -I /build/source/llvm/include -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-17/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/source/= -fcoverage-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/source/= -source-date-epoch 1683717183 -O2 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2023-05-10-133810-16478-1 -x c++ /build/source/llvm/lib/IR/DebugInfoMetadata.cpp
1//===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the debug info Metadata classes.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/DebugInfoMetadata.h"
14#include "LLVMContextImpl.h"
15#include "MetadataImpl.h"
16#include "llvm/ADT/SmallPtrSet.h"
17#include "llvm/ADT/SmallSet.h"
18#include "llvm/ADT/StringSwitch.h"
19#include "llvm/BinaryFormat/Dwarf.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/IntrinsicInst.h"
22#include "llvm/IR/Type.h"
23#include "llvm/IR/Value.h"
24
25#include <numeric>
26#include <optional>
27
28using namespace llvm;
29
30namespace llvm {
31// Use FS-AFDO discriminator.
32cl::opt<bool> EnableFSDiscriminator(
33 "enable-fs-discriminator", cl::Hidden,
34 cl::desc("Enable adding flow sensitive discriminators"));
35} // namespace llvm
36
37const DIExpression::FragmentInfo DebugVariable::DefaultFragment = {
38 std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::min()};
39
40DebugVariable::DebugVariable(const DbgVariableIntrinsic *DII)
41 : Variable(DII->getVariable()),
42 Fragment(DII->getExpression()->getFragmentInfo()),
43 InlinedAt(DII->getDebugLoc().getInlinedAt()) {}
44
45DebugVariableAggregate::DebugVariableAggregate(const DbgVariableIntrinsic *DVI)
46 : DebugVariable(DVI->getVariable(), std::nullopt,
47 DVI->getDebugLoc()->getInlinedAt()) {}
48
49DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
50 unsigned Column, ArrayRef<Metadata *> MDs,
51 bool ImplicitCode)
52 : MDNode(C, DILocationKind, Storage, MDs) {
53 assert((MDs.size() == 1 || MDs.size() == 2) &&(static_cast <bool> ((MDs.size() == 1 || MDs.size() == 2
) && "Expected a scope and optional inlined-at") ? void
(0) : __assert_fail ("(MDs.size() == 1 || MDs.size() == 2) && \"Expected a scope and optional inlined-at\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 54, __extension__ __PRETTY_FUNCTION__
))
54 "Expected a scope and optional inlined-at")(static_cast <bool> ((MDs.size() == 1 || MDs.size() == 2
) && "Expected a scope and optional inlined-at") ? void
(0) : __assert_fail ("(MDs.size() == 1 || MDs.size() == 2) && \"Expected a scope and optional inlined-at\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 54, __extension__ __PRETTY_FUNCTION__
))
;
55
56 // Set line and column.
57 assert(Column < (1u << 16) && "Expected 16-bit column")(static_cast <bool> (Column < (1u << 16) &&
"Expected 16-bit column") ? void (0) : __assert_fail ("Column < (1u << 16) && \"Expected 16-bit column\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 57, __extension__ __PRETTY_FUNCTION__
))
;
58
59 SubclassData32 = Line;
60 SubclassData16 = Column;
61
62 setImplicitCode(ImplicitCode);
63}
64
65static void adjustColumn(unsigned &Column) {
66 // Set to unknown on overflow. We only have 16 bits to play with here.
67 if (Column >= (1u << 16))
68 Column = 0;
69}
70
71DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
72 unsigned Column, Metadata *Scope,
73 Metadata *InlinedAt, bool ImplicitCode,
74 StorageType Storage, bool ShouldCreate) {
75 // Fixup column.
76 adjustColumn(Column);
77
78 if (Storage == Uniqued) {
79 if (auto *N = getUniqued(Context.pImpl->DILocations,
80 DILocationInfo::KeyTy(Line, Column, Scope,
81 InlinedAt, ImplicitCode)))
82 return N;
83 if (!ShouldCreate)
84 return nullptr;
85 } else {
86 assert(ShouldCreate && "Expected non-uniqued nodes to always be created")(static_cast <bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 86, __extension__ __PRETTY_FUNCTION__
))
;
87 }
88
89 SmallVector<Metadata *, 2> Ops;
90 Ops.push_back(Scope);
91 if (InlinedAt)
92 Ops.push_back(InlinedAt);
93 return storeImpl(new (Ops.size(), Storage) DILocation(
94 Context, Storage, Line, Column, Ops, ImplicitCode),
95 Storage, Context.pImpl->DILocations);
96}
97
98const DILocation *
99DILocation::getMergedLocations(ArrayRef<const DILocation *> Locs) {
100 if (Locs.empty())
101 return nullptr;
102 if (Locs.size() == 1)
103 return Locs[0];
104 auto *Merged = Locs[0];
105 for (const DILocation *L : llvm::drop_begin(Locs)) {
106 Merged = getMergedLocation(Merged, L);
107 if (Merged == nullptr)
108 break;
109 }
110 return Merged;
111}
112
113const DILocation *DILocation::getMergedLocation(const DILocation *LocA,
114 const DILocation *LocB) {
115 if (!LocA || !LocB)
116 return nullptr;
117
118 if (LocA == LocB)
119 return LocA;
120
121 LLVMContext &C = LocA->getContext();
122
123 using LocVec = SmallVector<const DILocation *>;
124 LocVec ALocs;
125 LocVec BLocs;
126 SmallDenseMap<std::pair<const DISubprogram *, const DILocation *>, unsigned,
127 4>
128 ALookup;
129
130 // Walk through LocA and its inlined-at locations, populate them in ALocs and
131 // save the index for the subprogram and inlined-at pair, which we use to find
132 // a matching starting location in LocB's chain.
133 for (auto [L, I] = std::make_pair(LocA, 0U); L; L = L->getInlinedAt(), I++) {
134 ALocs.push_back(L);
135 auto Res = ALookup.try_emplace(
136 {L->getScope()->getSubprogram(), L->getInlinedAt()}, I);
137 assert(Res.second && "Multiple <SP, InlinedAt> pairs in a location chain?")(static_cast <bool> (Res.second && "Multiple <SP, InlinedAt> pairs in a location chain?"
) ? void (0) : __assert_fail ("Res.second && \"Multiple <SP, InlinedAt> pairs in a location chain?\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 137, __extension__ __PRETTY_FUNCTION__
))
;
138 (void)Res;
139 }
140
141 LocVec::reverse_iterator ARIt = ALocs.rend();
142 LocVec::reverse_iterator BRIt = BLocs.rend();
143
144 // Populate BLocs and look for a matching starting location, the first
145 // location with the same subprogram and inlined-at location as in LocA's
146 // chain. Since the two locations have the same inlined-at location we do
147 // not need to look at those parts of the chains.
148 for (auto [L, I] = std::make_pair(LocB, 0U); L; L = L->getInlinedAt(), I++) {
149 BLocs.push_back(L);
150
151 if (ARIt != ALocs.rend())
152 // We have already found a matching starting location.
153 continue;
154
155 auto IT = ALookup.find({L->getScope()->getSubprogram(), L->getInlinedAt()});
156 if (IT == ALookup.end())
157 continue;
158
159 // The + 1 is to account for the &*rev_it = &(it - 1) relationship.
160 ARIt = LocVec::reverse_iterator(ALocs.begin() + IT->second + 1);
161 BRIt = LocVec::reverse_iterator(BLocs.begin() + I + 1);
162
163 // If we have found a matching starting location we do not need to add more
164 // locations to BLocs, since we will only look at location pairs preceding
165 // the matching starting location, and adding more elements to BLocs could
166 // invalidate the iterator that we initialized here.
167 break;
168 }
169
170 // Merge the two locations if possible, using the supplied
171 // inlined-at location for the created location.
172 auto MergeLocPair = [&C](const DILocation *L1, const DILocation *L2,
173 DILocation *InlinedAt) -> DILocation * {
174 if (L1 == L2)
175 return DILocation::get(C, L1->getLine(), L1->getColumn(), L1->getScope(),
176 InlinedAt);
177
178 // If the locations originate from different subprograms we can't produce
179 // a common location.
180 if (L1->getScope()->getSubprogram() != L2->getScope()->getSubprogram())
181 return nullptr;
182
183 // Return the nearest common scope inside a subprogram.
184 auto GetNearestCommonScope = [](DIScope *S1, DIScope *S2) -> DIScope * {
185 SmallPtrSet<DIScope *, 8> Scopes;
186 for (; S1; S1 = S1->getScope()) {
187 Scopes.insert(S1);
188 if (isa<DISubprogram>(S1))
189 break;
190 }
191
192 for (; S2; S2 = S2->getScope()) {
193 if (Scopes.count(S2))
194 return S2;
195 if (isa<DISubprogram>(S2))
196 break;
197 }
198
199 return nullptr;
200 };
201
202 auto Scope = GetNearestCommonScope(L1->getScope(), L2->getScope());
203 assert(Scope && "No common scope in the same subprogram?")(static_cast <bool> (Scope && "No common scope in the same subprogram?"
) ? void (0) : __assert_fail ("Scope && \"No common scope in the same subprogram?\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 203, __extension__ __PRETTY_FUNCTION__
))
;
204
205 bool SameLine = L1->getLine() == L2->getLine();
206 bool SameCol = L1->getColumn() == L2->getColumn();
207 unsigned Line = SameLine ? L1->getLine() : 0;
208 unsigned Col = SameLine && SameCol ? L1->getColumn() : 0;
209
210 return DILocation::get(C, Line, Col, Scope, InlinedAt);
211 };
212
213 DILocation *Result = ARIt != ALocs.rend() ? (*ARIt)->getInlinedAt() : nullptr;
214
215 // If we have found a common starting location, walk up the inlined-at chains
216 // and try to produce common locations.
217 for (; ARIt != ALocs.rend() && BRIt != BLocs.rend(); ++ARIt, ++BRIt) {
218 DILocation *Tmp = MergeLocPair(*ARIt, *BRIt, Result);
219
220 if (!Tmp)
221 // We have walked up to a point in the chains where the two locations
222 // are irreconsilable. At this point Result contains the nearest common
223 // location in the inlined-at chains of LocA and LocB, so we break here.
224 break;
225
226 Result = Tmp;
227 }
228
229 if (Result)
230 return Result;
231
232 // We ended up with LocA and LocB as irreconsilable locations. Produce a
233 // location at 0:0 with one of the locations' scope. The function has
234 // historically picked A's scope, and a nullptr inlined-at location, so that
235 // behavior is mimicked here but I am not sure if this is always the correct
236 // way to handle this.
237 return DILocation::get(C, 0, 0, LocA->getScope(), nullptr);
238}
239
240std::optional<unsigned>
241DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
242 std::array<unsigned, 3> Components = {BD, DF, CI};
243 uint64_t RemainingWork = 0U;
244 // We use RemainingWork to figure out if we have no remaining components to
245 // encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
246 // encode anything for the latter 2.
247 // Since any of the input components is at most 32 bits, their sum will be
248 // less than 34 bits, and thus RemainingWork won't overflow.
249 RemainingWork =
250 std::accumulate(Components.begin(), Components.end(), RemainingWork);
251
252 int I = 0;
253 unsigned Ret = 0;
254 unsigned NextBitInsertionIndex = 0;
255 while (RemainingWork > 0) {
256 unsigned C = Components[I++];
257 RemainingWork -= C;
258 unsigned EC = encodeComponent(C);
259 Ret |= (EC << NextBitInsertionIndex);
260 NextBitInsertionIndex += encodingBits(C);
261 }
262
263 // Encoding may be unsuccessful because of overflow. We determine success by
264 // checking equivalence of components before & after encoding. Alternatively,
265 // we could determine Success during encoding, but the current alternative is
266 // simpler.
267 unsigned TBD, TDF, TCI = 0;
268 decodeDiscriminator(Ret, TBD, TDF, TCI);
269 if (TBD == BD && TDF == DF && TCI == CI)
270 return Ret;
271 return std::nullopt;
272}
273
274void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
275 unsigned &CI) {
276 BD = getUnsignedFromPrefixEncoding(D);
277 DF = getUnsignedFromPrefixEncoding(getNextComponentInDiscriminator(D));
278 CI = getUnsignedFromPrefixEncoding(
279 getNextComponentInDiscriminator(getNextComponentInDiscriminator(D)));
280}
281dwarf::Tag DINode::getTag() const { return (dwarf::Tag)SubclassData16; }
282
283DINode::DIFlags DINode::getFlag(StringRef Flag) {
284 return StringSwitch<DIFlags>(Flag)
285#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
286#include "llvm/IR/DebugInfoFlags.def"
287 .Default(DINode::FlagZero);
288}
289
290StringRef DINode::getFlagString(DIFlags Flag) {
291 switch (Flag) {
292#define HANDLE_DI_FLAG(ID, NAME) \
293 case Flag##NAME: \
294 return "DIFlag" #NAME;
295#include "llvm/IR/DebugInfoFlags.def"
296 }
297 return "";
298}
299
300DINode::DIFlags DINode::splitFlags(DIFlags Flags,
301 SmallVectorImpl<DIFlags> &SplitFlags) {
302 // Flags that are packed together need to be specially handled, so
303 // that, for example, we emit "DIFlagPublic" and not
304 // "DIFlagPrivate | DIFlagProtected".
305 if (DIFlags A = Flags & FlagAccessibility) {
306 if (A == FlagPrivate)
307 SplitFlags.push_back(FlagPrivate);
308 else if (A == FlagProtected)
309 SplitFlags.push_back(FlagProtected);
310 else
311 SplitFlags.push_back(FlagPublic);
312 Flags &= ~A;
313 }
314 if (DIFlags R = Flags & FlagPtrToMemberRep) {
315 if (R == FlagSingleInheritance)
316 SplitFlags.push_back(FlagSingleInheritance);
317 else if (R == FlagMultipleInheritance)
318 SplitFlags.push_back(FlagMultipleInheritance);
319 else
320 SplitFlags.push_back(FlagVirtualInheritance);
321 Flags &= ~R;
322 }
323 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
324 Flags &= ~FlagIndirectVirtualBase;
325 SplitFlags.push_back(FlagIndirectVirtualBase);
326 }
327
328#define HANDLE_DI_FLAG(ID, NAME) \
329 if (DIFlags Bit = Flags & Flag##NAME) { \
330 SplitFlags.push_back(Bit); \
331 Flags &= ~Bit; \
332 }
333#include "llvm/IR/DebugInfoFlags.def"
334 return Flags;
335}
336
337DIScope *DIScope::getScope() const {
338 if (auto *T = dyn_cast<DIType>(this))
339 return T->getScope();
340
341 if (auto *SP = dyn_cast<DISubprogram>(this))
342 return SP->getScope();
343
344 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
345 return LB->getScope();
346
347 if (auto *NS = dyn_cast<DINamespace>(this))
348 return NS->getScope();
349
350 if (auto *CB = dyn_cast<DICommonBlock>(this))
351 return CB->getScope();
352
353 if (auto *M = dyn_cast<DIModule>(this))
354 return M->getScope();
355
356 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&(static_cast <bool> ((isa<DIFile>(this) || isa<
DICompileUnit>(this)) && "Unhandled type of scope."
) ? void (0) : __assert_fail ("(isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 357, __extension__ __PRETTY_FUNCTION__
))
357 "Unhandled type of scope.")(static_cast <bool> ((isa<DIFile>(this) || isa<
DICompileUnit>(this)) && "Unhandled type of scope."
) ? void (0) : __assert_fail ("(isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 357, __extension__ __PRETTY_FUNCTION__
))
;
358 return nullptr;
359}
360
361StringRef DIScope::getName() const {
362 if (auto *T = dyn_cast<DIType>(this))
363 return T->getName();
364 if (auto *SP = dyn_cast<DISubprogram>(this))
365 return SP->getName();
366 if (auto *NS = dyn_cast<DINamespace>(this))
367 return NS->getName();
368 if (auto *CB = dyn_cast<DICommonBlock>(this))
369 return CB->getName();
370 if (auto *M = dyn_cast<DIModule>(this))
371 return M->getName();
372 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||(static_cast <bool> ((isa<DILexicalBlockBase>(this
) || isa<DIFile>(this) || isa<DICompileUnit>(this
)) && "Unhandled type of scope.") ? void (0) : __assert_fail
("(isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 374, __extension__ __PRETTY_FUNCTION__
))
373 isa<DICompileUnit>(this)) &&(static_cast <bool> ((isa<DILexicalBlockBase>(this
) || isa<DIFile>(this) || isa<DICompileUnit>(this
)) && "Unhandled type of scope.") ? void (0) : __assert_fail
("(isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 374, __extension__ __PRETTY_FUNCTION__
))
374 "Unhandled type of scope.")(static_cast <bool> ((isa<DILexicalBlockBase>(this
) || isa<DIFile>(this) || isa<DICompileUnit>(this
)) && "Unhandled type of scope.") ? void (0) : __assert_fail
("(isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 374, __extension__ __PRETTY_FUNCTION__
))
;
375 return "";
376}
377
378#ifndef NDEBUG
379static bool isCanonical(const MDString *S) {
380 return !S || !S->getString().empty();
381}
382#endif
383
384dwarf::Tag GenericDINode::getTag() const { return (dwarf::Tag)SubclassData16; }
385GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
386 MDString *Header,
387 ArrayRef<Metadata *> DwarfOps,
388 StorageType Storage, bool ShouldCreate) {
389 unsigned Hash = 0;
390 if (Storage == Uniqued) {
391 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
392 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
393 return N;
394 if (!ShouldCreate)
395 return nullptr;
396 Hash = Key.getHash();
397 } else {
398 assert(ShouldCreate && "Expected non-uniqued nodes to always be created")(static_cast <bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 398, __extension__ __PRETTY_FUNCTION__
))
;
399 }
400
401 // Use a nullptr for empty headers.
402 assert(isCanonical(Header) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Header) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Header) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 402, __extension__ __PRETTY_FUNCTION__
))
;
403 Metadata *PreOps[] = {Header};
404 return storeImpl(new (DwarfOps.size() + 1, Storage) GenericDINode(
405 Context, Storage, Hash, Tag, PreOps, DwarfOps),
406 Storage, Context.pImpl->GenericDINodes);
407}
408
409void GenericDINode::recalculateHash() {
410 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
411}
412
413#define UNWRAP_ARGS_IMPL(...)... __VA_ARGS__
414#define UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS UNWRAP_ARGS_IMPL ARGS
415#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 { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 415, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
\
416 do { \
417 if (Storage == Uniqued) { \
418 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
419 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS))) \
420 return N; \
421 if (!ShouldCreate) \
422 return nullptr; \
423 } else { \
424 assert(ShouldCreate && \(static_cast <bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 425, __extension__ __PRETTY_FUNCTION__
))
425 "Expected non-uniqued nodes to always be created")(static_cast <bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 425, __extension__ __PRETTY_FUNCTION__
))
; \
426 } \
427 } while (false)
428#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS)return storeImpl(new (std::size(OPS), Storage) CLASS(Context,
Storage, UNWRAP_ARGS_IMPL ARGS, OPS), Storage, Context.pImpl
->CLASSs)
\
429 return storeImpl(new (std::size(OPS), Storage) \
430 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS, OPS), \
431 Storage, Context.pImpl->CLASS##s)
432#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS)return storeImpl(new (0u, Storage) CLASS(Context, Storage, UNWRAP_ARGS_IMPL
ARGS), Storage, Context.pImpl->CLASSs)
\
433 return storeImpl(new (0u, Storage) \
434 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS), \
435 Storage, Context.pImpl->CLASS##s)
436#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS)return storeImpl(new (std::size(OPS), Storage) CLASS(Context,
Storage, OPS), Storage, Context.pImpl->CLASSs)
\
437 return storeImpl(new (std::size(OPS), Storage) CLASS(Context, Storage, OPS), \
438 Storage, Context.pImpl->CLASS##s)
439#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS)return storeImpl(new (NUM_OPS, Storage) CLASS(Context, Storage
, UNWRAP_ARGS_IMPL ARGS, OPS), Storage, Context.pImpl->CLASSs
)
\
440 return storeImpl(new (NUM_OPS, Storage) \
441 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS, OPS), \
442 Storage, Context.pImpl->CLASS##s)
443
444DISubrange::DISubrange(LLVMContext &C, StorageType Storage,
445 ArrayRef<Metadata *> Ops)
446 : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, Ops) {}
447DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
448 StorageType Storage, bool ShouldCreate) {
449 auto *CountNode = ConstantAsMetadata::get(
450 ConstantInt::getSigned(Type::getInt64Ty(Context), Count));
451 auto *LB = ConstantAsMetadata::get(
452 ConstantInt::getSigned(Type::getInt64Ty(Context), Lo));
453 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
454 ShouldCreate);
455}
456
457DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
458 int64_t Lo, StorageType Storage,
459 bool ShouldCreate) {
460 auto *LB = ConstantAsMetadata::get(
461 ConstantInt::getSigned(Type::getInt64Ty(Context), Lo));
462 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
463 ShouldCreate);
464}
465
466DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
467 Metadata *LB, Metadata *UB, Metadata *Stride,
468 StorageType Storage, bool ShouldCreate) {
469 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, LB, UB, Stride))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubranges, DISubrangeInfo::KeyTy(CountNode, LB, UB
, Stride))) return N; if (!ShouldCreate) return nullptr; } else
{ (static_cast <bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 469, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
470 Metadata *Ops[] = {CountNode, LB, UB, Stride};
471 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DISubrange, Ops)return storeImpl(new (std::size(Ops), Storage) DISubrange(Context
, Storage, Ops), Storage, Context.pImpl->DISubranges)
;
472}
473
474DISubrange::BoundType DISubrange::getCount() const {
475 Metadata *CB = getRawCountNode();
476 if (!CB)
477 return BoundType();
478
479 assert((isa<ConstantAsMetadata>(CB) || isa<DIVariable>(CB) ||(static_cast <bool> ((isa<ConstantAsMetadata>(CB)
|| isa<DIVariable>(CB) || isa<DIExpression>(CB))
&& "Count must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(CB) || isa<DIVariable>(CB) || isa<DIExpression>(CB)) && \"Count must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 481, __extension__ __PRETTY_FUNCTION__
))
480 isa<DIExpression>(CB)) &&(static_cast <bool> ((isa<ConstantAsMetadata>(CB)
|| isa<DIVariable>(CB) || isa<DIExpression>(CB))
&& "Count must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(CB) || isa<DIVariable>(CB) || isa<DIExpression>(CB)) && \"Count must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 481, __extension__ __PRETTY_FUNCTION__
))
481 "Count must be signed constant or DIVariable or DIExpression")(static_cast <bool> ((isa<ConstantAsMetadata>(CB)
|| isa<DIVariable>(CB) || isa<DIExpression>(CB))
&& "Count must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(CB) || isa<DIVariable>(CB) || isa<DIExpression>(CB)) && \"Count must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 481, __extension__ __PRETTY_FUNCTION__
))
;
482
483 if (auto *MD = dyn_cast<ConstantAsMetadata>(CB))
484 return BoundType(cast<ConstantInt>(MD->getValue()));
485
486 if (auto *MD = dyn_cast<DIVariable>(CB))
487 return BoundType(MD);
488
489 if (auto *MD = dyn_cast<DIExpression>(CB))
490 return BoundType(MD);
491
492 return BoundType();
493}
494
495DISubrange::BoundType DISubrange::getLowerBound() const {
496 Metadata *LB = getRawLowerBound();
497 if (!LB)
498 return BoundType();
499
500 assert((isa<ConstantAsMetadata>(LB) || isa<DIVariable>(LB) ||(static_cast <bool> ((isa<ConstantAsMetadata>(LB)
|| isa<DIVariable>(LB) || isa<DIExpression>(LB))
&& "LowerBound must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(LB) || isa<DIVariable>(LB) || isa<DIExpression>(LB)) && \"LowerBound must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 502, __extension__ __PRETTY_FUNCTION__
))
501 isa<DIExpression>(LB)) &&(static_cast <bool> ((isa<ConstantAsMetadata>(LB)
|| isa<DIVariable>(LB) || isa<DIExpression>(LB))
&& "LowerBound must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(LB) || isa<DIVariable>(LB) || isa<DIExpression>(LB)) && \"LowerBound must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 502, __extension__ __PRETTY_FUNCTION__
))
502 "LowerBound must be signed constant or DIVariable or DIExpression")(static_cast <bool> ((isa<ConstantAsMetadata>(LB)
|| isa<DIVariable>(LB) || isa<DIExpression>(LB))
&& "LowerBound must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(LB) || isa<DIVariable>(LB) || isa<DIExpression>(LB)) && \"LowerBound must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 502, __extension__ __PRETTY_FUNCTION__
))
;
503
504 if (auto *MD = dyn_cast<ConstantAsMetadata>(LB))
505 return BoundType(cast<ConstantInt>(MD->getValue()));
506
507 if (auto *MD = dyn_cast<DIVariable>(LB))
508 return BoundType(MD);
509
510 if (auto *MD = dyn_cast<DIExpression>(LB))
511 return BoundType(MD);
512
513 return BoundType();
514}
515
516DISubrange::BoundType DISubrange::getUpperBound() const {
517 Metadata *UB = getRawUpperBound();
518 if (!UB)
519 return BoundType();
520
521 assert((isa<ConstantAsMetadata>(UB) || isa<DIVariable>(UB) ||(static_cast <bool> ((isa<ConstantAsMetadata>(UB)
|| isa<DIVariable>(UB) || isa<DIExpression>(UB))
&& "UpperBound must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(UB) || isa<DIVariable>(UB) || isa<DIExpression>(UB)) && \"UpperBound must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 523, __extension__ __PRETTY_FUNCTION__
))
522 isa<DIExpression>(UB)) &&(static_cast <bool> ((isa<ConstantAsMetadata>(UB)
|| isa<DIVariable>(UB) || isa<DIExpression>(UB))
&& "UpperBound must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(UB) || isa<DIVariable>(UB) || isa<DIExpression>(UB)) && \"UpperBound must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 523, __extension__ __PRETTY_FUNCTION__
))
523 "UpperBound must be signed constant or DIVariable or DIExpression")(static_cast <bool> ((isa<ConstantAsMetadata>(UB)
|| isa<DIVariable>(UB) || isa<DIExpression>(UB))
&& "UpperBound must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(UB) || isa<DIVariable>(UB) || isa<DIExpression>(UB)) && \"UpperBound must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 523, __extension__ __PRETTY_FUNCTION__
))
;
524
525 if (auto *MD = dyn_cast<ConstantAsMetadata>(UB))
526 return BoundType(cast<ConstantInt>(MD->getValue()));
527
528 if (auto *MD = dyn_cast<DIVariable>(UB))
529 return BoundType(MD);
530
531 if (auto *MD = dyn_cast<DIExpression>(UB))
532 return BoundType(MD);
533
534 return BoundType();
535}
536
537DISubrange::BoundType DISubrange::getStride() const {
538 Metadata *ST = getRawStride();
539 if (!ST)
540 return BoundType();
541
542 assert((isa<ConstantAsMetadata>(ST) || isa<DIVariable>(ST) ||(static_cast <bool> ((isa<ConstantAsMetadata>(ST)
|| isa<DIVariable>(ST) || isa<DIExpression>(ST))
&& "Stride must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(ST) || isa<DIVariable>(ST) || isa<DIExpression>(ST)) && \"Stride must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 544, __extension__ __PRETTY_FUNCTION__
))
543 isa<DIExpression>(ST)) &&(static_cast <bool> ((isa<ConstantAsMetadata>(ST)
|| isa<DIVariable>(ST) || isa<DIExpression>(ST))
&& "Stride must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(ST) || isa<DIVariable>(ST) || isa<DIExpression>(ST)) && \"Stride must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 544, __extension__ __PRETTY_FUNCTION__
))
544 "Stride must be signed constant or DIVariable or DIExpression")(static_cast <bool> ((isa<ConstantAsMetadata>(ST)
|| isa<DIVariable>(ST) || isa<DIExpression>(ST))
&& "Stride must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<ConstantAsMetadata>(ST) || isa<DIVariable>(ST) || isa<DIExpression>(ST)) && \"Stride must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 544, __extension__ __PRETTY_FUNCTION__
))
;
545
546 if (auto *MD = dyn_cast<ConstantAsMetadata>(ST))
547 return BoundType(cast<ConstantInt>(MD->getValue()));
548
549 if (auto *MD = dyn_cast<DIVariable>(ST))
550 return BoundType(MD);
551
552 if (auto *MD = dyn_cast<DIExpression>(ST))
553 return BoundType(MD);
554
555 return BoundType();
556}
557DIGenericSubrange::DIGenericSubrange(LLVMContext &C, StorageType Storage,
558 ArrayRef<Metadata *> Ops)
559 : DINode(C, DIGenericSubrangeKind, Storage, dwarf::DW_TAG_generic_subrange,
560 Ops) {}
561
562DIGenericSubrange *DIGenericSubrange::getImpl(LLVMContext &Context,
563 Metadata *CountNode, Metadata *LB,
564 Metadata *UB, Metadata *Stride,
565 StorageType Storage,
566 bool ShouldCreate) {
567 DEFINE_GETIMPL_LOOKUP(DIGenericSubrange, (CountNode, LB, UB, Stride))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGenericSubranges, DIGenericSubrangeInfo::KeyTy(CountNode
, LB, UB, Stride))) return N; if (!ShouldCreate) return nullptr
; } else { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 567, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
568 Metadata *Ops[] = {CountNode, LB, UB, Stride};
569 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGenericSubrange, Ops)return storeImpl(new (std::size(Ops), Storage) DIGenericSubrange
(Context, Storage, Ops), Storage, Context.pImpl->DIGenericSubranges
)
;
570}
571
572DIGenericSubrange::BoundType DIGenericSubrange::getCount() const {
573 Metadata *CB = getRawCountNode();
574 if (!CB)
575 return BoundType();
576
577 assert((isa<DIVariable>(CB) || isa<DIExpression>(CB)) &&(static_cast <bool> ((isa<DIVariable>(CB) || isa<
DIExpression>(CB)) && "Count must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<DIVariable>(CB) || isa<DIExpression>(CB)) && \"Count must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 578, __extension__ __PRETTY_FUNCTION__
))
578 "Count must be signed constant or DIVariable or DIExpression")(static_cast <bool> ((isa<DIVariable>(CB) || isa<
DIExpression>(CB)) && "Count must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<DIVariable>(CB) || isa<DIExpression>(CB)) && \"Count must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 578, __extension__ __PRETTY_FUNCTION__
))
;
579
580 if (auto *MD = dyn_cast<DIVariable>(CB))
581 return BoundType(MD);
582
583 if (auto *MD = dyn_cast<DIExpression>(CB))
584 return BoundType(MD);
585
586 return BoundType();
587}
588
589DIGenericSubrange::BoundType DIGenericSubrange::getLowerBound() const {
590 Metadata *LB = getRawLowerBound();
591 if (!LB)
592 return BoundType();
593
594 assert((isa<DIVariable>(LB) || isa<DIExpression>(LB)) &&(static_cast <bool> ((isa<DIVariable>(LB) || isa<
DIExpression>(LB)) && "LowerBound must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<DIVariable>(LB) || isa<DIExpression>(LB)) && \"LowerBound must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 595, __extension__ __PRETTY_FUNCTION__
))
595 "LowerBound must be signed constant or DIVariable or DIExpression")(static_cast <bool> ((isa<DIVariable>(LB) || isa<
DIExpression>(LB)) && "LowerBound must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<DIVariable>(LB) || isa<DIExpression>(LB)) && \"LowerBound must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 595, __extension__ __PRETTY_FUNCTION__
))
;
596
597 if (auto *MD = dyn_cast<DIVariable>(LB))
598 return BoundType(MD);
599
600 if (auto *MD = dyn_cast<DIExpression>(LB))
601 return BoundType(MD);
602
603 return BoundType();
604}
605
606DIGenericSubrange::BoundType DIGenericSubrange::getUpperBound() const {
607 Metadata *UB = getRawUpperBound();
608 if (!UB)
609 return BoundType();
610
611 assert((isa<DIVariable>(UB) || isa<DIExpression>(UB)) &&(static_cast <bool> ((isa<DIVariable>(UB) || isa<
DIExpression>(UB)) && "UpperBound must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<DIVariable>(UB) || isa<DIExpression>(UB)) && \"UpperBound must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 612, __extension__ __PRETTY_FUNCTION__
))
612 "UpperBound must be signed constant or DIVariable or DIExpression")(static_cast <bool> ((isa<DIVariable>(UB) || isa<
DIExpression>(UB)) && "UpperBound must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<DIVariable>(UB) || isa<DIExpression>(UB)) && \"UpperBound must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 612, __extension__ __PRETTY_FUNCTION__
))
;
613
614 if (auto *MD = dyn_cast<DIVariable>(UB))
615 return BoundType(MD);
616
617 if (auto *MD = dyn_cast<DIExpression>(UB))
618 return BoundType(MD);
619
620 return BoundType();
621}
622
623DIGenericSubrange::BoundType DIGenericSubrange::getStride() const {
624 Metadata *ST = getRawStride();
625 if (!ST)
626 return BoundType();
627
628 assert((isa<DIVariable>(ST) || isa<DIExpression>(ST)) &&(static_cast <bool> ((isa<DIVariable>(ST) || isa<
DIExpression>(ST)) && "Stride must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<DIVariable>(ST) || isa<DIExpression>(ST)) && \"Stride must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 629, __extension__ __PRETTY_FUNCTION__
))
629 "Stride must be signed constant or DIVariable or DIExpression")(static_cast <bool> ((isa<DIVariable>(ST) || isa<
DIExpression>(ST)) && "Stride must be signed constant or DIVariable or DIExpression"
) ? void (0) : __assert_fail ("(isa<DIVariable>(ST) || isa<DIExpression>(ST)) && \"Stride must be signed constant or DIVariable or DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 629, __extension__ __PRETTY_FUNCTION__
))
;
630
631 if (auto *MD = dyn_cast<DIVariable>(ST))
632 return BoundType(MD);
633
634 if (auto *MD = dyn_cast<DIExpression>(ST))
635 return BoundType(MD);
636
637 return BoundType();
638}
639
640DIEnumerator::DIEnumerator(LLVMContext &C, StorageType Storage,
641 const APInt &Value, bool IsUnsigned,
642 ArrayRef<Metadata *> Ops)
643 : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
644 Value(Value) {
645 SubclassData32 = IsUnsigned;
646}
647DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, const APInt &Value,
648 bool IsUnsigned, MDString *Name,
649 StorageType Storage, bool ShouldCreate) {
650 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 650, __extension__ __PRETTY_FUNCTION__
))
;
651 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
{ (static_cast <bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 651, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
652 Metadata *Ops[] = {Name};
653 DEFINE_GETIMPL_STORE(DIEnumerator, (Value, IsUnsigned), Ops)return storeImpl(new (std::size(Ops), Storage) DIEnumerator(Context
, Storage, Value, IsUnsigned, Ops), Storage, Context.pImpl->
DIEnumerators)
;
654}
655
656DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
657 MDString *Name, uint64_t SizeInBits,
658 uint32_t AlignInBits, unsigned Encoding,
659 DIFlags Flags, StorageType Storage,
660 bool ShouldCreate) {
661 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 661, __extension__ __PRETTY_FUNCTION__
))
;
662 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 { (static_cast <bool> (ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 663, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
663 (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 { (static_cast <bool> (ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 663, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
664 Metadata *Ops[] = {nullptr, nullptr, Name};
665 DEFINE_GETIMPL_STORE(DIBasicType,return storeImpl(new (std::size(Ops), Storage) DIBasicType(Context
, Storage, Tag, SizeInBits, AlignInBits, Encoding, Flags, Ops
), Storage, Context.pImpl->DIBasicTypes)
666 (Tag, SizeInBits, AlignInBits, Encoding, Flags), Ops)return storeImpl(new (std::size(Ops), Storage) DIBasicType(Context
, Storage, Tag, SizeInBits, AlignInBits, Encoding, Flags, Ops
), Storage, Context.pImpl->DIBasicTypes)
;
667}
668
669std::optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
670 switch (getEncoding()) {
671 case dwarf::DW_ATE_signed:
672 case dwarf::DW_ATE_signed_char:
673 return Signedness::Signed;
674 case dwarf::DW_ATE_unsigned:
675 case dwarf::DW_ATE_unsigned_char:
676 return Signedness::Unsigned;
677 default:
678 return std::nullopt;
679 }
680}
681
682DIStringType *DIStringType::getImpl(LLVMContext &Context, unsigned Tag,
683 MDString *Name, Metadata *StringLength,
684 Metadata *StringLengthExp,
685 Metadata *StringLocationExp,
686 uint64_t SizeInBits, uint32_t AlignInBits,
687 unsigned Encoding, StorageType Storage,
688 bool ShouldCreate) {
689 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 689, __extension__ __PRETTY_FUNCTION__
))
;
690 DEFINE_GETIMPL_LOOKUP(DIStringType,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIStringTypes, DIStringTypeInfo::KeyTy(Tag, Name, StringLength
, StringLengthExp, StringLocationExp, SizeInBits, AlignInBits
, Encoding))) return N; if (!ShouldCreate) return nullptr; } else
{ (static_cast <bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 692, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
691 (Tag, Name, StringLength, StringLengthExp,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIStringTypes, DIStringTypeInfo::KeyTy(Tag, Name, StringLength
, StringLengthExp, StringLocationExp, SizeInBits, AlignInBits
, Encoding))) return N; if (!ShouldCreate) return nullptr; } else
{ (static_cast <bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 692, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
692 StringLocationExp, SizeInBits, AlignInBits, Encoding))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIStringTypes, DIStringTypeInfo::KeyTy(Tag, Name, StringLength
, StringLengthExp, StringLocationExp, SizeInBits, AlignInBits
, Encoding))) return N; if (!ShouldCreate) return nullptr; } else
{ (static_cast <bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 692, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
693 Metadata *Ops[] = {nullptr, nullptr, Name,
694 StringLength, StringLengthExp, StringLocationExp};
695 DEFINE_GETIMPL_STORE(DIStringType, (Tag, SizeInBits, AlignInBits, Encoding),return storeImpl(new (std::size(Ops), Storage) DIStringType(Context
, Storage, Tag, SizeInBits, AlignInBits, Encoding, Ops), Storage
, Context.pImpl->DIStringTypes)
696 Ops)return storeImpl(new (std::size(Ops), Storage) DIStringType(Context
, Storage, Tag, SizeInBits, AlignInBits, Encoding, Ops), Storage
, Context.pImpl->DIStringTypes)
;
697}
698DIType *DIDerivedType::getClassType() const {
699 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type)(static_cast <bool> (getTag() == dwarf::DW_TAG_ptr_to_member_type
) ? void (0) : __assert_fail ("getTag() == dwarf::DW_TAG_ptr_to_member_type"
, "llvm/lib/IR/DebugInfoMetadata.cpp", 699, __extension__ __PRETTY_FUNCTION__
))
;
700 return cast_or_null<DIType>(getExtraData());
701}
702uint32_t DIDerivedType::getVBPtrOffset() const {
703 assert(getTag() == dwarf::DW_TAG_inheritance)(static_cast <bool> (getTag() == dwarf::DW_TAG_inheritance
) ? void (0) : __assert_fail ("getTag() == dwarf::DW_TAG_inheritance"
, "llvm/lib/IR/DebugInfoMetadata.cpp", 703, __extension__ __PRETTY_FUNCTION__
))
;
704 if (auto *CM = cast_or_null<ConstantAsMetadata>(getExtraData()))
705 if (auto *CI = dyn_cast_or_null<ConstantInt>(CM->getValue()))
706 return static_cast<uint32_t>(CI->getZExtValue());
707 return 0;
708}
709Constant *DIDerivedType::getStorageOffsetInBits() const {
710 assert(getTag() == dwarf::DW_TAG_member && isBitField())(static_cast <bool> (getTag() == dwarf::DW_TAG_member &&
isBitField()) ? void (0) : __assert_fail ("getTag() == dwarf::DW_TAG_member && isBitField()"
, "llvm/lib/IR/DebugInfoMetadata.cpp", 710, __extension__ __PRETTY_FUNCTION__
))
;
711 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
712 return C->getValue();
713 return nullptr;
714}
715
716Constant *DIDerivedType::getConstant() const {
717 assert(getTag() == dwarf::DW_TAG_member && isStaticMember())(static_cast <bool> (getTag() == dwarf::DW_TAG_member &&
isStaticMember()) ? void (0) : __assert_fail ("getTag() == dwarf::DW_TAG_member && isStaticMember()"
, "llvm/lib/IR/DebugInfoMetadata.cpp", 717, __extension__ __PRETTY_FUNCTION__
))
;
718 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
719 return C->getValue();
720 return nullptr;
721}
722Constant *DIDerivedType::getDiscriminantValue() const {
723 assert(getTag() == dwarf::DW_TAG_member && !isStaticMember())(static_cast <bool> (getTag() == dwarf::DW_TAG_member &&
!isStaticMember()) ? void (0) : __assert_fail ("getTag() == dwarf::DW_TAG_member && !isStaticMember()"
, "llvm/lib/IR/DebugInfoMetadata.cpp", 723, __extension__ __PRETTY_FUNCTION__
))
;
724 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
725 return C->getValue();
726 return nullptr;
727}
728
729DIDerivedType *
730DIDerivedType::getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
731 Metadata *File, unsigned Line, Metadata *Scope,
732 Metadata *BaseType, uint64_t SizeInBits,
733 uint32_t AlignInBits, uint64_t OffsetInBits,
734 std::optional<unsigned> DWARFAddressSpace, DIFlags Flags,
735 Metadata *ExtraData, Metadata *Annotations,
736 StorageType Storage, bool ShouldCreate) {
737 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 737, __extension__ __PRETTY_FUNCTION__
))
;
738 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, Annotations))) return N
; if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 741, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
739 (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, Annotations))) return N
; if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 741, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
740 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, Annotations))) return N
; if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 741, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
741 ExtraData, Annotations))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, Annotations))) return N
; if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 741, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
742 Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData, Annotations};
743 DEFINE_GETIMPL_STORE(DIDerivedType,return storeImpl(new (std::size(Ops), Storage) DIDerivedType(
Context, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, Ops), Storage, Context.pImpl->
DIDerivedTypes)
744 (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,return storeImpl(new (std::size(Ops), Storage) DIDerivedType(
Context, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, Ops), Storage, Context.pImpl->
DIDerivedTypes)
745 DWARFAddressSpace, Flags),return storeImpl(new (std::size(Ops), Storage) DIDerivedType(
Context, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, Ops), Storage, Context.pImpl->
DIDerivedTypes)
746 Ops)return storeImpl(new (std::size(Ops), Storage) DIDerivedType(
Context, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, Ops), Storage, Context.pImpl->
DIDerivedTypes)
;
747}
748
749DICompositeType *DICompositeType::getImpl(
750 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
751 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
752 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
753 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
754 Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
755 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
756 Metadata *Rank, Metadata *Annotations, StorageType Storage,
757 bool ShouldCreate) {
758 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 758, __extension__ __PRETTY_FUNCTION__
))
;
759
760 // Keep this in sync with buildODRType.
761 DEFINE_GETIMPL_LOOKUP(DICompositeType,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, DataLocation, Associated, Allocated
, Rank, Annotations))) return N; if (!ShouldCreate) return nullptr
; } else { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 766, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
762 (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, DataLocation, Associated, Allocated
, Rank, Annotations))) return N; if (!ShouldCreate) return nullptr
; } else { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 766, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
763 AlignInBits, OffsetInBits, Flags, Elements,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, DataLocation, Associated, Allocated
, Rank, Annotations))) return N; if (!ShouldCreate) return nullptr
; } else { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 766, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
764 RuntimeLang, VTableHolder, TemplateParams, Identifier,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, DataLocation, Associated, Allocated
, Rank, Annotations))) return N; if (!ShouldCreate) return nullptr
; } else { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 766, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
765 Discriminator, DataLocation, Associated, Allocated,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, DataLocation, Associated, Allocated
, Rank, Annotations))) return N; if (!ShouldCreate) return nullptr
; } else { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 766, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
766 Rank, Annotations))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, DataLocation, Associated, Allocated
, Rank, Annotations))) return N; if (!ShouldCreate) return nullptr
; } else { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 766, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
767 Metadata *Ops[] = {File, Scope, Name, BaseType,
768 Elements, VTableHolder, TemplateParams, Identifier,
769 Discriminator, DataLocation, Associated, Allocated,
770 Rank, Annotations};
771 DEFINE_GETIMPL_STORE(return storeImpl(new (std::size(Ops), Storage) DICompositeType
(Context, Storage, Tag, Line, RuntimeLang, SizeInBits, AlignInBits
, OffsetInBits, Flags, Ops), Storage, Context.pImpl->DICompositeTypes
)
772 DICompositeType,return storeImpl(new (std::size(Ops), Storage) DICompositeType
(Context, Storage, Tag, Line, RuntimeLang, SizeInBits, AlignInBits
, OffsetInBits, Flags, Ops), Storage, Context.pImpl->DICompositeTypes
)
773 (Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits, Flags),return storeImpl(new (std::size(Ops), Storage) DICompositeType
(Context, Storage, Tag, Line, RuntimeLang, SizeInBits, AlignInBits
, OffsetInBits, Flags, Ops), Storage, Context.pImpl->DICompositeTypes
)
774 Ops)return storeImpl(new (std::size(Ops), Storage) DICompositeType
(Context, Storage, Tag, Line, RuntimeLang, SizeInBits, AlignInBits
, OffsetInBits, Flags, Ops), Storage, Context.pImpl->DICompositeTypes
)
;
775}
776
777DICompositeType *DICompositeType::buildODRType(
778 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
779 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
780 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
781 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
782 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
783 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
784 Metadata *Rank, Metadata *Annotations) {
785 assert(!Identifier.getString().empty() && "Expected valid identifier")(static_cast <bool> (!Identifier.getString().empty() &&
"Expected valid identifier") ? void (0) : __assert_fail ("!Identifier.getString().empty() && \"Expected valid identifier\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 785, __extension__ __PRETTY_FUNCTION__
))
;
786 if (!Context.isODRUniquingDebugTypes())
787 return nullptr;
788 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
789 if (!CT)
790 return CT = DICompositeType::getDistinct(
791 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
792 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
793 VTableHolder, TemplateParams, &Identifier, Discriminator,
794 DataLocation, Associated, Allocated, Rank, Annotations);
795
796 if (CT->getTag() != Tag)
797 return nullptr;
798
799 // Only mutate CT if it's a forward declaration and the new operands aren't.
800 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?")(static_cast <bool> (CT->getRawIdentifier() == &
Identifier && "Wrong ODR identifier?") ? void (0) : __assert_fail
("CT->getRawIdentifier() == &Identifier && \"Wrong ODR identifier?\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 800, __extension__ __PRETTY_FUNCTION__
))
;
801 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
802 return CT;
803
804 // Mutate CT in place. Keep this in sync with getImpl.
805 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
806 Flags);
807 Metadata *Ops[] = {File, Scope, Name, BaseType,
808 Elements, VTableHolder, TemplateParams, &Identifier,
809 Discriminator, DataLocation, Associated, Allocated,
810 Rank, Annotations};
811 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&(static_cast <bool> ((std::end(Ops) - std::begin(Ops)) ==
(int)CT->getNumOperands() && "Mismatched number of operands"
) ? void (0) : __assert_fail ("(std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() && \"Mismatched number of operands\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 812, __extension__ __PRETTY_FUNCTION__
))
812 "Mismatched number of operands")(static_cast <bool> ((std::end(Ops) - std::begin(Ops)) ==
(int)CT->getNumOperands() && "Mismatched number of operands"
) ? void (0) : __assert_fail ("(std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() && \"Mismatched number of operands\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 812, __extension__ __PRETTY_FUNCTION__
))
;
813 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
814 if (Ops[I] != CT->getOperand(I))
815 CT->setOperand(I, Ops[I]);
816 return CT;
817}
818
819DICompositeType *DICompositeType::getODRType(
820 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
821 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
822 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
823 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
824 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
825 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
826 Metadata *Rank, Metadata *Annotations) {
827 assert(!Identifier.getString().empty() && "Expected valid identifier")(static_cast <bool> (!Identifier.getString().empty() &&
"Expected valid identifier") ? void (0) : __assert_fail ("!Identifier.getString().empty() && \"Expected valid identifier\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 827, __extension__ __PRETTY_FUNCTION__
))
;
828 if (!Context.isODRUniquingDebugTypes())
829 return nullptr;
830 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
831 if (!CT) {
832 CT = DICompositeType::getDistinct(
833 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
834 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
835 TemplateParams, &Identifier, Discriminator, DataLocation, Associated,
836 Allocated, Rank, Annotations);
837 } else {
838 if (CT->getTag() != Tag)
839 return nullptr;
840 }
841 return CT;
842}
843
844DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context,
845 MDString &Identifier) {
846 assert(!Identifier.getString().empty() && "Expected valid identifier")(static_cast <bool> (!Identifier.getString().empty() &&
"Expected valid identifier") ? void (0) : __assert_fail ("!Identifier.getString().empty() && \"Expected valid identifier\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 846, __extension__ __PRETTY_FUNCTION__
))
;
847 if (!Context.isODRUniquingDebugTypes())
848 return nullptr;
849 return Context.pImpl->DITypeMap->lookup(&Identifier);
850}
851DISubroutineType::DISubroutineType(LLVMContext &C, StorageType Storage,
852 DIFlags Flags, uint8_t CC,
853 ArrayRef<Metadata *> Ops)
854 : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type, 0,
855 0, 0, 0, Flags, Ops),
856 CC(CC) {}
857
858DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
859 uint8_t CC, Metadata *TypeArray,
860 StorageType Storage,
861 bool ShouldCreate) {
862 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 { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 862, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
863 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
864 DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops)return storeImpl(new (std::size(Ops), Storage) DISubroutineType
(Context, Storage, Flags, CC, Ops), Storage, Context.pImpl->
DISubroutineTypes)
;
865}
866
867DIFile::DIFile(LLVMContext &C, StorageType Storage,
868 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
869 ArrayRef<Metadata *> Ops)
870 : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops),
871 Checksum(CS), Source(Src) {}
872
873// FIXME: Implement this string-enum correspondence with a .def file and macros,
874// so that the association is explicit rather than implied.
875static const char *ChecksumKindName[DIFile::CSK_Last] = {
876 "CSK_MD5",
877 "CSK_SHA1",
878 "CSK_SHA256",
879};
880
881StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
882 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind")(static_cast <bool> (CSKind <= DIFile::CSK_Last &&
"Invalid checksum kind") ? void (0) : __assert_fail ("CSKind <= DIFile::CSK_Last && \"Invalid checksum kind\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 882, __extension__ __PRETTY_FUNCTION__
))
;
883 // The first space was originally the CSK_None variant, which is now
884 // obsolete, but the space is still reserved in ChecksumKind, so we account
885 // for it here.
886 return ChecksumKindName[CSKind - 1];
887}
888
889std::optional<DIFile::ChecksumKind>
890DIFile::getChecksumKind(StringRef CSKindStr) {
891 return StringSwitch<std::optional<DIFile::ChecksumKind>>(CSKindStr)
892 .Case("CSK_MD5", DIFile::CSK_MD5)
893 .Case("CSK_SHA1", DIFile::CSK_SHA1)
894 .Case("CSK_SHA256", DIFile::CSK_SHA256)
895 .Default(std::nullopt);
896}
897
898DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
899 MDString *Directory,
900 std::optional<DIFile::ChecksumInfo<MDString *>> CS,
901 MDString *Source, StorageType Storage,
902 bool ShouldCreate) {
903 assert(isCanonical(Filename) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Filename) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Filename) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 903, __extension__ __PRETTY_FUNCTION__
))
;
904 assert(isCanonical(Directory) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Directory) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Directory) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 904, __extension__ __PRETTY_FUNCTION__
))
;
905 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString")(static_cast <bool> ((!CS || isCanonical(CS->Value))
&& "Expected canonical MDString") ? void (0) : __assert_fail
("(!CS || isCanonical(CS->Value)) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 905, __extension__ __PRETTY_FUNCTION__
))
;
906 // We do *NOT* expect Source to be a canonical MDString because nullptr
907 // means none, so we need something to represent the empty file.
908 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
{ (static_cast <bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 908, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
909 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr, Source};
910 DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops)return storeImpl(new (std::size(Ops), Storage) DIFile(Context
, Storage, CS, Source, Ops), Storage, Context.pImpl->DIFiles
)
;
911}
912DICompileUnit::DICompileUnit(LLVMContext &C, StorageType Storage,
913 unsigned SourceLanguage, bool IsOptimized,
914 unsigned RuntimeVersion, unsigned EmissionKind,
915 uint64_t DWOId, bool SplitDebugInlining,
916 bool DebugInfoForProfiling, unsigned NameTableKind,
917 bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
918 : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
919 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
920 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind), DWOId(DWOId),
921 SplitDebugInlining(SplitDebugInlining),
922 DebugInfoForProfiling(DebugInfoForProfiling),
923 NameTableKind(NameTableKind), RangesBaseAddress(RangesBaseAddress) {
924 assert(Storage != Uniqued)(static_cast <bool> (Storage != Uniqued) ? void (0) : __assert_fail
("Storage != Uniqued", "llvm/lib/IR/DebugInfoMetadata.cpp", 924
, __extension__ __PRETTY_FUNCTION__))
;
925}
926
927DICompileUnit *DICompileUnit::getImpl(
928 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
929 MDString *Producer, bool IsOptimized, MDString *Flags,
930 unsigned RuntimeVersion, MDString *SplitDebugFilename,
931 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
932 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
933 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
934 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
935 MDString *SDK, StorageType Storage, bool ShouldCreate) {
936 assert(Storage != Uniqued && "Cannot unique DICompileUnit")(static_cast <bool> (Storage != Uniqued && "Cannot unique DICompileUnit"
) ? void (0) : __assert_fail ("Storage != Uniqued && \"Cannot unique DICompileUnit\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 936, __extension__ __PRETTY_FUNCTION__
))
;
937 assert(isCanonical(Producer) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Producer) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Producer) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 937, __extension__ __PRETTY_FUNCTION__
))
;
938 assert(isCanonical(Flags) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Flags) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Flags) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 938, __extension__ __PRETTY_FUNCTION__
))
;
939 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString")(static_cast <bool> (isCanonical(SplitDebugFilename) &&
"Expected canonical MDString") ? void (0) : __assert_fail ("isCanonical(SplitDebugFilename) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 939, __extension__ __PRETTY_FUNCTION__
))
;
940
941 Metadata *Ops[] = {File,
942 Producer,
943 Flags,
944 SplitDebugFilename,
945 EnumTypes,
946 RetainedTypes,
947 GlobalVariables,
948 ImportedEntities,
949 Macros,
950 SysRoot,
951 SDK};
952 return storeImpl(new (std::size(Ops), Storage) DICompileUnit(
953 Context, Storage, SourceLanguage, IsOptimized,
954 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
955 DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
956 Ops),
957 Storage);
958}
959
960std::optional<DICompileUnit::DebugEmissionKind>
961DICompileUnit::getEmissionKind(StringRef Str) {
962 return StringSwitch<std::optional<DebugEmissionKind>>(Str)
963 .Case("NoDebug", NoDebug)
964 .Case("FullDebug", FullDebug)
965 .Case("LineTablesOnly", LineTablesOnly)
966 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
967 .Default(std::nullopt);
968}
969
970std::optional<DICompileUnit::DebugNameTableKind>
971DICompileUnit::getNameTableKind(StringRef Str) {
972 return StringSwitch<std::optional<DebugNameTableKind>>(Str)
973 .Case("Default", DebugNameTableKind::Default)
974 .Case("GNU", DebugNameTableKind::GNU)
975 .Case("None", DebugNameTableKind::None)
976 .Default(std::nullopt);
977}
978
979const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
980 switch (EK) {
981 case NoDebug:
982 return "NoDebug";
983 case FullDebug:
984 return "FullDebug";
985 case LineTablesOnly:
986 return "LineTablesOnly";
987 case DebugDirectivesOnly:
988 return "DebugDirectivesOnly";
989 }
990 return nullptr;
991}
992
993const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) {
994 switch (NTK) {
995 case DebugNameTableKind::Default:
996 return nullptr;
997 case DebugNameTableKind::GNU:
998 return "GNU";
999 case DebugNameTableKind::None:
1000 return "None";
1001 }
1002 return nullptr;
1003}
1004DISubprogram::DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1005 unsigned ScopeLine, unsigned VirtualIndex,
1006 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags,
1007 ArrayRef<Metadata *> Ops)
1008 : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
1009 Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
1010 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) {
1011 static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
1012}
1013DISubprogram::DISPFlags
1014DISubprogram::toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized,
1015 unsigned Virtuality, bool IsMainSubprogram) {
1016 // We're assuming virtuality is the low-order field.
1017 static_assert(int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
1018 int(SPFlagPureVirtual) ==
1019 int(dwarf::DW_VIRTUALITY_pure_virtual),
1020 "Virtuality constant mismatch");
1021 return static_cast<DISPFlags>(
1022 (Virtuality & SPFlagVirtuality) |
1023 (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
1024 (IsDefinition ? SPFlagDefinition : SPFlagZero) |
1025 (IsOptimized ? SPFlagOptimized : SPFlagZero) |
1026 (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero));
1027}
1028
1029DISubprogram *DILocalScope::getSubprogram() const {
1030 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
1031 return Block->getScope()->getSubprogram();
1032 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
1033}
1034
1035DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
1036 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
1037 return File->getScope()->getNonLexicalBlockFileScope();
1038 return const_cast<DILocalScope *>(this);
1039}
1040
1041DILocalScope *DILocalScope::cloneScopeForSubprogram(
1042 DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx,
1043 DenseMap<const MDNode *, MDNode *> &Cache) {
1044 SmallVector<DIScope *> ScopeChain;
1045 DIScope *CachedResult = nullptr;
1046
1047 for (DIScope *Scope = &RootScope; !isa<DISubprogram>(Scope);
1048 Scope = Scope->getScope()) {
1049 if (auto It = Cache.find(Scope); It != Cache.end()) {
1050 CachedResult = cast<DIScope>(It->second);
1051 break;
1052 }
1053 ScopeChain.push_back(Scope);
1054 }
1055
1056 // Recreate the scope chain, bottom-up, starting at the new subprogram (or a
1057 // cached result).
1058 DIScope *UpdatedScope = CachedResult ? CachedResult : &NewSP;
1059 for (DIScope *ScopeToUpdate : reverse(ScopeChain)) {
1060 TempMDNode ClonedScope = ScopeToUpdate->clone();
1061 cast<DILexicalBlockBase>(*ClonedScope).replaceScope(UpdatedScope);
1062 UpdatedScope =
1063 cast<DIScope>(MDNode::replaceWithUniqued(std::move(ClonedScope)));
1064 Cache[ScopeToUpdate] = UpdatedScope;
1065 }
1066
1067 return cast<DILocalScope>(UpdatedScope);
1068}
1069
1070DISubprogram::DISPFlags DISubprogram::getFlag(StringRef Flag) {
1071 return StringSwitch<DISPFlags>(Flag)
1072#define HANDLE_DISP_FLAG(ID, NAME) .Case("DISPFlag" #NAME, SPFlag##NAME)
1073#include "llvm/IR/DebugInfoFlags.def"
1074 .Default(SPFlagZero);
1075}
1076
1077StringRef DISubprogram::getFlagString(DISPFlags Flag) {
1078 switch (Flag) {
1079 // Appease a warning.
1080 case SPFlagVirtuality:
1081 return "";
1082#define HANDLE_DISP_FLAG(ID, NAME) \
1083 case SPFlag##NAME: \
1084 return "DISPFlag" #NAME;
1085#include "llvm/IR/DebugInfoFlags.def"
1086 }
1087 return "";
1088}
1089
1090DISubprogram::DISPFlags
1091DISubprogram::splitFlags(DISPFlags Flags,
1092 SmallVectorImpl<DISPFlags> &SplitFlags) {
1093 // Multi-bit fields can require special handling. In our case, however, the
1094 // only multi-bit field is virtuality, and all its values happen to be
1095 // single-bit values, so the right behavior just falls out.
1096#define HANDLE_DISP_FLAG(ID, NAME) \
1097 if (DISPFlags Bit = Flags & SPFlag##NAME) { \
1098 SplitFlags.push_back(Bit); \
1099 Flags &= ~Bit; \
1100 }
1101#include "llvm/IR/DebugInfoFlags.def"
1102 return Flags;
1103}
1104
1105DISubprogram *DISubprogram::getImpl(
1106 LLVMContext &Context, Metadata *Scope, MDString *Name,
1107 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1108 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
1109 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1110 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
1111 Metadata *ThrownTypes, Metadata *Annotations, MDString *TargetFuncName,
1112 StorageType Storage, bool ShouldCreate) {
1113 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1113, __extension__ __PRETTY_FUNCTION__
))
;
1114 assert(isCanonical(LinkageName) && "Expected canonical MDString")(static_cast <bool> (isCanonical(LinkageName) &&
"Expected canonical MDString") ? void (0) : __assert_fail ("isCanonical(LinkageName) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1114, __extension__ __PRETTY_FUNCTION__
))
;
1115 assert(isCanonical(TargetFuncName) && "Expected canonical MDString")(static_cast <bool> (isCanonical(TargetFuncName) &&
"Expected canonical MDString") ? void (0) : __assert_fail ("isCanonical(TargetFuncName) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1115, __extension__ __PRETTY_FUNCTION__
))
;
1116 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, Annotations, TargetFuncName))) return
N; if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1121, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1117 (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, Annotations, TargetFuncName))) return
N; if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1121, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1118 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, Annotations, TargetFuncName))) return
N; if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1121, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1119 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, Annotations, TargetFuncName))) return
N; if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1121, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1120 RetainedNodes, ThrownTypes, Annotations,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, Annotations, TargetFuncName))) return
N; if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1121, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1121 TargetFuncName))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, Annotations, TargetFuncName))) return
N; if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1121, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1122 SmallVector<Metadata *, 13> Ops = {
1123 File, Scope, Name, LinkageName,
1124 Type, Unit, Declaration, RetainedNodes,
1125 ContainingType, TemplateParams, ThrownTypes, Annotations,
1126 TargetFuncName};
1127 if (!TargetFuncName) {
1128 Ops.pop_back();
1129 if (!Annotations) {
1130 Ops.pop_back();
1131 if (!ThrownTypes) {
1132 Ops.pop_back();
1133 if (!TemplateParams) {
1134 Ops.pop_back();
1135 if (!ContainingType)
1136 Ops.pop_back();
1137 }
1138 }
1139 }
1140 }
1141 DEFINE_GETIMPL_STORE_N(return storeImpl(new (Ops.size(), Storage) DISubprogram(Context
, Storage, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags
, SPFlags, Ops), Storage, Context.pImpl->DISubprograms)
1142 DISubprogram,return storeImpl(new (Ops.size(), Storage) DISubprogram(Context
, Storage, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags
, SPFlags, Ops), Storage, Context.pImpl->DISubprograms)
1143 (Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags), Ops,return storeImpl(new (Ops.size(), Storage) DISubprogram(Context
, Storage, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags
, SPFlags, Ops), Storage, Context.pImpl->DISubprograms)
1144 Ops.size())return storeImpl(new (Ops.size(), Storage) DISubprogram(Context
, Storage, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags
, SPFlags, Ops), Storage, Context.pImpl->DISubprograms)
;
1145}
1146
1147bool DISubprogram::describes(const Function *F) const {
1148 assert(F && "Invalid function")(static_cast <bool> (F && "Invalid function") ?
void (0) : __assert_fail ("F && \"Invalid function\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1148, __extension__ __PRETTY_FUNCTION__
))
;
1149 return F->getSubprogram() == this;
1150}
1151DILexicalBlockBase::DILexicalBlockBase(LLVMContext &C, unsigned ID,
1152 StorageType Storage,
1153 ArrayRef<Metadata *> Ops)
1154 : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1155
1156DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1157 Metadata *File, unsigned Line,
1158 unsigned Column, StorageType Storage,
1159 bool ShouldCreate) {
1160 // Fixup column.
1161 adjustColumn(Column);
1162
1163 assert(Scope && "Expected scope")(static_cast <bool> (Scope && "Expected scope")
? void (0) : __assert_fail ("Scope && \"Expected scope\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1163, __extension__ __PRETTY_FUNCTION__
))
;
1164 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 { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1164, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1165 Metadata *Ops[] = {File, Scope};
1166 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops)return storeImpl(new (std::size(Ops), Storage) DILexicalBlock
(Context, Storage, Line, Column, Ops), Storage, Context.pImpl
->DILexicalBlocks)
;
1167}
1168
1169DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
1170 Metadata *Scope, Metadata *File,
1171 unsigned Discriminator,
1172 StorageType Storage,
1173 bool ShouldCreate) {
1174 assert(Scope && "Expected scope")(static_cast <bool> (Scope && "Expected scope")
? void (0) : __assert_fail ("Scope && \"Expected scope\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1174, __extension__ __PRETTY_FUNCTION__
))
;
1175 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 { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1175, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1176 Metadata *Ops[] = {File, Scope};
1177 DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops)return storeImpl(new (std::size(Ops), Storage) DILexicalBlockFile
(Context, Storage, Discriminator, Ops), Storage, Context.pImpl
->DILexicalBlockFiles)
;
1178}
1179
1180DINamespace::DINamespace(LLVMContext &Context, StorageType Storage,
1181 bool ExportSymbols, ArrayRef<Metadata *> Ops)
1182 : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, Ops),
1183 ExportSymbols(ExportSymbols) {}
1184DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
1185 MDString *Name, bool ExportSymbols,
1186 StorageType Storage, bool ShouldCreate) {
1187 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1187, __extension__ __PRETTY_FUNCTION__
))
;
1188 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 { (static_cast
<bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1188, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1189 // The nullptr is for DIScope's File operand. This should be refactored.
1190 Metadata *Ops[] = {nullptr, Scope, Name};
1191 DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops)return storeImpl(new (std::size(Ops), Storage) DINamespace(Context
, Storage, ExportSymbols, Ops), Storage, Context.pImpl->DINamespaces
)
;
1192}
1193
1194DICommonBlock::DICommonBlock(LLVMContext &Context, StorageType Storage,
1195 unsigned LineNo, ArrayRef<Metadata *> Ops)
1196 : DIScope(Context, DICommonBlockKind, Storage, dwarf::DW_TAG_common_block,
1197 Ops),
1198 LineNo(LineNo) {}
1199DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1200 Metadata *Decl, MDString *Name,
1201 Metadata *File, unsigned LineNo,
1202 StorageType Storage, bool ShouldCreate) {
1203 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1203, __extension__ __PRETTY_FUNCTION__
))
;
1204 DEFINE_GETIMPL_LOOKUP(DICommonBlock, (Scope, Decl, Name, File, LineNo))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DICommonBlocks, DICommonBlockInfo::KeyTy(Scope, Decl
, Name, File, LineNo))) return N; if (!ShouldCreate) return nullptr
; } else { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1204, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1205 // The nullptr is for DIScope's File operand. This should be refactored.
1206 Metadata *Ops[] = {Scope, Decl, Name, File};
1207 DEFINE_GETIMPL_STORE(DICommonBlock, (LineNo), Ops)return storeImpl(new (std::size(Ops), Storage) DICommonBlock(
Context, Storage, LineNo, Ops), Storage, Context.pImpl->DICommonBlocks
)
;
1208}
1209
1210DIModule::DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
1211 bool IsDecl, ArrayRef<Metadata *> Ops)
1212 : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops),
1213 LineNo(LineNo), IsDecl(IsDecl) {}
1214DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *File,
1215 Metadata *Scope, MDString *Name,
1216 MDString *ConfigurationMacros,
1217 MDString *IncludePath, MDString *APINotesFile,
1218 unsigned LineNo, bool IsDecl, StorageType Storage,
1219 bool ShouldCreate) {
1220 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1220, __extension__ __PRETTY_FUNCTION__
))
;
1221 DEFINE_GETIMPL_LOOKUP(DIModule, (File, Scope, Name, ConfigurationMacros,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIModules, DIModuleInfo::KeyTy(File, Scope, Name, ConfigurationMacros
, IncludePath, APINotesFile, LineNo, IsDecl))) return N; if (
!ShouldCreate) return nullptr; } else { (static_cast <bool
> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1222, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1222 IncludePath, APINotesFile, LineNo, IsDecl))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIModules, DIModuleInfo::KeyTy(File, Scope, Name, ConfigurationMacros
, IncludePath, APINotesFile, LineNo, IsDecl))) return N; if (
!ShouldCreate) return nullptr; } else { (static_cast <bool
> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1222, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1223 Metadata *Ops[] = {File, Scope, Name, ConfigurationMacros,
1224 IncludePath, APINotesFile};
1225 DEFINE_GETIMPL_STORE(DIModule, (LineNo, IsDecl), Ops)return storeImpl(new (std::size(Ops), Storage) DIModule(Context
, Storage, LineNo, IsDecl, Ops), Storage, Context.pImpl->DIModules
)
;
1226}
1227DITemplateTypeParameter::DITemplateTypeParameter(LLVMContext &Context,
1228 StorageType Storage,
1229 bool IsDefault,
1230 ArrayRef<Metadata *> Ops)
1231 : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
1232 dwarf::DW_TAG_template_type_parameter, IsDefault,
1233 Ops) {}
1234
1235DITemplateTypeParameter *
1236DITemplateTypeParameter::getImpl(LLVMContext &Context, MDString *Name,
1237 Metadata *Type, bool isDefault,
1238 StorageType Storage, bool ShouldCreate) {
1239 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1239, __extension__ __PRETTY_FUNCTION__
))
;
1240 DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type, isDefault))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DITemplateTypeParameters, DITemplateTypeParameterInfo
::KeyTy(Name, Type, isDefault))) return N; if (!ShouldCreate)
return nullptr; } else { (static_cast <bool> (ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1240, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1241 Metadata *Ops[] = {Name, Type};
1242 DEFINE_GETIMPL_STORE(DITemplateTypeParameter, (isDefault), Ops)return storeImpl(new (std::size(Ops), Storage) DITemplateTypeParameter
(Context, Storage, isDefault, Ops), Storage, Context.pImpl->
DITemplateTypeParameters)
;
1243}
1244
1245DITemplateValueParameter *DITemplateValueParameter::getImpl(
1246 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
1247 bool isDefault, Metadata *Value, StorageType Storage, bool ShouldCreate) {
1248 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1248, __extension__ __PRETTY_FUNCTION__
))
;
1249 DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DITemplateValueParameters, DITemplateValueParameterInfo
::KeyTy(Tag, Name, Type, isDefault, Value))) return N; if (!ShouldCreate
) return nullptr; } else { (static_cast <bool> (ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1250, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1250 (Tag, Name, Type, isDefault, Value))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DITemplateValueParameters, DITemplateValueParameterInfo
::KeyTy(Tag, Name, Type, isDefault, Value))) return N; if (!ShouldCreate
) return nullptr; } else { (static_cast <bool> (ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1250, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1251 Metadata *Ops[] = {Name, Type, Value};
1252 DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag, isDefault), Ops)return storeImpl(new (std::size(Ops), Storage) DITemplateValueParameter
(Context, Storage, Tag, isDefault, Ops), Storage, Context.pImpl
->DITemplateValueParameters)
;
1253}
1254
1255DIGlobalVariable *
1256DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1257 MDString *LinkageName, Metadata *File, unsigned Line,
1258 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1259 Metadata *StaticDataMemberDeclaration,
1260 Metadata *TemplateParams, uint32_t AlignInBits,
1261 Metadata *Annotations, StorageType Storage,
1262 bool ShouldCreate) {
1263 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1263, __extension__ __PRETTY_FUNCTION__
))
;
1264 assert(isCanonical(LinkageName) && "Expected canonical MDString")(static_cast <bool> (isCanonical(LinkageName) &&
"Expected canonical MDString") ? void (0) : __assert_fail ("isCanonical(LinkageName) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1264, __extension__ __PRETTY_FUNCTION__
))
;
1265 DEFINE_GETIMPL_LOOKUP(do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits, Annotations
))) return N; if (!ShouldCreate) return nullptr; } else { (static_cast
<bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1268, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1266 DIGlobalVariable,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits, Annotations
))) return N; if (!ShouldCreate) return nullptr; } else { (static_cast
<bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1268, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1267 (Scope, Name, LinkageName, File, Line, 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, Annotations
))) return N; if (!ShouldCreate) return nullptr; } else { (static_cast
<bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1268, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1268 StaticDataMemberDeclaration, TemplateParams, AlignInBits, Annotations))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits, Annotations
))) return N; if (!ShouldCreate) return nullptr; } else { (static_cast
<bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1268, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1269 Metadata *Ops[] = {Scope,
1270 Name,
1271 File,
1272 Type,
1273 Name,
1274 LinkageName,
1275 StaticDataMemberDeclaration,
1276 TemplateParams,
1277 Annotations};
1278 DEFINE_GETIMPL_STORE(DIGlobalVariable,return storeImpl(new (std::size(Ops), Storage) DIGlobalVariable
(Context, Storage, Line, IsLocalToUnit, IsDefinition, AlignInBits
, Ops), Storage, Context.pImpl->DIGlobalVariables)
1279 (Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops)return storeImpl(new (std::size(Ops), Storage) DIGlobalVariable
(Context, Storage, Line, IsLocalToUnit, IsDefinition, AlignInBits
, Ops), Storage, Context.pImpl->DIGlobalVariables)
;
1280}
1281
1282DILocalVariable *
1283DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1284 Metadata *File, unsigned Line, Metadata *Type,
1285 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
1286 Metadata *Annotations, StorageType Storage,
1287 bool ShouldCreate) {
1288 // 64K ought to be enough for any frontend.
1289 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits")(static_cast <bool> (Arg <= (65535) && "Expected argument number to fit in 16-bits"
) ? void (0) : __assert_fail ("Arg <= UINT16_MAX && \"Expected argument number to fit in 16-bits\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1289, __extension__ __PRETTY_FUNCTION__
))
;
1290
1291 assert(Scope && "Expected scope")(static_cast <bool> (Scope && "Expected scope")
? void (0) : __assert_fail ("Scope && \"Expected scope\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1291, __extension__ __PRETTY_FUNCTION__
))
;
1292 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1292, __extension__ __PRETTY_FUNCTION__
))
;
1293 DEFINE_GETIMPL_LOOKUP(DILocalVariable, (Scope, Name, File, Line, Type, Arg,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILocalVariables, DILocalVariableInfo::KeyTy(Scope
, Name, File, Line, Type, Arg, Flags, AlignInBits, Annotations
))) return N; if (!ShouldCreate) return nullptr; } else { (static_cast
<bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1294, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
1294 Flags, AlignInBits, Annotations))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILocalVariables, DILocalVariableInfo::KeyTy(Scope
, Name, File, Line, Type, Arg, Flags, AlignInBits, Annotations
))) return N; if (!ShouldCreate) return nullptr; } else { (static_cast
<bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1294, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1295 Metadata *Ops[] = {Scope, Name, File, Type, Annotations};
1296 DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops)return storeImpl(new (std::size(Ops), Storage) DILocalVariable
(Context, Storage, Line, Arg, Flags, AlignInBits, Ops), Storage
, Context.pImpl->DILocalVariables)
;
1297}
1298
1299DIVariable::DIVariable(LLVMContext &C, unsigned ID, StorageType Storage,
1300 signed Line, ArrayRef<Metadata *> Ops,
1301 uint32_t AlignInBits)
1302 : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line),
1303 AlignInBits(AlignInBits) {}
1304std::optional<uint64_t> DIVariable::getSizeInBits() const {
1305 // This is used by the Verifier so be mindful of broken types.
1306 const Metadata *RawType = getRawType();
1307 while (RawType) {
1308 // Try to get the size directly.
1309 if (auto *T = dyn_cast<DIType>(RawType))
1310 if (uint64_t Size = T->getSizeInBits())
1311 return Size;
1312
1313 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
1314 // Look at the base type.
1315 RawType = DT->getRawBaseType();
1316 continue;
1317 }
1318
1319 // Missing type or size.
1320 break;
1321 }
1322
1323 // Fail gracefully.
1324 return std::nullopt;
1325}
1326
1327DILabel::DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
1328 ArrayRef<Metadata *> Ops)
1329 : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops), Line(Line) {}
1330DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1331 Metadata *File, unsigned Line, StorageType Storage,
1332 bool ShouldCreate) {
1333 assert(Scope && "Expected scope")(static_cast <bool> (Scope && "Expected scope")
? void (0) : __assert_fail ("Scope && \"Expected scope\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1333, __extension__ __PRETTY_FUNCTION__
))
;
1334 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1334, __extension__ __PRETTY_FUNCTION__
))
;
1335 DEFINE_GETIMPL_LOOKUP(DILabel, (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 { (static_cast
<bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1335, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1336 Metadata *Ops[] = {Scope, Name, File};
1337 DEFINE_GETIMPL_STORE(DILabel, (Line), Ops)return storeImpl(new (std::size(Ops), Storage) DILabel(Context
, Storage, Line, Ops), Storage, Context.pImpl->DILabels)
;
1338}
1339
1340DIExpression *DIExpression::getImpl(LLVMContext &Context,
1341 ArrayRef<uint64_t> Elements,
1342 StorageType Storage, bool ShouldCreate) {
1343 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 { (static_cast
<bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1343, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
1344 DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements))return storeImpl(new (0u, Storage) DIExpression(Context, Storage
, Elements), Storage, Context.pImpl->DIExpressions)
;
1345}
1346bool DIExpression::isEntryValue() const {
1347 return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_LLVM_entry_value;
1348}
1349bool DIExpression::startsWithDeref() const {
1350 return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref;
1351}
1352bool DIExpression::isDeref() const {
1353 return getNumElements() == 1 && startsWithDeref();
1354}
1355
1356DIAssignID *DIAssignID::getImpl(LLVMContext &Context, StorageType Storage,
1357 bool ShouldCreate) {
1358 // Uniqued DIAssignID are not supported as the instance address *is* the ID.
1359 assert(Storage != StorageType::Uniqued && "uniqued DIAssignID unsupported")(static_cast <bool> (Storage != StorageType::Uniqued &&
"uniqued DIAssignID unsupported") ? void (0) : __assert_fail
("Storage != StorageType::Uniqued && \"uniqued DIAssignID unsupported\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1359, __extension__ __PRETTY_FUNCTION__
))
;
1360 return storeImpl(new (0u, Storage) DIAssignID(Context, Storage), Storage);
1361}
1362
1363unsigned DIExpression::ExprOperand::getSize() const {
1364 uint64_t Op = getOp();
1365
1366 if (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31)
1367 return 2;
1368
1369 switch (Op) {
1370 case dwarf::DW_OP_LLVM_convert:
1371 case dwarf::DW_OP_LLVM_fragment:
1372 case dwarf::DW_OP_bregx:
1373 return 3;
1374 case dwarf::DW_OP_constu:
1375 case dwarf::DW_OP_consts:
1376 case dwarf::DW_OP_deref_size:
1377 case dwarf::DW_OP_plus_uconst:
1378 case dwarf::DW_OP_LLVM_tag_offset:
1379 case dwarf::DW_OP_LLVM_entry_value:
1380 case dwarf::DW_OP_LLVM_arg:
1381 case dwarf::DW_OP_regx:
1382 return 2;
1383 default:
1384 return 1;
1385 }
1386}
1387
1388bool DIExpression::isValid() const {
1389 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
1390 // Check that there's space for the operand.
1391 if (I->get() + I->getSize() > E->get())
1392 return false;
1393
1394 uint64_t Op = I->getOp();
1395 if ((Op >= dwarf::DW_OP_reg0 && Op <= dwarf::DW_OP_reg31) ||
1396 (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31))
1397 return true;
1398
1399 // Check that the operand is valid.
1400 switch (Op) {
1401 default:
1402 return false;
1403 case dwarf::DW_OP_LLVM_fragment:
1404 // A fragment operator must appear at the end.
1405 return I->get() + I->getSize() == E->get();
1406 case dwarf::DW_OP_stack_value: {
1407 // Must be the last one or followed by a DW_OP_LLVM_fragment.
1408 if (I->get() + I->getSize() == E->get())
1409 break;
1410 auto J = I;
1411 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
1412 return false;
1413 break;
1414 }
1415 case dwarf::DW_OP_swap: {
1416 // Must be more than one implicit element on the stack.
1417
1418 // FIXME: A better way to implement this would be to add a local variable
1419 // that keeps track of the stack depth and introduce something like a
1420 // DW_LLVM_OP_implicit_location as a placeholder for the location this
1421 // DIExpression is attached to, or else pass the number of implicit stack
1422 // elements into isValid.
1423 if (getNumElements() == 1)
1424 return false;
1425 break;
1426 }
1427 case dwarf::DW_OP_LLVM_entry_value: {
1428 // An entry value operator must appear at the beginning or immediately
1429 // following `DW_OP_LLVM_arg 0`, and the number of operations it cover can
1430 // currently only be 1, because we support only entry values of a simple
1431 // register location. One reason for this is that we currently can't
1432 // calculate the size of the resulting DWARF block for other expressions.
1433 auto FirstOp = expr_op_begin();
1434 if (FirstOp->getOp() == dwarf::DW_OP_LLVM_arg && FirstOp->getArg(0) == 0)
1435 ++FirstOp;
1436 return I->get() == FirstOp->get() && I->getArg(0) == 1;
1437 }
1438 case dwarf::DW_OP_LLVM_implicit_pointer:
1439 case dwarf::DW_OP_LLVM_convert:
1440 case dwarf::DW_OP_LLVM_arg:
1441 case dwarf::DW_OP_LLVM_tag_offset:
1442 case dwarf::DW_OP_constu:
1443 case dwarf::DW_OP_plus_uconst:
1444 case dwarf::DW_OP_plus:
1445 case dwarf::DW_OP_minus:
1446 case dwarf::DW_OP_mul:
1447 case dwarf::DW_OP_div:
1448 case dwarf::DW_OP_mod:
1449 case dwarf::DW_OP_or:
1450 case dwarf::DW_OP_and:
1451 case dwarf::DW_OP_xor:
1452 case dwarf::DW_OP_shl:
1453 case dwarf::DW_OP_shr:
1454 case dwarf::DW_OP_shra:
1455 case dwarf::DW_OP_deref:
1456 case dwarf::DW_OP_deref_size:
1457 case dwarf::DW_OP_xderef:
1458 case dwarf::DW_OP_lit0:
1459 case dwarf::DW_OP_not:
1460 case dwarf::DW_OP_dup:
1461 case dwarf::DW_OP_regx:
1462 case dwarf::DW_OP_bregx:
1463 case dwarf::DW_OP_push_object_address:
1464 case dwarf::DW_OP_over:
1465 case dwarf::DW_OP_consts:
1466 break;
1467 }
1468 }
1469 return true;
1470}
1471
1472bool DIExpression::isImplicit() const {
1473 if (!isValid())
1474 return false;
1475
1476 if (getNumElements() == 0)
1477 return false;
1478
1479 for (const auto &It : expr_ops()) {
1480 switch (It.getOp()) {
1481 default:
1482 break;
1483 case dwarf::DW_OP_stack_value:
1484 case dwarf::DW_OP_LLVM_tag_offset:
1485 return true;
1486 }
1487 }
1488
1489 return false;
1490}
1491
1492bool DIExpression::isComplex() const {
1493 if (!isValid())
1494 return false;
1495
1496 if (getNumElements() == 0)
1497 return false;
1498
1499 // If there are any elements other than fragment or tag_offset, then some
1500 // kind of complex computation occurs.
1501 for (const auto &It : expr_ops()) {
1502 switch (It.getOp()) {
1503 case dwarf::DW_OP_LLVM_tag_offset:
1504 case dwarf::DW_OP_LLVM_fragment:
1505 case dwarf::DW_OP_LLVM_arg:
1506 continue;
1507 default:
1508 return true;
1509 }
1510 }
1511
1512 return false;
1513}
1514
1515bool DIExpression::isSingleLocationExpression() const {
1516 if (!isValid())
1517 return false;
1518
1519 if (getNumElements() == 0)
1520 return true;
1521
1522 auto ExprOpBegin = expr_ops().begin();
1523 auto ExprOpEnd = expr_ops().end();
1524 if (ExprOpBegin->getOp() == dwarf::DW_OP_LLVM_arg)
1525 ++ExprOpBegin;
1526
1527 return !std::any_of(ExprOpBegin, ExprOpEnd, [](auto Op) {
1528 return Op.getOp() == dwarf::DW_OP_LLVM_arg;
1529 });
1530}
1531
1532const DIExpression *
1533DIExpression::convertToUndefExpression(const DIExpression *Expr) {
1534 SmallVector<uint64_t, 3> UndefOps;
1535 if (auto FragmentInfo = Expr->getFragmentInfo()) {
1536 UndefOps.append({dwarf::DW_OP_LLVM_fragment, FragmentInfo->OffsetInBits,
1537 FragmentInfo->SizeInBits});
1538 }
1539 return DIExpression::get(Expr->getContext(), UndefOps);
1540}
1541
1542const DIExpression *
1543DIExpression::convertToVariadicExpression(const DIExpression *Expr) {
1544 if (any_of(Expr->expr_ops(), [](auto ExprOp) {
1545 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
1546 }))
1547 return Expr;
1548 SmallVector<uint64_t> NewOps;
1549 NewOps.reserve(Expr->getNumElements() + 2);
1550 NewOps.append({dwarf::DW_OP_LLVM_arg, 0});
1551 NewOps.append(Expr->elements_begin(), Expr->elements_end());
1552 return DIExpression::get(Expr->getContext(), NewOps);
1553}
1554
1555std::optional<const DIExpression *>
1556DIExpression::convertToNonVariadicExpression(const DIExpression *Expr) {
1557 // Check for `isValid` covered by `isSingleLocationExpression`.
1558 if (!Expr->isSingleLocationExpression())
1559 return std::nullopt;
1560
1561 // An empty expression is already non-variadic.
1562 if (!Expr->getNumElements())
1563 return Expr;
1564
1565 auto ElementsBegin = Expr->elements_begin();
1566 // If Expr does not have a leading DW_OP_LLVM_arg then we don't need to do
1567 // anything.
1568 if (*ElementsBegin != dwarf::DW_OP_LLVM_arg)
1569 return Expr;
1570
1571 SmallVector<uint64_t> NonVariadicOps(
1572 make_range(ElementsBegin + 2, Expr->elements_end()));
1573 return DIExpression::get(Expr->getContext(), NonVariadicOps);
1574}
1575
1576void DIExpression::canonicalizeExpressionOps(SmallVectorImpl<uint64_t> &Ops,
1577 const DIExpression *Expr,
1578 bool IsIndirect) {
1579 // If Expr is not already variadic, insert the implied `DW_OP_LLVM_arg 0`
1580 // to the existing expression ops.
1581 if (none_of(Expr->expr_ops(), [](auto ExprOp) {
1582 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
1583 }))
1584 Ops.append({dwarf::DW_OP_LLVM_arg, 0});
1585 // If Expr is not indirect, we only need to insert the expression elements and
1586 // we're done.
1587 if (!IsIndirect) {
1588 Ops.append(Expr->elements_begin(), Expr->elements_end());
1589 return;
1590 }
1591 // If Expr is indirect, insert the implied DW_OP_deref at the end of the
1592 // expression but before DW_OP_{stack_value, LLVM_fragment} if they are
1593 // present.
1594 for (auto Op : Expr->expr_ops()) {
1595 if (Op.getOp() == dwarf::DW_OP_stack_value ||
1596 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1597 Ops.push_back(dwarf::DW_OP_deref);
1598 IsIndirect = false;
1599 }
1600 Op.appendToVector(Ops);
1601 }
1602 if (IsIndirect)
1603 Ops.push_back(dwarf::DW_OP_deref);
1604}
1605
1606bool DIExpression::isEqualExpression(const DIExpression *FirstExpr,
1607 bool FirstIndirect,
1608 const DIExpression *SecondExpr,
1609 bool SecondIndirect) {
1610 SmallVector<uint64_t> FirstOps;
1611 DIExpression::canonicalizeExpressionOps(FirstOps, FirstExpr, FirstIndirect);
1612 SmallVector<uint64_t> SecondOps;
1613 DIExpression::canonicalizeExpressionOps(SecondOps, SecondExpr,
1614 SecondIndirect);
1615 return FirstOps == SecondOps;
1616}
1617
1618std::optional<DIExpression::FragmentInfo>
1619DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
1620 for (auto I = Start; I != End; ++I)
1621 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
1622 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
1623 return Info;
1624 }
1625 return std::nullopt;
1626}
1627
1628void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
1629 int64_t Offset) {
1630 if (Offset > 0) {
1631 Ops.push_back(dwarf::DW_OP_plus_uconst);
1632 Ops.push_back(Offset);
1633 } else if (Offset < 0) {
1634 Ops.push_back(dwarf::DW_OP_constu);
1635 // Avoid UB when encountering LLONG_MIN, because in 2's complement
1636 // abs(LLONG_MIN) is LLONG_MAX+1.
1637 uint64_t AbsMinusOne = -(Offset+1);
1638 Ops.push_back(AbsMinusOne + 1);
1639 Ops.push_back(dwarf::DW_OP_minus);
1640 }
1641}
1642
1643bool DIExpression::extractIfOffset(int64_t &Offset) const {
1644 if (getNumElements() == 0) {
1645 Offset = 0;
1646 return true;
1647 }
1648
1649 if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
1650 Offset = Elements[1];
1651 return true;
1652 }
1653
1654 if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
1655 if (Elements[2] == dwarf::DW_OP_plus) {
1656 Offset = Elements[1];
1657 return true;
1658 }
1659 if (Elements[2] == dwarf::DW_OP_minus) {
1660 Offset = -Elements[1];
1661 return true;
1662 }
1663 }
1664
1665 return false;
1666}
1667
1668bool DIExpression::hasAllLocationOps(unsigned N) const {
1669 SmallDenseSet<uint64_t, 4> SeenOps;
1670 for (auto ExprOp : expr_ops())
1671 if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
1672 SeenOps.insert(ExprOp.getArg(0));
1673 for (uint64_t Idx = 0; Idx < N; ++Idx)
1674 if (!SeenOps.contains(Idx))
1675 return false;
1676 return true;
1677}
1678
1679const DIExpression *DIExpression::extractAddressClass(const DIExpression *Expr,
1680 unsigned &AddrClass) {
1681 // FIXME: This seems fragile. Nothing that verifies that these elements
1682 // actually map to ops and not operands.
1683 const unsigned PatternSize = 4;
1684 if (Expr->Elements.size() >= PatternSize &&
1685 Expr->Elements[PatternSize - 4] == dwarf::DW_OP_constu &&
1686 Expr->Elements[PatternSize - 2] == dwarf::DW_OP_swap &&
1687 Expr->Elements[PatternSize - 1] == dwarf::DW_OP_xderef) {
1688 AddrClass = Expr->Elements[PatternSize - 3];
1689
1690 if (Expr->Elements.size() == PatternSize)
1691 return nullptr;
1692 return DIExpression::get(Expr->getContext(),
1693 ArrayRef(&*Expr->Elements.begin(),
1694 Expr->Elements.size() - PatternSize));
1695 }
1696 return Expr;
1697}
1698
1699DIExpression *DIExpression::prepend(const DIExpression *Expr, uint8_t Flags,
1700 int64_t Offset) {
1701 SmallVector<uint64_t, 8> Ops;
1702 if (Flags & DIExpression::DerefBefore)
1703 Ops.push_back(dwarf::DW_OP_deref);
1704
1705 appendOffset(Ops, Offset);
1706 if (Flags & DIExpression::DerefAfter)
1707 Ops.push_back(dwarf::DW_OP_deref);
1708
1709 bool StackValue = Flags & DIExpression::StackValue;
1710 bool EntryValue = Flags & DIExpression::EntryValue;
1711
1712 return prependOpcodes(Expr, Ops, StackValue, EntryValue);
1713}
1714
1715DIExpression *DIExpression::appendOpsToArg(const DIExpression *Expr,
1716 ArrayRef<uint64_t> Ops,
1717 unsigned ArgNo, bool StackValue) {
1718 assert(Expr && "Can't add ops to this expression")(static_cast <bool> (Expr && "Can't add ops to this expression"
) ? void (0) : __assert_fail ("Expr && \"Can't add ops to this expression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1718, __extension__ __PRETTY_FUNCTION__
))
;
1719
1720 // Handle non-variadic intrinsics by prepending the opcodes.
1721 if (!any_of(Expr->expr_ops(),
1722 [](auto Op) { return Op.getOp() == dwarf::DW_OP_LLVM_arg; })) {
1723 assert(ArgNo == 0 &&(static_cast <bool> (ArgNo == 0 && "Location Index must be 0 for a non-variadic expression."
) ? void (0) : __assert_fail ("ArgNo == 0 && \"Location Index must be 0 for a non-variadic expression.\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1724, __extension__ __PRETTY_FUNCTION__
))
1724 "Location Index must be 0 for a non-variadic expression.")(static_cast <bool> (ArgNo == 0 && "Location Index must be 0 for a non-variadic expression."
) ? void (0) : __assert_fail ("ArgNo == 0 && \"Location Index must be 0 for a non-variadic expression.\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1724, __extension__ __PRETTY_FUNCTION__
))
;
1725 SmallVector<uint64_t, 8> NewOps(Ops.begin(), Ops.end());
1726 return DIExpression::prependOpcodes(Expr, NewOps, StackValue);
1727 }
1728
1729 SmallVector<uint64_t, 8> NewOps;
1730 for (auto Op : Expr->expr_ops()) {
1731 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
1732 if (StackValue) {
1733 if (Op.getOp() == dwarf::DW_OP_stack_value)
1734 StackValue = false;
1735 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1736 NewOps.push_back(dwarf::DW_OP_stack_value);
1737 StackValue = false;
1738 }
1739 }
1740 Op.appendToVector(NewOps);
1741 if (Op.getOp() == dwarf::DW_OP_LLVM_arg && Op.getArg(0) == ArgNo)
1742 NewOps.insert(NewOps.end(), Ops.begin(), Ops.end());
1743 }
1744 if (StackValue)
1745 NewOps.push_back(dwarf::DW_OP_stack_value);
1746
1747 return DIExpression::get(Expr->getContext(), NewOps);
1748}
1749
1750DIExpression *DIExpression::replaceArg(const DIExpression *Expr,
1751 uint64_t OldArg, uint64_t NewArg) {
1752 assert(Expr && "Can't replace args in this expression")(static_cast <bool> (Expr && "Can't replace args in this expression"
) ? void (0) : __assert_fail ("Expr && \"Can't replace args in this expression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1752, __extension__ __PRETTY_FUNCTION__
))
;
1753
1754 SmallVector<uint64_t, 8> NewOps;
1755
1756 for (auto Op : Expr->expr_ops()) {
1757 if (Op.getOp() != dwarf::DW_OP_LLVM_arg || Op.getArg(0) < OldArg) {
1758 Op.appendToVector(NewOps);
1759 continue;
1760 }
1761 NewOps.push_back(dwarf::DW_OP_LLVM_arg);
1762 uint64_t Arg = Op.getArg(0) == OldArg ? NewArg : Op.getArg(0);
1763 // OldArg has been deleted from the Op list, so decrement all indices
1764 // greater than it.
1765 if (Arg > OldArg)
1766 --Arg;
1767 NewOps.push_back(Arg);
1768 }
1769 return DIExpression::get(Expr->getContext(), NewOps);
1770}
1771
1772DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
1773 SmallVectorImpl<uint64_t> &Ops,
1774 bool StackValue, bool EntryValue) {
1775 assert(Expr && "Can't prepend ops to this expression")(static_cast <bool> (Expr && "Can't prepend ops to this expression"
) ? void (0) : __assert_fail ("Expr && \"Can't prepend ops to this expression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1775, __extension__ __PRETTY_FUNCTION__
))
;
1776
1777 if (EntryValue) {
1778 Ops.push_back(dwarf::DW_OP_LLVM_entry_value);
1779 // Use a block size of 1 for the target register operand. The
1780 // DWARF backend currently cannot emit entry values with a block
1781 // size > 1.
1782 Ops.push_back(1);
1783 }
1784
1785 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
1786 if (Ops.empty())
1787 StackValue = false;
1788 for (auto Op : Expr->expr_ops()) {
1789 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
1790 if (StackValue) {
1791 if (Op.getOp() == dwarf::DW_OP_stack_value)
1792 StackValue = false;
1793 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1794 Ops.push_back(dwarf::DW_OP_stack_value);
1795 StackValue = false;
1796 }
1797 }
1798 Op.appendToVector(Ops);
1799 }
1800 if (StackValue)
1801 Ops.push_back(dwarf::DW_OP_stack_value);
1802 return DIExpression::get(Expr->getContext(), Ops);
1803}
1804
1805DIExpression *DIExpression::append(const DIExpression *Expr,
1806 ArrayRef<uint64_t> Ops) {
1807 assert(Expr && !Ops.empty() && "Can't append ops to this expression")(static_cast <bool> (Expr && !Ops.empty() &&
"Can't append ops to this expression") ? void (0) : __assert_fail
("Expr && !Ops.empty() && \"Can't append ops to this expression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1807, __extension__ __PRETTY_FUNCTION__
))
;
1808
1809 // Copy Expr's current op list.
1810 SmallVector<uint64_t, 16> NewOps;
1811 for (auto Op : Expr->expr_ops()) {
1812 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
1813 if (Op.getOp() == dwarf::DW_OP_stack_value ||
1814 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1815 NewOps.append(Ops.begin(), Ops.end());
1816
1817 // Ensure that the new opcodes are only appended once.
1818 Ops = std::nullopt;
1819 }
1820 Op.appendToVector(NewOps);
1821 }
1822
1823 NewOps.append(Ops.begin(), Ops.end());
1824 auto *result = DIExpression::get(Expr->getContext(), NewOps);
1825 assert(result->isValid() && "concatenated expression is not valid")(static_cast <bool> (result->isValid() && "concatenated expression is not valid"
) ? void (0) : __assert_fail ("result->isValid() && \"concatenated expression is not valid\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1825, __extension__ __PRETTY_FUNCTION__
))
;
1826 return result;
1827}
1828
1829DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
1830 ArrayRef<uint64_t> Ops) {
1831 assert(Expr && !Ops.empty() && "Can't append ops to this expression")(static_cast <bool> (Expr && !Ops.empty() &&
"Can't append ops to this expression") ? void (0) : __assert_fail
("Expr && !Ops.empty() && \"Can't append ops to this expression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1831, __extension__ __PRETTY_FUNCTION__
))
;
1832 assert(none_of(Ops,(static_cast <bool> (none_of(Ops, [](uint64_t Op) { return
Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment
; }) && "Can't append this op") ? 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\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1837, __extension__ __PRETTY_FUNCTION__
))
1833 [](uint64_t Op) {(static_cast <bool> (none_of(Ops, [](uint64_t Op) { return
Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment
; }) && "Can't append this op") ? 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\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1837, __extension__ __PRETTY_FUNCTION__
))
1834 return Op == dwarf::DW_OP_stack_value ||(static_cast <bool> (none_of(Ops, [](uint64_t Op) { return
Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment
; }) && "Can't append this op") ? 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\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1837, __extension__ __PRETTY_FUNCTION__
))
1835 Op == dwarf::DW_OP_LLVM_fragment;(static_cast <bool> (none_of(Ops, [](uint64_t Op) { return
Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment
; }) && "Can't append this op") ? 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\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1837, __extension__ __PRETTY_FUNCTION__
))
1836 }) &&(static_cast <bool> (none_of(Ops, [](uint64_t Op) { return
Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment
; }) && "Can't append this op") ? 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\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1837, __extension__ __PRETTY_FUNCTION__
))
1837 "Can't append this op")(static_cast <bool> (none_of(Ops, [](uint64_t Op) { return
Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment
; }) && "Can't append this op") ? 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\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1837, __extension__ __PRETTY_FUNCTION__
))
;
1838
1839 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
1840 // has no DW_OP_stack_value.
1841 //
1842 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
1843 std::optional<FragmentInfo> FI = Expr->getFragmentInfo();
1844 unsigned DropUntilStackValue = FI ? 3 : 0;
1845 ArrayRef<uint64_t> ExprOpsBeforeFragment =
1846 Expr->getElements().drop_back(DropUntilStackValue);
1847 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
1848 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
1849 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
1850
1851 // Append a DW_OP_deref after Expr's current op list if needed, then append
1852 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
1853 SmallVector<uint64_t, 16> NewOps;
1854 if (NeedsDeref)
1855 NewOps.push_back(dwarf::DW_OP_deref);
1856 NewOps.append(Ops.begin(), Ops.end());
1857 if (NeedsStackValue)
1858 NewOps.push_back(dwarf::DW_OP_stack_value);
1859 return DIExpression::append(Expr, NewOps);
1860}
1861
1862std::optional<DIExpression *> DIExpression::createFragmentExpression(
1863 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
1864 SmallVector<uint64_t, 8> Ops;
1865 // Track whether it's safe to split the value at the top of the DWARF stack,
1866 // assuming that it'll be used as an implicit location value.
1867 bool CanSplitValue = true;
1868 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
1869 if (Expr) {
1
Assuming 'Expr' is null
1870 for (auto Op : Expr->expr_ops()) {
1871 switch (Op.getOp()) {
1872 default:
1873 break;
1874 case dwarf::DW_OP_shr:
1875 case dwarf::DW_OP_shra:
1876 case dwarf::DW_OP_shl:
1877 case dwarf::DW_OP_plus:
1878 case dwarf::DW_OP_plus_uconst:
1879 case dwarf::DW_OP_minus:
1880 // We can't safely split arithmetic or shift operations into multiple
1881 // fragments because we can't express carry-over between fragments.
1882 //
1883 // FIXME: We *could* preserve the lowest fragment of a constant offset
1884 // operation if the offset fits into SizeInBits.
1885 CanSplitValue = false;
1886 break;
1887 case dwarf::DW_OP_deref:
1888 case dwarf::DW_OP_deref_size:
1889 case dwarf::DW_OP_deref_type:
1890 case dwarf::DW_OP_xderef:
1891 case dwarf::DW_OP_xderef_size:
1892 case dwarf::DW_OP_xderef_type:
1893 // Preceeding arithmetic operations have been applied to compute an
1894 // address. It's okay to split the value loaded from that address.
1895 CanSplitValue = true;
1896 break;
1897 case dwarf::DW_OP_stack_value:
1898 // Bail if this expression computes a value that cannot be split.
1899 if (!CanSplitValue)
1900 return std::nullopt;
1901 break;
1902 case dwarf::DW_OP_LLVM_fragment: {
1903 // Make the new offset point into the existing fragment.
1904 uint64_t FragmentOffsetInBits = Op.getArg(0);
1905 uint64_t FragmentSizeInBits = Op.getArg(1);
1906 (void)FragmentSizeInBits;
1907 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&(static_cast <bool> ((OffsetInBits + SizeInBits <= FragmentSizeInBits
) && "new fragment outside of original fragment") ? void
(0) : __assert_fail ("(OffsetInBits + SizeInBits <= FragmentSizeInBits) && \"new fragment outside of original fragment\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1908, __extension__ __PRETTY_FUNCTION__
))
1908 "new fragment outside of original fragment")(static_cast <bool> ((OffsetInBits + SizeInBits <= FragmentSizeInBits
) && "new fragment outside of original fragment") ? void
(0) : __assert_fail ("(OffsetInBits + SizeInBits <= FragmentSizeInBits) && \"new fragment outside of original fragment\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1908, __extension__ __PRETTY_FUNCTION__
))
;
1909 OffsetInBits += FragmentOffsetInBits;
1910 continue;
1911 }
1912 }
1913 Op.appendToVector(Ops);
1914 }
1915 }
1916 assert((!Expr->isImplicit() || CanSplitValue) && "Expr can't be split")(static_cast <bool> ((!Expr->isImplicit() || CanSplitValue
) && "Expr can't be split") ? void (0) : __assert_fail
("(!Expr->isImplicit() || CanSplitValue) && \"Expr can't be split\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1916, __extension__ __PRETTY_FUNCTION__
))
;
2
Taking false branch
3
Called C++ object pointer is null
1917 assert(Expr && "Unknown DIExpression")(static_cast <bool> (Expr && "Unknown DIExpression"
) ? void (0) : __assert_fail ("Expr && \"Unknown DIExpression\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1917, __extension__ __PRETTY_FUNCTION__
))
;
1918 Ops.push_back(dwarf::DW_OP_LLVM_fragment);
1919 Ops.push_back(OffsetInBits);
1920 Ops.push_back(SizeInBits);
1921 return DIExpression::get(Expr->getContext(), Ops);
1922}
1923
1924std::pair<DIExpression *, const ConstantInt *>
1925DIExpression::constantFold(const ConstantInt *CI) {
1926 // Copy the APInt so we can modify it.
1927 APInt NewInt = CI->getValue();
1928 SmallVector<uint64_t, 8> Ops;
1929
1930 // Fold operators only at the beginning of the expression.
1931 bool First = true;
1932 bool Changed = false;
1933 for (auto Op : expr_ops()) {
1934 switch (Op.getOp()) {
1935 default:
1936 // We fold only the leading part of the expression; if we get to a part
1937 // that we're going to copy unchanged, and haven't done any folding,
1938 // then the entire expression is unchanged and we can return early.
1939 if (!Changed)
1940 return {this, CI};
1941 First = false;
1942 break;
1943 case dwarf::DW_OP_LLVM_convert:
1944 if (!First)
1945 break;
1946 Changed = true;
1947 if (Op.getArg(1) == dwarf::DW_ATE_signed)
1948 NewInt = NewInt.sextOrTrunc(Op.getArg(0));
1949 else {
1950 assert(Op.getArg(1) == dwarf::DW_ATE_unsigned && "Unexpected operand")(static_cast <bool> (Op.getArg(1) == dwarf::DW_ATE_unsigned
&& "Unexpected operand") ? void (0) : __assert_fail (
"Op.getArg(1) == dwarf::DW_ATE_unsigned && \"Unexpected operand\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1950, __extension__ __PRETTY_FUNCTION__
))
;
1951 NewInt = NewInt.zextOrTrunc(Op.getArg(0));
1952 }
1953 continue;
1954 }
1955 Op.appendToVector(Ops);
1956 }
1957 if (!Changed)
1958 return {this, CI};
1959 return {DIExpression::get(getContext(), Ops),
1960 ConstantInt::get(getContext(), NewInt)};
1961}
1962
1963uint64_t DIExpression::getNumLocationOperands() const {
1964 uint64_t Result = 0;
1965 for (auto ExprOp : expr_ops())
1966 if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
1967 Result = std::max(Result, ExprOp.getArg(0) + 1);
1968 assert(hasAllLocationOps(Result) &&(static_cast <bool> (hasAllLocationOps(Result) &&
"Expression is missing one or more location operands.") ? void
(0) : __assert_fail ("hasAllLocationOps(Result) && \"Expression is missing one or more location operands.\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1969, __extension__ __PRETTY_FUNCTION__
))
1969 "Expression is missing one or more location operands.")(static_cast <bool> (hasAllLocationOps(Result) &&
"Expression is missing one or more location operands.") ? void
(0) : __assert_fail ("hasAllLocationOps(Result) && \"Expression is missing one or more location operands.\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 1969, __extension__ __PRETTY_FUNCTION__
))
;
1970 return Result;
1971}
1972
1973std::optional<DIExpression::SignedOrUnsignedConstant>
1974DIExpression::isConstant() const {
1975
1976 // Recognize signed and unsigned constants.
1977 // An signed constants can be represented as DW_OP_consts C DW_OP_stack_value
1978 // (DW_OP_LLVM_fragment of Len).
1979 // An unsigned constant can be represented as
1980 // DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment of Len).
1981
1982 if ((getNumElements() != 2 && getNumElements() != 3 &&
1983 getNumElements() != 6) ||
1984 (getElement(0) != dwarf::DW_OP_consts &&
1985 getElement(0) != dwarf::DW_OP_constu))
1986 return std::nullopt;
1987
1988 if (getNumElements() == 2 && getElement(0) == dwarf::DW_OP_consts)
1989 return SignedOrUnsignedConstant::SignedConstant;
1990
1991 if ((getNumElements() == 3 && getElement(2) != dwarf::DW_OP_stack_value) ||
1992 (getNumElements() == 6 && (getElement(2) != dwarf::DW_OP_stack_value ||
1993 getElement(3) != dwarf::DW_OP_LLVM_fragment)))
1994 return std::nullopt;
1995 return getElement(0) == dwarf::DW_OP_constu
1996 ? SignedOrUnsignedConstant::UnsignedConstant
1997 : SignedOrUnsignedConstant::SignedConstant;
1998}
1999
2000DIExpression::ExtOps DIExpression::getExtOps(unsigned FromSize, unsigned ToSize,
2001 bool Signed) {
2002 dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
2003 DIExpression::ExtOps Ops{{dwarf::DW_OP_LLVM_convert, FromSize, TK,
2004 dwarf::DW_OP_LLVM_convert, ToSize, TK}};
2005 return Ops;
2006}
2007
2008DIExpression *DIExpression::appendExt(const DIExpression *Expr,
2009 unsigned FromSize, unsigned ToSize,
2010 bool Signed) {
2011 return appendToStack(Expr, getExtOps(FromSize, ToSize, Signed));
2012}
2013
2014DIGlobalVariableExpression *
2015DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
2016 Metadata *Expression, StorageType Storage,
2017 bool ShouldCreate) {
2018 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 { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2018, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
2019 Metadata *Ops[] = {Variable, Expression};
2020 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops)return storeImpl(new (std::size(Ops), Storage) DIGlobalVariableExpression
(Context, Storage, Ops), Storage, Context.pImpl->DIGlobalVariableExpressions
)
;
2021}
2022DIObjCProperty::DIObjCProperty(LLVMContext &C, StorageType Storage,
2023 unsigned Line, unsigned Attributes,
2024 ArrayRef<Metadata *> Ops)
2025 : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property, Ops),
2026 Line(Line), Attributes(Attributes) {}
2027
2028DIObjCProperty *DIObjCProperty::getImpl(
2029 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
2030 MDString *GetterName, MDString *SetterName, unsigned Attributes,
2031 Metadata *Type, StorageType Storage, bool ShouldCreate) {
2032 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2032, __extension__ __PRETTY_FUNCTION__
))
;
2033 assert(isCanonical(GetterName) && "Expected canonical MDString")(static_cast <bool> (isCanonical(GetterName) &&
"Expected canonical MDString") ? void (0) : __assert_fail ("isCanonical(GetterName) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2033, __extension__ __PRETTY_FUNCTION__
))
;
2034 assert(isCanonical(SetterName) && "Expected canonical MDString")(static_cast <bool> (isCanonical(SetterName) &&
"Expected canonical MDString") ? void (0) : __assert_fail ("isCanonical(SetterName) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2034, __extension__ __PRETTY_FUNCTION__
))
;
2035 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 { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2036, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
2036 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 { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2036, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
2037 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
2038 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops)return storeImpl(new (std::size(Ops), Storage) DIObjCProperty
(Context, Storage, Line, Attributes, Ops), Storage, Context.pImpl
->DIObjCPropertys)
;
2039}
2040
2041DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
2042 Metadata *Scope, Metadata *Entity,
2043 Metadata *File, unsigned Line,
2044 MDString *Name, Metadata *Elements,
2045 StorageType Storage,
2046 bool ShouldCreate) {
2047 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2047, __extension__ __PRETTY_FUNCTION__
))
;
2048 DEFINE_GETIMPL_LOOKUP(DIImportedEntity,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIImportedEntitys, DIImportedEntityInfo::KeyTy(Tag
, Scope, Entity, File, Line, Name, Elements))) return N; if (
!ShouldCreate) return nullptr; } else { (static_cast <bool
> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2049, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
2049 (Tag, Scope, Entity, File, Line, Name, Elements))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIImportedEntitys, DIImportedEntityInfo::KeyTy(Tag
, Scope, Entity, File, Line, Name, Elements))) return N; if (
!ShouldCreate) return nullptr; } else { (static_cast <bool
> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2049, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
2050 Metadata *Ops[] = {Scope, Entity, Name, File, Elements};
2051 DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops)return storeImpl(new (std::size(Ops), Storage) DIImportedEntity
(Context, Storage, Tag, Line, Ops), Storage, Context.pImpl->
DIImportedEntitys)
;
2052}
2053
2054DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
2055 MDString *Name, MDString *Value, StorageType Storage,
2056 bool ShouldCreate) {
2057 assert(isCanonical(Name) && "Expected canonical MDString")(static_cast <bool> (isCanonical(Name) && "Expected canonical MDString"
) ? void (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2057, __extension__ __PRETTY_FUNCTION__
))
;
2058 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 { (static_cast
<bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2058, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
2059 Metadata *Ops[] = {Name, Value};
2060 DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops)return storeImpl(new (std::size(Ops), Storage) DIMacro(Context
, Storage, MIType, Line, Ops), Storage, Context.pImpl->DIMacros
)
;
2061}
2062
2063DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
2064 unsigned Line, Metadata *File,
2065 Metadata *Elements, StorageType Storage,
2066 bool ShouldCreate) {
2067 DEFINE_GETIMPL_LOOKUP(DIMacroFile, (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 { (static_cast <bool> (ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? void (0
) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2067, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
2068 Metadata *Ops[] = {File, Elements};
2069 DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops)return storeImpl(new (std::size(Ops), Storage) DIMacroFile(Context
, Storage, MIType, Line, Ops), Storage, Context.pImpl->DIMacroFiles
)
;
2070}
2071
2072DIArgList *DIArgList::getImpl(LLVMContext &Context,
2073 ArrayRef<ValueAsMetadata *> Args,
2074 StorageType Storage, bool ShouldCreate) {
2075 DEFINE_GETIMPL_LOOKUP(DIArgList, (Args))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIArgLists, DIArgListInfo::KeyTy(Args))) return N;
if (!ShouldCreate) return nullptr; } else { (static_cast <
bool> (ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? void (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2075, __extension__ __PRETTY_FUNCTION__
)); } } while (false)
;
2076 DEFINE_GETIMPL_STORE_NO_OPS(DIArgList, (Args))return storeImpl(new (0u, Storage) DIArgList(Context, Storage
, Args), Storage, Context.pImpl->DIArgLists)
;
2077}
2078
2079void DIArgList::handleChangedOperand(void *Ref, Metadata *New) {
2080 ValueAsMetadata **OldVMPtr = static_cast<ValueAsMetadata **>(Ref);
2081 assert((!New || isa<ValueAsMetadata>(New)) &&(static_cast <bool> ((!New || isa<ValueAsMetadata>
(New)) && "DIArgList must be passed a ValueAsMetadata"
) ? void (0) : __assert_fail ("(!New || isa<ValueAsMetadata>(New)) && \"DIArgList must be passed a ValueAsMetadata\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2082, __extension__ __PRETTY_FUNCTION__
))
2082 "DIArgList must be passed a ValueAsMetadata")(static_cast <bool> ((!New || isa<ValueAsMetadata>
(New)) && "DIArgList must be passed a ValueAsMetadata"
) ? void (0) : __assert_fail ("(!New || isa<ValueAsMetadata>(New)) && \"DIArgList must be passed a ValueAsMetadata\""
, "llvm/lib/IR/DebugInfoMetadata.cpp", 2082, __extension__ __PRETTY_FUNCTION__
))
;
2083 untrack();
2084 bool Uniq = isUniqued();
2085 if (Uniq) {
2086 // We need to update the uniqueness once the Args are updated since they
2087 // form the key to the DIArgLists store.
2088 eraseFromStore();
2089 }
2090 ValueAsMetadata *NewVM = cast_or_null<ValueAsMetadata>(New);
2091 for (ValueAsMetadata *&VM : Args) {
2092 if (&VM == OldVMPtr) {
2093 if (NewVM)
2094 VM = NewVM;
2095 else
2096 VM = ValueAsMetadata::get(PoisonValue::get(VM->getValue()->getType()));
2097 }
2098 }
2099 if (Uniq) {
2100 if (uniquify() != this)
2101 storeDistinctInContext();
2102 }
2103 track();
2104}
2105void DIArgList::track() {
2106 for (ValueAsMetadata *&VAM : Args)
2107 if (VAM)
2108 MetadataTracking::track(&VAM, *VAM, *this);
2109}
2110void DIArgList::untrack() {
2111 for (ValueAsMetadata *&VAM : Args)
2112 if (VAM)
2113 MetadataTracking::untrack(&VAM, *VAM);
2114}
2115void DIArgList::dropAllReferences() {
2116 untrack();
2117 Args.clear();
2118 MDNode::dropAllReferences();
2119}