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