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