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"
20 #include "clang/Basic/SourceLocation.h"
21 #include "clang/Frontend/CodeGenOptions.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 VarDecl;
36 class ObjCInterfaceDecl;
37 class ObjCIvarDecl;
38 class ClassTemplateSpecializationDecl;
39 class GlobalDecl;
40 class UsingDecl;
41 
42 namespace CodeGen {
43 class CodeGenModule;
44 class CodeGenFunction;
45 class CGBlockInfo;
46 
47 /// This class gathers all debug information during compilation and is
48 /// responsible for emitting to llvm globals or pass directly to the
49 /// backend.
50 class CGDebugInfo {
51   friend class ApplyDebugLocation;
52   friend class SaveAndRestoreLocation;
53   CodeGenModule &CGM;
54   const CodeGenOptions::DebugInfoKind DebugKind;
55   llvm::DIBuilder DBuilder;
56   llvm::DICompileUnit *TheCU = nullptr;
57   SourceLocation CurLoc;
58   llvm::DIType *VTablePtrType = nullptr;
59   llvm::DIType *ClassTy = nullptr;
60   llvm::DICompositeType *ObjTy = nullptr;
61   llvm::DIType *SelTy = nullptr;
62   llvm::DIType *OCLImage1dDITy = nullptr;
63   llvm::DIType *OCLImage1dArrayDITy = nullptr;
64   llvm::DIType *OCLImage1dBufferDITy = nullptr;
65   llvm::DIType *OCLImage2dDITy = nullptr;
66   llvm::DIType *OCLImage2dArrayDITy = nullptr;
67   llvm::DIType *OCLImage3dDITy = nullptr;
68   llvm::DIType *OCLEventDITy = nullptr;
69 
70   /// Cache of previously constructed Types.
71   llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
72 
73   struct ObjCInterfaceCacheEntry {
74     const ObjCInterfaceType *Type;
75     llvm::DIType *Decl;
76     llvm::DIFile *Unit;
77     ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType *Decl,
78                             llvm::DIFile *Unit)
79         : Type(Type), Decl(Decl), Unit(Unit) {}
80   };
81 
82   /// Cache of previously constructed interfaces which may change.
83   llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache;
84 
85   /// Cache of references to AST files such as PCHs or modules.
86   llvm::DenseMap<uint64_t, llvm::DIModule *> ModuleRefCache;
87 
88   /// List of interfaces we want to keep even if orphaned.
89   std::vector<void *> RetainedTypes;
90 
91   /// Cache of forward declared types to RAUW at the end of
92   /// compilation.
93   std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
94 
95   /// Cache of replaceable forward declarartions (functions and
96   /// variables) to RAUW at the end of compilation.
97   std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
98       FwdDeclReplaceMap;
99 
100   /// Keep track of our current nested lexical block.
101   std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
102   llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
103   /// Keep track of LexicalBlockStack counter at the beginning of a
104   /// function. This is used to pop unbalanced regions at the end of a
105   /// function.
106   std::vector<unsigned> FnBeginRegionCount;
107 
108   /// This is a storage for names that are constructed on demand. For
109   /// example, C++ destructors, C++ operators etc..
110   llvm::BumpPtrAllocator DebugInfoNames;
111   StringRef CWDName;
112 
113   llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
114   llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
115   /// Cache declarations relevant to DW_TAG_imported_declarations (C++
116   /// using declarations) that aren't covered by other more specific caches.
117   llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
118   llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NameSpaceCache;
119   llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
120       NamespaceAliasCache;
121   llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
122       StaticDataMemberCache;
123 
124   /// Helper functions for getOrCreateType.
125   /// @{
126   /// Currently the checksum of an interface includes the number of
127   /// ivars and property accessors.
128   unsigned Checksum(const ObjCInterfaceDecl *InterfaceDecl);
129   llvm::DIType *CreateType(const BuiltinType *Ty);
130   llvm::DIType *CreateType(const ComplexType *Ty);
131   llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
132   llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
133   llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
134                            llvm::DIFile *Fg);
135   llvm::DIType *CreateType(const ObjCObjectPointerType *Ty, llvm::DIFile *F);
136   llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
137   llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
138   llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
139   /// Get structure or union type.
140   llvm::DIType *CreateType(const RecordType *Tyg);
141   llvm::DIType *CreateTypeDefinition(const RecordType *Ty);
142   llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
143   void CollectContainingType(const CXXRecordDecl *RD,
144                              llvm::DICompositeType *CT);
145   /// Get Objective-C interface type.
146   llvm::DIType *CreateType(const ObjCInterfaceType *Ty, llvm::DIFile *F);
147   llvm::DIType *CreateTypeDefinition(const ObjCInterfaceType *Ty,
148                                      llvm::DIFile *F);
149   /// Get Objective-C object type.
150   llvm::DIType *CreateType(const ObjCObjectType *Ty, llvm::DIFile *F);
151   llvm::DIType *CreateType(const VectorType *Ty, llvm::DIFile *F);
152   llvm::DIType *CreateType(const ArrayType *Ty, llvm::DIFile *F);
153   llvm::DIType *CreateType(const LValueReferenceType *Ty, llvm::DIFile *F);
154   llvm::DIType *CreateType(const RValueReferenceType *Ty, llvm::DIFile *Unit);
155   llvm::DIType *CreateType(const MemberPointerType *Ty, llvm::DIFile *F);
156   llvm::DIType *CreateType(const AtomicType *Ty, llvm::DIFile *F);
157   /// Get enumeration type.
158   llvm::DIType *CreateEnumType(const EnumType *Ty);
159   llvm::DIType *CreateTypeDefinition(const EnumType *Ty);
160   /// Look up the completed type for a self pointer in the TypeCache and
161   /// create a copy of it with the ObjectPointer and Artificial flags
162   /// set. If the type is not cached, a new one is created. This should
163   /// never happen though, since creating a type for the implicit self
164   /// argument implies that we already parsed the interface definition
165   /// and the ivar declarations in the implementation.
166   llvm::DIType *CreateSelfType(const QualType &QualTy, llvm::DIType *Ty);
167   /// @}
168 
169   /// Get the type from the cache or return null type if it doesn't
170   /// exist.
171   llvm::DIType *getTypeOrNull(const QualType);
172   /// Return the debug type for a C++ method.
173   /// \arg CXXMethodDecl is of FunctionType. This function type is
174   /// not updated to include implicit \c this pointer. Use this routine
175   /// to get a method type which includes \c this pointer.
176   llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
177                                                 llvm::DIFile *F);
178   llvm::DISubroutineType *
179   getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func,
180                                 llvm::DIFile *Unit);
181   llvm::DISubroutineType *
182   getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
183   /// \return debug info descriptor for vtable.
184   llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
185   /// \return namespace descriptor for the given namespace decl.
186   llvm::DINamespace *getOrCreateNameSpace(const NamespaceDecl *N);
187   llvm::DIType *getOrCreateTypeDeclaration(QualType PointeeTy, llvm::DIFile *F);
188   llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
189                                       QualType PointeeTy, llvm::DIFile *F);
190 
191   llvm::Value *getCachedInterfaceTypeOrNull(const QualType Ty);
192   llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
193 
194   /// A helper function to create a subprogram for a single member
195   /// function GlobalDecl.
196   llvm::DISubprogram *CreateCXXMemberFunction(const CXXMethodDecl *Method,
197                                               llvm::DIFile *F,
198                                               llvm::DIType *RecordTy);
199 
200   /// A helper function to collect debug info for C++ member
201   /// functions. This is used while creating debug info entry for a
202   /// Record.
203   void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile *F,
204                                  SmallVectorImpl<llvm::Metadata *> &E,
205                                  llvm::DIType *T);
206 
207   /// A helper function to collect debug info for C++ base
208   /// classes. This is used while creating debug info entry for a
209   /// Record.
210   void CollectCXXBases(const CXXRecordDecl *Decl, llvm::DIFile *F,
211                        SmallVectorImpl<llvm::Metadata *> &EltTys,
212                        llvm::DIType *RecordTy);
213 
214   /// A helper function to collect template parameters.
215   llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList,
216                                           ArrayRef<TemplateArgument> TAList,
217                                           llvm::DIFile *Unit);
218   /// A helper function to collect debug info for function template
219   /// parameters.
220   llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
221                                                   llvm::DIFile *Unit);
222 
223   /// A helper function to collect debug info for template
224   /// parameters.
225   llvm::DINodeArray
226   CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS,
227                            llvm::DIFile *F);
228 
229   llvm::DIType *createFieldType(StringRef name, QualType type,
230                                 uint64_t sizeInBitsOverride, SourceLocation loc,
231                                 AccessSpecifier AS, uint64_t offsetInBits,
232                                 llvm::DIFile *tunit, llvm::DIScope *scope,
233                                 const RecordDecl *RD = nullptr);
234 
235   /// Helpers for collecting fields of a record.
236   /// @{
237   void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
238                                  SmallVectorImpl<llvm::Metadata *> &E,
239                                  llvm::DIType *RecordTy);
240   llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
241                                                llvm::DIType *RecordTy,
242                                                const RecordDecl *RD);
243   void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
244                                 llvm::DIFile *F,
245                                 SmallVectorImpl<llvm::Metadata *> &E,
246                                 llvm::DIType *RecordTy, const RecordDecl *RD);
247   void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
248                            SmallVectorImpl<llvm::Metadata *> &E,
249                            llvm::DICompositeType *RecordTy);
250 
251   /// If the C++ class has vtable info then insert appropriate debug
252   /// info entry in EltTys vector.
253   void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile *F,
254                          SmallVectorImpl<llvm::Metadata *> &EltTys);
255   /// @}
256 
257   /// Create a new lexical block node and push it on the stack.
258   void CreateLexicalBlock(SourceLocation Loc);
259 
260 public:
261   CGDebugInfo(CodeGenModule &CGM);
262   ~CGDebugInfo();
263 
264   void finalize();
265 
266   /// Update the current source location. If \arg loc is invalid it is
267   /// ignored.
268   void setLocation(SourceLocation Loc);
269 
270   /// Emit metadata to indicate a change in line/column information in
271   /// the source file. If the location is invalid, the previous
272   /// location will be reused.
273   void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc);
274 
275   /// Emit a call to llvm.dbg.function.start to indicate
276   /// start of a new function.
277   /// \param Loc       The location of the function header.
278   /// \param ScopeLoc  The location of the function body.
279   void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
280                          SourceLocation ScopeLoc, QualType FnType,
281                          llvm::Function *Fn, CGBuilderTy &Builder);
282 
283   /// Constructs the debug code for exiting a function.
284   void EmitFunctionEnd(CGBuilderTy &Builder);
285 
286   /// Emit metadata to indicate the beginning of a new lexical block
287   /// and push the block onto the stack.
288   void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
289 
290   /// Emit metadata to indicate the end of a new lexical block and pop
291   /// the current block.
292   void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
293 
294   /// Emit call to \c llvm.dbg.declare for an automatic variable
295   /// declaration.
296   void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
297                                  CGBuilderTy &Builder);
298 
299   /// Emit call to \c llvm.dbg.declare for an imported variable
300   /// declaration in a block.
301   void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable,
302                                          llvm::Value *storage,
303                                          CGBuilderTy &Builder,
304                                          const CGBlockInfo &blockInfo,
305                                          llvm::Instruction *InsertPoint = 0);
306 
307   /// Emit call to \c llvm.dbg.declare for an argument variable
308   /// declaration.
309   void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
310                                 unsigned ArgNo, CGBuilderTy &Builder);
311 
312   /// Emit call to \c llvm.dbg.declare for the block-literal argument
313   /// to a block invocation function.
314   void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
315                                             llvm::Value *Arg, unsigned ArgNo,
316                                             llvm::Value *LocalAddr,
317                                             CGBuilderTy &Builder);
318 
319   /// Emit information about a global variable.
320   void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
321 
322   /// Emit global variable's debug info.
323   void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init);
324 
325   /// Emit C++ using directive.
326   void EmitUsingDirective(const UsingDirectiveDecl &UD);
327 
328   /// Emit the type explicitly casted to.
329   void EmitExplicitCastType(QualType Ty);
330 
331   /// Emit C++ using declaration.
332   void EmitUsingDecl(const UsingDecl &UD);
333 
334   /// Emit an @import declaration.
335   void EmitImportDecl(const ImportDecl &ID);
336 
337   /// Emit C++ namespace alias.
338   llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
339 
340   /// Emit record type's standalone debug info.
341   llvm::DIType *getOrCreateRecordType(QualType Ty, SourceLocation L);
342 
343   /// Emit an Objective-C interface type standalone debug info.
344   llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
345 
346   void completeType(const EnumDecl *ED);
347   void completeType(const RecordDecl *RD);
348   void completeRequiredType(const RecordDecl *RD);
349   void completeClassData(const RecordDecl *RD);
350 
351   void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD);
352 
353 private:
354   /// Emit call to llvm.dbg.declare for a variable declaration.
355   void EmitDeclare(const VarDecl *decl, llvm::Value *AI,
356                    llvm::Optional<unsigned> ArgNo, CGBuilderTy &Builder);
357 
358   /// Build up structure info for the byref.  See \a BuildByRefType.
359   llvm::DIType *EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
360                                              uint64_t *OffSet);
361 
362   /// Get context info for the decl.
363   llvm::DIScope *getContextDescriptor(const Decl *Decl);
364 
365   llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);
366 
367   /// Create a forward decl for a RecordType in a given context.
368   llvm::DICompositeType *getOrCreateRecordFwdDecl(const RecordType *,
369                                                   llvm::DIScope *);
370 
371   /// Return current directory name.
372   StringRef getCurrentDirname();
373 
374   /// Create new compile unit.
375   void CreateCompileUnit();
376 
377   /// Get the file debug info descriptor for the input location.
378   llvm::DIFile *getOrCreateFile(SourceLocation Loc);
379 
380   /// Get the file info for main compile unit.
381   llvm::DIFile *getOrCreateMainFile();
382 
383   /// Get the type from the cache or create a new type if necessary.
384   llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
385 
386   /// Get a reference to a clang module.
387   llvm::DIModule *
388   getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod);
389 
390   /// Get the type from the cache or create a new partial type if
391   /// necessary.
392   llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty,
393                                                 llvm::DIFile *F);
394 
395   /// Create type metadata for a source language type.
396   llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
397 
398   /// Return the underlying ObjCInterfaceDecl if \arg Ty is an
399   /// ObjCInterface or a pointer to one.
400   ObjCInterfaceDecl *getObjCInterfaceDecl(QualType Ty);
401 
402   /// Create new member and increase Offset by FType's size.
403   llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,
404                                  StringRef Name, uint64_t *Offset);
405 
406   /// Retrieve the DIDescriptor, if any, for the canonical form of this
407   /// declaration.
408   llvm::DINode *getDeclarationOrDefinition(const Decl *D);
409 
410   /// \return debug info descriptor to describe method
411   /// declaration for the given method definition.
412   llvm::DISubprogram *getFunctionDeclaration(const Decl *D);
413 
414   /// \return debug info descriptor to describe in-class static data
415   /// member declaration for the given out-of-class definition.  If D
416   /// is an out-of-class definition of a static data member of a
417   /// class, find its corresponding in-class declaration.
418   llvm::DIDerivedType *
419   getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
420 
421   /// Create a subprogram describing the forward declaration
422   /// represented in the given FunctionDecl.
423   llvm::DISubprogram *getFunctionForwardDeclaration(const FunctionDecl *FD);
424 
425   /// Create a global variable describing the forward decalration
426   /// represented in the given VarDecl.
427   llvm::DIGlobalVariable *
428   getGlobalVariableForwardDeclaration(const VarDecl *VD);
429 
430   /// \brief Return a global variable that represents one of the
431   /// collection of global variables created for an anonmyous union.
432   ///
433   /// Recursively collect all of the member fields of a global
434   /// anonymous decl and create static variables for them. The first
435   /// time this is called it needs to be on a union and then from
436   /// there we can have additional unnamed fields.
437   llvm::DIGlobalVariable *
438   CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
439                          unsigned LineNo, StringRef LinkageName,
440                          llvm::GlobalVariable *Var, llvm::DIScope *DContext);
441 
442   /// Get function name for the given FunctionDecl. If the name is
443   /// constructed on demand (e.g., C++ destructor) then the name is
444   /// stored on the side.
445   StringRef getFunctionName(const FunctionDecl *FD);
446 
447   /// Returns the unmangled name of an Objective-C method.
448   /// This is the display name for the debugging info.
449   StringRef getObjCMethodName(const ObjCMethodDecl *FD);
450 
451   /// Return selector name. This is used for debugging
452   /// info.
453   StringRef getSelectorName(Selector S);
454 
455   /// Get class name including template argument list.
456   StringRef getClassName(const RecordDecl *RD);
457 
458   /// Get the vtable name for the given class.
459   StringRef getVTableName(const CXXRecordDecl *Decl);
460 
461   /// Get line number for the location. If location is invalid
462   /// then use current location.
463   unsigned getLineNumber(SourceLocation Loc);
464 
465   /// Get column number for the location. If location is
466   /// invalid then use current location.
467   /// \param Force  Assume DebugColumnInfo option is true.
468   unsigned getColumnNumber(SourceLocation Loc, bool Force = false);
469 
470   /// Collect various properties of a FunctionDecl.
471   /// \param GD  A GlobalDecl whose getDecl() must return a FunctionDecl.
472   void collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
473                                 StringRef &Name, StringRef &LinkageName,
474                                 llvm::DIScope *&FDContext,
475                                 llvm::DINodeArray &TParamsArray,
476                                 unsigned &Flags);
477 
478   /// Collect various properties of a VarDecl.
479   void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
480                            unsigned &LineNo, QualType &T, StringRef &Name,
481                            StringRef &LinkageName, llvm::DIScope *&VDContext);
482 
483   /// Allocate a copy of \p A using the DebugInfoNames allocator
484   /// and return a reference to it. If multiple arguments are given the strings
485   /// are concatenated.
486   StringRef internString(StringRef A, StringRef B = StringRef()) {
487     char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
488     if (!A.empty())
489       std::memcpy(Data, A.data(), A.size());
490     if (!B.empty())
491       std::memcpy(Data + A.size(), B.data(), B.size());
492     return StringRef(Data, A.size() + B.size());
493   }
494 };
495 
496 /// A scoped helper to set the current debug location to the specified
497 /// location or preferred location of the specified Expr.
498 class ApplyDebugLocation {
499 private:
500   void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
501   ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
502                      SourceLocation TemporaryLocation);
503 
504   llvm::DebugLoc OriginalLocation;
505   CodeGenFunction &CGF;
506 
507 public:
508   /// Set the location to the (valid) TemporaryLocation.
509   ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
510   ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
511   ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
512 
513   ~ApplyDebugLocation();
514 
515   /// \brief Apply TemporaryLocation if it is valid. Otherwise switch
516   /// to an artificial debug location that has a valid scope, but no
517   /// line information.
518   ///
519   /// Artificial locations are useful when emitting compiler-generated
520   /// helper functions that have no source location associated with
521   /// them. The DWARF specification allows the compiler to use the
522   /// special line number 0 to indicate code that can not be
523   /// attributed to any source location. Note that passing an empty
524   /// SourceLocation to CGDebugInfo::setLocation() will result in the
525   /// last valid location being reused.
526   static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF) {
527     return ApplyDebugLocation(CGF, false, SourceLocation());
528   }
529   /// \brief Apply TemporaryLocation if it is valid. Otherwise switch
530   /// to an artificial debug location that has a valid scope, but no
531   /// line information.
532   static ApplyDebugLocation
533   CreateDefaultArtificial(CodeGenFunction &CGF,
534                           SourceLocation TemporaryLocation) {
535     return ApplyDebugLocation(CGF, false, TemporaryLocation);
536   }
537 
538   /// Set the IRBuilder to not attach debug locations.  Note that
539   /// passing an empty SourceLocation to \a CGDebugInfo::setLocation()
540   /// will result in the last valid location being reused.  Note that
541   /// all instructions that do not have a location at the beginning of
542   /// a function are counted towards to funciton prologue.
543   static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF) {
544     return ApplyDebugLocation(CGF, true, SourceLocation());
545   }
546 
547   /// \brief Apply TemporaryLocation if it is valid. Otherwise set the IRBuilder
548   /// to not attach debug locations.
549   static ApplyDebugLocation
550   CreateDefaultEmpty(CodeGenFunction &CGF, SourceLocation TemporaryLocation) {
551     return ApplyDebugLocation(CGF, true, TemporaryLocation);
552   }
553 };
554 
555 } // namespace CodeGen
556 } // namespace clang
557 
558 #endif
559