xref: /freebsd/contrib/llvm-project/clang/lib/CodeGen/CGDebugInfo.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This is the source-level debug info generator for llvm translation.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
140b57cec5SDimitry Andric #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "CGBuilder.h"
170b57cec5SDimitry Andric #include "clang/AST/DeclCXX.h"
180b57cec5SDimitry Andric #include "clang/AST/Expr.h"
190b57cec5SDimitry Andric #include "clang/AST/ExternalASTSource.h"
205ffd83dbSDimitry Andric #include "clang/AST/PrettyPrinter.h"
210b57cec5SDimitry Andric #include "clang/AST/Type.h"
220b57cec5SDimitry Andric #include "clang/AST/TypeOrdering.h"
23*0fca6ea1SDimitry Andric #include "clang/Basic/ASTSourceDescriptor.h"
240b57cec5SDimitry Andric #include "clang/Basic/CodeGenOptions.h"
250b57cec5SDimitry Andric #include "clang/Basic/SourceLocation.h"
260b57cec5SDimitry Andric #include "llvm/ADT/DenseMap.h"
270b57cec5SDimitry Andric #include "llvm/ADT/DenseSet.h"
280b57cec5SDimitry Andric #include "llvm/IR/DIBuilder.h"
290b57cec5SDimitry Andric #include "llvm/IR/DebugInfo.h"
300b57cec5SDimitry Andric #include "llvm/IR/ValueHandle.h"
310b57cec5SDimitry Andric #include "llvm/Support/Allocator.h"
32*0fca6ea1SDimitry Andric #include <map>
33bdd1243dSDimitry Andric #include <optional>
34*0fca6ea1SDimitry Andric #include <string>
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric namespace llvm {
370b57cec5SDimitry Andric class MDNode;
380b57cec5SDimitry Andric }
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric namespace clang {
410b57cec5SDimitry Andric class ClassTemplateSpecializationDecl;
420b57cec5SDimitry Andric class GlobalDecl;
43*0fca6ea1SDimitry Andric class Module;
440b57cec5SDimitry Andric class ModuleMap;
450b57cec5SDimitry Andric class ObjCInterfaceDecl;
460b57cec5SDimitry Andric class UsingDecl;
470b57cec5SDimitry Andric class VarDecl;
480b57cec5SDimitry Andric enum class DynamicInitKind : unsigned;
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric namespace CodeGen {
510b57cec5SDimitry Andric class CodeGenModule;
520b57cec5SDimitry Andric class CodeGenFunction;
530b57cec5SDimitry Andric class CGBlockInfo;
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric /// This class gathers all debug information during compilation and is
560b57cec5SDimitry Andric /// responsible for emitting to llvm globals or pass directly to the
570b57cec5SDimitry Andric /// backend.
580b57cec5SDimitry Andric class CGDebugInfo {
590b57cec5SDimitry Andric   friend class ApplyDebugLocation;
600b57cec5SDimitry Andric   friend class SaveAndRestoreLocation;
610b57cec5SDimitry Andric   CodeGenModule &CGM;
6206c3fb27SDimitry Andric   const llvm::codegenoptions::DebugInfoKind DebugKind;
630b57cec5SDimitry Andric   bool DebugTypeExtRefs;
640b57cec5SDimitry Andric   llvm::DIBuilder DBuilder;
650b57cec5SDimitry Andric   llvm::DICompileUnit *TheCU = nullptr;
660b57cec5SDimitry Andric   ModuleMap *ClangModuleMap = nullptr;
675ffd83dbSDimitry Andric   ASTSourceDescriptor PCHDescriptor;
680b57cec5SDimitry Andric   SourceLocation CurLoc;
690b57cec5SDimitry Andric   llvm::MDNode *CurInlinedAt = nullptr;
700b57cec5SDimitry Andric   llvm::DIType *VTablePtrType = nullptr;
710b57cec5SDimitry Andric   llvm::DIType *ClassTy = nullptr;
720b57cec5SDimitry Andric   llvm::DICompositeType *ObjTy = nullptr;
730b57cec5SDimitry Andric   llvm::DIType *SelTy = nullptr;
740b57cec5SDimitry Andric #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)                   \
750b57cec5SDimitry Andric   llvm::DIType *SingletonId = nullptr;
760b57cec5SDimitry Andric #include "clang/Basic/OpenCLImageTypes.def"
770b57cec5SDimitry Andric   llvm::DIType *OCLSamplerDITy = nullptr;
780b57cec5SDimitry Andric   llvm::DIType *OCLEventDITy = nullptr;
790b57cec5SDimitry Andric   llvm::DIType *OCLClkEventDITy = nullptr;
800b57cec5SDimitry Andric   llvm::DIType *OCLQueueDITy = nullptr;
810b57cec5SDimitry Andric   llvm::DIType *OCLNDRangeDITy = nullptr;
820b57cec5SDimitry Andric   llvm::DIType *OCLReserveIDDITy = nullptr;
830b57cec5SDimitry Andric #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
840b57cec5SDimitry Andric   llvm::DIType *Id##Ty = nullptr;
850b57cec5SDimitry Andric #include "clang/Basic/OpenCLExtensionTypes.def"
8606c3fb27SDimitry Andric #define WASM_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
8706c3fb27SDimitry Andric #include "clang/Basic/WebAssemblyReferenceTypes.def"
88*0fca6ea1SDimitry Andric #define AMDGPU_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
89*0fca6ea1SDimitry Andric #include "clang/Basic/AMDGPUTypes.def"
900b57cec5SDimitry Andric 
910b57cec5SDimitry Andric   /// Cache of previously constructed Types.
920b57cec5SDimitry Andric   llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
930b57cec5SDimitry Andric 
940b57cec5SDimitry Andric   /// Cache that maps VLA types to size expressions for that type,
950b57cec5SDimitry Andric   /// represented by instantiated Metadata nodes.
960b57cec5SDimitry Andric   llvm::SmallDenseMap<QualType, llvm::Metadata *> SizeExprCache;
970b57cec5SDimitry Andric 
98480093f4SDimitry Andric   /// Callbacks to use when printing names and types.
99480093f4SDimitry Andric   class PrintingCallbacks final : public clang::PrintingCallbacks {
100480093f4SDimitry Andric     const CGDebugInfo &Self;
101480093f4SDimitry Andric 
102480093f4SDimitry Andric   public:
PrintingCallbacks(const CGDebugInfo & Self)103480093f4SDimitry Andric     PrintingCallbacks(const CGDebugInfo &Self) : Self(Self) {}
remapPath(StringRef Path)104480093f4SDimitry Andric     std::string remapPath(StringRef Path) const override {
105480093f4SDimitry Andric       return Self.remapDIPath(Path);
106480093f4SDimitry Andric     }
107480093f4SDimitry Andric   };
108480093f4SDimitry Andric   PrintingCallbacks PrintCB = {*this};
109480093f4SDimitry Andric 
1100b57cec5SDimitry Andric   struct ObjCInterfaceCacheEntry {
1110b57cec5SDimitry Andric     const ObjCInterfaceType *Type;
1120b57cec5SDimitry Andric     llvm::DIType *Decl;
1130b57cec5SDimitry Andric     llvm::DIFile *Unit;
ObjCInterfaceCacheEntryObjCInterfaceCacheEntry1140b57cec5SDimitry Andric     ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType *Decl,
1150b57cec5SDimitry Andric                             llvm::DIFile *Unit)
1160b57cec5SDimitry Andric         : Type(Type), Decl(Decl), Unit(Unit) {}
1170b57cec5SDimitry Andric   };
1180b57cec5SDimitry Andric 
1190b57cec5SDimitry Andric   /// Cache of previously constructed interfaces which may change.
1200b57cec5SDimitry Andric   llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache;
1210b57cec5SDimitry Andric 
1220b57cec5SDimitry Andric   /// Cache of forward declarations for methods belonging to the interface.
123480093f4SDimitry Andric   /// The extra bit on the DISubprogram specifies whether a method is
124480093f4SDimitry Andric   /// "objc_direct".
125480093f4SDimitry Andric   llvm::DenseMap<const ObjCInterfaceDecl *,
126480093f4SDimitry Andric                  std::vector<llvm::PointerIntPair<llvm::DISubprogram *, 1>>>
1270b57cec5SDimitry Andric       ObjCMethodCache;
1280b57cec5SDimitry Andric 
1290b57cec5SDimitry Andric   /// Cache of references to clang modules and precompiled headers.
1300b57cec5SDimitry Andric   llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
1310b57cec5SDimitry Andric 
1320b57cec5SDimitry Andric   /// List of interfaces we want to keep even if orphaned.
1330b57cec5SDimitry Andric   std::vector<void *> RetainedTypes;
1340b57cec5SDimitry Andric 
1350b57cec5SDimitry Andric   /// Cache of forward declared types to RAUW at the end of compilation.
1360b57cec5SDimitry Andric   std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
1370b57cec5SDimitry Andric 
1380b57cec5SDimitry Andric   /// Cache of replaceable forward declarations (functions and
1390b57cec5SDimitry Andric   /// variables) to RAUW at the end of compilation.
1400b57cec5SDimitry Andric   std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
1410b57cec5SDimitry Andric       FwdDeclReplaceMap;
1420b57cec5SDimitry Andric 
1430b57cec5SDimitry Andric   /// Keep track of our current nested lexical block.
1440b57cec5SDimitry Andric   std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
1450b57cec5SDimitry Andric   llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
1460b57cec5SDimitry Andric   /// Keep track of LexicalBlockStack counter at the beginning of a
1470b57cec5SDimitry Andric   /// function. This is used to pop unbalanced regions at the end of a
1480b57cec5SDimitry Andric   /// function.
1490b57cec5SDimitry Andric   std::vector<unsigned> FnBeginRegionCount;
1500b57cec5SDimitry Andric 
1510b57cec5SDimitry Andric   /// This is a storage for names that are constructed on demand. For
1520b57cec5SDimitry Andric   /// example, C++ destructors, C++ operators etc..
1530b57cec5SDimitry Andric   llvm::BumpPtrAllocator DebugInfoNames;
1540b57cec5SDimitry Andric   StringRef CWDName;
1550b57cec5SDimitry Andric 
1568a4dda33SDimitry Andric   llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
1570b57cec5SDimitry Andric   llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
1580b57cec5SDimitry Andric   /// Cache declarations relevant to DW_TAG_imported_declarations (C++
15981ad6265SDimitry Andric   /// using declarations and global alias variables) that aren't covered
16081ad6265SDimitry Andric   /// by other more specific caches.
1610b57cec5SDimitry Andric   llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
16281ad6265SDimitry Andric   llvm::DenseMap<const Decl *, llvm::TrackingMDRef> ImportedDeclCache;
1630b57cec5SDimitry Andric   llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NamespaceCache;
1640b57cec5SDimitry Andric   llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
1650b57cec5SDimitry Andric       NamespaceAliasCache;
1660b57cec5SDimitry Andric   llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
1670b57cec5SDimitry Andric       StaticDataMemberCache;
1680b57cec5SDimitry Andric 
169fe6060f1SDimitry Andric   using ParamDecl2StmtTy = llvm::DenseMap<const ParmVarDecl *, const Stmt *>;
170fe6060f1SDimitry Andric   using Param2DILocTy =
171fe6060f1SDimitry Andric       llvm::DenseMap<const ParmVarDecl *, llvm::DILocalVariable *>;
172fe6060f1SDimitry Andric 
173fe6060f1SDimitry Andric   /// The key is coroutine real parameters, value is coroutine move parameters.
174fe6060f1SDimitry Andric   ParamDecl2StmtTy CoroutineParameterMappings;
175fe6060f1SDimitry Andric   /// The key is coroutine real parameters, value is DIVariable in LLVM IR.
176fe6060f1SDimitry Andric   Param2DILocTy ParamDbgMappings;
177fe6060f1SDimitry Andric 
1780b57cec5SDimitry Andric   /// Helper functions for getOrCreateType.
1790b57cec5SDimitry Andric   /// @{
1800b57cec5SDimitry Andric   /// Currently the checksum of an interface includes the number of
1810b57cec5SDimitry Andric   /// ivars and property accessors.
1820b57cec5SDimitry Andric   llvm::DIType *CreateType(const BuiltinType *Ty);
1830b57cec5SDimitry Andric   llvm::DIType *CreateType(const ComplexType *Ty);
1840eae32dcSDimitry Andric   llvm::DIType *CreateType(const BitIntType *Ty);
18581ad6265SDimitry Andric   llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
186349cc55cSDimitry Andric   llvm::DIType *CreateQualifiedType(const FunctionProtoType *Ty,
187349cc55cSDimitry Andric                                     llvm::DIFile *Fg);
1880b57cec5SDimitry Andric   llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
1890b57cec5SDimitry Andric   llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
1900b57cec5SDimitry Andric                            llvm::DIFile *Fg);
1910b57cec5SDimitry Andric   llvm::DIType *CreateType(const ObjCObjectPointerType *Ty, llvm::DIFile *F);
19281ad6265SDimitry Andric   llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
1930b57cec5SDimitry Andric   llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
19481ad6265SDimitry Andric   llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
1950b57cec5SDimitry Andric   /// Get structure or union type.
1960b57cec5SDimitry Andric   llvm::DIType *CreateType(const RecordType *Tyg);
19706c3fb27SDimitry Andric 
19806c3fb27SDimitry Andric   /// Create definition for the specified 'Ty'.
19906c3fb27SDimitry Andric   ///
20006c3fb27SDimitry Andric   /// \returns A pair of 'llvm::DIType's. The first is the definition
20106c3fb27SDimitry Andric   /// of the 'Ty'. The second is the type specified by the preferred_name
20206c3fb27SDimitry Andric   /// attribute on 'Ty', which can be a nullptr if no such attribute
20306c3fb27SDimitry Andric   /// exists.
20406c3fb27SDimitry Andric   std::pair<llvm::DIType *, llvm::DIType *>
20506c3fb27SDimitry Andric   CreateTypeDefinition(const RecordType *Ty);
2060b57cec5SDimitry Andric   llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
2070b57cec5SDimitry Andric   void CollectContainingType(const CXXRecordDecl *RD,
2080b57cec5SDimitry Andric                              llvm::DICompositeType *CT);
2090b57cec5SDimitry Andric   /// Get Objective-C interface type.
2100b57cec5SDimitry Andric   llvm::DIType *CreateType(const ObjCInterfaceType *Ty, llvm::DIFile *F);
2110b57cec5SDimitry Andric   llvm::DIType *CreateTypeDefinition(const ObjCInterfaceType *Ty,
2120b57cec5SDimitry Andric                                      llvm::DIFile *F);
2130b57cec5SDimitry Andric   /// Get Objective-C object type.
2140b57cec5SDimitry Andric   llvm::DIType *CreateType(const ObjCObjectType *Ty, llvm::DIFile *F);
2150b57cec5SDimitry Andric   llvm::DIType *CreateType(const ObjCTypeParamType *Ty, llvm::DIFile *Unit);
2160b57cec5SDimitry Andric 
2170b57cec5SDimitry Andric   llvm::DIType *CreateType(const VectorType *Ty, llvm::DIFile *F);
2185ffd83dbSDimitry Andric   llvm::DIType *CreateType(const ConstantMatrixType *Ty, llvm::DIFile *F);
2190b57cec5SDimitry Andric   llvm::DIType *CreateType(const ArrayType *Ty, llvm::DIFile *F);
2200b57cec5SDimitry Andric   llvm::DIType *CreateType(const LValueReferenceType *Ty, llvm::DIFile *F);
2210b57cec5SDimitry Andric   llvm::DIType *CreateType(const RValueReferenceType *Ty, llvm::DIFile *Unit);
2220b57cec5SDimitry Andric   llvm::DIType *CreateType(const MemberPointerType *Ty, llvm::DIFile *F);
2230b57cec5SDimitry Andric   llvm::DIType *CreateType(const AtomicType *Ty, llvm::DIFile *F);
2240b57cec5SDimitry Andric   llvm::DIType *CreateType(const PipeType *Ty, llvm::DIFile *F);
2250b57cec5SDimitry Andric   /// Get enumeration type.
2260b57cec5SDimitry Andric   llvm::DIType *CreateEnumType(const EnumType *Ty);
2270b57cec5SDimitry Andric   llvm::DIType *CreateTypeDefinition(const EnumType *Ty);
2280b57cec5SDimitry Andric   /// Look up the completed type for a self pointer in the TypeCache and
2290b57cec5SDimitry Andric   /// create a copy of it with the ObjectPointer and Artificial flags
2300b57cec5SDimitry Andric   /// set. If the type is not cached, a new one is created. This should
2310b57cec5SDimitry Andric   /// never happen though, since creating a type for the implicit self
2320b57cec5SDimitry Andric   /// argument implies that we already parsed the interface definition
2330b57cec5SDimitry Andric   /// and the ivar declarations in the implementation.
2340b57cec5SDimitry Andric   llvm::DIType *CreateSelfType(const QualType &QualTy, llvm::DIType *Ty);
2350b57cec5SDimitry Andric   /// @}
2360b57cec5SDimitry Andric 
2370b57cec5SDimitry Andric   /// Get the type from the cache or return null type if it doesn't
2380b57cec5SDimitry Andric   /// exist.
2390b57cec5SDimitry Andric   llvm::DIType *getTypeOrNull(const QualType);
2400b57cec5SDimitry Andric   /// Return the debug type for a C++ method.
2410b57cec5SDimitry Andric   /// \arg CXXMethodDecl is of FunctionType. This function type is
2420b57cec5SDimitry Andric   /// not updated to include implicit \c this pointer. Use this routine
2430b57cec5SDimitry Andric   /// to get a method type which includes \c this pointer.
2440b57cec5SDimitry Andric   llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
245bdd1243dSDimitry Andric                                                 llvm::DIFile *F);
2460b57cec5SDimitry Andric   llvm::DISubroutineType *
2470b57cec5SDimitry Andric   getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func,
248bdd1243dSDimitry Andric                                 llvm::DIFile *Unit);
2490b57cec5SDimitry Andric   llvm::DISubroutineType *
2500b57cec5SDimitry Andric   getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
2510b57cec5SDimitry Andric   /// \return debug info descriptor for vtable.
2520b57cec5SDimitry Andric   llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
2530b57cec5SDimitry Andric 
2540b57cec5SDimitry Andric   /// \return namespace descriptor for the given namespace decl.
2550b57cec5SDimitry Andric   llvm::DINamespace *getOrCreateNamespace(const NamespaceDecl *N);
2560b57cec5SDimitry Andric   llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
25781ad6265SDimitry Andric                                       QualType PointeeTy, llvm::DIFile *F);
2580b57cec5SDimitry Andric   llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
2590b57cec5SDimitry Andric 
2600b57cec5SDimitry Andric   /// A helper function to create a subprogram for a single member
2610b57cec5SDimitry Andric   /// function GlobalDecl.
2620b57cec5SDimitry Andric   llvm::DISubprogram *CreateCXXMemberFunction(const CXXMethodDecl *Method,
2630b57cec5SDimitry Andric                                               llvm::DIFile *F,
2640b57cec5SDimitry Andric                                               llvm::DIType *RecordTy);
2650b57cec5SDimitry Andric 
2660b57cec5SDimitry Andric   /// A helper function to collect debug info for C++ member
2670b57cec5SDimitry Andric   /// functions. This is used while creating debug info entry for a
2680b57cec5SDimitry Andric   /// Record.
2690b57cec5SDimitry Andric   void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile *F,
2700b57cec5SDimitry Andric                                  SmallVectorImpl<llvm::Metadata *> &E,
2710b57cec5SDimitry Andric                                  llvm::DIType *T);
2720b57cec5SDimitry Andric 
2730b57cec5SDimitry Andric   /// A helper function to collect debug info for C++ base
2740b57cec5SDimitry Andric   /// classes. This is used while creating debug info entry for a
2750b57cec5SDimitry Andric   /// Record.
2760b57cec5SDimitry Andric   void CollectCXXBases(const CXXRecordDecl *Decl, llvm::DIFile *F,
2770b57cec5SDimitry Andric                        SmallVectorImpl<llvm::Metadata *> &EltTys,
2780b57cec5SDimitry Andric                        llvm::DIType *RecordTy);
2790b57cec5SDimitry Andric 
2800b57cec5SDimitry Andric   /// Helper function for CollectCXXBases.
2810b57cec5SDimitry Andric   /// Adds debug info entries for types in Bases that are not in SeenTypes.
2820b57cec5SDimitry Andric   void CollectCXXBasesAux(
2830b57cec5SDimitry Andric       const CXXRecordDecl *RD, llvm::DIFile *Unit,
2840b57cec5SDimitry Andric       SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
2850b57cec5SDimitry Andric       const CXXRecordDecl::base_class_const_range &Bases,
2860b57cec5SDimitry Andric       llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
2870b57cec5SDimitry Andric       llvm::DINode::DIFlags StartingFlags);
2880b57cec5SDimitry Andric 
28906c3fb27SDimitry Andric   /// Helper function that returns the llvm::DIType that the
29006c3fb27SDimitry Andric   /// PreferredNameAttr attribute on \ref RD refers to. If no such
29106c3fb27SDimitry Andric   /// attribute exists, returns nullptr.
29206c3fb27SDimitry Andric   llvm::DIType *GetPreferredNameType(const CXXRecordDecl *RD,
29306c3fb27SDimitry Andric                                      llvm::DIFile *Unit);
29406c3fb27SDimitry Andric 
295349cc55cSDimitry Andric   struct TemplateArgs {
296349cc55cSDimitry Andric     const TemplateParameterList *TList;
297349cc55cSDimitry Andric     llvm::ArrayRef<TemplateArgument> Args;
298349cc55cSDimitry Andric   };
2990b57cec5SDimitry Andric   /// A helper function to collect template parameters.
300bdd1243dSDimitry Andric   llvm::DINodeArray CollectTemplateParams(std::optional<TemplateArgs> Args,
3010b57cec5SDimitry Andric                                           llvm::DIFile *Unit);
3020b57cec5SDimitry Andric   /// A helper function to collect debug info for function template
3030b57cec5SDimitry Andric   /// parameters.
3040b57cec5SDimitry Andric   llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
3050b57cec5SDimitry Andric                                                   llvm::DIFile *Unit);
3060b57cec5SDimitry Andric 
3070b57cec5SDimitry Andric   /// A helper function to collect debug info for function template
3080b57cec5SDimitry Andric   /// parameters.
3090b57cec5SDimitry Andric   llvm::DINodeArray CollectVarTemplateParams(const VarDecl *VD,
3100b57cec5SDimitry Andric                                              llvm::DIFile *Unit);
3110b57cec5SDimitry Andric 
312bdd1243dSDimitry Andric   std::optional<TemplateArgs> GetTemplateArgs(const VarDecl *) const;
313bdd1243dSDimitry Andric   std::optional<TemplateArgs> GetTemplateArgs(const RecordDecl *) const;
314bdd1243dSDimitry Andric   std::optional<TemplateArgs> GetTemplateArgs(const FunctionDecl *) const;
315349cc55cSDimitry Andric 
3160b57cec5SDimitry Andric   /// A helper function to collect debug info for template
3170b57cec5SDimitry Andric   /// parameters.
318349cc55cSDimitry Andric   llvm::DINodeArray CollectCXXTemplateParams(const RecordDecl *TS,
3190b57cec5SDimitry Andric                                              llvm::DIFile *F);
3200b57cec5SDimitry Andric 
321349cc55cSDimitry Andric   /// A helper function to collect debug info for btf_decl_tag annotations.
322349cc55cSDimitry Andric   llvm::DINodeArray CollectBTFDeclTagAnnotations(const Decl *D);
323349cc55cSDimitry Andric 
3240b57cec5SDimitry Andric   llvm::DIType *createFieldType(StringRef name, QualType type,
3250b57cec5SDimitry Andric                                 SourceLocation loc, AccessSpecifier AS,
3260b57cec5SDimitry Andric                                 uint64_t offsetInBits, uint32_t AlignInBits,
3270b57cec5SDimitry Andric                                 llvm::DIFile *tunit, llvm::DIScope *scope,
328349cc55cSDimitry Andric                                 const RecordDecl *RD = nullptr,
32981ad6265SDimitry Andric                                 llvm::DINodeArray Annotations = nullptr);
3300b57cec5SDimitry Andric 
3310b57cec5SDimitry Andric   llvm::DIType *createFieldType(StringRef name, QualType type,
3320b57cec5SDimitry Andric                                 SourceLocation loc, AccessSpecifier AS,
3330b57cec5SDimitry Andric                                 uint64_t offsetInBits, llvm::DIFile *tunit,
3340b57cec5SDimitry Andric                                 llvm::DIScope *scope,
3350b57cec5SDimitry Andric                                 const RecordDecl *RD = nullptr) {
3360b57cec5SDimitry Andric     return createFieldType(name, type, loc, AS, offsetInBits, 0, tunit, scope,
3370b57cec5SDimitry Andric                            RD);
3380b57cec5SDimitry Andric   }
3390b57cec5SDimitry Andric 
3400b57cec5SDimitry Andric   /// Create new bit field member.
34106c3fb27SDimitry Andric   llvm::DIDerivedType *createBitFieldType(const FieldDecl *BitFieldDecl,
3420b57cec5SDimitry Andric                                           llvm::DIScope *RecordTy,
3430b57cec5SDimitry Andric                                           const RecordDecl *RD);
3440b57cec5SDimitry Andric 
34506c3fb27SDimitry Andric   /// Create an anonnymous zero-size separator for bit-field-decl if needed on
34606c3fb27SDimitry Andric   /// the target.
34706c3fb27SDimitry Andric   llvm::DIDerivedType *createBitFieldSeparatorIfNeeded(
34806c3fb27SDimitry Andric       const FieldDecl *BitFieldDecl, const llvm::DIDerivedType *BitFieldDI,
34906c3fb27SDimitry Andric       llvm::ArrayRef<llvm::Metadata *> PreviousFieldsDI, const RecordDecl *RD);
35006c3fb27SDimitry Andric 
351*0fca6ea1SDimitry Andric   /// A cache that maps names of artificial inlined functions to subprograms.
352*0fca6ea1SDimitry Andric   llvm::StringMap<llvm::DISubprogram *> InlinedTrapFuncMap;
353*0fca6ea1SDimitry Andric 
354*0fca6ea1SDimitry Andric   /// A function that returns the subprogram corresponding to the artificial
355*0fca6ea1SDimitry Andric   /// inlined function for traps.
356*0fca6ea1SDimitry Andric   llvm::DISubprogram *createInlinedTrapSubprogram(StringRef FuncName,
357*0fca6ea1SDimitry Andric                                                   llvm::DIFile *FileScope);
358*0fca6ea1SDimitry Andric 
3590b57cec5SDimitry Andric   /// Helpers for collecting fields of a record.
3600b57cec5SDimitry Andric   /// @{
3610b57cec5SDimitry Andric   void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
3620b57cec5SDimitry Andric                                  SmallVectorImpl<llvm::Metadata *> &E,
3630b57cec5SDimitry Andric                                  llvm::DIType *RecordTy);
3640b57cec5SDimitry Andric   llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
3650b57cec5SDimitry Andric                                                llvm::DIType *RecordTy,
3660b57cec5SDimitry Andric                                                const RecordDecl *RD);
3670b57cec5SDimitry Andric   void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
3680b57cec5SDimitry Andric                                 llvm::DIFile *F,
3690b57cec5SDimitry Andric                                 SmallVectorImpl<llvm::Metadata *> &E,
3700b57cec5SDimitry Andric                                 llvm::DIType *RecordTy, const RecordDecl *RD);
3710b57cec5SDimitry Andric   void CollectRecordNestedType(const TypeDecl *RD,
3720b57cec5SDimitry Andric                                SmallVectorImpl<llvm::Metadata *> &E);
3730b57cec5SDimitry Andric   void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
3740b57cec5SDimitry Andric                            SmallVectorImpl<llvm::Metadata *> &E,
3750b57cec5SDimitry Andric                            llvm::DICompositeType *RecordTy);
3760b57cec5SDimitry Andric 
3770b57cec5SDimitry Andric   /// If the C++ class has vtable info then insert appropriate debug
3780b57cec5SDimitry Andric   /// info entry in EltTys vector.
3790b57cec5SDimitry Andric   void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile *F,
380e8d8bef9SDimitry Andric                          SmallVectorImpl<llvm::Metadata *> &EltTys);
3810b57cec5SDimitry Andric   /// @}
3820b57cec5SDimitry Andric 
3830b57cec5SDimitry Andric   /// Create a new lexical block node and push it on the stack.
3840b57cec5SDimitry Andric   void CreateLexicalBlock(SourceLocation Loc);
3850b57cec5SDimitry Andric 
3860b57cec5SDimitry Andric   /// If target-specific LLVM \p AddressSpace directly maps to target-specific
3870b57cec5SDimitry Andric   /// DWARF address space, appends extended dereferencing mechanism to complex
3880b57cec5SDimitry Andric   /// expression \p Expr. Otherwise, does nothing.
3890b57cec5SDimitry Andric   ///
3900b57cec5SDimitry Andric   /// Extended dereferencing mechanism is has the following format:
3910b57cec5SDimitry Andric   ///     DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef
3920b57cec5SDimitry Andric   void AppendAddressSpaceXDeref(unsigned AddressSpace,
39304eeddc0SDimitry Andric                                 SmallVectorImpl<uint64_t> &Expr) const;
3940b57cec5SDimitry Andric 
3950b57cec5SDimitry Andric   /// A helper function to collect debug info for the default elements of a
3960b57cec5SDimitry Andric   /// block.
3970b57cec5SDimitry Andric   ///
3980b57cec5SDimitry Andric   /// \returns The next available field offset after the default elements.
3990b57cec5SDimitry Andric   uint64_t collectDefaultElementTypesForBlockPointer(
4000b57cec5SDimitry Andric       const BlockPointerType *Ty, llvm::DIFile *Unit,
4010b57cec5SDimitry Andric       llvm::DIDerivedType *DescTy, unsigned LineNo,
4020b57cec5SDimitry Andric       SmallVectorImpl<llvm::Metadata *> &EltTys);
4030b57cec5SDimitry Andric 
4040b57cec5SDimitry Andric   /// A helper function to collect debug info for the default fields of a
4050b57cec5SDimitry Andric   /// block.
4060b57cec5SDimitry Andric   void collectDefaultFieldsForBlockLiteralDeclare(
4070b57cec5SDimitry Andric       const CGBlockInfo &Block, const ASTContext &Context, SourceLocation Loc,
4080b57cec5SDimitry Andric       const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
4090b57cec5SDimitry Andric       SmallVectorImpl<llvm::Metadata *> &Fields);
4100b57cec5SDimitry Andric 
4110b57cec5SDimitry Andric public:
4120b57cec5SDimitry Andric   CGDebugInfo(CodeGenModule &CGM);
4130b57cec5SDimitry Andric   ~CGDebugInfo();
4140b57cec5SDimitry Andric 
4150b57cec5SDimitry Andric   void finalize();
4160b57cec5SDimitry Andric 
4170b57cec5SDimitry Andric   /// Remap a given path with the current debug prefix map
4180b57cec5SDimitry Andric   std::string remapDIPath(StringRef) const;
4190b57cec5SDimitry Andric 
4200b57cec5SDimitry Andric   /// Register VLA size expression debug node with the qualified type.
registerVLASizeExpression(QualType Ty,llvm::Metadata * SizeExpr)4210b57cec5SDimitry Andric   void registerVLASizeExpression(QualType Ty, llvm::Metadata *SizeExpr) {
4220b57cec5SDimitry Andric     SizeExprCache[Ty] = SizeExpr;
4230b57cec5SDimitry Andric   }
4240b57cec5SDimitry Andric 
4250b57cec5SDimitry Andric   /// Module debugging: Support for building PCMs.
4260b57cec5SDimitry Andric   /// @{
4270b57cec5SDimitry Andric   /// Set the main CU's DwoId field to \p Signature.
4280b57cec5SDimitry Andric   void setDwoId(uint64_t Signature);
4290b57cec5SDimitry Andric 
4300b57cec5SDimitry Andric   /// When generating debug information for a clang module or
4310b57cec5SDimitry Andric   /// precompiled header, this module map will be used to determine
4320b57cec5SDimitry Andric   /// the module of origin of each Decl.
setModuleMap(ModuleMap & MMap)4330b57cec5SDimitry Andric   void setModuleMap(ModuleMap &MMap) { ClangModuleMap = &MMap; }
4340b57cec5SDimitry Andric 
4350b57cec5SDimitry Andric   /// When generating debug information for a clang module or
4360b57cec5SDimitry Andric   /// precompiled header, this module map will be used to determine
4370b57cec5SDimitry Andric   /// the module of origin of each Decl.
setPCHDescriptor(ASTSourceDescriptor PCH)4385ffd83dbSDimitry Andric   void setPCHDescriptor(ASTSourceDescriptor PCH) { PCHDescriptor = PCH; }
4390b57cec5SDimitry Andric   /// @}
4400b57cec5SDimitry Andric 
4410b57cec5SDimitry Andric   /// Update the current source location. If \arg loc is invalid it is
4420b57cec5SDimitry Andric   /// ignored.
4430b57cec5SDimitry Andric   void setLocation(SourceLocation Loc);
4440b57cec5SDimitry Andric 
4450b57cec5SDimitry Andric   /// Return the current source location. This does not necessarily correspond
4460b57cec5SDimitry Andric   /// to the IRBuilder's current DebugLoc.
getLocation()4470b57cec5SDimitry Andric   SourceLocation getLocation() const { return CurLoc; }
4480b57cec5SDimitry Andric 
4490b57cec5SDimitry Andric   /// Update the current inline scope. All subsequent calls to \p EmitLocation
4500b57cec5SDimitry Andric   /// will create a location with this inlinedAt field.
setInlinedAt(llvm::MDNode * InlinedAt)4510b57cec5SDimitry Andric   void setInlinedAt(llvm::MDNode *InlinedAt) { CurInlinedAt = InlinedAt; }
4520b57cec5SDimitry Andric 
4530b57cec5SDimitry Andric   /// \return the current inline scope.
getInlinedAt()4540b57cec5SDimitry Andric   llvm::MDNode *getInlinedAt() const { return CurInlinedAt; }
4550b57cec5SDimitry Andric 
4560b57cec5SDimitry Andric   // Converts a SourceLocation to a DebugLoc
4570b57cec5SDimitry Andric   llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Loc);
4580b57cec5SDimitry Andric 
4590b57cec5SDimitry Andric   /// Emit metadata to indicate a change in line/column information in
4600b57cec5SDimitry Andric   /// the source file. If the location is invalid, the previous
4610b57cec5SDimitry Andric   /// location will be reused.
4620b57cec5SDimitry Andric   void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc);
4630b57cec5SDimitry Andric 
464349cc55cSDimitry Andric   QualType getFunctionType(const FunctionDecl *FD, QualType RetTy,
465349cc55cSDimitry Andric                            const SmallVectorImpl<const VarDecl *> &Args);
466349cc55cSDimitry Andric 
4670b57cec5SDimitry Andric   /// Emit a call to llvm.dbg.function.start to indicate
4680b57cec5SDimitry Andric   /// start of a new function.
4690b57cec5SDimitry Andric   /// \param Loc       The location of the function header.
4700b57cec5SDimitry Andric   /// \param ScopeLoc  The location of the function body.
471e8d8bef9SDimitry Andric   void emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
4720b57cec5SDimitry Andric                          SourceLocation ScopeLoc, QualType FnType,
473e8d8bef9SDimitry Andric                          llvm::Function *Fn, bool CurFnIsThunk);
4740b57cec5SDimitry Andric 
4750b57cec5SDimitry Andric   /// Start a new scope for an inlined function.
4760b57cec5SDimitry Andric   void EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD);
4770b57cec5SDimitry Andric   /// End an inlined function scope.
4780b57cec5SDimitry Andric   void EmitInlineFunctionEnd(CGBuilderTy &Builder);
4790b57cec5SDimitry Andric 
4800b57cec5SDimitry Andric   /// Emit debug info for a function declaration.
4810b57cec5SDimitry Andric   /// \p Fn is set only when a declaration for a debug call site gets created.
4820b57cec5SDimitry Andric   void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
4830b57cec5SDimitry Andric                         QualType FnType, llvm::Function *Fn = nullptr);
4840b57cec5SDimitry Andric 
4850b57cec5SDimitry Andric   /// Emit debug info for an extern function being called.
4860b57cec5SDimitry Andric   /// This is needed for call site debug info.
4870b57cec5SDimitry Andric   void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
4880b57cec5SDimitry Andric                                QualType CalleeType,
4890b57cec5SDimitry Andric                                const FunctionDecl *CalleeDecl);
4900b57cec5SDimitry Andric 
4910b57cec5SDimitry Andric   /// Constructs the debug code for exiting a function.
4920b57cec5SDimitry Andric   void EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn);
4930b57cec5SDimitry Andric 
4940b57cec5SDimitry Andric   /// Emit metadata to indicate the beginning of a new lexical block
4950b57cec5SDimitry Andric   /// and push the block onto the stack.
4960b57cec5SDimitry Andric   void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
4970b57cec5SDimitry Andric 
4980b57cec5SDimitry Andric   /// Emit metadata to indicate the end of a new lexical block and pop
4990b57cec5SDimitry Andric   /// the current block.
5000b57cec5SDimitry Andric   void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
5010b57cec5SDimitry Andric 
5020b57cec5SDimitry Andric   /// Emit call to \c llvm.dbg.declare for an automatic variable
5030b57cec5SDimitry Andric   /// declaration.
5040b57cec5SDimitry Andric   /// Returns a pointer to the DILocalVariable associated with the
5050b57cec5SDimitry Andric   /// llvm.dbg.declare, or nullptr otherwise.
5060b57cec5SDimitry Andric   llvm::DILocalVariable *
5070b57cec5SDimitry Andric   EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
5080b57cec5SDimitry Andric                             CGBuilderTy &Builder,
5090b57cec5SDimitry Andric                             const bool UsePointerValue = false);
5100b57cec5SDimitry Andric 
5110b57cec5SDimitry Andric   /// Emit call to \c llvm.dbg.label for an label.
5120b57cec5SDimitry Andric   void EmitLabel(const LabelDecl *D, CGBuilderTy &Builder);
5130b57cec5SDimitry Andric 
5140b57cec5SDimitry Andric   /// Emit call to \c llvm.dbg.declare for an imported variable
5150b57cec5SDimitry Andric   /// declaration in a block.
5160b57cec5SDimitry Andric   void EmitDeclareOfBlockDeclRefVariable(
5170b57cec5SDimitry Andric       const VarDecl *variable, llvm::Value *storage, CGBuilderTy &Builder,
5180b57cec5SDimitry Andric       const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint = nullptr);
5190b57cec5SDimitry Andric 
5200b57cec5SDimitry Andric   /// Emit call to \c llvm.dbg.declare for an argument variable
5210b57cec5SDimitry Andric   /// declaration.
52206c3fb27SDimitry Andric   llvm::DILocalVariable *
52306c3fb27SDimitry Andric   EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, unsigned ArgNo,
52406c3fb27SDimitry Andric                            CGBuilderTy &Builder, bool UsePointerValue = false);
5250b57cec5SDimitry Andric 
5260b57cec5SDimitry Andric   /// Emit call to \c llvm.dbg.declare for the block-literal argument
5270b57cec5SDimitry Andric   /// to a block invocation function.
5280b57cec5SDimitry Andric   void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
5290b57cec5SDimitry Andric                                             StringRef Name, unsigned ArgNo,
5300b57cec5SDimitry Andric                                             llvm::AllocaInst *LocalAddr,
5310b57cec5SDimitry Andric                                             CGBuilderTy &Builder);
5320b57cec5SDimitry Andric 
5330b57cec5SDimitry Andric   /// Emit information about a global variable.
5340b57cec5SDimitry Andric   void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
5350b57cec5SDimitry Andric 
5360b57cec5SDimitry Andric   /// Emit a constant global variable's debug info.
5370b57cec5SDimitry Andric   void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
5380b57cec5SDimitry Andric 
539480093f4SDimitry Andric   /// Emit information about an external variable.
540480093f4SDimitry Andric   void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
541480093f4SDimitry Andric 
542*0fca6ea1SDimitry Andric   /// Emit a pseudo variable and debug info for an intermediate value if it does
543*0fca6ea1SDimitry Andric   /// not correspond to a variable in the source code, so that a profiler can
544*0fca6ea1SDimitry Andric   /// track more accurate usage of certain instructions of interest.
545*0fca6ea1SDimitry Andric   void EmitPseudoVariable(CGBuilderTy &Builder, llvm::Instruction *Value,
546*0fca6ea1SDimitry Andric                           QualType Ty);
547*0fca6ea1SDimitry Andric 
54881ad6265SDimitry Andric   /// Emit information about global variable alias.
54981ad6265SDimitry Andric   void EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl Decl);
55081ad6265SDimitry Andric 
5510b57cec5SDimitry Andric   /// Emit C++ using directive.
5520b57cec5SDimitry Andric   void EmitUsingDirective(const UsingDirectiveDecl &UD);
5530b57cec5SDimitry Andric 
5540b57cec5SDimitry Andric   /// Emit the type explicitly casted to.
5550b57cec5SDimitry Andric   void EmitExplicitCastType(QualType Ty);
5560b57cec5SDimitry Andric 
557e8d8bef9SDimitry Andric   /// Emit the type even if it might not be used.
558e8d8bef9SDimitry Andric   void EmitAndRetainType(QualType Ty);
559e8d8bef9SDimitry Andric 
560fe6060f1SDimitry Andric   /// Emit a shadow decl brought in by a using or using-enum
561fe6060f1SDimitry Andric   void EmitUsingShadowDecl(const UsingShadowDecl &USD);
562fe6060f1SDimitry Andric 
5630b57cec5SDimitry Andric   /// Emit C++ using declaration.
5640b57cec5SDimitry Andric   void EmitUsingDecl(const UsingDecl &UD);
5650b57cec5SDimitry Andric 
566fe6060f1SDimitry Andric   /// Emit C++ using-enum declaration.
567fe6060f1SDimitry Andric   void EmitUsingEnumDecl(const UsingEnumDecl &UD);
568fe6060f1SDimitry Andric 
5690b57cec5SDimitry Andric   /// Emit an @import declaration.
5700b57cec5SDimitry Andric   void EmitImportDecl(const ImportDecl &ID);
5710b57cec5SDimitry Andric 
57281ad6265SDimitry Andric   /// DebugInfo isn't attached to string literals by default. While certain
57381ad6265SDimitry Andric   /// aspects of debuginfo aren't useful for string literals (like a name), it's
57481ad6265SDimitry Andric   /// nice to be able to symbolize the line and column information. This is
57581ad6265SDimitry Andric   /// especially useful for sanitizers, as it allows symbolization of
57681ad6265SDimitry Andric   /// heap-buffer-overflows on constant strings.
57781ad6265SDimitry Andric   void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
57881ad6265SDimitry Andric                                  const StringLiteral *S);
57981ad6265SDimitry Andric 
5800b57cec5SDimitry Andric   /// Emit C++ namespace alias.
5810b57cec5SDimitry Andric   llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
5820b57cec5SDimitry Andric 
5830b57cec5SDimitry Andric   /// Emit record type's standalone debug info.
5840b57cec5SDimitry Andric   llvm::DIType *getOrCreateRecordType(QualType Ty, SourceLocation L);
5850b57cec5SDimitry Andric 
5860b57cec5SDimitry Andric   /// Emit an Objective-C interface type standalone debug info.
5870b57cec5SDimitry Andric   llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
5880b57cec5SDimitry Andric 
5890b57cec5SDimitry Andric   /// Emit standalone debug info for a type.
5900b57cec5SDimitry Andric   llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
5910b57cec5SDimitry Andric 
5920b57cec5SDimitry Andric   /// Add heapallocsite metadata for MSAllocator calls.
5935ffd83dbSDimitry Andric   void addHeapAllocSiteMetadata(llvm::CallBase *CallSite, QualType AllocatedTy,
5940b57cec5SDimitry Andric                                 SourceLocation Loc);
5950b57cec5SDimitry Andric 
5960b57cec5SDimitry Andric   void completeType(const EnumDecl *ED);
5970b57cec5SDimitry Andric   void completeType(const RecordDecl *RD);
5980b57cec5SDimitry Andric   void completeRequiredType(const RecordDecl *RD);
5990b57cec5SDimitry Andric   void completeClassData(const RecordDecl *RD);
6000b57cec5SDimitry Andric   void completeClass(const RecordDecl *RD);
6010b57cec5SDimitry Andric 
6020b57cec5SDimitry Andric   void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD);
6030b57cec5SDimitry Andric   void completeUnusedClass(const CXXRecordDecl &D);
6040b57cec5SDimitry Andric 
6050b57cec5SDimitry Andric   /// Create debug info for a macro defined by a #define directive or a macro
6060b57cec5SDimitry Andric   /// undefined by a #undef directive.
6070b57cec5SDimitry Andric   llvm::DIMacro *CreateMacro(llvm::DIMacroFile *Parent, unsigned MType,
6080b57cec5SDimitry Andric                              SourceLocation LineLoc, StringRef Name,
6090b57cec5SDimitry Andric                              StringRef Value);
6100b57cec5SDimitry Andric 
6110b57cec5SDimitry Andric   /// Create debug info for a file referenced by an #include directive.
6120b57cec5SDimitry Andric   llvm::DIMacroFile *CreateTempMacroFile(llvm::DIMacroFile *Parent,
6130b57cec5SDimitry Andric                                          SourceLocation LineLoc,
6140b57cec5SDimitry Andric                                          SourceLocation FileLoc);
6150b57cec5SDimitry Andric 
getParamDbgMappings()616fe6060f1SDimitry Andric   Param2DILocTy &getParamDbgMappings() { return ParamDbgMappings; }
getCoroutineParameterMappings()617fe6060f1SDimitry Andric   ParamDecl2StmtTy &getCoroutineParameterMappings() {
618fe6060f1SDimitry Andric     return CoroutineParameterMappings;
619fe6060f1SDimitry Andric   }
620fe6060f1SDimitry Andric 
621*0fca6ea1SDimitry Andric   /// Create a debug location from `TrapLocation` that adds an artificial inline
622*0fca6ea1SDimitry Andric   /// frame where the frame name is
623*0fca6ea1SDimitry Andric   ///
624*0fca6ea1SDimitry Andric   /// * `<Prefix>:<Category>:<FailureMsg>`
625*0fca6ea1SDimitry Andric   ///
626*0fca6ea1SDimitry Andric   /// `<Prefix>` is "__clang_trap_msg".
627*0fca6ea1SDimitry Andric   ///
628*0fca6ea1SDimitry Andric   /// This is used to store failure reasons for traps.
629*0fca6ea1SDimitry Andric   llvm::DILocation *CreateTrapFailureMessageFor(llvm::DebugLoc TrapLocation,
630*0fca6ea1SDimitry Andric                                                 StringRef Category,
631*0fca6ea1SDimitry Andric                                                 StringRef FailureMsg);
632*0fca6ea1SDimitry Andric 
6330b57cec5SDimitry Andric private:
6340b57cec5SDimitry Andric   /// Emit call to llvm.dbg.declare for a variable declaration.
6350b57cec5SDimitry Andric   /// Returns a pointer to the DILocalVariable associated with the
6360b57cec5SDimitry Andric   /// llvm.dbg.declare, or nullptr otherwise.
6370b57cec5SDimitry Andric   llvm::DILocalVariable *EmitDeclare(const VarDecl *decl, llvm::Value *AI,
638bdd1243dSDimitry Andric                                      std::optional<unsigned> ArgNo,
6390b57cec5SDimitry Andric                                      CGBuilderTy &Builder,
6400b57cec5SDimitry Andric                                      const bool UsePointerValue = false);
6410b57cec5SDimitry Andric 
64281ad6265SDimitry Andric   /// Emit call to llvm.dbg.declare for a binding declaration.
64381ad6265SDimitry Andric   /// Returns a pointer to the DILocalVariable associated with the
64481ad6265SDimitry Andric   /// llvm.dbg.declare, or nullptr otherwise.
64581ad6265SDimitry Andric   llvm::DILocalVariable *EmitDeclare(const BindingDecl *decl, llvm::Value *AI,
646bdd1243dSDimitry Andric                                      std::optional<unsigned> ArgNo,
64781ad6265SDimitry Andric                                      CGBuilderTy &Builder,
64881ad6265SDimitry Andric                                      const bool UsePointerValue = false);
64981ad6265SDimitry Andric 
6500b57cec5SDimitry Andric   struct BlockByRefType {
6510b57cec5SDimitry Andric     /// The wrapper struct used inside the __block_literal struct.
6520b57cec5SDimitry Andric     llvm::DIType *BlockByRefWrapper;
6530b57cec5SDimitry Andric     /// The type as it appears in the source code.
6540b57cec5SDimitry Andric     llvm::DIType *WrappedType;
6550b57cec5SDimitry Andric   };
6560b57cec5SDimitry Andric 
657*0fca6ea1SDimitry Andric   bool HasReconstitutableArgs(ArrayRef<TemplateArgument> Args) const;
658fe6060f1SDimitry Andric   std::string GetName(const Decl *, bool Qualified = false) const;
659fe6060f1SDimitry Andric 
6600b57cec5SDimitry Andric   /// Build up structure info for the byref.  See \a BuildByRefType.
6610b57cec5SDimitry Andric   BlockByRefType EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
6620b57cec5SDimitry Andric                                               uint64_t *OffSet);
6630b57cec5SDimitry Andric 
6640b57cec5SDimitry Andric   /// Get context info for the DeclContext of \p Decl.
6650b57cec5SDimitry Andric   llvm::DIScope *getDeclContextDescriptor(const Decl *D);
6660b57cec5SDimitry Andric   /// Get context info for a given DeclContext \p Decl.
6670b57cec5SDimitry Andric   llvm::DIScope *getContextDescriptor(const Decl *Context,
6680b57cec5SDimitry Andric                                       llvm::DIScope *Default);
6690b57cec5SDimitry Andric 
6700b57cec5SDimitry Andric   llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);
6710b57cec5SDimitry Andric 
6720b57cec5SDimitry Andric   /// Create a forward decl for a RecordType in a given context.
6730b57cec5SDimitry Andric   llvm::DICompositeType *getOrCreateRecordFwdDecl(const RecordType *,
6740b57cec5SDimitry Andric                                                   llvm::DIScope *);
6750b57cec5SDimitry Andric 
6760b57cec5SDimitry Andric   /// Return current directory name.
6770b57cec5SDimitry Andric   StringRef getCurrentDirname();
6780b57cec5SDimitry Andric 
6790b57cec5SDimitry Andric   /// Create new compile unit.
6800b57cec5SDimitry Andric   void CreateCompileUnit();
6810b57cec5SDimitry Andric 
6820b57cec5SDimitry Andric   /// Compute the file checksum debug info for input file ID.
683bdd1243dSDimitry Andric   std::optional<llvm::DIFile::ChecksumKind>
684bdd1243dSDimitry Andric   computeChecksum(FileID FID, SmallString<64> &Checksum) const;
6850b57cec5SDimitry Andric 
6860b57cec5SDimitry Andric   /// Get the source of the given file ID.
687bdd1243dSDimitry Andric   std::optional<StringRef> getSource(const SourceManager &SM, FileID FID);
6880b57cec5SDimitry Andric 
6890b57cec5SDimitry Andric   /// Convenience function to get the file debug info descriptor for the input
6900b57cec5SDimitry Andric   /// location.
6910b57cec5SDimitry Andric   llvm::DIFile *getOrCreateFile(SourceLocation Loc);
6920b57cec5SDimitry Andric 
6930b57cec5SDimitry Andric   /// Create a file debug info descriptor for a source file.
6940b57cec5SDimitry Andric   llvm::DIFile *
6950b57cec5SDimitry Andric   createFile(StringRef FileName,
696bdd1243dSDimitry Andric              std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
697bdd1243dSDimitry Andric              std::optional<StringRef> Source);
6980b57cec5SDimitry Andric 
6990b57cec5SDimitry Andric   /// Get the type from the cache or create a new type if necessary.
70081ad6265SDimitry Andric   llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
7010b57cec5SDimitry Andric 
7020b57cec5SDimitry Andric   /// Get a reference to a clang module.  If \p CreateSkeletonCU is true,
7030b57cec5SDimitry Andric   /// this also creates a split dwarf skeleton compile unit.
7045ffd83dbSDimitry Andric   llvm::DIModule *getOrCreateModuleRef(ASTSourceDescriptor Mod,
7050b57cec5SDimitry Andric                                        bool CreateSkeletonCU);
7060b57cec5SDimitry Andric 
7070b57cec5SDimitry Andric   /// DebugTypeExtRefs: If \p D originated in a clang module, return it.
7080b57cec5SDimitry Andric   llvm::DIModule *getParentModuleOrNull(const Decl *D);
7090b57cec5SDimitry Andric 
7100b57cec5SDimitry Andric   /// Get the type from the cache or create a new partial type if
7110b57cec5SDimitry Andric   /// necessary.
712e8d8bef9SDimitry Andric   llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty);
7130b57cec5SDimitry Andric 
7140b57cec5SDimitry Andric   /// Create type metadata for a source language type.
71581ad6265SDimitry Andric   llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
7160b57cec5SDimitry Andric 
7170b57cec5SDimitry Andric   /// Create new member and increase Offset by FType's size.
7180b57cec5SDimitry Andric   llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,
7190b57cec5SDimitry Andric                                  StringRef Name, uint64_t *Offset);
7200b57cec5SDimitry Andric 
7210b57cec5SDimitry Andric   /// Retrieve the DIDescriptor, if any, for the canonical form of this
7220b57cec5SDimitry Andric   /// declaration.
7230b57cec5SDimitry Andric   llvm::DINode *getDeclarationOrDefinition(const Decl *D);
7240b57cec5SDimitry Andric 
7250b57cec5SDimitry Andric   /// \return debug info descriptor to describe method
7260b57cec5SDimitry Andric   /// declaration for the given method definition.
7270b57cec5SDimitry Andric   llvm::DISubprogram *getFunctionDeclaration(const Decl *D);
7280b57cec5SDimitry Andric 
729480093f4SDimitry Andric   /// \return          debug info descriptor to the describe method declaration
730480093f4SDimitry Andric   ///                  for the given method definition.
731480093f4SDimitry Andric   /// \param FnType    For Objective-C methods, their type.
732480093f4SDimitry Andric   /// \param LineNo    The declaration's line number.
733480093f4SDimitry Andric   /// \param Flags     The DIFlags for the method declaration.
734480093f4SDimitry Andric   /// \param SPFlags   The subprogram-spcific flags for the method declaration.
735480093f4SDimitry Andric   llvm::DISubprogram *
736480093f4SDimitry Andric   getObjCMethodDeclaration(const Decl *D, llvm::DISubroutineType *FnType,
737480093f4SDimitry Andric                            unsigned LineNo, llvm::DINode::DIFlags Flags,
738480093f4SDimitry Andric                            llvm::DISubprogram::DISPFlags SPFlags);
739480093f4SDimitry Andric 
7400b57cec5SDimitry Andric   /// \return debug info descriptor to describe in-class static data
7410b57cec5SDimitry Andric   /// member declaration for the given out-of-class definition.  If D
7420b57cec5SDimitry Andric   /// is an out-of-class definition of a static data member of a
7430b57cec5SDimitry Andric   /// class, find its corresponding in-class declaration.
7440b57cec5SDimitry Andric   llvm::DIDerivedType *
7450b57cec5SDimitry Andric   getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
7460b57cec5SDimitry Andric 
7470b57cec5SDimitry Andric   /// Helper that either creates a forward declaration or a stub.
7480b57cec5SDimitry Andric   llvm::DISubprogram *getFunctionFwdDeclOrStub(GlobalDecl GD, bool Stub);
7490b57cec5SDimitry Andric 
7500b57cec5SDimitry Andric   /// Create a subprogram describing the forward declaration
7510b57cec5SDimitry Andric   /// represented in the given FunctionDecl wrapped in a GlobalDecl.
7520b57cec5SDimitry Andric   llvm::DISubprogram *getFunctionForwardDeclaration(GlobalDecl GD);
7530b57cec5SDimitry Andric 
7540b57cec5SDimitry Andric   /// Create a DISubprogram describing the function
7550b57cec5SDimitry Andric   /// represented in the given FunctionDecl wrapped in a GlobalDecl.
7560b57cec5SDimitry Andric   llvm::DISubprogram *getFunctionStub(GlobalDecl GD);
7570b57cec5SDimitry Andric 
7580b57cec5SDimitry Andric   /// Create a global variable describing the forward declaration
7590b57cec5SDimitry Andric   /// represented in the given VarDecl.
7600b57cec5SDimitry Andric   llvm::DIGlobalVariable *
7610b57cec5SDimitry Andric   getGlobalVariableForwardDeclaration(const VarDecl *VD);
7620b57cec5SDimitry Andric 
7630b57cec5SDimitry Andric   /// Return a global variable that represents one of the collection of global
7640b57cec5SDimitry Andric   /// variables created for an anonmyous union.
7650b57cec5SDimitry Andric   ///
7660b57cec5SDimitry Andric   /// Recursively collect all of the member fields of a global
7670b57cec5SDimitry Andric   /// anonymous decl and create static variables for them. The first
7680b57cec5SDimitry Andric   /// time this is called it needs to be on a union and then from
7690b57cec5SDimitry Andric   /// there we can have additional unnamed fields.
7700b57cec5SDimitry Andric   llvm::DIGlobalVariableExpression *
7710b57cec5SDimitry Andric   CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
7720b57cec5SDimitry Andric                          unsigned LineNo, StringRef LinkageName,
7730b57cec5SDimitry Andric                          llvm::GlobalVariable *Var, llvm::DIScope *DContext);
7740b57cec5SDimitry Andric 
7750b57cec5SDimitry Andric 
7760b57cec5SDimitry Andric   /// Return flags which enable debug info emission for call sites, provided
7770b57cec5SDimitry Andric   /// that it is supported and enabled.
7780b57cec5SDimitry Andric   llvm::DINode::DIFlags getCallSiteRelatedAttrs() const;
7790b57cec5SDimitry Andric 
7800b57cec5SDimitry Andric   /// Get the printing policy for producing names for debug info.
7810b57cec5SDimitry Andric   PrintingPolicy getPrintingPolicy() const;
7820b57cec5SDimitry Andric 
7830b57cec5SDimitry Andric   /// Get function name for the given FunctionDecl. If the name is
7840b57cec5SDimitry Andric   /// constructed on demand (e.g., C++ destructor) then the name is
7850b57cec5SDimitry Andric   /// stored on the side.
7860b57cec5SDimitry Andric   StringRef getFunctionName(const FunctionDecl *FD);
7870b57cec5SDimitry Andric 
7880b57cec5SDimitry Andric   /// Returns the unmangled name of an Objective-C method.
7890b57cec5SDimitry Andric   /// This is the display name for the debugging info.
7900b57cec5SDimitry Andric   StringRef getObjCMethodName(const ObjCMethodDecl *FD);
7910b57cec5SDimitry Andric 
7920b57cec5SDimitry Andric   /// Return selector name. This is used for debugging
7930b57cec5SDimitry Andric   /// info.
7940b57cec5SDimitry Andric   StringRef getSelectorName(Selector S);
7950b57cec5SDimitry Andric 
7960b57cec5SDimitry Andric   /// Get class name including template argument list.
7970b57cec5SDimitry Andric   StringRef getClassName(const RecordDecl *RD);
7980b57cec5SDimitry Andric 
7990b57cec5SDimitry Andric   /// Get the vtable name for the given class.
8000b57cec5SDimitry Andric   StringRef getVTableName(const CXXRecordDecl *Decl);
8010b57cec5SDimitry Andric 
8020b57cec5SDimitry Andric   /// Get the name to use in the debug info for a dynamic initializer or atexit
8030b57cec5SDimitry Andric   /// stub function.
8040b57cec5SDimitry Andric   StringRef getDynamicInitializerName(const VarDecl *VD,
8050b57cec5SDimitry Andric                                       DynamicInitKind StubKind,
8060b57cec5SDimitry Andric                                       llvm::Function *InitFn);
8070b57cec5SDimitry Andric 
8080b57cec5SDimitry Andric   /// Get line number for the location. If location is invalid
8090b57cec5SDimitry Andric   /// then use current location.
8100b57cec5SDimitry Andric   unsigned getLineNumber(SourceLocation Loc);
8110b57cec5SDimitry Andric 
8120b57cec5SDimitry Andric   /// Get column number for the location. If location is
8130b57cec5SDimitry Andric   /// invalid then use current location.
8140b57cec5SDimitry Andric   /// \param Force  Assume DebugColumnInfo option is true.
8150b57cec5SDimitry Andric   unsigned getColumnNumber(SourceLocation Loc, bool Force = false);
8160b57cec5SDimitry Andric 
8170b57cec5SDimitry Andric   /// Collect various properties of a FunctionDecl.
8180b57cec5SDimitry Andric   /// \param GD  A GlobalDecl whose getDecl() must return a FunctionDecl.
8190b57cec5SDimitry Andric   void collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
8200b57cec5SDimitry Andric                                 StringRef &Name, StringRef &LinkageName,
8210b57cec5SDimitry Andric                                 llvm::DIScope *&FDContext,
8220b57cec5SDimitry Andric                                 llvm::DINodeArray &TParamsArray,
8230b57cec5SDimitry Andric                                 llvm::DINode::DIFlags &Flags);
8240b57cec5SDimitry Andric 
8250b57cec5SDimitry Andric   /// Collect various properties of a VarDecl.
8260b57cec5SDimitry Andric   void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
8270b57cec5SDimitry Andric                            unsigned &LineNo, QualType &T, StringRef &Name,
8280b57cec5SDimitry Andric                            StringRef &LinkageName,
8290b57cec5SDimitry Andric                            llvm::MDTuple *&TemplateParameters,
8300b57cec5SDimitry Andric                            llvm::DIScope *&VDContext);
8310b57cec5SDimitry Andric 
8325f757f3fSDimitry Andric   /// Create a DIExpression representing the constant corresponding
8335f757f3fSDimitry Andric   /// to the specified 'Val'. Returns nullptr on failure.
8345f757f3fSDimitry Andric   llvm::DIExpression *createConstantValueExpression(const clang::ValueDecl *VD,
8355f757f3fSDimitry Andric                                                     const APValue &Val);
8365f757f3fSDimitry Andric 
8370b57cec5SDimitry Andric   /// Allocate a copy of \p A using the DebugInfoNames allocator
8380b57cec5SDimitry Andric   /// and return a reference to it. If multiple arguments are given the strings
8390b57cec5SDimitry Andric   /// are concatenated.
8400b57cec5SDimitry Andric   StringRef internString(StringRef A, StringRef B = StringRef()) {
8410b57cec5SDimitry Andric     char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
8420b57cec5SDimitry Andric     if (!A.empty())
8430b57cec5SDimitry Andric       std::memcpy(Data, A.data(), A.size());
8440b57cec5SDimitry Andric     if (!B.empty())
8450b57cec5SDimitry Andric       std::memcpy(Data + A.size(), B.data(), B.size());
8460b57cec5SDimitry Andric     return StringRef(Data, A.size() + B.size());
8470b57cec5SDimitry Andric   }
8480b57cec5SDimitry Andric };
8490b57cec5SDimitry Andric 
8500b57cec5SDimitry Andric /// A scoped helper to set the current debug location to the specified
8510b57cec5SDimitry Andric /// location or preferred location of the specified Expr.
8520b57cec5SDimitry Andric class ApplyDebugLocation {
8530b57cec5SDimitry Andric private:
8540b57cec5SDimitry Andric   void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
8550b57cec5SDimitry Andric   ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
8560b57cec5SDimitry Andric                      SourceLocation TemporaryLocation);
8570b57cec5SDimitry Andric 
8580b57cec5SDimitry Andric   llvm::DebugLoc OriginalLocation;
8590b57cec5SDimitry Andric   CodeGenFunction *CGF;
8600b57cec5SDimitry Andric 
8610b57cec5SDimitry Andric public:
8620b57cec5SDimitry Andric   /// Set the location to the (valid) TemporaryLocation.
8630b57cec5SDimitry Andric   ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
8640b57cec5SDimitry Andric   ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
8650b57cec5SDimitry Andric   ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
ApplyDebugLocation(ApplyDebugLocation && Other)8660b57cec5SDimitry Andric   ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
8670b57cec5SDimitry Andric     Other.CGF = nullptr;
8680b57cec5SDimitry Andric   }
86906c3fb27SDimitry Andric 
87006c3fb27SDimitry Andric   // Define copy assignment operator.
87106c3fb27SDimitry Andric   ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
8725f757f3fSDimitry Andric     if (this != &Other) {
87306c3fb27SDimitry Andric       CGF = Other.CGF;
87406c3fb27SDimitry Andric       Other.CGF = nullptr;
8755f757f3fSDimitry Andric     }
87606c3fb27SDimitry Andric     return *this;
87706c3fb27SDimitry Andric   }
8780b57cec5SDimitry Andric 
8790b57cec5SDimitry Andric   ~ApplyDebugLocation();
8800b57cec5SDimitry Andric 
8810b57cec5SDimitry Andric   /// Apply TemporaryLocation if it is valid. Otherwise switch
8820b57cec5SDimitry Andric   /// to an artificial debug location that has a valid scope, but no
8830b57cec5SDimitry Andric   /// line information.
8840b57cec5SDimitry Andric   ///
8850b57cec5SDimitry Andric   /// Artificial locations are useful when emitting compiler-generated
8860b57cec5SDimitry Andric   /// helper functions that have no source location associated with
8870b57cec5SDimitry Andric   /// them. The DWARF specification allows the compiler to use the
8880b57cec5SDimitry Andric   /// special line number 0 to indicate code that can not be
8890b57cec5SDimitry Andric   /// attributed to any source location. Note that passing an empty
8900b57cec5SDimitry Andric   /// SourceLocation to CGDebugInfo::setLocation() will result in the
8910b57cec5SDimitry Andric   /// last valid location being reused.
CreateArtificial(CodeGenFunction & CGF)8920b57cec5SDimitry Andric   static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF) {
8930b57cec5SDimitry Andric     return ApplyDebugLocation(CGF, false, SourceLocation());
8940b57cec5SDimitry Andric   }
8950b57cec5SDimitry Andric   /// Apply TemporaryLocation if it is valid. Otherwise switch
8960b57cec5SDimitry Andric   /// to an artificial debug location that has a valid scope, but no
8970b57cec5SDimitry Andric   /// line information.
8980b57cec5SDimitry Andric   static ApplyDebugLocation
CreateDefaultArtificial(CodeGenFunction & CGF,SourceLocation TemporaryLocation)8990b57cec5SDimitry Andric   CreateDefaultArtificial(CodeGenFunction &CGF,
9000b57cec5SDimitry Andric                           SourceLocation TemporaryLocation) {
9010b57cec5SDimitry Andric     return ApplyDebugLocation(CGF, false, TemporaryLocation);
9020b57cec5SDimitry Andric   }
9030b57cec5SDimitry Andric 
9040b57cec5SDimitry Andric   /// Set the IRBuilder to not attach debug locations.  Note that
9050b57cec5SDimitry Andric   /// passing an empty SourceLocation to \a CGDebugInfo::setLocation()
9060b57cec5SDimitry Andric   /// will result in the last valid location being reused.  Note that
9070b57cec5SDimitry Andric   /// all instructions that do not have a location at the beginning of
9080b57cec5SDimitry Andric   /// a function are counted towards to function prologue.
CreateEmpty(CodeGenFunction & CGF)9090b57cec5SDimitry Andric   static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF) {
9100b57cec5SDimitry Andric     return ApplyDebugLocation(CGF, true, SourceLocation());
9110b57cec5SDimitry Andric   }
9120b57cec5SDimitry Andric };
9130b57cec5SDimitry Andric 
9140b57cec5SDimitry Andric /// A scoped helper to set the current debug location to an inlined location.
9150b57cec5SDimitry Andric class ApplyInlineDebugLocation {
9160b57cec5SDimitry Andric   SourceLocation SavedLocation;
9170b57cec5SDimitry Andric   CodeGenFunction *CGF;
9180b57cec5SDimitry Andric 
9190b57cec5SDimitry Andric public:
9200b57cec5SDimitry Andric   /// Set up the CodeGenFunction's DebugInfo to produce inline locations for the
9210b57cec5SDimitry Andric   /// function \p InlinedFn. The current debug location becomes the inlined call
9220b57cec5SDimitry Andric   /// site of the inlined function.
9230b57cec5SDimitry Andric   ApplyInlineDebugLocation(CodeGenFunction &CGF, GlobalDecl InlinedFn);
9240b57cec5SDimitry Andric   /// Restore everything back to the original state.
9250b57cec5SDimitry Andric   ~ApplyInlineDebugLocation();
9260b57cec5SDimitry Andric };
9270b57cec5SDimitry Andric 
9280b57cec5SDimitry Andric } // namespace CodeGen
9290b57cec5SDimitry Andric } // namespace clang
9300b57cec5SDimitry Andric 
9310b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
932