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