LLVM  4.0.0
DebugInfoMetadata.cpp
Go to the documentation of this file.
1 //===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the debug info Metadata classes.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "LLVMContextImpl.h"
16 #include "MetadataImpl.h"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/IR/Function.h"
19 
20 using namespace llvm;
21 
22 DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
23  unsigned Column, ArrayRef<Metadata *> MDs)
24  : MDNode(C, DILocationKind, Storage, MDs) {
25  assert((MDs.size() == 1 || MDs.size() == 2) &&
26  "Expected a scope and optional inlined-at");
27 
28  // Set line and column.
29  assert(Column < (1u << 16) && "Expected 16-bit column");
30 
31  SubclassData32 = Line;
32  SubclassData16 = Column;
33 }
34 
35 static void adjustColumn(unsigned &Column) {
36  // Set to unknown on overflow. We only have 16 bits to play with here.
37  if (Column >= (1u << 16))
38  Column = 0;
39 }
40 
41 DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
42  unsigned Column, Metadata *Scope,
43  Metadata *InlinedAt, StorageType Storage,
44  bool ShouldCreate) {
45  // Fixup column.
46  adjustColumn(Column);
47 
48  if (Storage == Uniqued) {
49  if (auto *N =
50  getUniqued(Context.pImpl->DILocations,
51  DILocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
52  return N;
53  if (!ShouldCreate)
54  return nullptr;
55  } else {
56  assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
57  }
58 
60  Ops.push_back(Scope);
61  if (InlinedAt)
62  Ops.push_back(InlinedAt);
63  return storeImpl(new (Ops.size())
64  DILocation(Context, Storage, Line, Column, Ops),
65  Storage, Context.pImpl->DILocations);
66 }
67 
70 #define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
71 #include "llvm/IR/DebugInfoFlags.def"
72  .Default(DINode::FlagZero);
73 }
74 
76  switch (Flag) {
77 #define HANDLE_DI_FLAG(ID, NAME) \
78  case Flag##NAME: \
79  return "DIFlag" #NAME;
80 #include "llvm/IR/DebugInfoFlags.def"
81  }
82  return "";
83 }
84 
86  SmallVectorImpl<DIFlags> &SplitFlags) {
87  // Flags that are packed together need to be specially handled, so
88  // that, for example, we emit "DIFlagPublic" and not
89  // "DIFlagPrivate | DIFlagProtected".
90  if (DIFlags A = Flags & FlagAccessibility) {
91  if (A == FlagPrivate)
92  SplitFlags.push_back(FlagPrivate);
93  else if (A == FlagProtected)
94  SplitFlags.push_back(FlagProtected);
95  else
96  SplitFlags.push_back(FlagPublic);
97  Flags &= ~A;
98  }
99  if (DIFlags R = Flags & FlagPtrToMemberRep) {
100  if (R == FlagSingleInheritance)
101  SplitFlags.push_back(FlagSingleInheritance);
102  else if (R == FlagMultipleInheritance)
103  SplitFlags.push_back(FlagMultipleInheritance);
104  else
105  SplitFlags.push_back(FlagVirtualInheritance);
106  Flags &= ~R;
107  }
108  if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
109  Flags &= ~FlagIndirectVirtualBase;
110  SplitFlags.push_back(FlagIndirectVirtualBase);
111  }
112 
113 #define HANDLE_DI_FLAG(ID, NAME) \
114  if (DIFlags Bit = Flags & Flag##NAME) { \
115  SplitFlags.push_back(Bit); \
116  Flags &= ~Bit; \
117  }
118 #include "llvm/IR/DebugInfoFlags.def"
119  return Flags;
120 }
121 
123  if (auto *T = dyn_cast<DIType>(this))
124  return T->getScope();
125 
126  if (auto *SP = dyn_cast<DISubprogram>(this))
127  return SP->getScope();
128 
129  if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
130  return LB->getScope();
131 
132  if (auto *NS = dyn_cast<DINamespace>(this))
133  return NS->getScope();
134 
135  if (auto *M = dyn_cast<DIModule>(this))
136  return M->getScope();
137 
138  assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
139  "Unhandled type of scope.");
140  return nullptr;
141 }
142 
144  if (auto *T = dyn_cast<DIType>(this))
145  return T->getName();
146  if (auto *SP = dyn_cast<DISubprogram>(this))
147  return SP->getName();
148  if (auto *NS = dyn_cast<DINamespace>(this))
149  return NS->getName();
150  if (auto *M = dyn_cast<DIModule>(this))
151  return M->getName();
152  assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
153  isa<DICompileUnit>(this)) &&
154  "Unhandled type of scope.");
155  return "";
156 }
157 
158 #ifndef NDEBUG
159 static bool isCanonical(const MDString *S) {
160  return !S || !S->getString().empty();
161 }
162 #endif
163 
164 GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
165  MDString *Header,
166  ArrayRef<Metadata *> DwarfOps,
167  StorageType Storage, bool ShouldCreate) {
168  unsigned Hash = 0;
169  if (Storage == Uniqued) {
170  GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
171  if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
172  return N;
173  if (!ShouldCreate)
174  return nullptr;
175  Hash = Key.getHash();
176  } else {
177  assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
178  }
179 
180  // Use a nullptr for empty headers.
181  assert(isCanonical(Header) && "Expected canonical MDString");
182  Metadata *PreOps[] = {Header};
183  return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
184  Context, Storage, Hash, Tag, PreOps, DwarfOps),
185  Storage, Context.pImpl->GenericDINodes);
186 }
187 
188 void GenericDINode::recalculateHash() {
189  setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
190 }
191 
192 #define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
193 #define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
194 #define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
195  do { \
196  if (Storage == Uniqued) { \
197  if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
198  CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
199  return N; \
200  if (!ShouldCreate) \
201  return nullptr; \
202  } else { \
203  assert(ShouldCreate && \
204  "Expected non-uniqued nodes to always be created"); \
205  } \
206  } while (false)
207 #define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
208  return storeImpl(new (array_lengthof(OPS)) \
209  CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
210  Storage, Context.pImpl->CLASS##s)
211 #define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
212  return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
213  Storage, Context.pImpl->CLASS##s)
214 #define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
215  return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \
216  Storage, Context.pImpl->CLASS##s)
217 
218 DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
219  StorageType Storage, bool ShouldCreate) {
220  DEFINE_GETIMPL_LOOKUP(DISubrange, (Count, Lo));
222 }
223 
224 DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
225  MDString *Name, StorageType Storage,
226  bool ShouldCreate) {
227  assert(isCanonical(Name) && "Expected canonical MDString");
228  DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, Name));
229  Metadata *Ops[] = {Name};
230  DEFINE_GETIMPL_STORE(DIEnumerator, (Value), Ops);
231 }
232 
233 DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
234  MDString *Name, uint64_t SizeInBits,
235  uint32_t AlignInBits, unsigned Encoding,
236  StorageType Storage, bool ShouldCreate) {
237  assert(isCanonical(Name) && "Expected canonical MDString");
239  (Tag, Name, SizeInBits, AlignInBits, Encoding));
240  Metadata *Ops[] = {nullptr, nullptr, Name};
241  DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
242  Ops);
243 }
244 
245 DIDerivedType *DIDerivedType::getImpl(
246  LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
247  unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
248  uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
249  Metadata *ExtraData, StorageType Storage, bool ShouldCreate) {
250  assert(isCanonical(Name) && "Expected canonical MDString");
252  (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
253  AlignInBits, OffsetInBits, Flags, ExtraData));
254  Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
256  DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags),
257  Ops);
258 }
259 
260 DICompositeType *DICompositeType::getImpl(
261  LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
262  unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
263  uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
264  Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
265  Metadata *TemplateParams, MDString *Identifier, StorageType Storage,
266  bool ShouldCreate) {
267  assert(isCanonical(Name) && "Expected canonical MDString");
268 
269  // Keep this in sync with buildODRType.
271  DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
272  AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
273  VTableHolder, TemplateParams, Identifier));
274  Metadata *Ops[] = {File, Scope, Name, BaseType,
275  Elements, VTableHolder, TemplateParams, Identifier};
276  DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
277  AlignInBits, OffsetInBits, Flags),
278  Ops);
279 }
280 
282  LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
283  Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
284  uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
285  DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
286  Metadata *VTableHolder, Metadata *TemplateParams) {
287  assert(!Identifier.getString().empty() && "Expected valid identifier");
288  if (!Context.isODRUniquingDebugTypes())
289  return nullptr;
290  auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
291  if (!CT)
292  return CT = DICompositeType::getDistinct(
293  Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
294  AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
295  VTableHolder, TemplateParams, &Identifier);
296 
297  // Only mutate CT if it's a forward declaration and the new operands aren't.
298  assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
299  if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
300  return CT;
301 
302  // Mutate CT in place. Keep this in sync with getImpl.
303  CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
304  Flags);
305  Metadata *Ops[] = {File, Scope, Name, BaseType,
306  Elements, VTableHolder, TemplateParams, &Identifier};
307  assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
308  "Mismatched number of operands");
309  for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
310  if (Ops[I] != CT->getOperand(I))
311  CT->setOperand(I, Ops[I]);
312  return CT;
313 }
314 
315 DICompositeType *DICompositeType::getODRType(
316  LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
317  Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
318  uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
319  DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
320  Metadata *VTableHolder, Metadata *TemplateParams) {
321  assert(!Identifier.getString().empty() && "Expected valid identifier");
322  if (!Context.isODRUniquingDebugTypes())
323  return nullptr;
324  auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
325  if (!CT)
327  Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
328  AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
329  TemplateParams, &Identifier);
330  return CT;
331 }
332 
334  MDString &Identifier) {
335  assert(!Identifier.getString().empty() && "Expected valid identifier");
336  if (!Context.isODRUniquingDebugTypes())
337  return nullptr;
338  return Context.pImpl->DITypeMap->lookup(&Identifier);
339 }
340 
341 DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
342  uint8_t CC, Metadata *TypeArray,
343  StorageType Storage,
344  bool ShouldCreate) {
345  DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray));
346  Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
347  DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops);
348 }
349 
350 static const char *ChecksumKindName[DIFile::CSK_Last + 1] = {
351  "CSK_None",
352  "CSK_MD5",
353  "CSK_SHA1"
354 };
355 
357  return StringSwitch<DIFile::ChecksumKind>(CSKindStr)
358  .Case("CSK_MD5", DIFile::CSK_MD5)
359  .Case("CSK_SHA1", DIFile::CSK_SHA1)
361 }
362 
363 StringRef DIFile::getChecksumKindAsString() const {
364  assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
365  return ChecksumKindName[CSKind];
366 }
367 
368 DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
369  MDString *Directory, DIFile::ChecksumKind CSKind,
370  MDString *Checksum, StorageType Storage,
371  bool ShouldCreate) {
372  assert(isCanonical(Filename) && "Expected canonical MDString");
373  assert(isCanonical(Directory) && "Expected canonical MDString");
374  assert(isCanonical(Checksum) && "Expected canonical MDString");
375  DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CSKind, Checksum));
376  Metadata *Ops[] = {Filename, Directory, Checksum};
377  DEFINE_GETIMPL_STORE(DIFile, (CSKind), Ops);
378 }
379 
380 DICompileUnit *DICompileUnit::getImpl(
381  LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
382  MDString *Producer, bool IsOptimized, MDString *Flags,
383  unsigned RuntimeVersion, MDString *SplitDebugFilename,
384  unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
385  Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
386  uint64_t DWOId, bool SplitDebugInlining, StorageType Storage,
387  bool ShouldCreate) {
388  assert(Storage != Uniqued && "Cannot unique DICompileUnit");
389  assert(isCanonical(Producer) && "Expected canonical MDString");
390  assert(isCanonical(Flags) && "Expected canonical MDString");
391  assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
392 
393  Metadata *Ops[] = {
396  Macros};
397  return storeImpl(new (array_lengthof(Ops))
398  DICompileUnit(Context, Storage, SourceLanguage,
399  IsOptimized, RuntimeVersion, EmissionKind,
400  DWOId, SplitDebugInlining, Ops),
401  Storage);
402 }
403 
407  .Case("NoDebug", NoDebug)
408  .Case("FullDebug", FullDebug)
409  .Case("LineTablesOnly", LineTablesOnly)
410  .Default(None);
411 }
412 
414  switch (EK) {
415  case NoDebug: return "NoDebug";
416  case FullDebug: return "FullDebug";
417  case LineTablesOnly: return "LineTablesOnly";
418  }
419  return nullptr;
420 }
421 
423  if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
424  return Block->getScope()->getSubprogram();
425  return const_cast<DISubprogram *>(cast<DISubprogram>(this));
426 }
427 
429  if (auto *File = dyn_cast<DILexicalBlockFile>(this))
430  return File->getScope()->getNonLexicalBlockFileScope();
431  return const_cast<DILocalScope *>(this);
432 }
433 
434 DISubprogram *DISubprogram::getImpl(
435  LLVMContext &Context, Metadata *Scope, MDString *Name,
436  MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
437  bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
438  Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
439  int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit,
440  Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
441  StorageType Storage, bool ShouldCreate) {
442  assert(isCanonical(Name) && "Expected canonical MDString");
443  assert(isCanonical(LinkageName) && "Expected canonical MDString");
445  DISubprogram,
446  (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
447  ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment,
448  Flags, IsOptimized, Unit, TemplateParams, Declaration, Variables));
449  Metadata *Ops[] = {File, Scope, Name, Name,
451  TemplateParams, Declaration, Variables};
452  DEFINE_GETIMPL_STORE(DISubprogram, (Line, ScopeLine, Virtuality, VirtualIndex,
453  ThisAdjustment, Flags, IsLocalToUnit,
454  IsDefinition, IsOptimized),
455  Ops);
456 }
457 
458 bool DISubprogram::describes(const Function *F) const {
459  assert(F && "Invalid function");
460  if (F->getSubprogram() == this)
461  return true;
462  StringRef Name = getLinkageName();
463  if (Name.empty())
464  Name = getName();
465  return F->getName() == Name;
466 }
467 
468 DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
469  Metadata *File, unsigned Line,
470  unsigned Column, StorageType Storage,
471  bool ShouldCreate) {
472  // Fixup column.
473  adjustColumn(Column);
474 
475  assert(Scope && "Expected scope");
476  DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
477  Metadata *Ops[] = {File, Scope};
478  DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
479 }
480 
481 DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
482  Metadata *Scope, Metadata *File,
483  unsigned Discriminator,
484  StorageType Storage,
485  bool ShouldCreate) {
486  assert(Scope && "Expected scope");
487  DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
488  Metadata *Ops[] = {File, Scope};
489  DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
490 }
491 
492 DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
493  Metadata *File, MDString *Name, unsigned Line,
494  bool ExportSymbols, StorageType Storage,
495  bool ShouldCreate) {
496  assert(isCanonical(Name) && "Expected canonical MDString");
497  DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, Name, Line, ExportSymbols));
498  Metadata *Ops[] = {File, Scope, Name};
499  DEFINE_GETIMPL_STORE(DINamespace, (Line, ExportSymbols), Ops);
500 }
501 
502 DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
503  MDString *Name, MDString *ConfigurationMacros,
504  MDString *IncludePath, MDString *ISysRoot,
505  StorageType Storage, bool ShouldCreate) {
506  assert(isCanonical(Name) && "Expected canonical MDString");
508  DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot));
509  Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
511 }
512 
513 DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
514  MDString *Name,
515  Metadata *Type,
516  StorageType Storage,
517  bool ShouldCreate) {
518  assert(isCanonical(Name) && "Expected canonical MDString");
520  Metadata *Ops[] = {Name, Type};
522 }
523 
524 DITemplateValueParameter *DITemplateValueParameter::getImpl(
525  LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
526  Metadata *Value, StorageType Storage, bool ShouldCreate) {
527  assert(isCanonical(Name) && "Expected canonical MDString");
528  DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value));
529  Metadata *Ops[] = {Name, Type, Value};
531 }
532 
534 DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
535  MDString *LinkageName, Metadata *File, unsigned Line,
536  Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
537  Metadata *StaticDataMemberDeclaration,
538  uint32_t AlignInBits, StorageType Storage,
539  bool ShouldCreate) {
540  assert(isCanonical(Name) && "Expected canonical MDString");
541  assert(isCanonical(LinkageName) && "Expected canonical MDString");
543  (Scope, Name, LinkageName, File, Line, Type,
544  IsLocalToUnit, IsDefinition,
545  StaticDataMemberDeclaration, AlignInBits));
546  Metadata *Ops[] = {
547  Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration};
549  (Line, IsLocalToUnit, IsDefinition, AlignInBits),
550  Ops);
551 }
552 
553 DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
554  MDString *Name, Metadata *File,
555  unsigned Line, Metadata *Type,
556  unsigned Arg, DIFlags Flags,
557  uint32_t AlignInBits,
558  StorageType Storage,
559  bool ShouldCreate) {
560  // 64K ought to be enough for any frontend.
561  assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
562 
563  assert(Scope && "Expected scope");
564  assert(isCanonical(Name) && "Expected canonical MDString");
566  (Scope, Name, File, Line, Type, Arg, Flags,
567  AlignInBits));
568  Metadata *Ops[] = {Scope, Name, File, Type};
569  DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
570 }
571 
572 DIExpression *DIExpression::getImpl(LLVMContext &Context,
573  ArrayRef<uint64_t> Elements,
574  StorageType Storage, bool ShouldCreate) {
575  DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
577 }
578 
580  switch (getOp()) {
582  return 3;
583  case dwarf::DW_OP_constu:
584  case dwarf::DW_OP_plus:
585  case dwarf::DW_OP_minus:
586  return 2;
587  default:
588  return 1;
589  }
590 }
591 
592 bool DIExpression::isValid() const {
593  for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
594  // Check that there's space for the operand.
595  if (I->get() + I->getSize() > E->get())
596  return false;
597 
598  // Check that the operand is valid.
599  switch (I->getOp()) {
600  default:
601  return false;
603  // A fragment operator must appear at the end.
604  return I->get() + I->getSize() == E->get();
605  case dwarf::DW_OP_stack_value: {
606  // Must be the last one or followed by a DW_OP_LLVM_fragment.
607  if (I->get() + I->getSize() == E->get())
608  break;
609  auto J = I;
610  if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
611  return false;
612  break;
613  }
614  case dwarf::DW_OP_constu:
615  case dwarf::DW_OP_plus:
616  case dwarf::DW_OP_minus:
617  case dwarf::DW_OP_deref:
618  break;
619  }
620  }
621  return true;
622 }
623 
626  for (auto I = Start; I != End; ++I)
627  if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
628  DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
629  return Info;
630  }
631  return None;
632 }
633 
635  // Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
636  if (getNumElements() != 3 && getNumElements() != 6)
637  return false;
638  if (getElement(0) != dwarf::DW_OP_constu ||
639  getElement(2) != dwarf::DW_OP_stack_value)
640  return false;
642  return false;
643  return true;
644 }
645 
647 DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
648  Metadata *Expression, StorageType Storage,
649  bool ShouldCreate) {
650  DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression));
651  Metadata *Ops[] = {Variable, Expression};
653 }
654 
655 DIObjCProperty *DIObjCProperty::getImpl(
656  LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
657  MDString *GetterName, MDString *SetterName, unsigned Attributes,
658  Metadata *Type, StorageType Storage, bool ShouldCreate) {
659  assert(isCanonical(Name) && "Expected canonical MDString");
660  assert(isCanonical(GetterName) && "Expected canonical MDString");
661  assert(isCanonical(SetterName) && "Expected canonical MDString");
662  DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,
663  SetterName, Attributes, Type));
664  Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
665  DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
666 }
667 
668 DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
669  Metadata *Scope, Metadata *Entity,
670  unsigned Line, MDString *Name,
671  StorageType Storage,
672  bool ShouldCreate) {
673  assert(isCanonical(Name) && "Expected canonical MDString");
674  DEFINE_GETIMPL_LOOKUP(DIImportedEntity, (Tag, Scope, Entity, Line, Name));
675  Metadata *Ops[] = {Scope, Entity, Name};
676  DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
677 }
678 
679 DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
680  unsigned Line, MDString *Name, MDString *Value,
681  StorageType Storage, bool ShouldCreate) {
682  assert(isCanonical(Name) && "Expected canonical MDString");
683  DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value));
684  Metadata *Ops[] = { Name, Value };
685  DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
686 }
687 
688 DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
689  unsigned Line, Metadata *File,
690  Metadata *Elements, StorageType Storage,
691  bool ShouldCreate) {
693  (MIType, Line, File, Elements));
694  Metadata *Ops[] = { File, Elements };
695  DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
696 }
697 
Metadata MDString MDString * ConfigurationMacros
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:241
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition: Metadata.h:66
LLVMContext & Context
MDString MDString * Directory
static DICompositeType * getODRTypeIfExists(LLVMContext &Context, MDString &Identifier)
unsigned MDString Metadata unsigned Metadata Metadata * BaseType
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1140
uint64_t getElement(unsigned I) const
const_iterator begin(StringRef path)
Get begin iterator over path.
Definition: Path.cpp:233
static bool isCanonical(const MDString *S)
Metadata node.
Definition: Metadata.h:830
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
Definition: MetadataImpl.h:43
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata * TemplateParams
unsigned Metadata MDString bool MDString * Flags
unsigned MDString Metadata * Type
A scope for locals.
#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS)
Metadata MDString MDString Metadata unsigned Metadata * Type
DebugEmissionKind getEmissionKind() const
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:191
bool isODRUniquingDebugTypes() const
Whether there is a string map for uniquing debug info identifiers across the context.
DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
struct fuzzer::@269 Flags
Array subrange.
unsigned Metadata MDString * Producer
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:32
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
Definition: StringSwitch.h:244
MDString * Filename
unsigned Metadata MDString bool MDString unsigned MDString * SplitDebugFilename
static const char * EmissionKindString(DebugEmissionKind EK)
Only used in LLVM metadata.
Definition: Dwarf.h:112
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata * GlobalVariables
Holds a subclass of DINode.
Subprogram description.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:74
#define F(x, y, z)
Definition: MD5.cpp:51
unsigned StringRef DIFile unsigned DIScopeRef DITypeRef BaseType
Holds the characteristics of one fragment of a larger variable.
unsigned StringRef DIFile * File
expr_op_iterator expr_op_begin() const
Visit the elements via ExprOperand wrappers.
Enumeration value.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Metadata MDString * Name
DIScopeRef getScope() const
Debug location.
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata * Elements
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:141
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:121
static ChecksumKind getChecksumKind(StringRef CSKindStr)
static StringRef getFlagString(DIFlags Flag)
Metadata MDString MDString Metadata unsigned Metadata bool bool unsigned Metadata unsigned unsigned int DIFlags bool Metadata Metadata * TemplateParams
Metadata MDString MDString Metadata * File
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
static T * getUniqued(DenseSet< T *, InfoT > &Store, const typename InfoT::KeyTy &Key)
Definition: MetadataImpl.h:23
unsigned getNumElements() const
unsigned StringRef Name
StringRef getName() const
unsigned MDString * Name
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
static DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder, Metadata *TemplateParams)
Build a DICompositeType with the given ODR identifier.
Metadata Metadata * File
#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS)
static void adjustColumn(unsigned &Column)
SourceLanguage
Definition: Dwarf.h:166
unsigned getSize() const
Return the size of the operand.
unsigned StringRef DIFile unsigned DIScopeRef Scope
Metadata Metadata * File
unsigned Metadata * File
StorageType
Active type of storage.
Definition: Metadata.h:63
A pair of DIGlobalVariable and DIExpression.
static const unsigned End
Metadata MDString MDString * LinkageName
Metadata Metadata * File
Metadata MDString * Name
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata * RetainedTypes
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:50
Metadata MDString MDString Metadata unsigned Metadata bool bool unsigned Metadata unsigned unsigned int DIFlags bool Metadata Metadata Metadata * Declaration
An imported module (C++ using directive or similar).
#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS)
StringRef getString() const
Definition: Metadata.cpp:424
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
Metadata MDString MDString * LinkageName
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Definition: STLExtras.h:649
static DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
Optional< FragmentInfo > getFragmentInfo() const
Retrieve the details of this fragment expression.
DWARF expression.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
Metadata MDString MDString Metadata unsigned Metadata bool bool unsigned Metadata * ContainingType
static DIFlags getFlag(StringRef Flag)
A (clang) module that has been imported by the compile unit.
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1458
Metadata MDString MDString Metadata unsigned Metadata bool bool unsigned Metadata unsigned unsigned int DIFlags bool Metadata * Unit
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata * EnumTypes
Generic tagged DWARF-like metadata node.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:130
Metadata MDString Metadata * File
#define HANDLE_DI_FLAG(ID, NAME)
Type array for a subprogram.
DIFlags
Debug info flags.
static const char * ChecksumKindName[DIFile::CSK_Last+1]
Metadata MDString MDString Metadata * File
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
Metadata MDString * Name
Metadata MDString MDString MDString * IncludePath
unsigned MDString Metadata unsigned Metadata * Scope
bool isConstant() const
Determine whether this represents a standalone constant value.
std::vector< uint8_t > Unit
Definition: FuzzerDefs.h:71
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata * VTableHolder
LLVM Value Representation.
Definition: Value.h:71
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata * ImportedEntities
#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS)
Metadata MDString MDString Metadata unsigned Metadata * Type
An iterator for expression operands.
uint64_t getOp() const
Get the operand code.
std::string Hash(const Unit &U)
Definition: FuzzerSHA1.cpp:216
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
A single uniqued string.
Definition: Metadata.h:586
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
expr_op_iterator expr_op_end() const
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
Optional< DenseMap< const MDString *, DICompositeType * > > DITypeMap
Root of the metadata hierarchy.
Definition: Metadata.h:55
Metadata MDString * Name
unsigned MDString Metadata * File
Basic type, like 'int' or 'float'.