1//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is the source-level debug info generator for llvm translation.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
14#define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
15
16#include "CGBuilder.h"
17#include "SanitizerHandler.h"
18#include "clang/AST/DeclCXX.h"
19#include "clang/AST/Expr.h"
20#include "clang/AST/ExternalASTSource.h"
21#include "clang/AST/PrettyPrinter.h"
22#include "clang/AST/Type.h"
23#include "clang/AST/TypeOrdering.h"
24#include "clang/Basic/ASTSourceDescriptor.h"
25#include "clang/Basic/CodeGenOptions.h"
26#include "clang/Basic/FileEntry.h"
27#include "clang/Basic/SourceLocation.h"
28#include "llvm/ADT/DenseMap.h"
29#include "llvm/ADT/DenseSet.h"
30#include "llvm/IR/DIBuilder.h"
31#include "llvm/IR/DebugInfo.h"
32#include "llvm/IR/ValueHandle.h"
33#include "llvm/Support/Allocator.h"
34#include <map>
35#include <optional>
36#include <string>
37
38namespace llvm {
39class MDNode;
40}
41
42namespace clang {
43class ClassTemplateSpecializationDecl;
44class GlobalDecl;
45class Module;
46class ModuleMap;
47class ObjCInterfaceDecl;
48class UsingDecl;
49class VarDecl;
50enum class DynamicInitKind : unsigned;
51
52namespace CodeGen {
53class CodeGenModule;
54class CodeGenFunction;
55class CGBlockInfo;
56
57/// This class gathers all debug information during compilation and is
58/// responsible for emitting to llvm globals or pass directly to the
59/// backend.
60class CGDebugInfo {
61 friend class ApplyDebugLocation;
62 friend class ApplyAtomGroup;
63
64 CodeGenModule &CGM;
65 const llvm::codegenoptions::DebugInfoKind DebugKind;
66 bool DebugTypeExtRefs;
67 llvm::DIBuilder DBuilder;
68 llvm::DICompileUnit *TheCU = nullptr;
69 ModuleMap *ClangModuleMap = nullptr;
70 ASTSourceDescriptor PCHDescriptor;
71 SourceLocation CurLoc;
72 llvm::DIFile *CurLocFile = nullptr;
73 unsigned CurLocLine = 0;
74 unsigned CurLocColumn = 0;
75 llvm::DILocation *CurInlinedAt = nullptr;
76 llvm::DIType *VTablePtrType = nullptr;
77 llvm::DIType *ClassTy = nullptr;
78 llvm::DICompositeType *ObjTy = nullptr;
79 llvm::DIType *SelTy = nullptr;
80#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
81 llvm::DIType *SingletonId = nullptr;
82#include "clang/Basic/OpenCLImageTypes.def"
83 llvm::DIType *OCLSamplerDITy = nullptr;
84 llvm::DIType *OCLEventDITy = nullptr;
85 llvm::DIType *OCLClkEventDITy = nullptr;
86 llvm::DIType *OCLQueueDITy = nullptr;
87 llvm::DIType *OCLReserveIDDITy = nullptr;
88#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
89 llvm::DIType *Id##Ty = nullptr;
90#include "clang/Basic/OpenCLExtensionTypes.def"
91#define WASM_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
92#include "clang/Basic/WebAssemblyReferenceTypes.def"
93#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
94 llvm::DIType *SingletonId = nullptr;
95#include "clang/Basic/AMDGPUTypes.def"
96#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
97 llvm::DIType *SingletonId = nullptr;
98#include "clang/Basic/HLSLIntangibleTypes.def"
99#define SPIRV_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
100#include "clang/Basic/SPIRVTypes.def"
101
102 /// Cache of previously constructed Types.
103 llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
104
105 /// DI element indices used by preserve-access intrinsics.
106 llvm::DenseMap<const FieldDecl *, unsigned> FieldIndexCache;
107
108 /// Cache that maps VLA types to size expressions for that type,
109 /// represented by instantiated Metadata nodes.
110 llvm::SmallDenseMap<QualType, llvm::Metadata *> SizeExprCache;
111
112 /// Callbacks to use when printing names and types.
113 class PrintingCallbacks final : public clang::PrintingCallbacks {
114 const CGDebugInfo &Self;
115
116 public:
117 PrintingCallbacks(const CGDebugInfo &Self) : Self(Self) {}
118 std::string remapPath(StringRef Path) const override {
119 return Self.remapDIPath(Path);
120 }
121 };
122 PrintingCallbacks PrintCB = {*this};
123
124 struct ObjCInterfaceCacheEntry {
125 const ObjCInterfaceType *Type;
126 llvm::DIType *Decl;
127 llvm::DIFile *Unit;
128 ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType *Decl,
129 llvm::DIFile *Unit)
130 : Type(Type), Decl(Decl), Unit(Unit) {}
131 };
132
133 /// Cache of previously constructed interfaces which may change.
134 llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache;
135
136 /// Cache of forward declarations for methods belonging to the interface.
137 /// The extra bit on the DISubprogram specifies whether a method is
138 /// "objc_direct".
139 llvm::DenseMap<const ObjCInterfaceDecl *,
140 std::vector<llvm::PointerIntPair<llvm::DISubprogram *, 1>>>
141 ObjCMethodCache;
142
143 /// Cache of references to clang modules and precompiled headers.
144 llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
145
146 /// List of interfaces we want to keep even if orphaned.
147 std::vector<void *> RetainedTypes;
148
149 /// Cache of forward declared types to RAUW at the end of compilation.
150 std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
151
152 /// Cache of replaceable forward declarations (functions and
153 /// variables) to RAUW at the end of compilation.
154 std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
155 FwdDeclReplaceMap;
156
157 /// Keep track of our current nested lexical block.
158 std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
159
160 /// Map of AST declaration to its lexical block scope.
161 llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIScope>>
162 LexicalBlockMap;
163
164 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
165 /// Keep track of LexicalBlockStack counter at the beginning of a
166 /// function. This is used to pop unbalanced regions at the end of a
167 /// function.
168 std::vector<unsigned> FnBeginRegionCount;
169
170 /// This is a storage for names that are constructed on demand. For
171 /// example, C++ destructors, C++ operators etc..
172 llvm::BumpPtrAllocator DebugInfoNames;
173
174 llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
175 /// Where a DIFile came from, for mapping debug locations back to files.
176 struct DIFileSource {
177 /// The file the DIFile was first created for. Invalid if the DIFile was
178 /// also created for a location that is not in a file, such as one renamed
179 /// by a line directive.
180 FileID FID;
181 /// Whether the DIFile was also created for a different file.
182 bool Shared = false;
183 };
184 llvm::DenseMap<const llvm::DIFile *, DIFileSource> DIFileSources;
185 llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
186 /// Cache declarations relevant to DW_TAG_imported_declarations (C++
187 /// using declarations and global alias variables) that aren't covered
188 /// by other more specific caches.
189 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
190 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> ImportedDeclCache;
191 llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NamespaceCache;
192 llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
193 NamespaceAliasCache;
194 llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
195 StaticDataMemberCache;
196
197 using ParamDecl2StmtTy = llvm::DenseMap<const ParmVarDecl *, const Stmt *>;
198 using Param2DILocTy =
199 llvm::DenseMap<const ParmVarDecl *, llvm::DILocalVariable *>;
200
201 /// The key is coroutine real parameters, value is coroutine move parameters.
202 ParamDecl2StmtTy CoroutineParameterMappings;
203 /// The key is coroutine real parameters, value is DIVariable in LLVM IR.
204 Param2DILocTy ParamDbgMappings;
205
206 /// Key Instructions bookkeeping.
207 /// Source atoms are identified by a {AtomGroup, InlinedAt} pair, meaning
208 /// AtomGroup numbers can be repeated across different functions.
209 struct {
210 uint64_t NextAtom = 1;
211 uint64_t HighestEmittedAtom = 0;
212 uint64_t CurrentAtom = 0;
213 } KeyInstructionsInfo;
214
215private:
216 /// Helper functions for getOrCreateType.
217 /// @{
218 /// Currently the checksum of an interface includes the number of
219 /// ivars and property accessors.
220 llvm::DIType *CreateType(const BuiltinType *Ty);
221 llvm::DIType *CreateType(const ComplexType *Ty);
222 llvm::DIType *CreateType(const BitIntType *Ty);
223 llvm::DIType *CreateType(const OverflowBehaviorType *Ty, llvm::DIFile *U);
224 llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
225 llvm::DIType *CreateQualifiedType(const FunctionProtoType *Ty,
226 llvm::DIFile *Fg);
227 llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
228 llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
229 llvm::DIFile *Fg);
230 llvm::DIType *CreateType(const ObjCObjectPointerType *Ty, llvm::DIFile *F);
231 llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
232 llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
233 llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
234 llvm::DIType *CreateType(const HLSLAttributedResourceType *Ty,
235 llvm::DIFile *F);
236 llvm::DIType *CreateType(const HLSLInlineSpirvType *Ty, llvm::DIFile *F);
237 /// Get structure or union type.
238 llvm::DIType *CreateType(const RecordType *Tyg);
239
240 /// Create definition for the specified 'Ty'.
241 ///
242 /// \returns A pair of 'llvm::DIType's. The first is the definition
243 /// of the 'Ty'. The second is the type specified by the preferred_name
244 /// attribute on 'Ty', which can be a nullptr if no such attribute
245 /// exists.
246 std::pair<llvm::DIType *, llvm::DIType *>
247 CreateTypeDefinition(const RecordType *Ty);
248 llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
249 void CollectContainingType(const CXXRecordDecl *RD,
250 llvm::DICompositeType *CT);
251 /// Get Objective-C interface type.
252 llvm::DIType *CreateType(const ObjCInterfaceType *Ty, llvm::DIFile *F);
253 llvm::DIType *CreateTypeDefinition(const ObjCInterfaceType *Ty,
254 llvm::DIFile *F);
255 /// Get Objective-C object type.
256 llvm::DIType *CreateType(const ObjCObjectType *Ty, llvm::DIFile *F);
257 llvm::DIType *CreateType(const ObjCTypeParamType *Ty, llvm::DIFile *Unit);
258
259 llvm::DIType *CreateType(const VectorType *Ty, llvm::DIFile *F);
260 llvm::DIType *CreateType(const ConstantMatrixType *Ty, llvm::DIFile *F);
261 llvm::DIType *CreateType(const ArrayType *Ty, llvm::DIFile *F);
262 llvm::DIType *CreateType(const LValueReferenceType *Ty, llvm::DIFile *F);
263 llvm::DIType *CreateType(const RValueReferenceType *Ty, llvm::DIFile *Unit);
264 llvm::DIType *CreateType(const MemberPointerType *Ty, llvm::DIFile *F);
265 llvm::DIType *CreateType(const AtomicType *Ty, llvm::DIFile *F);
266 llvm::DIType *CreateType(const PipeType *Ty, llvm::DIFile *F);
267 /// Get enumeration type.
268 llvm::DIType *CreateEnumType(const EnumType *Ty);
269 llvm::DIType *CreateTypeDefinition(const EnumType *Ty);
270 /// Look up the completed type for a self pointer in the TypeCache and
271 /// create a copy of it with the ObjectPointer and Artificial flags
272 /// set. If the type is not cached, a new one is created. This should
273 /// never happen though, since creating a type for the implicit self
274 /// argument implies that we already parsed the interface definition
275 /// and the ivar declarations in the implementation.
276 llvm::DIType *CreateSelfType(const QualType &QualTy, llvm::DIType *Ty);
277 /// @}
278
279 /// Get the type from the cache or return null type if it doesn't
280 /// exist.
281 llvm::DIType *getTypeOrNull(const QualType);
282 /// Return the debug type for a C++ method.
283 /// \arg CXXMethodDecl is of FunctionType. This function type is
284 /// not updated to include implicit \c this pointer. Use this routine
285 /// to get a method type which includes \c this pointer.
286 llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
287 llvm::DIFile *F);
288
289 llvm::DISubroutineType *
290 getOrCreateMethodTypeForDestructor(const CXXMethodDecl *Method,
291 llvm::DIFile *F, QualType FNType);
292
293 llvm::DISubroutineType *
294 getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func,
295 llvm::DIFile *Unit, bool SkipFirst = false);
296 llvm::DISubroutineType *
297 getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
298 /// \return debug info descriptor for vtable.
299 llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
300
301 /// \return namespace descriptor for the given namespace decl.
302 llvm::DINamespace *getOrCreateNamespace(const NamespaceDecl *N);
303 llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
304 QualType PointeeTy, llvm::DIFile *F);
305 llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
306
307 /// A helper function to create a subprogram for a single member
308 /// function GlobalDecl.
309 llvm::DISubprogram *CreateCXXMemberFunction(const CXXMethodDecl *Method,
310 llvm::DIFile *F,
311 llvm::DIType *RecordTy);
312
313 /// A helper function to collect debug info for C++ member
314 /// functions. This is used while creating debug info entry for a
315 /// Record.
316 void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile *F,
317 SmallVectorImpl<llvm::Metadata *> &E,
318 llvm::DIType *T);
319
320 /// A helper function to collect debug info for C++ base
321 /// classes. This is used while creating debug info entry for a
322 /// Record.
323 void CollectCXXBases(const CXXRecordDecl *Decl, llvm::DIFile *F,
324 SmallVectorImpl<llvm::Metadata *> &EltTys,
325 llvm::DIType *RecordTy);
326
327 /// Helper function for CollectCXXBases.
328 /// Adds debug info entries for types in Bases that are not in SeenTypes.
329 void CollectCXXBasesAux(
330 const CXXRecordDecl *RD, llvm::DIFile *Unit,
331 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
332 const CXXRecordDecl::base_class_const_range &Bases,
333 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
334 llvm::DINode::DIFlags StartingFlags);
335
336 /// Helper function that returns the llvm::DIType that the
337 /// PreferredNameAttr attribute on \ref RD refers to. If no such
338 /// attribute exists, returns nullptr.
339 llvm::DIType *GetPreferredNameType(const CXXRecordDecl *RD,
340 llvm::DIFile *Unit);
341
342 struct TemplateArgs {
343 const TemplateParameterList *TList;
344 llvm::ArrayRef<TemplateArgument> Args;
345 };
346 /// A helper function to collect template parameters.
347 llvm::DINodeArray CollectTemplateParams(std::optional<TemplateArgs> Args,
348 llvm::DIFile *Unit);
349 /// A helper function to collect debug info for function template
350 /// parameters.
351 llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
352 llvm::DIFile *Unit);
353
354 /// A helper function to collect debug info for function template
355 /// parameters.
356 llvm::DINodeArray CollectVarTemplateParams(const VarDecl *VD,
357 llvm::DIFile *Unit);
358
359 std::optional<TemplateArgs> GetTemplateArgs(const VarDecl *) const;
360 std::optional<TemplateArgs> GetTemplateArgs(const RecordDecl *) const;
361 std::optional<TemplateArgs> GetTemplateArgs(const FunctionDecl *) const;
362
363 /// A helper function to collect debug info for template
364 /// parameters.
365 llvm::DINodeArray CollectCXXTemplateParams(const RecordDecl *TS,
366 llvm::DIFile *F);
367
368 /// A helper function to collect debug info for btf_decl_tag annotations.
369 llvm::DINodeArray CollectBTFDeclTagAnnotations(const Decl *D);
370
371 /// A helper function to collect debug info for btf_decl_tag annotations and
372 /// append them to Annotations.
373 void
374 CollectBTFDeclTagAnnotations(const Decl *D,
375 SmallVectorImpl<llvm::Metadata *> &Annotations);
376
377 /// A helper function to collect debug info for btf_type_tag annotations and
378 /// append them to Annotations.
379 void
380 CollectBTFTypeTagAnnotations(QualType Ty,
381 SmallVectorImpl<llvm::Metadata *> &Annotations);
382
383 llvm::DIType *createFieldType(StringRef name, QualType type,
384 SourceLocation loc, AccessSpecifier AS,
385 uint64_t offsetInBits, uint32_t AlignInBits,
386 llvm::DIFile *tunit, llvm::DIScope *scope,
387 const RecordDecl *RD = nullptr,
388 llvm::DINodeArray Annotations = nullptr);
389
390 llvm::DIType *createFieldType(StringRef name, QualType type,
391 SourceLocation loc, AccessSpecifier AS,
392 uint64_t offsetInBits, llvm::DIFile *tunit,
393 llvm::DIScope *scope,
394 const RecordDecl *RD = nullptr) {
395 return createFieldType(name, type, loc, AS, offsetInBits, AlignInBits: 0, tunit, scope,
396 RD);
397 }
398
399 /// Create new bit field member.
400 llvm::DIDerivedType *createBitFieldType(const FieldDecl *BitFieldDecl,
401 llvm::DIScope *RecordTy,
402 const RecordDecl *RD);
403
404 /// Create an anonnymous zero-size separator for bit-field-decl if needed on
405 /// the target.
406 llvm::DIDerivedType *createBitFieldSeparatorIfNeeded(
407 const FieldDecl *BitFieldDecl, const llvm::DIDerivedType *BitFieldDI,
408 llvm::ArrayRef<llvm::Metadata *> PreviousFieldsDI, const RecordDecl *RD);
409
410 /// A cache that maps names of artificial inlined functions to subprograms.
411 llvm::StringMap<llvm::DISubprogram *> InlinedSubprogramMap;
412
413 /// A function that returns the subprogram corresponding to the artificial
414 /// inlined function for traps.
415 llvm::DISubprogram *createInlinedSubprogram(StringRef FuncName,
416 llvm::DIFile *FileScope);
417
418 /// Helpers for collecting fields of a record.
419 /// @{
420 void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
421 SmallVectorImpl<llvm::Metadata *> &E,
422 llvm::DIType *RecordTy);
423 llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
424 llvm::DIType *RecordTy,
425 const RecordDecl *RD);
426 void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
427 llvm::DIFile *F,
428 SmallVectorImpl<llvm::Metadata *> &E,
429 llvm::DIType *RecordTy, const RecordDecl *RD);
430 void CollectRecordNestedType(const TypeDecl *RD,
431 SmallVectorImpl<llvm::Metadata *> &E);
432 void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
433 SmallVectorImpl<llvm::Metadata *> &E,
434 llvm::DICompositeType *RecordTy);
435 llvm::StringRef GetLambdaCaptureName(const LambdaCapture &Capture);
436
437 /// If the C++ class has vtable info then insert appropriate debug
438 /// info entry in EltTys vector.
439 void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile *F,
440 SmallVectorImpl<llvm::Metadata *> &EltTys);
441 /// @}
442
443 /// Create a new lexical block node and push it on the stack.
444 void CreateLexicalBlock(SourceLocation Loc);
445
446 /// If target-specific LLVM \p AddressSpace directly maps to target-specific
447 /// DWARF address space, appends extended dereferencing mechanism to complex
448 /// expression \p Expr. Otherwise, does nothing.
449 ///
450 /// Extended dereferencing mechanism is has the following format:
451 /// DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef
452 void AppendAddressSpaceXDeref(unsigned AddressSpace,
453 SmallVectorImpl<uint64_t> &Expr) const;
454
455 /// A helper function to collect debug info for the default elements of a
456 /// block.
457 ///
458 /// \returns The next available field offset after the default elements.
459 uint64_t collectDefaultElementTypesForBlockPointer(
460 const BlockPointerType *Ty, llvm::DIFile *Unit,
461 llvm::DIDerivedType *DescTy, unsigned LineNo,
462 SmallVectorImpl<llvm::Metadata *> &EltTys);
463
464 /// A helper function to collect debug info for the default fields of a
465 /// block.
466 void collectDefaultFieldsForBlockLiteralDeclare(
467 const CGBlockInfo &Block, const ASTContext &Context, SourceLocation Loc,
468 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
469 SmallVectorImpl<llvm::Metadata *> &Fields);
470
471public:
472 CGDebugInfo(CodeGenModule &CGM);
473 ~CGDebugInfo();
474
475 void finalize();
476
477 /// Remap a given path with the current debug prefix map
478 std::string remapDIPath(StringRef) const;
479
480 /// Register VLA size expression debug node with the qualified type.
481 void registerVLASizeExpression(QualType Ty, llvm::Metadata *SizeExpr) {
482 SizeExprCache[Ty] = SizeExpr;
483 }
484
485 /// Module debugging: Support for building PCMs.
486 /// @{
487 /// Set the main CU's DwoId field to \p Signature.
488 void setDwoId(uint64_t Signature);
489
490 /// When generating debug information for a clang module or
491 /// precompiled header, this module map will be used to determine
492 /// the module of origin of each Decl.
493 void setModuleMap(ModuleMap &MMap) { ClangModuleMap = &MMap; }
494
495 /// When generating debug information for a clang module or
496 /// precompiled header, this module map will be used to determine
497 /// the module of origin of each Decl.
498 void setPCHDescriptor(ASTSourceDescriptor PCH) { PCHDescriptor = PCH; }
499 /// @}
500
501 /// Update the current source location. If \arg loc is invalid it is
502 /// ignored.
503 void setLocation(SourceLocation Loc);
504
505 /// Return the current source location. This does not necessarily correspond
506 /// to the IRBuilder's current DebugLoc.
507 SourceLocation getLocation() const { return CurLoc; }
508
509 /// Update the current inline scope. All subsequent calls to \p EmitLocation
510 /// will create a location with this inlinedAt field.
511 void setInlinedAt(llvm::DILocation *InlinedAt) { CurInlinedAt = InlinedAt; }
512
513 /// \return the current inline scope.
514 llvm::DILocation *getInlinedAt() const { return CurInlinedAt; }
515
516 // Converts a SourceLocation to a DebugLoc
517 llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Loc);
518
519 /// Emit metadata to indicate a change in line/column information in
520 /// the source file. If the location is invalid, the previous
521 /// location will be reused.
522 void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc);
523
524 QualType getFunctionType(const FunctionDecl *FD, QualType RetTy,
525 const SmallVectorImpl<const VarDecl *> &Args);
526
527 /// Emit a call to llvm.dbg.function.start to indicate
528 /// start of a new function.
529 /// \param Loc The location of the function header.
530 /// \param ScopeLoc The location of the function body.
531 void emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
532 SourceLocation ScopeLoc, QualType FnType,
533 llvm::Function *Fn, bool CurFnIsThunk);
534
535 /// Start a new scope for an inlined function.
536 void EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD);
537 /// End an inlined function scope.
538 void EmitInlineFunctionEnd(CGBuilderTy &Builder);
539
540 /// Emit debug info for a function declaration.
541 /// \p Fn is set only when a declaration for a debug call site gets created.
542 void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
543 QualType FnType, llvm::Function *Fn = nullptr);
544
545 /// Emit debug info for an extern function being called.
546 /// This is needed for call site debug info.
547 void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
548 QualType CalleeType,
549 GlobalDecl CalleeGlobalDecl);
550
551 /// Constructs the debug code for exiting a function.
552 void EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn);
553
554 /// Emit metadata to indicate the beginning of a new lexical block
555 /// and push the block onto the stack.
556 void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
557
558 /// Emit metadata to indicate the end of a new lexical block and pop
559 /// the current block.
560 void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
561
562 /// Emit call to \c llvm.dbg.declare for an automatic variable
563 /// declaration.
564 /// Returns a pointer to the DILocalVariable associated with the
565 /// llvm.dbg.declare, or nullptr otherwise.
566 llvm::DILocalVariable *
567 EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
568 CGBuilderTy &Builder,
569 const bool UsePointerValue = false);
570
571 /// Emit call to \c llvm.dbg.label for an label.
572 void EmitLabel(const LabelDecl *D, CGBuilderTy &Builder);
573
574 /// Emit call to \c llvm.dbg.declare for an imported variable
575 /// declaration in a block.
576 void EmitDeclareOfBlockDeclRefVariable(
577 const VarDecl *variable, llvm::Value *storage, CGBuilderTy &Builder,
578 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint = nullptr);
579
580 /// Emit call to \c llvm.dbg.declare for an argument variable
581 /// declaration.
582 llvm::DILocalVariable *
583 EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, unsigned ArgNo,
584 CGBuilderTy &Builder, bool UsePointerValue = false);
585
586 /// Emit call to \c llvm.dbg.declare for the block-literal argument
587 /// to a block invocation function.
588 void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
589 StringRef Name, unsigned ArgNo,
590 llvm::AllocaInst *LocalAddr,
591 CGBuilderTy &Builder);
592
593 /// Emit information about a global variable.
594 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
595
596 /// Emit a constant global variable's debug info.
597 void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
598
599 /// Emit information about an external variable.
600 void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
601
602 /// Emit a pseudo variable and debug info for an intermediate value if it does
603 /// not correspond to a variable in the source code, so that a profiler can
604 /// track more accurate usage of certain instructions of interest.
605 void EmitPseudoVariable(CGBuilderTy &Builder, llvm::Instruction *Value,
606 QualType Ty);
607
608 /// Emit information about global variable alias.
609 void EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl Decl);
610
611 /// Return the source file each DIFile was created for, or std::nullopt for a
612 /// DIFile shared by several files. DIFiles of files with line directives are
613 /// omitted, because debug locations in them use presumed lines. Line
614 /// directives are only all known once the translation unit is parsed.
615 llvm::DenseMap<const llvm::DIFile *, OptionalFileEntryRef>
616 getDIFileSources() const;
617
618 /// Emit C++ using directive.
619 void EmitUsingDirective(const UsingDirectiveDecl &UD);
620
621 /// Emit the type explicitly casted to.
622 void EmitExplicitCastType(QualType Ty);
623
624 /// Emit the type even if it might not be used.
625 void EmitAndRetainType(QualType Ty);
626
627 /// Emit a shadow decl brought in by a using or using-enum
628 void EmitUsingShadowDecl(const UsingShadowDecl &USD);
629
630 /// Emit C++ using declaration.
631 void EmitUsingDecl(const UsingDecl &UD);
632
633 /// Emit C++ using-enum declaration.
634 void EmitUsingEnumDecl(const UsingEnumDecl &UD);
635
636 /// Emit an @import declaration.
637 void EmitImportDecl(const ImportDecl &ID);
638
639 /// DebugInfo isn't attached to string literals by default. While certain
640 /// aspects of debuginfo aren't useful for string literals (like a name), it's
641 /// nice to be able to symbolize the line and column information. This is
642 /// especially useful for sanitizers, as it allows symbolization of
643 /// heap-buffer-overflows on constant strings.
644 void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
645 const StringLiteral *S);
646
647 /// Emit C++ namespace alias.
648 llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
649
650 /// Return the complete record type and field index for preserve-access
651 /// intrinsics.
652 std::pair<llvm::DIType *, unsigned>
653 getOrCreatePreserveAccessInfo(QualType Ty, const FieldDecl *Field);
654
655 /// Emit an Objective-C interface type standalone debug info.
656 llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
657
658 /// Map AST declaration to its lexical block scope if available.
659 void recordDeclarationLexicalScope(const Decl &D);
660
661 /// Get lexical scope of AST declaration.
662 llvm::DIScope *getDeclarationLexicalScope(const Decl *D);
663
664 /// Emit standalone debug info for a type.
665 llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
666
667 /// Add heapallocsite metadata for MSAllocator calls.
668 void addHeapAllocSiteMetadata(llvm::CallBase *CallSite, QualType AllocatedTy,
669 SourceLocation Loc);
670
671 void completeType(const EnumDecl *ED);
672 void completeType(const RecordDecl *RD);
673 void completeRequiredType(const RecordDecl *RD);
674 void completeClassData(const RecordDecl *RD);
675 void completeClass(const RecordDecl *RD);
676
677 void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD);
678 void completeUnusedClass(const CXXRecordDecl &D);
679
680 /// Create debug info for a macro defined by a #define directive or a macro
681 /// undefined by a #undef directive.
682 llvm::DIMacro *CreateMacro(llvm::DIMacroFile *Parent, unsigned MType,
683 SourceLocation LineLoc, StringRef Name,
684 StringRef Value);
685
686 /// Create debug info for a file referenced by an #include directive.
687 llvm::DIMacroFile *CreateTempMacroFile(llvm::DIMacroFile *Parent,
688 SourceLocation LineLoc,
689 SourceLocation FileLoc);
690
691 Param2DILocTy &getParamDbgMappings() { return ParamDbgMappings; }
692 ParamDecl2StmtTy &getCoroutineParameterMappings() {
693 return CoroutineParameterMappings;
694 }
695
696 /// Create a debug location from `TrapLocation` that adds an artificial inline
697 /// frame where the frame name is
698 ///
699 /// * `<Prefix>:<Category>:<FailureMsg>`
700 ///
701 /// `<Prefix>` is "__clang_trap_msg".
702 ///
703 /// This is used to store failure reasons for traps.
704 llvm::DILocation *CreateTrapFailureMessageFor(llvm::DebugLoc TrapLocation,
705 StringRef Category,
706 StringRef FailureMsg);
707 /// Create a debug location from `Location` that adds an artificial inline
708 /// frame where the frame name is FuncName
709 ///
710 /// This is used to indiciate instructions that come from compiler
711 /// instrumentation.
712 llvm::DILocation *
713 CreateSyntheticInlineAt(llvm::DebugLoc ParentLocation,
714 llvm::DISubprogram *SynthSubprogram);
715 llvm::DILocation *CreateSyntheticInlineAt(llvm::DebugLoc ParentLocation,
716 StringRef SynthFuncName,
717 llvm::DIFile *SynthFile);
718
719 /// Reset internal state.
720 void completeFunction();
721
722 /// Add \p KeyInstruction and an optional \p Backup instruction to the
723 /// current atom group, created using ApplyAtomGroup.
724 void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction,
725 llvm::Value *Backup);
726
727 /// Add \p KeyInstruction and an optional \p Backup instruction to the atom
728 /// group \p Atom.
729 void addInstToSpecificSourceAtom(llvm::Instruction *KeyInstruction,
730 llvm::Value *Backup, uint64_t Atom);
731
732 /// Emit symbol for debugger that holds the pointer to the vtable.
733 void emitVTableSymbol(llvm::GlobalVariable *VTable, const CXXRecordDecl *RD);
734
735 /// Return flags which enable debug info emission for call sites, provided
736 /// that it is supported and enabled.
737 llvm::DINode::DIFlags getCallSiteRelatedAttrs() const;
738
739 /// Add call target information.
740 void addCallTargetIfVirtual(const FunctionDecl *FD, llvm::CallBase *CI);
741
742private:
743 /// Amend \p I's DebugLoc with \p Group (its source atom group) and \p
744 /// Rank (lower nonzero rank is higher precedence). Does nothing if \p I
745 /// has no DebugLoc, and chooses the atom group in which the instruction
746 /// has the highest precedence if it's already in one.
747 void addInstSourceAtomMetadata(llvm::Instruction *I, uint64_t Group,
748 uint8_t Rank);
749
750 /// Emit call to llvm.dbg.declare for a variable declaration.
751 /// Returns a pointer to the DILocalVariable associated with the
752 /// llvm.dbg.declare, or nullptr otherwise.
753 llvm::DILocalVariable *EmitDeclare(const VarDecl *decl, llvm::Value *AI,
754 std::optional<unsigned> ArgNo,
755 CGBuilderTy &Builder,
756 const bool UsePointerValue = false);
757
758 /// Emit call to llvm.dbg.declare for a binding declaration.
759 /// Returns a pointer to the DILocalVariable associated with the
760 /// llvm.dbg.declare, or nullptr otherwise.
761 llvm::DILocalVariable *EmitDeclare(const BindingDecl *decl, llvm::Value *AI,
762 std::optional<unsigned> ArgNo,
763 CGBuilderTy &Builder,
764 const bool UsePointerValue = false);
765
766 struct BlockByRefType {
767 /// The wrapper struct used inside the __block_literal struct.
768 llvm::DIType *BlockByRefWrapper;
769 /// The type as it appears in the source code.
770 llvm::DIType *WrappedType;
771 };
772
773 bool HasReconstitutableArgs(ArrayRef<TemplateArgument> Args) const;
774 std::string GetName(const Decl *, bool Qualified = false,
775 bool *NameIsSimplified = nullptr) const;
776
777 /// Build up structure info for the byref. See \a BuildByRefType.
778 BlockByRefType EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
779 uint64_t *OffSet);
780
781 /// Get context info for the DeclContext of \p Decl.
782 llvm::DIScope *getDeclContextDescriptor(const Decl *D);
783 /// Get context info for a given DeclContext \p Decl.
784 llvm::DIScope *getContextDescriptor(const Decl *Context,
785 llvm::DIScope *Default);
786
787 llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);
788
789 /// Create a forward decl for a RecordType in a given context.
790 llvm::DICompositeType *getOrCreateRecordFwdDecl(const RecordType *,
791 llvm::DIScope *);
792
793 /// Return current directory name.
794 StringRef getCurrentDirname();
795
796 /// Create new compile unit.
797 void CreateCompileUnit();
798
799 /// Compute the file checksum debug info for input file ID.
800 std::optional<llvm::DIFile::ChecksumKind>
801 computeChecksum(FileID FID, SmallString<64> &Checksum) const;
802
803 /// Get the source of the given file ID.
804 std::optional<StringRef> getSource(const SourceManager &SM, FileID FID);
805
806 /// Convenience function to get the file debug info descriptor for the input
807 /// location.
808 llvm::DIFile *getOrCreateFile(SourceLocation Loc);
809
810 /// Note that \p F was created for a location in \p FID.
811 void recordDIFileSource(const llvm::DIFile *F, FileID FID);
812
813 /// Create a file debug info descriptor for a source file.
814 llvm::DIFile *
815 createFile(StringRef FileName,
816 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
817 std::optional<StringRef> Source);
818
819 /// Get the type from the cache or create a new type if necessary.
820 llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
821
822 /// Get a reference to a clang module. If \p CreateSkeletonCU is true,
823 /// this also creates a split dwarf skeleton compile unit.
824 llvm::DIModule *getOrCreateModuleRef(ASTSourceDescriptor Mod,
825 bool CreateSkeletonCU);
826
827 /// DebugTypeExtRefs: If \p D originated in a clang module, return it.
828 llvm::DIModule *getParentModuleOrNull(const Decl *D);
829
830 /// Get the type from the cache or create a new partial type if
831 /// necessary.
832 llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty);
833
834 /// Create type metadata for a source language type.
835 llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
836
837 /// Create new member and increase Offset by FType's size.
838 llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,
839 StringRef Name, uint64_t *Offset);
840
841 /// Retrieve the DIDescriptor, if any, for the canonical form of this
842 /// declaration.
843 llvm::DINode *getDeclarationOrDefinition(const Decl *D);
844
845 /// \return debug info descriptor to describe method
846 /// declaration for the given method definition.
847 llvm::DISubprogram *getFunctionDeclaration(const Decl *D);
848
849 /// \return debug info descriptor to the describe method declaration
850 /// for the given method definition.
851 /// \param FnType For Objective-C methods, their type.
852 /// \param LineNo The declaration's line number.
853 /// \param Flags The DIFlags for the method declaration.
854 /// \param SPFlags The subprogram-spcific flags for the method declaration.
855 llvm::DISubprogram *
856 getObjCMethodDeclaration(const Decl *D, llvm::DISubroutineType *FnType,
857 unsigned LineNo, llvm::DINode::DIFlags Flags,
858 llvm::DISubprogram::DISPFlags SPFlags);
859
860 /// \return debug info descriptor to describe in-class static data
861 /// member declaration for the given out-of-class definition. If D
862 /// is an out-of-class definition of a static data member of a
863 /// class, find its corresponding in-class declaration.
864 llvm::DIDerivedType *
865 getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
866
867 /// Helper that either creates a forward declaration or a stub.
868 llvm::DISubprogram *getFunctionFwdDeclOrStub(GlobalDecl GD, bool Stub);
869
870 /// Create a subprogram describing the forward declaration
871 /// represented in the given FunctionDecl wrapped in a GlobalDecl.
872 llvm::DISubprogram *getFunctionForwardDeclaration(GlobalDecl GD);
873
874 /// Create a DISubprogram describing the function
875 /// represented in the given FunctionDecl wrapped in a GlobalDecl.
876 llvm::DISubprogram *getFunctionStub(GlobalDecl GD);
877
878 /// Create a global variable describing the forward declaration
879 /// represented in the given VarDecl.
880 llvm::DIGlobalVariable *
881 getGlobalVariableForwardDeclaration(const VarDecl *VD);
882
883 /// Return a global variable that represents one of the collection of global
884 /// variables created for an anonmyous union.
885 ///
886 /// Recursively collect all of the member fields of a global
887 /// anonymous decl and create static variables for them. The first
888 /// time this is called it needs to be on a union and then from
889 /// there we can have additional unnamed fields.
890 llvm::DIGlobalVariableExpression *
891 CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
892 unsigned LineNo, StringRef LinkageName,
893 llvm::GlobalVariable *Var, llvm::DIScope *DContext);
894
895 /// Get the printing policy for producing names for debug info.
896 PrintingPolicy getPrintingPolicy() const;
897
898 /// Get function name for the given FunctionDecl. If the name is
899 /// constructed on demand (e.g., C++ destructor) then the name is
900 /// stored on the side.
901 StringRef getFunctionName(const FunctionDecl *FD,
902 bool *NameIsSimplified = nullptr);
903
904 /// Returns the unmangled name of an Objective-C method.
905 /// This is the display name for the debugging info.
906 StringRef getObjCMethodName(const ObjCMethodDecl *FD);
907
908 /// Return selector name. This is used for debugging
909 /// info.
910 StringRef getSelectorName(Selector S);
911
912 /// Get class name including template argument list.
913 StringRef getClassName(const RecordDecl *RD,
914 bool *NameIsSimplified = nullptr);
915
916 /// Get the vtable name for the given class.
917 StringRef getVTableName(const CXXRecordDecl *Decl);
918
919 /// Get the name to use in the debug info for a dynamic initializer or atexit
920 /// stub function.
921 StringRef getDynamicInitializerName(const VarDecl *VD,
922 DynamicInitKind StubKind,
923 llvm::Function *InitFn);
924
925 /// Get line number for the location. If location is invalid
926 /// then use current location.
927 unsigned getLineNumber(SourceLocation Loc);
928
929 /// Get column number for the location. If location is
930 /// invalid then use current location.
931 unsigned getColumnNumber(SourceLocation Loc);
932
933 /// Clear the current location and its derived metadata.
934 void clearCurLoc() {
935 CurLoc = SourceLocation();
936 CurLocFile = nullptr;
937 CurLocLine = 0;
938 CurLocColumn = 0;
939 }
940
941 /// Collect various properties of a FunctionDecl.
942 /// \param GD A GlobalDecl whose getDecl() must return a FunctionDecl.
943 void collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
944 StringRef &Name, StringRef &LinkageName,
945 llvm::DIScope *&FDContext,
946 llvm::DINodeArray &TParamsArray,
947 llvm::DINode::DIFlags &Flags);
948
949 /// Collect various properties of a VarDecl.
950 void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
951 unsigned &LineNo, QualType &T, StringRef &Name,
952 StringRef &LinkageName,
953 llvm::MDTuple *&TemplateParameters,
954 llvm::DIScope *&VDContext);
955
956 /// Create a DIExpression representing the constant corresponding
957 /// to the specified 'Val'. Returns nullptr on failure.
958 llvm::DIExpression *createConstantValueExpression(const clang::ValueDecl *VD,
959 const APValue &Val);
960
961 /// Allocate a copy of \p A using the DebugInfoNames allocator
962 /// and return a reference to it. If multiple arguments are given the strings
963 /// are concatenated.
964 StringRef internString(StringRef A, StringRef B = StringRef()) {
965 char *Data = DebugInfoNames.Allocate<char>(Num: A.size() + B.size());
966 if (!A.empty())
967 std::memcpy(dest: Data, src: A.data(), n: A.size());
968 if (!B.empty())
969 std::memcpy(dest: Data + A.size(), src: B.data(), n: B.size());
970 return StringRef(Data, A.size() + B.size());
971 }
972
973 /// If one exists, returns the linkage name of the specified \
974 /// (non-null) \c Method. Returns empty string otherwise.
975 llvm::StringRef GetMethodLinkageName(const CXXMethodDecl *Method) const;
976
977 /// Returns true if we should generate call target information.
978 bool shouldGenerateVirtualCallSite() const;
979};
980
981/// A scoped helper to set the current debug location to the specified
982/// location or preferred location of the specified Expr.
983class ApplyDebugLocation {
984private:
985 void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
986 ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
987 SourceLocation TemporaryLocation);
988
989 llvm::DebugLoc OriginalLocation;
990 CodeGenFunction *CGF;
991
992public:
993 /// Set the location to the (valid) TemporaryLocation.
994 ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
995 ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
996 ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
997 ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
998 Other.CGF = nullptr;
999 }
1000
1001 // Define move assignment operator.
1002 ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
1003 if (this != &Other) {
1004 CGF = Other.CGF;
1005 Other.CGF = nullptr;
1006 }
1007 return *this;
1008 }
1009
1010 ~ApplyDebugLocation();
1011
1012 /// Apply TemporaryLocation if it is valid. Otherwise switch
1013 /// to an artificial debug location that has a valid scope, but no
1014 /// line information.
1015 ///
1016 /// Artificial locations are useful when emitting compiler-generated
1017 /// helper functions that have no source location associated with
1018 /// them. The DWARF specification allows the compiler to use the
1019 /// special line number 0 to indicate code that can not be
1020 /// attributed to any source location. Note that passing an empty
1021 /// SourceLocation to CGDebugInfo::setLocation() will result in the
1022 /// last valid location being reused.
1023 static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF) {
1024 return ApplyDebugLocation(CGF, false, SourceLocation());
1025 }
1026 /// Apply TemporaryLocation if it is valid. Otherwise switch
1027 /// to an artificial debug location that has a valid scope, but no
1028 /// line information.
1029 static ApplyDebugLocation
1030 CreateDefaultArtificial(CodeGenFunction &CGF,
1031 SourceLocation TemporaryLocation) {
1032 return ApplyDebugLocation(CGF, false, TemporaryLocation);
1033 }
1034
1035 /// Set the IRBuilder to not attach debug locations. Note that
1036 /// passing an empty SourceLocation to \a CGDebugInfo::setLocation()
1037 /// will result in the last valid location being reused. Note that
1038 /// all instructions that do not have a location at the beginning of
1039 /// a function are counted towards to function prologue.
1040 static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF) {
1041 return ApplyDebugLocation(CGF, true, SourceLocation());
1042 }
1043};
1044
1045/// A scoped helper to set the current debug location to an inlined location.
1046class ApplyInlineDebugLocation {
1047 SourceLocation SavedLocation;
1048 CodeGenFunction *CGF;
1049
1050public:
1051 /// Set up the CodeGenFunction's DebugInfo to produce inline locations for the
1052 /// function \p InlinedFn. The current debug location becomes the inlined call
1053 /// site of the inlined function.
1054 ApplyInlineDebugLocation(CodeGenFunction &CGF, GlobalDecl InlinedFn);
1055 /// Restore everything back to the original state.
1056 ~ApplyInlineDebugLocation();
1057 ApplyInlineDebugLocation(const ApplyInlineDebugLocation &) = delete;
1058 ApplyInlineDebugLocation &
1059 operator=(const ApplyInlineDebugLocation &) = delete;
1060};
1061
1062class SanitizerDebugLocation {
1063 CodeGenFunction *CGF;
1064 ApplyDebugLocation Apply;
1065
1066public:
1067 SanitizerDebugLocation(CodeGenFunction *CGF,
1068 ArrayRef<SanitizerKind::SanitizerOrdinal> Ordinals,
1069 SanitizerHandler Handler);
1070 ~SanitizerDebugLocation();
1071 SanitizerDebugLocation(const SanitizerDebugLocation &) = delete;
1072 SanitizerDebugLocation &operator=(const SanitizerDebugLocation &) = delete;
1073};
1074
1075} // namespace CodeGen
1076} // namespace clang
1077
1078#endif // LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
1079