clang  3.8.0
CGDebugInfo.h
Go to the documentation of this file.
1 //===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This is the source-level debug info generator for llvm translation.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
16 
17 #include "CGBuilder.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/Type.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/IR/DIBuilder.h"
25 #include "llvm/IR/DebugInfo.h"
26 #include "llvm/IR/ValueHandle.h"
27 #include "llvm/Support/Allocator.h"
28 
29 namespace llvm {
30 class MDNode;
31 }
32 
33 namespace clang {
34 class CXXMethodDecl;
35 class ClassTemplateSpecializationDecl;
36 class GlobalDecl;
37 class ModuleMap;
38 class ObjCInterfaceDecl;
39 class ObjCIvarDecl;
40 class UsingDecl;
41 class VarDecl;
42 
43 namespace CodeGen {
44 class CodeGenModule;
45 class CodeGenFunction;
46 class CGBlockInfo;
47 
48 /// This class gathers all debug information during compilation and is
49 /// responsible for emitting to llvm globals or pass directly to the
50 /// backend.
51 class CGDebugInfo {
52  friend class ApplyDebugLocation;
53  friend class SaveAndRestoreLocation;
54  CodeGenModule &CGM;
55  const CodeGenOptions::DebugInfoKind DebugKind;
56  bool DebugTypeExtRefs;
57  llvm::DIBuilder DBuilder;
58  llvm::DICompileUnit *TheCU = nullptr;
59  ModuleMap *ClangModuleMap = nullptr;
60  SourceLocation CurLoc;
61  llvm::DIType *VTablePtrType = nullptr;
62  llvm::DIType *ClassTy = nullptr;
63  llvm::DICompositeType *ObjTy = nullptr;
64  llvm::DIType *SelTy = nullptr;
65  llvm::DIType *OCLImage1dDITy = nullptr;
66  llvm::DIType *OCLImage1dArrayDITy = nullptr;
67  llvm::DIType *OCLImage1dBufferDITy = nullptr;
68  llvm::DIType *OCLImage2dDITy = nullptr;
69  llvm::DIType *OCLImage2dArrayDITy = nullptr;
70  llvm::DIType *OCLImage2dDepthDITy = nullptr;
71  llvm::DIType *OCLImage2dArrayDepthDITy = nullptr;
72  llvm::DIType *OCLImage2dMSAADITy = nullptr;
73  llvm::DIType *OCLImage2dArrayMSAADITy = nullptr;
74  llvm::DIType *OCLImage2dMSAADepthDITy = nullptr;
75  llvm::DIType *OCLImage2dArrayMSAADepthDITy = nullptr;
76  llvm::DIType *OCLImage3dDITy = nullptr;
77  llvm::DIType *OCLEventDITy = nullptr;
78  llvm::DIType *OCLClkEventDITy = nullptr;
79  llvm::DIType *OCLQueueDITy = nullptr;
80  llvm::DIType *OCLNDRangeDITy = nullptr;
81  llvm::DIType *OCLReserveIDDITy = nullptr;
82 
83  /// Cache of previously constructed Types.
84  llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
85 
86  llvm::SmallDenseMap<llvm::StringRef, llvm::StringRef> DebugPrefixMap;
87 
88  struct ObjCInterfaceCacheEntry {
89  const ObjCInterfaceType *Type;
90  llvm::DIType *Decl;
91  llvm::DIFile *Unit;
92  ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType *Decl,
93  llvm::DIFile *Unit)
94  : Type(Type), Decl(Decl), Unit(Unit) {}
95  };
96 
97  /// Cache of previously constructed interfaces which may change.
99 
100  /// Cache of references to clang modules and precompiled headers.
101  llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
102 
103  /// List of interfaces we want to keep even if orphaned.
104  std::vector<void *> RetainedTypes;
105 
106  /// Cache of forward declared types to RAUW at the end of
107  /// compilation.
108  std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
109 
110  /// Cache of replaceable forward declarartions (functions and
111  /// variables) to RAUW at the end of compilation.
112  std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
113  FwdDeclReplaceMap;
114 
115  /// Keep track of our current nested lexical block.
116  std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
117  llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
118  /// Keep track of LexicalBlockStack counter at the beginning of a
119  /// function. This is used to pop unbalanced regions at the end of a
120  /// function.
121  std::vector<unsigned> FnBeginRegionCount;
122 
123  /// This is a storage for names that are constructed on demand. For
124  /// example, C++ destructors, C++ operators etc..
125  llvm::BumpPtrAllocator DebugInfoNames;
126  StringRef CWDName;
127 
128  llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
129  llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
130  /// Cache declarations relevant to DW_TAG_imported_declarations (C++
131  /// using declarations) that aren't covered by other more specific caches.
132  llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
133  llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NameSpaceCache;
134  llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
135  NamespaceAliasCache;
136  llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
137  StaticDataMemberCache;
138 
139  /// Helper functions for getOrCreateType.
140  /// @{
141  /// Currently the checksum of an interface includes the number of
142  /// ivars and property accessors.
143  llvm::DIType *CreateType(const BuiltinType *Ty);
144  llvm::DIType *CreateType(const ComplexType *Ty);
145  llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
146  llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
147  llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
148  llvm::DIFile *Fg);
149  llvm::DIType *CreateType(const ObjCObjectPointerType *Ty, llvm::DIFile *F);
150  llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
151  llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
152  llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
153  /// Get structure or union type.
154  llvm::DIType *CreateType(const RecordType *Tyg);
155  llvm::DIType *CreateTypeDefinition(const RecordType *Ty);
156  llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
157  void CollectContainingType(const CXXRecordDecl *RD,
158  llvm::DICompositeType *CT);
159  /// Get Objective-C interface type.
160  llvm::DIType *CreateType(const ObjCInterfaceType *Ty, llvm::DIFile *F);
161  llvm::DIType *CreateTypeDefinition(const ObjCInterfaceType *Ty,
162  llvm::DIFile *F);
163  /// Get Objective-C object type.
164  llvm::DIType *CreateType(const ObjCObjectType *Ty, llvm::DIFile *F);
165  llvm::DIType *CreateType(const VectorType *Ty, llvm::DIFile *F);
166  llvm::DIType *CreateType(const ArrayType *Ty, llvm::DIFile *F);
167  llvm::DIType *CreateType(const LValueReferenceType *Ty, llvm::DIFile *F);
168  llvm::DIType *CreateType(const RValueReferenceType *Ty, llvm::DIFile *Unit);
169  llvm::DIType *CreateType(const MemberPointerType *Ty, llvm::DIFile *F);
170  llvm::DIType *CreateType(const AtomicType *Ty, llvm::DIFile *F);
171  llvm::DIType *CreateType(const PipeType *Ty, llvm::DIFile *F);
172  /// Get enumeration type.
173  llvm::DIType *CreateEnumType(const EnumType *Ty);
174  llvm::DIType *CreateTypeDefinition(const EnumType *Ty);
175  /// Look up the completed type for a self pointer in the TypeCache and
176  /// create a copy of it with the ObjectPointer and Artificial flags
177  /// set. If the type is not cached, a new one is created. This should
178  /// never happen though, since creating a type for the implicit self
179  /// argument implies that we already parsed the interface definition
180  /// and the ivar declarations in the implementation.
181  llvm::DIType *CreateSelfType(const QualType &QualTy, llvm::DIType *Ty);
182  /// @}
183 
184  /// Get the type from the cache or return null type if it doesn't
185  /// exist.
186  llvm::DIType *getTypeOrNull(const QualType);
187  /// Return the debug type for a C++ method.
188  /// \arg CXXMethodDecl is of FunctionType. This function type is
189  /// not updated to include implicit \c this pointer. Use this routine
190  /// to get a method type which includes \c this pointer.
191  llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
192  llvm::DIFile *F);
193  llvm::DISubroutineType *
194  getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func,
195  llvm::DIFile *Unit);
196  llvm::DISubroutineType *
197  getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
198  /// \return debug info descriptor for vtable.
199  llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
200  /// \return namespace descriptor for the given namespace decl.
201  llvm::DINamespace *getOrCreateNameSpace(const NamespaceDecl *N);
202  llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
203  QualType PointeeTy, llvm::DIFile *F);
204  llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
205 
206  /// A helper function to create a subprogram for a single member
207  /// function GlobalDecl.
208  llvm::DISubprogram *CreateCXXMemberFunction(const CXXMethodDecl *Method,
209  llvm::DIFile *F,
210  llvm::DIType *RecordTy);
211 
212  /// A helper function to collect debug info for C++ member
213  /// functions. This is used while creating debug info entry for a
214  /// Record.
215  void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile *F,
217  llvm::DIType *T);
218 
219  /// A helper function to collect debug info for C++ base
220  /// classes. This is used while creating debug info entry for a
221  /// Record.
222  void CollectCXXBases(const CXXRecordDecl *Decl, llvm::DIFile *F,
224  llvm::DIType *RecordTy);
225 
226  /// A helper function to collect template parameters.
227  llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList,
229  llvm::DIFile *Unit);
230  /// A helper function to collect debug info for function template
231  /// parameters.
232  llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
233  llvm::DIFile *Unit);
234 
235  /// A helper function to collect debug info for template
236  /// parameters.
237  llvm::DINodeArray
238  CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS,
239  llvm::DIFile *F);
240 
241  llvm::DIType *createFieldType(StringRef name, QualType type,
242  uint64_t sizeInBitsOverride, SourceLocation loc,
243  AccessSpecifier AS, uint64_t offsetInBits,
244  llvm::DIFile *tunit, llvm::DIScope *scope,
245  const RecordDecl *RD = nullptr);
246 
247  /// Helpers for collecting fields of a record.
248  /// @{
249  void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
251  llvm::DIType *RecordTy);
252  llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
253  llvm::DIType *RecordTy,
254  const RecordDecl *RD);
255  void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
256  llvm::DIFile *F,
258  llvm::DIType *RecordTy, const RecordDecl *RD);
259  void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
261  llvm::DICompositeType *RecordTy);
262 
263  /// If the C++ class has vtable info then insert appropriate debug
264  /// info entry in EltTys vector.
265  void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile *F,
267  /// @}
268 
269  /// Create a new lexical block node and push it on the stack.
270  void CreateLexicalBlock(SourceLocation Loc);
271 
272 public:
273  CGDebugInfo(CodeGenModule &CGM);
274  ~CGDebugInfo();
275 
276  void finalize();
277 
278  /// Set the main CU's DwoId field to \p Signature.
279  void setDwoId(uint64_t Signature);
280 
281  /// When generating debug information for a clang module or
282  /// precompiled header, this module map will be used to determine
283  /// the module of origin of each Decl.
284  void setModuleMap(ModuleMap &MMap) { ClangModuleMap = &MMap; }
285 
286  /// Update the current source location. If \arg loc is invalid it is
287  /// ignored.
288  void setLocation(SourceLocation Loc);
289 
290  /// Emit metadata to indicate a change in line/column information in
291  /// the source file. If the location is invalid, the previous
292  /// location will be reused.
294 
295  /// Emit a call to llvm.dbg.function.start to indicate
296  /// start of a new function.
297  /// \param Loc The location of the function header.
298  /// \param ScopeLoc The location of the function body.
300  SourceLocation ScopeLoc, QualType FnType,
301  llvm::Function *Fn, CGBuilderTy &Builder);
302 
303  /// Emit debug info for a function declaration.
304  void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType);
305 
306  /// Constructs the debug code for exiting a function.
308 
309  /// Emit metadata to indicate the beginning of a new lexical block
310  /// and push the block onto the stack.
312 
313  /// Emit metadata to indicate the end of a new lexical block and pop
314  /// the current block.
316 
317  /// Emit call to \c llvm.dbg.declare for an automatic variable
318  /// declaration.
321 
322  /// Emit call to \c llvm.dbg.declare for an imported variable
323  /// declaration in a block.
324  void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable,
325  llvm::Value *storage,
327  const CGBlockInfo &blockInfo,
328  llvm::Instruction *InsertPoint = nullptr);
329 
330  /// Emit call to \c llvm.dbg.declare for an argument variable
331  /// declaration.
333  unsigned ArgNo, CGBuilderTy &Builder);
334 
335  /// Emit call to \c llvm.dbg.declare for the block-literal argument
336  /// to a block invocation function.
338  llvm::Value *Arg, unsigned ArgNo,
339  llvm::Value *LocalAddr,
341 
342  /// Emit information about a global variable.
343  void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
344 
345  /// Emit global variable's debug info.
346  void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init);
347 
348  /// Emit C++ using directive.
349  void EmitUsingDirective(const UsingDirectiveDecl &UD);
350 
351  /// Emit the type explicitly casted to.
353 
354  /// Emit C++ using declaration.
355  void EmitUsingDecl(const UsingDecl &UD);
356 
357  /// Emit an @import declaration.
358  void EmitImportDecl(const ImportDecl &ID);
359 
360  /// Emit C++ namespace alias.
361  llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
362 
363  /// Emit record type's standalone debug info.
364  llvm::DIType *getOrCreateRecordType(QualType Ty, SourceLocation L);
365 
366  /// Emit an Objective-C interface type standalone debug info.
367  llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
368 
369  /// Emit standalone debug info for a type.
370  llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
371 
372  void completeType(const EnumDecl *ED);
373  void completeType(const RecordDecl *RD);
374  void completeRequiredType(const RecordDecl *RD);
375  void completeClassData(const RecordDecl *RD);
376 
378 
379 private:
380  /// Emit call to llvm.dbg.declare for a variable declaration.
381  void EmitDeclare(const VarDecl *decl, llvm::Value *AI,
383 
384  /// Build up structure info for the byref. See \a BuildByRefType.
385  llvm::DIType *EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
386  uint64_t *OffSet);
387 
388  /// Get context info for the DeclContext of \p Decl.
389  llvm::DIScope *getDeclContextDescriptor(const Decl *D);
390  /// Get context info for a given DeclContext \p Decl.
391  llvm::DIScope *getContextDescriptor(const Decl *Context,
392  llvm::DIScope *Default);
393 
394  llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);
395 
396  /// Create a forward decl for a RecordType in a given context.
397  llvm::DICompositeType *getOrCreateRecordFwdDecl(const RecordType *,
398  llvm::DIScope *);
399 
400  /// Return current directory name.
401  StringRef getCurrentDirname();
402 
403  /// Create new compile unit.
404  void CreateCompileUnit();
405 
406  /// Remap a given path with the current debug prefix map
407  std::string remapDIPath(StringRef) const;
408 
409  /// Get the file debug info descriptor for the input location.
410  llvm::DIFile *getOrCreateFile(SourceLocation Loc);
411 
412  /// Get the file info for main compile unit.
413  llvm::DIFile *getOrCreateMainFile();
414 
415  /// Get the type from the cache or create a new type if necessary.
416  llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
417 
418  /// Get a reference to a clang module. If \p CreateSkeletonCU is true,
419  /// this also creates a split dwarf skeleton compile unit.
420  llvm::DIModule *
421  getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
422  bool CreateSkeletonCU);
423 
424  /// DebugTypeExtRefs: If \p D originated in a clang module, return it.
425  llvm::DIModule *getParentModuleOrNull(const Decl *D);
426 
427  /// Get the type from the cache or create a new partial type if
428  /// necessary.
429  llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty,
430  llvm::DIFile *F);
431 
432  /// Create type metadata for a source language type.
433  llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
434 
435  /// Create new member and increase Offset by FType's size.
436  llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,
437  StringRef Name, uint64_t *Offset);
438 
439  /// Retrieve the DIDescriptor, if any, for the canonical form of this
440  /// declaration.
441  llvm::DINode *getDeclarationOrDefinition(const Decl *D);
442 
443  /// \return debug info descriptor to describe method
444  /// declaration for the given method definition.
445  llvm::DISubprogram *getFunctionDeclaration(const Decl *D);
446 
447  /// \return debug info descriptor to describe in-class static data
448  /// member declaration for the given out-of-class definition. If D
449  /// is an out-of-class definition of a static data member of a
450  /// class, find its corresponding in-class declaration.
451  llvm::DIDerivedType *
452  getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
453 
454  /// Create a subprogram describing the forward declaration
455  /// represented in the given FunctionDecl.
456  llvm::DISubprogram *getFunctionForwardDeclaration(const FunctionDecl *FD);
457 
458  /// Create a global variable describing the forward decalration
459  /// represented in the given VarDecl.
460  llvm::DIGlobalVariable *
461  getGlobalVariableForwardDeclaration(const VarDecl *VD);
462 
463  /// \brief Return a global variable that represents one of the
464  /// collection of global variables created for an anonmyous union.
465  ///
466  /// Recursively collect all of the member fields of a global
467  /// anonymous decl and create static variables for them. The first
468  /// time this is called it needs to be on a union and then from
469  /// there we can have additional unnamed fields.
470  llvm::DIGlobalVariable *
471  CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
472  unsigned LineNo, StringRef LinkageName,
473  llvm::GlobalVariable *Var, llvm::DIScope *DContext);
474 
475  /// Get function name for the given FunctionDecl. If the name is
476  /// constructed on demand (e.g., C++ destructor) then the name is
477  /// stored on the side.
478  StringRef getFunctionName(const FunctionDecl *FD);
479 
480  /// Returns the unmangled name of an Objective-C method.
481  /// This is the display name for the debugging info.
482  StringRef getObjCMethodName(const ObjCMethodDecl *FD);
483 
484  /// Return selector name. This is used for debugging
485  /// info.
486  StringRef getSelectorName(Selector S);
487 
488  /// Get class name including template argument list.
489  StringRef getClassName(const RecordDecl *RD);
490 
491  /// Get the vtable name for the given class.
492  StringRef getVTableName(const CXXRecordDecl *Decl);
493 
494  /// Get line number for the location. If location is invalid
495  /// then use current location.
496  unsigned getLineNumber(SourceLocation Loc);
497 
498  /// Get column number for the location. If location is
499  /// invalid then use current location.
500  /// \param Force Assume DebugColumnInfo option is true.
501  unsigned getColumnNumber(SourceLocation Loc, bool Force = false);
502 
503  /// Collect various properties of a FunctionDecl.
504  /// \param GD A GlobalDecl whose getDecl() must return a FunctionDecl.
505  void collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
506  StringRef &Name, StringRef &LinkageName,
507  llvm::DIScope *&FDContext,
508  llvm::DINodeArray &TParamsArray,
509  unsigned &Flags);
510 
511  /// Collect various properties of a VarDecl.
512  void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
513  unsigned &LineNo, QualType &T, StringRef &Name,
514  StringRef &LinkageName, llvm::DIScope *&VDContext);
515 
516  /// Allocate a copy of \p A using the DebugInfoNames allocator
517  /// and return a reference to it. If multiple arguments are given the strings
518  /// are concatenated.
519  StringRef internString(StringRef A, StringRef B = StringRef()) {
520  char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
521  if (!A.empty())
522  std::memcpy(Data, A.data(), A.size());
523  if (!B.empty())
524  std::memcpy(Data + A.size(), B.data(), B.size());
525  return StringRef(Data, A.size() + B.size());
526  }
527 };
528 
529 /// A scoped helper to set the current debug location to the specified
530 /// location or preferred location of the specified Expr.
532 private:
533  void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
534  ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
535  SourceLocation TemporaryLocation);
536 
537  llvm::DebugLoc OriginalLocation;
538  CodeGenFunction *CGF;
539 
540 public:
541  /// Set the location to the (valid) TemporaryLocation.
542  ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
544  ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
545  ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
546  Other.CGF = nullptr;
547  }
548 
550 
551  /// \brief Apply TemporaryLocation if it is valid. Otherwise switch
552  /// to an artificial debug location that has a valid scope, but no
553  /// line information.
554  ///
555  /// Artificial locations are useful when emitting compiler-generated
556  /// helper functions that have no source location associated with
557  /// them. The DWARF specification allows the compiler to use the
558  /// special line number 0 to indicate code that can not be
559  /// attributed to any source location. Note that passing an empty
560  /// SourceLocation to CGDebugInfo::setLocation() will result in the
561  /// last valid location being reused.
563  return ApplyDebugLocation(CGF, false, SourceLocation());
564  }
565  /// \brief Apply TemporaryLocation if it is valid. Otherwise switch
566  /// to an artificial debug location that has a valid scope, but no
567  /// line information.
568  static ApplyDebugLocation
570  SourceLocation TemporaryLocation) {
571  return ApplyDebugLocation(CGF, false, TemporaryLocation);
572  }
573 
574  /// Set the IRBuilder to not attach debug locations. Note that
575  /// passing an empty SourceLocation to \a CGDebugInfo::setLocation()
576  /// will result in the last valid location being reused. Note that
577  /// all instructions that do not have a location at the beginning of
578  /// a function are counted towards to function prologue.
580  return ApplyDebugLocation(CGF, true, SourceLocation());
581  }
582 
583 };
584 
585 } // namespace CodeGen
586 } // namespace clang
587 
588 #endif // LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1483
void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, llvm::Value *Arg, unsigned ArgNo, llvm::Value *LocalAddr, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for the block-literal argument to a block invocation function...
Smart pointer class that efficiently represents Objective-C method names.
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2147
A (possibly-)qualified type.
Definition: Type.h:575
void EmitExplicitCastType(QualType Ty)
Emit the type explicitly casted to.
llvm::DIType * getOrCreateRecordType(QualType Ty, SourceLocation L)
Emit record type's standalone debug info.
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:2847
void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate the end of a new lexical block and pop the current block.
C Language Family Type Representation.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:77
TemplateSpecializationType(TemplateName T, const TemplateArgument *Args, unsigned NumArgs, QualType Canon, QualType Aliased)
Definition: Type.cpp:3118
The base class of the type hierarchy.
Definition: Type.h:1249
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2424
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:402
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:90
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:699
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:51
void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for an automatic variable declaration.
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:48
void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD)
PipeType - OpenCL20.
Definition: Type.h:5020
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3166
Represents a class template specialization, which refers to a class template with a given set of temp...
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4381
Represents a class type in Objective C.
Definition: Type.h:4557
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void EmitImportDecl(const ImportDecl &ID)
Emit an declaration.
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2209
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Definition: ASTMatchers.h:259
void completeClassData(const RecordDecl *RD)
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
Definition: CGDebugInfo.h:562
Represents a C++ using-declaration.
Definition: DeclCXX.h:2858
friend class SaveAndRestoreLocation
Definition: CGDebugInfo.h:53
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2351
uint32_t Offset
Definition: CacheTokens.cpp:44
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about a global variable.
llvm::DIType * getOrCreateInterfaceType(QualType Ty, SourceLocation Loc)
Emit an Objective-C interface type standalone debug info.
llvm::DIImportedEntity * EmitNamespaceAlias(const NamespaceAliasDecl &NA)
Emit C++ namespace alias.
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3041
CGBlockInfo - Information to generate a block literal.
Definition: CGBlocks.h:153
ASTContext * Context
void setDwoId(uint64_t Signature)
Set the main CU's DwoId field to Signature.
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate a change in line/column information in the source file. ...
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:521
Expr - This represents one expression.
Definition: Expr.h:104
Represents a GCC generic vector type.
Definition: Type.h:2724
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2334
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:28
The l-value was considered opaque, so the alignment was determined from a type.
void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, unsigned ArgNo, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for an argument variable declaration.
void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType)
Emit debug info for a function declaration.
Encodes a location in the source.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:3570
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:4766
void completeRequiredType(const RecordDecl *RD)
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:531
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1701
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:3658
This class organizes the cross-function state that is used while generating LLVM code.
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
Apply TemporaryLocation if it is valid.
Definition: CGDebugInfo.h:569
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:1723
CGDebugInfo(CodeGenModule &CGM)
Definition: CGDebugInfo.cpp:46
EnumDecl - Represents an enum.
Definition: Decl.h:2930
detail::InMemoryDirectory::const_iterator E
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2369
void setModuleMap(ModuleMap &MMap)
When generating debug information for a clang module or precompiled header, this module map will be u...
Definition: CGDebugInfo.h:284
Represents a pointer to an Objective C object.
Definition: Type.h:4821
Pointer to a block type.
Definition: Type.h:2254
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:3544
Complex values, per C99 6.2.5p11.
Definition: Type.h:2087
llvm::DIType * getOrCreateStandaloneType(QualType Ty, SourceLocation Loc)
Emit standalone debug info for a type.
void completeType(const EnumDecl *ED)
ApplyDebugLocation(ApplyDebugLocation &&Other)
Definition: CGDebugInfo.h:545
The type-property cache.
Definition: Type.cpp:3238
void EmitUsingDecl(const UsingDecl &UD)
Emit C++ using declaration.
void EmitUsingDirective(const UsingDirectiveDecl &UD)
Emit C++ using directive.
void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate the beginning of a new lexical block and push the block onto the stack...
Defines the clang::SourceLocation class and associated facilities.
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
BoundNodesTreeBuilder *const Builder
void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable, llvm::Value *storage, CGBuilderTy &Builder, const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint=nullptr)
Emit call to llvm.dbg.declare for an imported variable declaration in a block.
void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc, SourceLocation ScopeLoc, QualType FnType, llvm::Function *Fn, CGBuilderTy &Builder)
Emit a call to llvm.dbg.function.start to indicate start of a new function.
This class is used for builtin types like 'int'.
Definition: Type.h:2011
void setLocation(SourceLocation Loc)
Update the current source location.
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
Definition: CGDebugInfo.h:579
Represents a C++ namespace alias.
Definition: DeclCXX.h:2649
Represents C++ using-directive.
Definition: DeclCXX.h:2546
void EmitFunctionEnd(CGBuilderTy &Builder)
Constructs the debug code for exiting a function.