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