clang 24.0.0git
ASTContext.h
Go to the documentation of this file.
1//===- ASTContext.h - Context to hold long-lived AST nodes ------*- 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/// \file
10/// Defines the clang::ASTContext interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_ASTCONTEXT_H
15#define LLVM_CLANG_AST_ASTCONTEXT_H
16
17#include "clang/AST/ASTFwd.h"
21#include "clang/AST/Decl.h"
28#include "clang/AST/Type.h"
30#include "clang/Basic/LLVM.h"
33#include "clang/Lex/MacroBase.h"
34#include "llvm/ADT/DenseMap.h"
35#include "llvm/ADT/DenseMapInfo.h"
36#include "llvm/ADT/DenseSet.h"
37#include "llvm/ADT/FoldingSet.h"
38#include "llvm/ADT/IntrusiveRefCntPtr.h"
39#include "llvm/ADT/MapVector.h"
40#include "llvm/ADT/PointerIntPair.h"
41#include "llvm/ADT/PointerUnion.h"
42#include "llvm/ADT/SetVector.h"
43#include "llvm/ADT/SmallPtrSet.h"
44#include "llvm/ADT/SmallVector.h"
45#include "llvm/ADT/StringMap.h"
46#include "llvm/ADT/StringRef.h"
47#include "llvm/ADT/StringSet.h"
48#include "llvm/ADT/TinyPtrVector.h"
49#include "llvm/Support/TypeSize.h"
50#include <optional>
51
52namespace llvm {
53
54class APFixedPoint;
56struct fltSemantics;
57template <typename T, unsigned N> class SmallPtrSet;
58
61 unsigned NumElts;
62 unsigned NumFields;
63
64 bool operator==(const ScalableVecTyKey &RHS) const {
65 return EltTy == RHS.EltTy && NumElts == RHS.NumElts &&
66 NumFields == RHS.NumFields;
67 }
68};
69
70// Provide a DenseMapInfo specialization so that ScalableVecTyKey can be used
71// as a key in DenseMap.
72template <> struct DenseMapInfo<ScalableVecTyKey> {
73 static unsigned getHashValue(const ScalableVecTyKey &Val) {
74 return hash_combine(DenseMapInfo<clang::QualType>::getHashValue(Val.EltTy),
75 Val.NumElts, Val.NumFields);
76 }
77 static bool isEqual(const ScalableVecTyKey &LHS,
78 const ScalableVecTyKey &RHS) {
79 return LHS == RHS;
80 }
81};
82
83} // namespace llvm
84
85namespace clang {
86
87class APValue;
89class ASTRecordLayout;
90class AtomicExpr;
91class BlockExpr;
92struct BlockVarCopyInit;
94class CharUnits;
95class ConceptDecl;
96class CXXABI;
98class CXXMethodDecl;
99class CXXRecordDecl;
101class DynTypedNodeList;
102class Expr;
104enum class FloatModeKind;
105class GlobalDecl;
106class IdentifierTable;
107class LangOptions;
108class MangleContext;
111class Module;
112struct MSGuidDeclParts;
114class NoSanitizeList;
115class ObjCCategoryDecl;
118class ObjCImplDecl;
121class ObjCIvarDecl;
122class ObjCMethodDecl;
123class ObjCPropertyDecl;
125class ObjCProtocolDecl;
127class OMPTraitInfo;
128class ParentMapContext;
129struct ParsedTargetAttr;
130class Preprocessor;
131class ProfileList;
132class StoredDeclsMap;
133class TargetAttr;
134class TargetInfo;
135class TemplateDecl;
139class TypeConstraint;
141class UsingShadowDecl;
142class VarTemplateDecl;
145
146/// A simple array of base specifiers.
148
149namespace Builtin {
150
151class Context;
152
153} // namespace Builtin
154
157
158namespace comments {
159
160class FullComment;
161
162} // namespace comments
163
164namespace interp {
165
166class Context;
167
168} // namespace interp
169
170namespace serialization {
171template <class> class AbstractTypeReader;
172} // namespace serialization
173
175 /// The alignment was not explicit in code.
177
178 /// The alignment comes from an alignment attribute on a typedef.
180
181 /// The alignment comes from an alignment attribute on a record type.
183
184 /// The alignment comes from an alignment attribute on a enum type.
186};
187
201
215
220
221/// UniquingSet info for pools keyed on a QualType and a bool. DenseMapInfo has
222/// no bool specialization, so we cannot use the default UniquingSetInfo.
224 using KeyTy = std::pair<QualType, bool>;
225
226 template <typename T> static KeyTy getKey(const T &N) { return N.getKey(); }
227
228 static unsigned getHashValue(const KeyTy &Key) {
229 return llvm::hash_combine(Key.first.getAsOpaquePtr(), Key.second);
230 }
231
232 template <typename T> static bool isEqual(const KeyTy &Key, const T &N) {
233 return Key == N.getKey();
234 }
235};
236
237/// Holds long-lived AST nodes (such as types and decls) that can be
238/// referred to throughout the semantic analysis of a file.
239class ASTContext : public RefCountedBase<ASTContext> {
241
242 mutable SmallVector<Type *, 0> Types;
243 mutable llvm::FoldingSet<ExtQuals> ExtQualNodes;
244 mutable llvm::UniquingSet<ComplexType> ComplexTypes;
245 mutable llvm::UniquingSet<PointerType> PointerTypes{GeneralTypesLog2InitSize};
246 mutable llvm::UniquingSet<AdjustedType> AdjustedTypes;
247 mutable llvm::UniquingSet<BlockPointerType> BlockPointerTypes;
248 mutable llvm::UniquingSet<LValueReferenceType, QualTypeBoolInfo>
249 LValueReferenceTypes;
250 mutable llvm::UniquingSet<RValueReferenceType, QualTypeBoolInfo>
251 RValueReferenceTypes;
252 mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
253 mutable llvm::ContextualFoldingSet<ConstantArrayType, ASTContext &>
254 ConstantArrayTypes;
255 mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
256 mutable std::vector<VariableArrayType*> VariableArrayTypes;
257 mutable llvm::ContextualFoldingSet<DependentSizedArrayType, ASTContext &>
258 DependentSizedArrayTypes;
259 mutable llvm::ContextualFoldingSet<DependentSizedExtVectorType, ASTContext &>
260 DependentSizedExtVectorTypes;
261 mutable llvm::ContextualFoldingSet<DependentAddressSpaceType, ASTContext &>
262 DependentAddressSpaceTypes;
263 mutable llvm::FoldingSet<VectorType> VectorTypes;
264 mutable llvm::ContextualFoldingSet<DependentVectorType, ASTContext &>
265 DependentVectorTypes;
266 mutable llvm::FoldingSet<ConstantMatrixType> MatrixTypes;
267 mutable llvm::ContextualFoldingSet<DependentSizedMatrixType, ASTContext &>
268 DependentSizedMatrixTypes;
269 mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
270 mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&>
271 FunctionProtoTypes;
272 mutable llvm::ContextualFoldingSet<DependentTypeOfExprType, ASTContext &>
273 DependentTypeOfExprTypes;
274 mutable llvm::ContextualFoldingSet<DependentDecltypeType, ASTContext &>
275 DependentDecltypeTypes;
276
277 mutable llvm::ContextualFoldingSet<PackIndexingType, ASTContext &>
278 DependentPackIndexingTypes;
279
280 mutable llvm::UniquingSet<TemplateTypeParmType> TemplateTypeParmTypes;
281 mutable llvm::UniquingSet<ObjCTypeParamType> ObjCTypeParamTypes;
282 mutable llvm::UniquingSet<SubstTemplateTypeParmType>
283 SubstTemplateTypeParmTypes;
284 mutable llvm::FoldingSet<SubstTemplateTypeParmPackType>
285 SubstTemplateTypeParmPackTypes;
286 mutable llvm::FoldingSet<SubstBuiltinTemplatePackType>
287 SubstBuiltinTemplatePackTypes;
288 mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
289 TemplateSpecializationTypes;
290 mutable llvm::UniquingSet<ParenType> ParenTypes{GeneralTypesLog2InitSize};
291 mutable llvm::FoldingSet<TagTypeFoldingSetPlaceholder> TagTypes;
292 mutable llvm::FoldingSet<FoldingSetPlaceholder<UnresolvedUsingType>>
293 UnresolvedUsingTypes;
294 mutable llvm::FoldingSet<UsingType> UsingTypes;
295 mutable llvm::FoldingSet<FoldingSetPlaceholder<TypedefType>> TypedefTypes;
296 mutable llvm::FoldingSet<DependentNameType> DependentNameTypes;
297 mutable llvm::UniquingSet<PackExpansionType> PackExpansionTypes;
298 mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
299 mutable llvm::UniquingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
300 mutable llvm::UniquingSet<UnaryTransformType> UnaryTransformTypes;
301 // An AutoType can have a dependency on another AutoType via its template
302 // arguments. Since both dependent and dependency are on the same set,
303 // we can end up in an infinite recursion when looking for a node if we used
304 // a `FoldingSet`, since both could end up in the same bucket.
305 // Keyed by an interned FoldingSetNodeIDRef rather than a FoldingSetNodeID to
306 // avoid its large inline SmallVector in every bucket.
307 mutable llvm::DenseMap<llvm::FoldingSetNodeIDRef, AutoType *> AutoTypes;
308 mutable llvm::FoldingSet<DeducedTemplateSpecializationType>
309 DeducedTemplateSpecializationTypes;
310 mutable llvm::UniquingSet<AtomicType> AtomicTypes;
311 mutable llvm::ContextualFoldingSet<AttributedType, ASTContext &>
312 AttributedTypes;
313 mutable llvm::UniquingSet<PipeType, QualTypeBoolInfo> PipeTypes;
314 mutable llvm::UniquingSet<BitIntType> BitIntTypes;
315 mutable llvm::ContextualFoldingSet<DependentBitIntType, ASTContext &>
316 DependentBitIntTypes;
317 mutable llvm::FoldingSet<BTFTagAttributedType> BTFTagAttributedTypes;
318 mutable llvm::UniquingSet<OverflowBehaviorType> OverflowBehaviorTypes;
319 mutable llvm::ContextualFoldingSet<HLSLAttributedResourceType, ASTContext &>
320 HLSLAttributedResourceTypes;
321 llvm::FoldingSet<HLSLInlineSpirvType> HLSLInlineSpirvTypes;
322
323 mutable llvm::FoldingSet<CountAttributedType> CountAttributedTypes;
324
325 mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
326 mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
327 mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage>
328 SubstTemplateTemplateParms;
329 mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage,
330 ASTContext&>
331 SubstTemplateTemplateParmPacks;
332 mutable llvm::ContextualFoldingSet<DeducedTemplateStorage, ASTContext &>
333 DeducedTemplates;
334 mutable llvm::ContextualFoldingSet<PackIndexingTemplateStorage, ASTContext &>
335 PackIndexingTemplates;
336
337 mutable llvm::ContextualFoldingSet<ArrayParameterType, ASTContext &>
338 ArrayParameterTypes;
339
340 /// Store the unique Type corresponding to each Kind.
341 mutable std::array<Type *,
342 llvm::to_underlying(PredefinedSugarType::Kind::Last) + 1>
343 PredefinedSugarTypes{};
344
345 /// Internal storage for NestedNameSpecifiers.
346 ///
347 /// This set is managed by the NestedNameSpecifier class.
348 mutable llvm::UniquingSet<NamespaceAndPrefixStorage>
349 NamespaceAndPrefixStorages;
350
351 /// A cache mapping from RecordDecls to ASTRecordLayouts.
352 ///
353 /// This is lazily created. This is intentionally not serialized.
354 mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>
355 ASTRecordLayouts;
356 mutable llvm::DenseMap<const ObjCInterfaceDecl *, const ASTRecordLayout *>
357 ObjCLayouts;
358
359 /// A cache from types to size and alignment information.
360 using TypeInfoMap = llvm::DenseMap<const Type *, struct TypeInfo>;
361 mutable TypeInfoMap MemoizedTypeInfo;
362
363 /// A cache from types to unadjusted alignment information. Only ARM and
364 /// AArch64 targets need this information, keeping it separate prevents
365 /// imposing overhead on TypeInfo size.
366 using UnadjustedAlignMap = llvm::DenseMap<const Type *, unsigned>;
367 mutable UnadjustedAlignMap MemoizedUnadjustedAlign;
368
369 /// A cache mapping from CXXRecordDecls to key functions.
370 llvm::DenseMap<const CXXRecordDecl*, LazyDeclPtr> KeyFunctions;
371
372 /// Mapping from ObjCContainers to their ObjCImplementations.
373 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
374
375 /// Mapping from ObjCMethod to its duplicate declaration in the same
376 /// interface.
377 llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls;
378
379 /// Mapping from __block VarDecls to BlockVarCopyInit.
380 llvm::DenseMap<const VarDecl *, BlockVarCopyInit> BlockVarCopyInits;
381
382 /// Mapping from GUIDs to the corresponding MSGuidDecl.
383 mutable llvm::FoldingSet<MSGuidDecl> MSGuidDecls;
384
385 /// Mapping from APValues to the corresponding UnnamedGlobalConstantDecl.
386 mutable llvm::FoldingSet<UnnamedGlobalConstantDecl>
387 UnnamedGlobalConstantDecls;
388
389 /// Mapping from APValues to the corresponding TemplateParamObjects.
390 mutable llvm::FoldingSet<TemplateParamObjectDecl> TemplateParamObjectDecls;
391
392 /// A cache mapping a string value to a StringLiteral object with the same
393 /// value.
394 ///
395 /// This is lazily created. This is intentionally not serialized.
396 mutable llvm::StringMap<StringLiteral *> StringLiteralCache;
397
398 mutable llvm::DenseSet<const FunctionDecl *> DestroyingOperatorDeletes;
399 mutable llvm::DenseSet<const FunctionDecl *> TypeAwareOperatorNewAndDeletes;
400
401 /// Global and array operators delete are only required for MSVC deleting
402 /// destructors support. Store them here to avoid keeping 4 pointers that are
403 /// not always used in each redeclaration of the destructor.
404 mutable llvm::DenseMap<const CXXDestructorDecl *, FunctionDecl *>
405 OperatorDeletesForVirtualDtor;
406 mutable llvm::DenseMap<const CXXDestructorDecl *, FunctionDecl *>
407 GlobalOperatorDeletesForVirtualDtor;
408 mutable llvm::DenseMap<const CXXDestructorDecl *, FunctionDecl *>
409 ArrayOperatorDeletesForVirtualDtor;
410 mutable llvm::DenseMap<const CXXDestructorDecl *, FunctionDecl *>
411 GlobalArrayOperatorDeletesForVirtualDtor;
412
413 /// To remember for which types we met new[] call, these potentially require a
414 /// vector deleting dtor.
415 llvm::DenseSet<const CXXRecordDecl *> MaybeRequireVectorDeletingDtor;
416
417 /// The next string literal "version" to allocate during constant evaluation.
418 /// This is used to distinguish between repeated evaluations of the same
419 /// string literal.
420 ///
421 /// We don't need to serialize this because constants get re-evaluated in the
422 /// current file before they are compared locally.
423 unsigned NextStringLiteralVersion = 0;
424
425 /// MD5 hash of CUID. It is calculated when first used and cached by this
426 /// data member.
427 mutable std::string CUIDHash;
428
429 /// Representation of a "canonical" template template parameter that
430 /// is used in canonical template names.
431 class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
432 TemplateTemplateParmDecl *Parm;
433
434 public:
435 CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm)
436 : Parm(Parm) {}
437
438 TemplateTemplateParmDecl *getParam() const { return Parm; }
439
440 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) {
441 Profile(ID, C, Parm);
442 }
443
444 static void Profile(llvm::FoldingSetNodeID &ID,
445 const ASTContext &C,
446 TemplateTemplateParmDecl *Parm);
447 };
448 mutable llvm::ContextualFoldingSet<CanonicalTemplateTemplateParm,
449 const ASTContext&>
450 CanonTemplateTemplateParms;
451
452 /// The typedef for the __int128_t type.
453 mutable TypedefDecl *Int128Decl = nullptr;
454
455 /// The typedef for the __uint128_t type.
456 mutable TypedefDecl *UInt128Decl = nullptr;
457
458 /// The typedef for the target specific predefined
459 /// __builtin_va_list type.
460 mutable TypedefDecl *BuiltinVaListDecl = nullptr;
461
462 /// The typedef for the predefined \c __builtin_ms_va_list type.
463 mutable TypedefDecl *BuiltinMSVaListDecl = nullptr;
464
465 /// The typedef for the predefined \c __builtin_zos_va_list type.
466 mutable TypedefDecl *BuiltinZOSVaListDecl = nullptr;
467
468 /// The typedef for the predefined \c id type.
469 mutable TypedefDecl *ObjCIdDecl = nullptr;
470
471 /// The typedef for the predefined \c SEL type.
472 mutable TypedefDecl *ObjCSelDecl = nullptr;
473
474 /// The typedef for the predefined \c Class type.
475 mutable TypedefDecl *ObjCClassDecl = nullptr;
476
477 /// The typedef for the predefined \c Protocol class in Objective-C.
478 mutable ObjCInterfaceDecl *ObjCProtocolClassDecl = nullptr;
479
480 /// The typedef for the predefined 'BOOL' type.
481 mutable TypedefDecl *BOOLDecl = nullptr;
482
483 // Typedefs which may be provided defining the structure of Objective-C
484 // pseudo-builtins
485 QualType ObjCIdRedefinitionType;
486 QualType ObjCClassRedefinitionType;
487 QualType ObjCSelRedefinitionType;
488
489 /// The identifier 'bool'.
490 mutable IdentifierInfo *BoolName = nullptr;
491
492 /// The identifier 'NSObject'.
493 mutable IdentifierInfo *NSObjectName = nullptr;
494
495 /// The identifier 'NSCopying'.
496 IdentifierInfo *NSCopyingName = nullptr;
497
498#define BuiltinTemplate(BTName) mutable IdentifierInfo *Name##BTName = nullptr;
499#include "clang/Basic/BuiltinTemplates.inc"
500
501 QualType ObjCConstantStringType;
502 mutable RecordDecl *CFConstantStringTagDecl = nullptr;
503 mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
504
505 mutable QualType ObjCSuperType;
506
507 QualType ObjCNSStringType;
508
509 /// The typedef declaration for the Objective-C "instancetype" type.
510 TypedefDecl *ObjCInstanceTypeDecl = nullptr;
511
512 /// The type for the C FILE type.
513 TypeDecl *FILEDecl = nullptr;
514
515 /// The type for the C jmp_buf type.
516 TypeDecl *jmp_bufDecl = nullptr;
517
518 /// The type for the C sigjmp_buf type.
519 TypeDecl *sigjmp_bufDecl = nullptr;
520
521 /// The type for the C ucontext_t type.
522 TypeDecl *ucontext_tDecl = nullptr;
523
524 /// Type for the Block descriptor for Blocks CodeGen.
525 ///
526 /// Since this is only used for generation of debug info, it is not
527 /// serialized.
528 mutable RecordDecl *BlockDescriptorType = nullptr;
529
530 /// Type for the Block descriptor for Blocks CodeGen.
531 ///
532 /// Since this is only used for generation of debug info, it is not
533 /// serialized.
534 mutable RecordDecl *BlockDescriptorExtendedType = nullptr;
535
536 /// Declaration for the CUDA cudaConfigureCall function.
537 FunctionDecl *cudaConfigureCallDecl = nullptr;
538 /// Declaration for the CUDA cudaGetParameterBuffer function.
539 FunctionDecl *cudaGetParameterBufferDecl = nullptr;
540 /// Declaration for the CUDA cudaLaunchDevice function.
541 FunctionDecl *cudaLaunchDeviceDecl = nullptr;
542
543 llvm::DenseMap<const CXXConstructorDecl *, ArrayRef<CXXDefaultArgExpr *>>
544 CtorClosureDefaultArgs;
545
546 /// Keeps track of all declaration attributes.
547 ///
548 /// Since so few decls have attrs, we keep them in a hash map instead of
549 /// wasting space in the Decl class.
550 llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs;
551
552 /// One-entry cache for getDeclAttrs().
553 const Decl *LastDeclAttrsDecl = nullptr;
554 AttrVec *LastDeclAttrs = nullptr;
555
556 /// A mapping from non-redeclarable declarations in modules that were
557 /// merged with other declarations to the canonical declaration that they were
558 /// merged into.
559 llvm::DenseMap<Decl*, Decl*> MergedDecls;
560
561 /// A mapping from a defining declaration to a list of modules (other
562 /// than the owning module of the declaration) that contain merged
563 /// definitions of that entity.
564 llvm::DenseMap<NamedDecl*, llvm::TinyPtrVector<Module*>> MergedDefModules;
565
566 /// Initializers for a module, in order. Each Decl will be either
567 /// something that has a semantic effect on startup (such as a variable with
568 /// a non-constant initializer), or an ImportDecl (which recursively triggers
569 /// initialization of another module).
570 struct PerModuleInitializers {
571 llvm::SmallVector<Decl*, 4> Initializers;
572 llvm::SmallVector<GlobalDeclID, 4> LazyInitializers;
573
574 void resolve(ASTContext &Ctx);
575 };
576 llvm::DenseMap<Module*, PerModuleInitializers*> ModuleInitializers;
577
578 /// This is the top-level (C++20) Named module we are building.
579 Module *CurrentCXXNamedModule = nullptr;
580
581 /// Help structures to decide whether two `const Module *` belongs
582 /// to the same conceptual module to avoid the expensive to string comparison
583 /// if possible.
584 ///
585 /// Not serialized intentionally.
586 mutable llvm::StringMap<const Module *> PrimaryModuleNameMap;
587 mutable llvm::DenseMap<const Module *, const Module *> SameModuleLookupSet;
588
589 static constexpr unsigned ConstantArrayTypesLog2InitSize = 8;
590 static constexpr unsigned GeneralTypesLog2InitSize = 9;
591 static constexpr unsigned FunctionProtoTypesLog2InitSize = 12;
592
593 /// A mapping from an ObjC class to its subclasses.
594 llvm::DenseMap<const ObjCInterfaceDecl *,
595 SmallVector<const ObjCInterfaceDecl *, 4>>
596 ObjCSubClasses;
597
598 // A mapping from Scalable Vector Type keys to their corresponding QualType.
599 mutable llvm::DenseMap<llvm::ScalableVecTyKey, QualType> ScalableVecTyMap;
600
601 ASTContext &this_() { return *this; }
602
603public:
604 /// A type synonym for the TemplateOrInstantiation mapping.
606 llvm::PointerUnion<VarTemplateDecl *, MemberSpecializationInfo *>;
607
608private:
609 friend class ASTDeclReader;
610 friend class ASTReader;
611 friend class ASTWriter;
612 template <class> friend class serialization::AbstractTypeReader;
613 friend class CXXRecordDecl;
614 friend class IncrementalParser;
615
616 /// A mapping to contain the template or declaration that
617 /// a variable declaration describes or was instantiated from,
618 /// respectively.
619 ///
620 /// For non-templates, this value will be NULL. For variable
621 /// declarations that describe a variable template, this will be a
622 /// pointer to a VarTemplateDecl. For static data members
623 /// of class template specializations, this will be the
624 /// MemberSpecializationInfo referring to the member variable that was
625 /// instantiated or specialized. Thus, the mapping will keep track of
626 /// the static data member templates from which static data members of
627 /// class template specializations were instantiated.
628 ///
629 /// Given the following example:
630 ///
631 /// \code
632 /// template<typename T>
633 /// struct X {
634 /// static T value;
635 /// };
636 ///
637 /// template<typename T>
638 /// T X<T>::value = T(17);
639 ///
640 /// int *x = &X<int>::value;
641 /// \endcode
642 ///
643 /// This mapping will contain an entry that maps from the VarDecl for
644 /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
645 /// class template X) and will be marked TSK_ImplicitInstantiation.
646 llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo>
647 TemplateOrInstantiation;
648
649 /// Keeps track of the declaration from which a using declaration was
650 /// created during instantiation.
651 ///
652 /// The source and target declarations are always a UsingDecl, an
653 /// UnresolvedUsingValueDecl, or an UnresolvedUsingTypenameDecl.
654 ///
655 /// For example:
656 /// \code
657 /// template<typename T>
658 /// struct A {
659 /// void f();
660 /// };
661 ///
662 /// template<typename T>
663 /// struct B : A<T> {
664 /// using A<T>::f;
665 /// };
666 ///
667 /// template struct B<int>;
668 /// \endcode
669 ///
670 /// This mapping will contain an entry that maps from the UsingDecl in
671 /// B<int> to the UnresolvedUsingDecl in B<T>.
672 llvm::DenseMap<NamedDecl *, NamedDecl *> InstantiatedFromUsingDecl;
673
674 /// Like InstantiatedFromUsingDecl, but for using-enum-declarations. Maps
675 /// from the instantiated using-enum to the templated decl from whence it
676 /// came.
677 /// Note that using-enum-declarations cannot be dependent and
678 /// thus will never be instantiated from an "unresolved"
679 /// version thereof (as with using-declarations), so each mapping is from
680 /// a (resolved) UsingEnumDecl to a (resolved) UsingEnumDecl.
681 llvm::DenseMap<UsingEnumDecl *, UsingEnumDecl *>
682 InstantiatedFromUsingEnumDecl;
683
684 /// Similarly maps instantiated UsingShadowDecls to their origin.
685 llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
686 InstantiatedFromUsingShadowDecl;
687
688 llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
689
690 /// Maps a canonical specialization Decl to all ExplicitInstantiationDecls
691 /// that reference it (declarations and definitions).
692 llvm::DenseMap<const NamedDecl *,
693 llvm::TinyPtrVector<ExplicitInstantiationDecl *>>
694 ExplicitInstantiations;
695
696 /// Mapping that stores the methods overridden by a given C++
697 /// member function.
698 ///
699 /// Since most C++ member functions aren't virtual and therefore
700 /// don't override anything, we store the overridden functions in
701 /// this map on the side rather than within the CXXMethodDecl structure.
702 using CXXMethodVector = llvm::TinyPtrVector<const CXXMethodDecl *>;
703 llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods;
704
705 /// Mapping from each declaration context to its corresponding
706 /// mangling numbering context (used for constructs like lambdas which
707 /// need to be consistently numbered for the mangler).
708 llvm::DenseMap<const DeclContext *, std::unique_ptr<MangleNumberingContext>>
709 MangleNumberingContexts;
710 llvm::DenseMap<const Decl *, std::unique_ptr<MangleNumberingContext>>
711 ExtraMangleNumberingContexts;
712
713 /// Side-table of mangling numbers for declarations which rarely
714 /// need them (like static local vars).
715 llvm::MapVector<const NamedDecl *, unsigned> MangleNumbers;
716 llvm::MapVector<const VarDecl *, unsigned> StaticLocalNumbers;
717 /// Mapping the associated device lambda mangling number if present.
718 mutable llvm::DenseMap<const CXXRecordDecl *, unsigned>
719 DeviceLambdaManglingNumbers;
720
721 /// Mapping that stores parameterIndex values for ParmVarDecls when
722 /// that value exceeds the bitfield size of ParmVarDeclBits.ParameterIndex.
723 using ParameterIndexTable = llvm::DenseMap<const VarDecl *, unsigned>;
724 ParameterIndexTable ParamIndices;
725
726 /// Map from numbering information for lambdas to the corresponding lambdas.
727 /// This is intentionally not serialized, and is instead reconstructed as we
728 /// read each lambda.
729 llvm::DenseMap<std::pair<const Decl *, unsigned>, CXXRecordDecl *>
730 LambdaDeclarationsForMerging;
731
732public:
736 std::optional<CXXRecordDeclRelocationInfo>
740
741 // Returns a reference to the first lambda declaration with a given index in a
742 // given context. Used to merge lambdas in the case where the same lambda is
743 // redefined in multiple modules.
745 int IndexInContext) {
746 return LambdaDeclarationsForMerging[{ContextDecl->getCanonicalDecl(),
747 IndexInContext}];
748 }
749
750 /// Examines a given type, and returns whether the type itself
751 /// is address discriminated, or any transitively embedded types
752 /// contain data that is address discriminated. This includes
753 /// implicitly authenticated values like vtable pointers, as well as
754 /// explicitly qualified fields.
756 if (!isPointerAuthenticationAvailable())
757 return false;
758 return findPointerAuthContent(T) != PointerAuthContent::None;
759 }
760
761 /// Examines a given type, and returns whether the type itself
762 /// or any data it transitively contains has a pointer authentication
763 /// schema that is not safely relocatable. e.g. any data or fields
764 /// with address discrimination other than any otherwise similar
765 /// vtable pointers.
767 if (!isPointerAuthenticationAvailable())
768 return false;
769 return findPointerAuthContent(T) != PointerAuthContent::None;
770 }
771
772private:
773 llvm::DenseMap<const CXXRecordDecl *, CXXRecordDeclRelocationInfo>
774 RelocatableClasses;
775
776 // FIXME: store in RecordDeclBitfields in future?
777 enum class PointerAuthContent : uint8_t {
778 None,
779 AddressDiscriminatedVTable,
780 AddressDiscriminatedData
781 };
782
783 // A simple helper function to short circuit pointer auth checks.
784 bool isPointerAuthenticationAvailable() const {
785 return LangOpts.PointerAuthCalls || LangOpts.PointerAuthIntrinsics;
786 }
787 PointerAuthContent findPointerAuthContent(QualType T) const;
788 mutable llvm::DenseMap<const RecordDecl *, PointerAuthContent>
789 RecordContainsAddressDiscriminatedPointerAuth;
790
791 ImportDecl *FirstLocalImport = nullptr;
792 ImportDecl *LastLocalImport = nullptr;
793
794 TranslationUnitDecl *TUDecl = nullptr;
795 mutable ExternCContextDecl *ExternCContext = nullptr;
796
797#define BuiltinTemplate(BTName) \
798 mutable BuiltinTemplateDecl *Decl##BTName = nullptr;
799#include "clang/Basic/BuiltinTemplates.inc"
800
801 /// The associated SourceManager object.
802 SourceManager &SourceMgr;
803
804 /// The language options used to create the AST associated with
805 /// this ASTContext object.
806 LangOptions &LangOpts;
807
808 /// NoSanitizeList object that is used by sanitizers to decide which
809 /// entities should not be instrumented.
810 std::unique_ptr<NoSanitizeList> NoSanitizeL;
811
812 /// Function filtering mechanism to determine whether a given function
813 /// should be imbued with the XRay "always" or "never" attributes.
814 std::unique_ptr<XRayFunctionFilter> XRayFilter;
815
816 /// ProfileList object that is used by the profile instrumentation
817 /// to decide which entities should be instrumented.
818 std::unique_ptr<ProfileList> ProfList;
819
820 /// The allocator used to create AST objects.
821 ///
822 /// AST objects are never destructed; rather, all memory associated with the
823 /// AST objects will be released when the ASTContext itself is destroyed.
824 mutable llvm::BumpPtrAllocator BumpAlloc;
825
826 /// Allocator for partial diagnostics.
828
829 /// The current C++ ABI.
830 std::unique_ptr<CXXABI> ABI;
831 CXXABI *createCXXABI(const TargetInfo &T);
832
833 /// Address space map mangling must be used with language specific
834 /// address spaces (e.g. OpenCL/CUDA)
835 bool AddrSpaceMapMangling;
836
837 /// For performance, track whether any function effects are in use.
838 mutable bool AnyFunctionEffects = false;
839
840 const TargetInfo *Target = nullptr;
841 const TargetInfo *AuxTarget = nullptr;
842 clang::PrintingPolicy PrintingPolicy;
843 mutable std::unique_ptr<interp::Context> InterpContext;
844 std::unique_ptr<ParentMapContext> ParentMapCtx;
845
846 /// Keeps track of the deallocated DeclListNodes for future reuse.
847 DeclListNode *ListNodeFreeList = nullptr;
848
849public:
857
858 /// Returns the clang bytecode interpreter context.
860
862 /// Do not allow wrong-sided variables in constant expressions.
863 bool NoWrongSidedVars = false;
874
875 /// Returns the dynamic AST node parent map context.
877
878 // A traversal scope limits the parts of the AST visible to certain analyses.
879 // RecursiveASTVisitor only visits specified children of TranslationUnitDecl.
880 // getParents() will only observe reachable parent edges.
881 //
882 // The scope is defined by a set of "top-level" declarations which will be
883 // visible under the TranslationUnitDecl.
884 // Initially, it is the entire TU, represented by {getTranslationUnitDecl()}.
885 //
886 // After setTraversalScope({foo, bar}), the exposed AST looks like:
887 // TranslationUnitDecl
888 // - foo
889 // - ...
890 // - bar
891 // - ...
892 // All other siblings of foo and bar are pruned from the tree.
893 // (However they are still accessible via TranslationUnitDecl->decls())
894 //
895 // Changing the scope clears the parent cache, which is expensive to rebuild.
896 ArrayRef<Decl *> getTraversalScope() const { return TraversalScope; }
897 void setTraversalScope(const std::vector<Decl *> &);
898
899 /// Forwards to get node parents from the ParentMapContext. New callers should
900 /// use ParentMapContext::getParents() directly.
901 template <typename NodeT> DynTypedNodeList getParents(const NodeT &Node);
902
904 return PrintingPolicy;
905 }
906
908 PrintingPolicy = Policy;
909 }
910
911 SourceManager& getSourceManager() { return SourceMgr; }
912 const SourceManager& getSourceManager() const { return SourceMgr; }
913
914 // Cleans up some of the data structures. This allows us to do cleanup
915 // normally done in the destructor earlier. Renders much of the ASTContext
916 // unusable, mostly the actual AST nodes, so should be called when we no
917 // longer need access to the AST.
918 void cleanup();
919
920 llvm::BumpPtrAllocator &getAllocator() const {
921 return BumpAlloc;
922 }
923
924 void *Allocate(size_t Size, unsigned Align = 8) const {
925 return BumpAlloc.Allocate(Size, Align);
926 }
927 template <typename T> T *Allocate(size_t Num = 1) const {
928 return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));
929 }
930 void Deallocate(void *Ptr) const {}
931
932 llvm::StringRef backupStr(llvm::StringRef S) const {
933 char *Buf = new (*this) char[S.size()];
934 llvm::copy(S, Buf);
935 return llvm::StringRef(Buf, S.size());
936 }
937
938 /// Allocates a \c DeclListNode or returns one from the \c ListNodeFreeList
939 /// pool.
941 if (DeclListNode *Alloc = ListNodeFreeList) {
942 ListNodeFreeList = dyn_cast_if_present<DeclListNode *>(Alloc->Rest);
943 Alloc->D = ND;
944 Alloc->Rest = nullptr;
945 return Alloc;
946 }
947 return new (*this) DeclListNode(ND);
948 }
949 /// Deallocates a \c DeclListNode by returning it to the \c ListNodeFreeList
950 /// pool.
952 N->Rest = ListNodeFreeList;
953 ListNodeFreeList = N;
954 }
955
956 /// Return the total amount of physical memory allocated for representing
957 /// AST nodes and type information.
958 size_t getASTAllocatedMemory() const {
959 return BumpAlloc.getTotalMemory();
960 }
961
962 /// Return the total memory used for various side tables.
963 size_t getSideTableAllocatedMemory() const;
964
966 return DiagAllocator;
967 }
968
969 const TargetInfo &getTargetInfo() const { return *Target; }
970 const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }
971
972 const QualType GetHigherPrecisionFPType(QualType ElementType) const {
973 const auto *CurrentBT = cast<BuiltinType>(ElementType);
974 switch (CurrentBT->getKind()) {
975 case BuiltinType::Kind::Half:
976 case BuiltinType::Kind::Float16:
977 return FloatTy;
978 case BuiltinType::Kind::Float:
979 case BuiltinType::Kind::BFloat16:
980 return DoubleTy;
981 case BuiltinType::Kind::Double:
982 return LongDoubleTy;
983 default:
984 return ElementType;
985 }
986 return ElementType;
987 }
988
989 /// getIntTypeForBitwidth -
990 /// sets integer QualTy according to specified details:
991 /// bitwidth, signed/unsigned.
992 /// Returns empty type if there is no appropriate target types.
993 QualType getIntTypeForBitwidth(unsigned DestWidth,
994 unsigned Signed) const;
995
996 QualType getLeastIntTypeForBitwidth(unsigned DestWidth,
997 unsigned Signed) const;
998
999 /// getRealTypeForBitwidth -
1000 /// sets floating point QualTy according to specified bitwidth.
1001 /// Returns empty type if there is no appropriate target types.
1002 QualType getRealTypeForBitwidth(unsigned DestWidth,
1003 FloatModeKind ExplicitType) const;
1004
1005 bool AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const;
1006
1007 const LangOptions& getLangOpts() const { return LangOpts; }
1008
1009 // If this condition is false, typo correction must be performed eagerly
1010 // rather than delayed in many places, as it makes use of dependent types.
1011 // the condition is false for clang's C-only codepath, as it doesn't support
1012 // dependent types yet.
1013 bool isDependenceAllowed() const {
1014 return LangOpts.CPlusPlus || LangOpts.RecoveryAST;
1015 }
1016
1017 const NoSanitizeList &getNoSanitizeList() const { return *NoSanitizeL; }
1018
1019 bool isTypeIgnoredBySanitizer(const SanitizerMask &Mask,
1020 const QualType &Ty) const;
1021
1023
1025 return *XRayFilter;
1026 }
1027
1028 const ProfileList &getProfileList() const { return *ProfList; }
1029
1031
1033 return FullSourceLoc(Loc,SourceMgr);
1034 }
1035
1036 /// Return the C++ ABI kind that should be used. The C++ ABI can be overriden
1037 /// at compile time with `-fc++-abi=`. If this is not provided, we instead use
1038 /// the default ABI set by the target.
1040
1041 /// All comments in this translation unit.
1043
1044 /// True if comments are already loaded from ExternalASTSource.
1045 mutable bool CommentsLoaded = false;
1046
1047 /// Key used to look up the raw comment attached to a declaration or macro.
1049 llvm::PointerUnion<const Decl *, const MacroInfo *>;
1050
1051 /// Mapping from declaration or macro to directly attached comment.
1052 ///
1053 /// Raw comments are owned by Comments list. This mapping is populated
1054 /// lazily.
1055 mutable llvm::DenseMap<RawCommentLookupKey, const RawComment *> RawComments;
1056
1057 /// Mapping from canonical declaration to the first redeclaration in chain
1058 /// that has a comment attached.
1059 ///
1060 /// Raw comments are owned by Comments list. This mapping is populated
1061 /// lazily.
1062 mutable llvm::DenseMap<const Decl *, const Decl *> RedeclChainComments;
1063
1064 /// Keeps track of redeclaration chains that don't have any comment attached.
1065 /// Mapping from canonical declaration to redeclaration chain that has no
1066 /// comments attached to any redeclaration. Specifically it's mapping to
1067 /// the last redeclaration we've checked.
1068 ///
1069 /// Shall not contain declarations that have comments attached to any
1070 /// redeclaration in their chain.
1071 mutable llvm::DenseMap<const Decl *, const Decl *> CommentlessRedeclChains;
1072
1073 /// Mapping from declarations to parsed comments attached to any
1074 /// redeclaration.
1075 mutable llvm::DenseMap<const Decl *, comments::FullComment *> ParsedComments;
1076
1077 /// Attaches \p Comment to \p Original (a declaration or macro), and to its
1078 /// redeclaration chain when \p Original is a declaration. Removes the
1079 /// redeclaration chain from the set of commentless chains.
1080 ///
1081 /// Don't do anything if a comment has already been attached to \p Original
1082 /// or its redeclaration chain.
1084 const RawComment &Comment) const;
1085
1086 /// \returns searches \p CommentsInFile for doc comment for \p Key.
1087 ///
1088 /// \p RepresentativeLocForDecl is used as a location for searching doc
1089 /// comments. \p CommentsInFile is a mapping offset -> comment of files in the
1090 /// same file where \p RepresentativeLocForDecl is.
1092 RawCommentLookupKey Key, const SourceLocation RepresentativeLoc,
1093 const std::map<unsigned, RawComment *> &CommentsInFile) const;
1094
1095 /// Return the documentation comment attached to a given declaration or
1096 /// macro, without looking into cache.
1098
1099public:
1100 void addComment(const RawComment &RC);
1101
1102 /// Return the documentation comment attached to a given declaration or
1103 /// macro. Returns nullptr if no comment is attached.
1104 ///
1105 /// \param OriginalDecl if not nullptr, is set to declaration AST node that
1106 /// had the comment, if the comment we found comes from a redeclaration.
1107 /// Macros have no redeclaration chain, so this is set to nullptr when
1108 /// \p Key is a \c MacroInfo.
1109 const RawComment *
1111 const Decl **OriginalDecl = nullptr) const;
1112
1113 /// Searches existing comments for doc comments that should be attached to \p
1114 /// Decls. If any doc comment is found, it is parsed.
1115 ///
1116 /// Requirement: All \p Decls are in the same file.
1117 ///
1118 /// If the last comment in the file is already attached we assume
1119 /// there are not comments left to be attached to \p Decls.
1121 const Preprocessor *PP);
1122
1123 /// Return parsed documentation comment attached to a given declaration.
1124 /// Returns nullptr if no comment is attached.
1125 ///
1126 /// \param PP the Preprocessor used with this TU. Could be nullptr if
1127 /// preprocessor is not available.
1129 const Preprocessor *PP) const;
1130
1131 /// Attempts to merge two types that may be OverflowBehaviorTypes.
1132 ///
1133 /// \returns A QualType if the types were handled, std::nullopt otherwise.
1134 /// A null QualType indicates an incompatible merge.
1135 std::optional<QualType>
1136 tryMergeOverflowBehaviorTypes(QualType LHS, QualType RHS, bool OfBlockPointer,
1137 bool Unqualified, bool BlockReturnType,
1138 bool IsConditionalOperator);
1139
1140 /// Return parsed documentation comment attached to a given declaration.
1141 /// Returns nullptr if no comment is attached. Does not look at any
1142 /// redeclarations of the declaration.
1144
1146 const Decl *D) const;
1147
1148private:
1149 mutable comments::CommandTraits CommentCommandTraits;
1150
1151 /// Iterator that visits import declarations.
1152 class import_iterator {
1153 ImportDecl *Import = nullptr;
1154
1155 public:
1156 using value_type = ImportDecl *;
1157 using reference = ImportDecl *;
1158 using pointer = ImportDecl *;
1159 using difference_type = int;
1160 using iterator_category = std::forward_iterator_tag;
1161
1162 import_iterator() = default;
1163 explicit import_iterator(ImportDecl *Import) : Import(Import) {}
1164
1165 reference operator*() const { return Import; }
1166 pointer operator->() const { return Import; }
1167
1168 import_iterator &operator++() {
1169 Import = ASTContext::getNextLocalImport(Import);
1170 return *this;
1171 }
1172
1173 import_iterator operator++(int) {
1174 import_iterator Other(*this);
1175 ++(*this);
1176 return Other;
1177 }
1178
1179 friend bool operator==(import_iterator X, import_iterator Y) {
1180 return X.Import == Y.Import;
1181 }
1182
1183 friend bool operator!=(import_iterator X, import_iterator Y) {
1184 return X.Import != Y.Import;
1185 }
1186 };
1187
1188public:
1190 return CommentCommandTraits;
1191 }
1192
1193 /// Retrieve the attributes for the given declaration.
1194 AttrVec& getDeclAttrs(const Decl *D);
1195
1196 /// Erase the attributes corresponding to the given declaration.
1197 void eraseDeclAttrs(const Decl *D);
1198
1203
1204 /// Get all ExplicitInstantiationDecls for a given specialization.
1206 getExplicitInstantiationDecls(const NamedDecl *Spec) const;
1207
1208 /// Add an ExplicitInstantiationDecl for a given specialization.
1209 void addExplicitInstantiationDecl(const NamedDecl *Spec,
1211
1212 /// If this variable is an instantiated static data member of a
1213 /// class template specialization, returns the templated static data member
1214 /// from which it was instantiated.
1215 // FIXME: Remove ?
1217 const VarDecl *Var);
1218
1219 /// Note that the static data member \p Inst is an instantiation of
1220 /// the static data member template \p Tmpl of a class template.
1223 SourceLocation PointOfInstantiation = SourceLocation());
1224
1227
1230
1231 /// If the given using decl \p Inst is an instantiation of
1232 /// another (possibly unresolved) using decl, return it.
1234
1235 /// Remember that the using decl \p Inst is an instantiation
1236 /// of the using decl \p Pattern of a class template.
1237 void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern);
1238
1239 /// If the given using-enum decl \p Inst is an instantiation of
1240 /// another using-enum decl, return it.
1242
1243 /// Remember that the using enum decl \p Inst is an instantiation
1244 /// of the using enum decl \p Pattern of a class template.
1246 UsingEnumDecl *Pattern);
1247
1250 UsingShadowDecl *Pattern);
1251
1253
1255
1256 // Access to the set of methods overridden by the given C++ method.
1257 using overridden_cxx_method_iterator = CXXMethodVector::const_iterator;
1260
1263
1264 unsigned overridden_methods_size(const CXXMethodDecl *Method) const;
1265
1267 llvm::iterator_range<overridden_cxx_method_iterator>;
1268
1270
1271 /// Note that the given C++ \p Method overrides the given \p
1272 /// Overridden method.
1274 const CXXMethodDecl *Overridden);
1275
1276 /// Return C++ or ObjC overridden methods for the given \p Method.
1277 ///
1278 /// An ObjC method is considered to override any method in the class's
1279 /// base classes, its protocols, or its categories' protocols, that has
1280 /// the same selector and is of the same kind (class or instance).
1281 /// A method in an implementation is not considered as overriding the same
1282 /// method in the interface or its categories.
1284 const NamedDecl *Method,
1285 SmallVectorImpl<const NamedDecl *> &Overridden) const;
1286
1287 /// Notify the AST context that a new import declaration has been
1288 /// parsed or implicitly created within this translation unit.
1289 void addedLocalImportDecl(ImportDecl *Import);
1290
1292 return Import->getNextLocalImport();
1293 }
1294
1295 using import_range = llvm::iterator_range<import_iterator>;
1296
1298 return import_range(import_iterator(FirstLocalImport), import_iterator());
1299 }
1300
1302 Decl *Result = MergedDecls.lookup(D);
1303 return Result ? Result : D;
1304 }
1305 void setPrimaryMergedDecl(Decl *D, Decl *Primary) {
1306 MergedDecls[D] = Primary;
1307 }
1308
1309 /// Note that the definition \p ND has been merged into module \p M,
1310 /// and should be visible whenever \p M is visible.
1312 bool NotifyListeners = true);
1313
1314 /// Clean up the merged definition list. Call this if you might have
1315 /// added duplicates into the list.
1317
1318 /// Get the additional modules in which the definition \p Def has
1319 /// been merged.
1321
1322 /// Add a declaration to the list of declarations that are initialized
1323 /// for a module. This will typically be a global variable (with internal
1324 /// linkage) that runs module initializers, such as the iostream initializer,
1325 /// or an ImportDecl nominating another module that has initializers.
1327
1329
1330 /// Get the initializations to perform when importing a module, if any.
1332
1333 /// Set the (C++20) module we are building.
1335
1336 /// Get module under construction, nullptr if this is not a C++20 module.
1337 Module *getCurrentNamedModule() const { return CurrentCXXNamedModule; }
1338
1339 /// If the two module \p M1 and \p M2 are in the same module.
1340 ///
1341 /// FIXME: The signature may be confusing since `clang::Module` means to
1342 /// a module fragment or a module unit but not a C++20 module.
1343 bool isInSameModule(const Module *M1, const Module *M2) const;
1344
1346 assert(TUDecl && "TUDecl might have been reset by 'cleanup' likely because "
1347 "'CodeGenOpts.ClearASTBeforeBackend' was set.");
1348 assert(TUDecl->getMostRecentDecl() == TUDecl &&
1349 "The active TU is not current one!");
1350 return TUDecl->getMostRecentDecl();
1351 }
1353 assert(!TUDecl || TUKind == TU_Incremental);
1355 if (TraversalScope.empty() || TraversalScope.back() == TUDecl)
1356 TraversalScope = {NewTUDecl};
1357 if (TUDecl)
1358 NewTUDecl->setPreviousDecl(TUDecl);
1359 TUDecl = NewTUDecl;
1360 }
1361
1363
1364#define BuiltinTemplate(BTName) BuiltinTemplateDecl *get##BTName##Decl() const;
1365#include "clang/Basic/BuiltinTemplates.inc"
1366
1367 // Builtin Types.
1371 CanQualType WCharTy; // [C++ 3.9.1p5].
1372 CanQualType WideCharTy; // Same as WCharTy in C++, integer type in C99.
1373 CanQualType WIntTy; // [C99 7.24.1], integer type unchanged by default promotions.
1374 CanQualType Char8Ty; // [C++20 proposal]
1375 CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
1376 CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
1382 LongAccumTy; // ISO/IEC JTC1 SC22 WG14 N1169 Extension
1392 CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
1394 CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
1403#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1404 CanQualType SingletonId;
1405#include "clang/Basic/OpenCLImageTypes.def"
1411#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1412 CanQualType Id##Ty;
1413#include "clang/Basic/OpenCLExtensionTypes.def"
1414#define SVE_TYPE(Name, Id, SingletonId) \
1415 CanQualType SingletonId;
1416#include "clang/Basic/AArch64ACLETypes.def"
1417#define PPC_VECTOR_TYPE(Name, Id, Size) \
1418 CanQualType Id##Ty;
1419#include "clang/Basic/PPCTypes.def"
1420#define RVV_TYPE(Name, Id, SingletonId) \
1421 CanQualType SingletonId;
1422#include "clang/Basic/RISCVVTypes.def"
1423#define WASM_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
1424#include "clang/Basic/WebAssemblyReferenceTypes.def"
1425#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1426 CanQualType SingletonId;
1427#include "clang/Basic/AMDGPUTypes.def"
1428#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
1429#include "clang/Basic/HLSLIntangibleTypes.def"
1430#define HLSL_PACKED_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
1431#include "clang/Basic/HLSLPackedTypes.def"
1432#define SPIRV_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
1433#include "clang/Basic/SPIRVTypes.def"
1434
1435 // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
1436 mutable QualType AutoDeductTy; // Deduction against 'auto'.
1437 mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'.
1438
1439 // Decl used to help define __builtin_va_list for some targets.
1440 // The decl is built when constructing 'BuiltinVaListDecl'.
1441 mutable Decl *VaListTagDecl = nullptr;
1442
1443 // Implicitly-declared type 'struct _GUID'.
1444 mutable TagDecl *MSGuidTagDecl = nullptr;
1445
1446 // Implicitly-declared type 'struct type_info'.
1447 mutable TagDecl *MSTypeInfoTagDecl = nullptr;
1448
1449 /// Keep track of CUDA/HIP device-side variables ODR-used by host code.
1450 /// This does not include extern shared variables used by device host
1451 /// functions as addresses of shared variables are per warp, therefore
1452 /// cannot be accessed by host code.
1453 llvm::SetVector<const VarDecl *> CUDADeviceVarODRUsedByHost;
1454
1455 /// Keep track of CUDA/HIP external kernels or device variables ODR-used by
1456 /// host code. SetVector is used to maintain the order.
1457 llvm::SetVector<const ValueDecl *> CUDAExternalDeviceDeclODRUsedByHost;
1458
1459 /// Keep track of CUDA/HIP implicit host device functions used on device side
1460 /// in device compilation.
1461 llvm::DenseSet<const FunctionDecl *> CUDAImplicitHostDeviceFunUsedByDevice;
1462
1463 /// Functions whose device body should be replaced with a trap stub.
1465
1466 /// Map of SYCL kernels indexed by the unique type used to name the kernel.
1467 /// Entries are not serialized but are recreated on deserialization of a
1468 /// sycl_kernel_entry_point attributed function declaration.
1469 llvm::DenseMap<CanQualType, SYCLKernelInfo> SYCLKernels;
1470
1471 /// For capturing lambdas with an explicit object parameter whose type is
1472 /// derived from the lambda type, we need to perform derived-to-base
1473 /// conversion so we can access the captures; the cast paths for that
1474 /// are stored here.
1475 llvm::DenseMap<const CXXMethodDecl *, CXXCastPath> LambdaCastPaths;
1476
1478 SelectorTable &sels, Builtin::Context &builtins,
1480 ASTContext(const ASTContext &) = delete;
1481 ASTContext &operator=(const ASTContext &) = delete;
1482 ~ASTContext();
1483
1484 /// Attach an external AST source to the AST context.
1485 ///
1486 /// The external AST source provides the ability to load parts of
1487 /// the abstract syntax tree as needed from some external storage,
1488 /// e.g., a precompiled header.
1490
1491 /// Retrieve a pointer to the external AST source associated
1492 /// with this AST context, if any.
1494 return ExternalSource.get();
1495 }
1496
1497 /// Retrieve a pointer to the external AST source associated
1498 /// with this AST context, if any. Returns as an IntrusiveRefCntPtr.
1502
1503 /// Attach an AST mutation listener to the AST context.
1504 ///
1505 /// The AST mutation listener provides the ability to track modifications to
1506 /// the abstract syntax tree entities committed after they were initially
1507 /// created.
1509 this->Listener = Listener;
1510 }
1511
1512 /// Retrieve a pointer to the AST mutation listener associated
1513 /// with this AST context, if any.
1515
1516 void PrintStats() const;
1517 const SmallVectorImpl<Type *>& getTypes() const { return Types; }
1518
1520 const IdentifierInfo *II) const;
1521
1522 /// Create a new implicit TU-level CXXRecordDecl or RecordDecl
1523 /// declaration.
1525 StringRef Name,
1526 RecordDecl::TagKind TK = RecordDecl::TagKind::Struct) const;
1527
1528 /// Create a new implicit TU-level typedef declaration.
1529 TypedefDecl *buildImplicitTypedef(QualType T, StringRef Name) const;
1530
1531 /// Retrieve the declaration for the 128-bit signed integer type.
1532 TypedefDecl *getInt128Decl() const;
1533
1534 /// Retrieve the declaration for the 128-bit unsigned integer type.
1535 TypedefDecl *getUInt128Decl() const;
1536
1537 //===--------------------------------------------------------------------===//
1538 // Type Constructors
1539 //===--------------------------------------------------------------------===//
1540
1541private:
1542 /// Return a type with extended qualifiers.
1543 QualType getExtQualType(const Type *Base, Qualifiers Quals) const;
1544
1545 QualType getPipeType(QualType T, bool ReadOnly) const;
1546
1547public:
1548 /// Return the uniqued reference to the type for an address space
1549 /// qualified type with the specified type and address space.
1550 ///
1551 /// The resulting type has a union of the qualifiers from T and the address
1552 /// space. If T already has an address space specifier, it is silently
1553 /// replaced.
1554 QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const;
1555
1556 /// Remove any existing address space on the type and returns the type
1557 /// with qualifiers intact (or that's the idea anyway)
1558 ///
1559 /// The return type should be T with all prior qualifiers minus the address
1560 /// space.
1562
1563 /// Return the "other" discriminator used for the pointer auth schema used for
1564 /// vtable pointers using the given discriminator type.
1566 bool IsVTTEntry);
1567
1568 /// Return the "other" type-specific discriminator for the given type.
1570
1571 /// Apply Objective-C protocol qualifiers to the given type.
1572 /// \param allowOnPointerType specifies if we can apply protocol
1573 /// qualifiers on ObjCObjectPointerType. It can be set to true when
1574 /// constructing the canonical type of a Objective-C type parameter.
1576 ArrayRef<ObjCProtocolDecl *> protocols, bool &hasError,
1577 bool allowOnPointerType = false) const;
1578
1579 /// Return the uniqued reference to the type for an Objective-C
1580 /// gc-qualified type.
1581 ///
1582 /// The resulting type has a union of the qualifiers from T and the gc
1583 /// attribute.
1585
1586 /// Remove the existing address space on the type if it is a pointer size
1587 /// address space and return the type with qualifiers intact.
1589
1590 /// Return the uniqued reference to the type for a \c restrict
1591 /// qualified type.
1592 ///
1593 /// The resulting type has a union of the qualifiers from \p T and
1594 /// \c restrict.
1596 return T.withFastQualifiers(Qualifiers::Restrict);
1597 }
1598
1599 /// Return the uniqued reference to the type for a \c volatile
1600 /// qualified type.
1601 ///
1602 /// The resulting type has a union of the qualifiers from \p T and
1603 /// \c volatile.
1605 return T.withFastQualifiers(Qualifiers::Volatile);
1606 }
1607
1608 /// Return the uniqued reference to the type for a \c const
1609 /// qualified type.
1610 ///
1611 /// The resulting type has a union of the qualifiers from \p T and \c const.
1612 ///
1613 /// It can be reasonably expected that this will always be equivalent to
1614 /// calling T.withConst().
1615 QualType getConstType(QualType T) const { return T.withConst(); }
1616
1617 /// Rebuild a type, preserving any existing type sugar. For function types,
1618 /// you probably want to just use \c adjustFunctionResultType and friends
1619 /// instead.
1621 llvm::function_ref<QualType(QualType)> Adjust) const;
1622
1623 /// Change the ExtInfo on a function type.
1625 FunctionType::ExtInfo EInfo);
1626
1627 /// Change the result type of a function type, preserving sugar such as
1628 /// attributed types.
1630 QualType NewResultType);
1631
1632 /// Adjust the given function result type.
1634
1635 /// Change the result type of a function type once it is deduced.
1637
1638 /// Get a function type and produce the equivalent function type with the
1639 /// specified exception specification. Type sugar that can be present on a
1640 /// declaration of a function with an exception specification is permitted
1641 /// and preserved. Other type sugar (for instance, typedefs) is not.
1643 QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI) const;
1644
1645 /// Determine whether two function types are the same, ignoring
1646 /// exception specifications in cases where they're part of the type.
1648
1649 /// Change the exception specification on a function once it is
1650 /// delay-parsed, instantiated, or computed.
1653 bool AsWritten = false);
1654
1655 /// Get a function type and produce the equivalent function type where
1656 /// pointer size address spaces in the return type and parameter types are
1657 /// replaced with the default address space.
1659
1660 /// Determine whether two function types are the same, ignoring pointer sizes
1661 /// in the return type and parameter types.
1663
1664 /// Get or construct a function type that is equivalent to the input type
1665 /// except that the parameter ABI annotations are stripped.
1667
1668 /// Determine if two function types are the same, ignoring parameter ABI
1669 /// annotations.
1671
1672 /// Return the uniqued reference to the type for a complex
1673 /// number with the specified element type.
1678
1679 /// Return the uniqued reference to the type for a pointer to
1680 /// the specified type.
1685
1686 QualType
1687 getCountAttributedType(QualType T, Expr *CountExpr, bool CountInBytes,
1688 bool OrNull,
1689 ArrayRef<TypeCoupledDeclRefInfo> DependentDecls) const;
1690
1691 /// Return a `CountAttributedType` whose count expression has not been parsed
1692 /// yet, for use by a late-parsed bounds attribute. The result is *not*
1693 /// uniqued, and must be completed with `completeCountAttributedType` once the
1694 /// argument becomes parseable. Returns the node rather than a `QualType` so
1695 /// the caller can retain it for completion.
1697 bool CountInBytes,
1698 bool OrNull) const;
1699
1700 /// Supply the count expression and coupled declarations for a type created by
1701 /// `getIncompleteCountAttributedType`. Enclosing types keep pointing at the
1702 /// same node, so nothing above it needs rebuilding.
1704 CountAttributedType *CATy, Expr *CountExpr,
1705 ArrayRef<TypeCoupledDeclRefInfo> DependentDecls) const;
1706
1707 /// Return a placeholder type for a late-parsed type attribute.
1708 /// This type wraps another type and holds the LateParsedAttribute
1709 /// that will be parsed later.
1711 LateParsedTypeAttribute *LateParsedAttr) const;
1712
1713 /// Return the uniqued reference to a type adjusted from the original
1714 /// type to a new type.
1720
1721 /// Return the uniqued reference to the decayed version of the given
1722 /// type. Can only be called on array and function types which decay to
1723 /// pointer types.
1728 /// Return the uniqued reference to a specified decay from the original
1729 /// type to the decayed type.
1730 QualType getDecayedType(QualType Orig, QualType Decayed) const;
1731
1732 /// Return the uniqued reference to a specified array parameter type from the
1733 /// original array type.
1735
1736 /// Return the uniqued reference to the atomic type for the specified
1737 /// type.
1739
1740 /// Return the uniqued reference to the type for a block of the
1741 /// specified type.
1743
1744 /// Gets the struct used to keep track of the descriptor for pointer to
1745 /// blocks.
1747
1748 /// Return a read_only pipe type for the specified type.
1750
1751 /// Return a write_only pipe type for the specified type.
1753
1754 /// Return a bit-precise integer type with the specified signedness and bit
1755 /// count.
1756 QualType getBitIntType(bool Unsigned, unsigned NumBits) const;
1757
1758 /// Return a dependent bit-precise integer type with the specified signedness
1759 /// and bit count.
1760 QualType getDependentBitIntType(bool Unsigned, Expr *BitsExpr) const;
1761
1763
1764 /// Gets the struct used to keep track of the extended descriptor for
1765 /// pointer to blocks.
1767
1768 /// Map an AST Type to an OpenCLTypeKind enum value.
1769 OpenCLTypeKind getOpenCLTypeKind(const Type *T) const;
1770
1771 /// Get address space for OpenCL type.
1772 LangAS getOpenCLTypeAddrSpace(const Type *T) const;
1773
1774 /// Returns default address space based on OpenCL version and enabled features
1776 return LangOpts.OpenCLGenericAddressSpace ? LangAS::opencl_generic
1778 }
1779
1781 cudaConfigureCallDecl = FD;
1782 }
1783
1785 return cudaConfigureCallDecl;
1786 }
1787
1789 cudaGetParameterBufferDecl = FD;
1790 }
1791
1793 return cudaGetParameterBufferDecl;
1794 }
1795
1796 void setcudaLaunchDeviceDecl(FunctionDecl *FD) { cudaLaunchDeviceDecl = FD; }
1797
1798 FunctionDecl *getcudaLaunchDeviceDecl() { return cudaLaunchDeviceDecl; }
1799
1800 /// Returns true iff we need copy/dispose helpers for the given type.
1801 bool BlockRequiresCopying(QualType Ty, const VarDecl *D);
1802
1803 /// Returns true, if given type has a known lifetime. HasByrefExtendedLayout
1804 /// is set to false in this case. If HasByrefExtendedLayout returns true,
1805 /// byref variable has extended lifetime.
1806 bool getByrefLifetime(QualType Ty,
1807 Qualifiers::ObjCLifetime &Lifetime,
1808 bool &HasByrefExtendedLayout) const;
1809
1810 /// Return the uniqued reference to the type for an lvalue reference
1811 /// to the specified type.
1812 QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true)
1813 const;
1814
1815 /// Return the uniqued reference to the type for an rvalue reference
1816 /// to the specified type.
1818
1819 /// Return the uniqued reference to the type for a member pointer to
1820 /// the specified type in the specified nested name.
1822 const CXXRecordDecl *Cls) const;
1823
1824 /// Return a non-unique reference to the type for a variable array of
1825 /// the specified element type.
1828 unsigned IndexTypeQuals) const;
1829
1830 /// Return a non-unique reference to the type for a dependently-sized
1831 /// array of the specified element type.
1832 ///
1833 /// FIXME: We will need these to be uniqued, or at least comparable, at some
1834 /// point.
1837 unsigned IndexTypeQuals) const;
1838
1839 /// Return a unique reference to the type for an incomplete array of
1840 /// the specified element type.
1842 unsigned IndexTypeQuals) const;
1843
1844 /// Return the unique reference to the type for a constant array of
1845 /// the specified element type.
1846 QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
1847 const Expr *SizeExpr, ArraySizeModifier ASM,
1848 unsigned IndexTypeQuals) const;
1849
1850 /// Return a type for a constant array for a string literal of the
1851 /// specified element type and length.
1852 QualType getStringLiteralArrayType(QualType EltTy, unsigned Length) const;
1853
1854 /// Returns a vla type where known sizes are replaced with [*].
1856
1857 // Convenience struct to return information about a builtin vector type.
1866
1867 /// Returns the element type, element count and number of vectors
1868 /// (in case of tuple) for a builtin vector type.
1869 BuiltinVectorTypeInfo
1870 getBuiltinVectorTypeInfo(const BuiltinType *VecTy) const;
1871
1872 /// Return the unique reference to a scalable vector type of the specified
1873 /// element type and scalable number of elements.
1874 /// For RISC-V, number of fields is also provided when it fetching for
1875 /// tuple type.
1876 ///
1877 /// \pre \p EltTy must be a built-in type.
1878 QualType getScalableVectorType(QualType EltTy, unsigned NumElts,
1879 unsigned NumFields = 1) const;
1880
1881 /// Return a WebAssembly externref type.
1883
1884 /// Return the unique reference to a vector type of the specified
1885 /// element type and size.
1886 ///
1887 /// \pre \p VectorType must be a built-in type.
1888 QualType getVectorType(QualType VectorType, unsigned NumElts,
1889 VectorKind VecKind) const;
1890 /// Return the unique reference to the type for a dependently sized vector of
1891 /// the specified element type.
1893 SourceLocation AttrLoc,
1894 VectorKind VecKind) const;
1895
1896 /// Return the unique reference to an extended vector type
1897 /// of the specified element type and size.
1898 ///
1899 /// \pre \p VectorType must be a built-in type.
1900 QualType getExtVectorType(QualType VectorType, unsigned NumElts) const;
1901
1902 /// \pre Return a non-unique reference to the type for a dependently-sized
1903 /// vector of the specified element type.
1904 ///
1905 /// FIXME: We will need these to be uniqued, or at least comparable, at some
1906 /// point.
1908 Expr *SizeExpr,
1909 SourceLocation AttrLoc) const;
1910
1911 /// Return the unique reference to the matrix type of the specified element
1912 /// type and size
1913 ///
1914 /// \pre \p ElementType must be a valid matrix element type (see
1915 /// MatrixType::isValidElementType).
1917 QualType ElementType, unsigned NumRows, unsigned NumColumns,
1918 std::optional<MatrixType::LayoutKind> Layout = std::nullopt) const;
1919
1920 /// Return the unique reference to the matrix type of the specified element
1921 /// type and size
1922 QualType getDependentSizedMatrixType(QualType ElementType, Expr *RowExpr,
1923 Expr *ColumnExpr,
1924 SourceLocation AttrLoc) const;
1925
1927 MatrixType::LayoutKind Layout) const;
1928
1930 Expr *AddrSpaceExpr,
1931 SourceLocation AttrLoc) const;
1932
1933 /// Return a K&R style C function type like 'int()'.
1935 const FunctionType::ExtInfo &Info) const;
1936
1940
1941 /// Return a normal function type with a typed argument list.
1943 const FunctionProtoType::ExtProtoInfo &EPI) const {
1944 return getFunctionTypeInternal(ResultTy, Args, EPI, false);
1945 }
1946
1948
1949 // Represents an inclusive-first/exclusive last bit-offset into a type.
1951 // [First, Last)
1952 uint64_t First;
1953 uint64_t Last;
1954 };
1955
1956 // Calculate and get the 'padding intervals' inside of a type. Note: calls to
1957 // this potentially invalidate all ArrayRef objects, so effort must be made to
1958 // copy the data if necessary.
1960
1961private:
1962 mutable llvm::DenseMap<QualType, llvm::SmallVector<BitInterval>>
1963 PaddingIntervalCache;
1964
1965 /// Return a normal function type with a typed argument list.
1966 QualType getFunctionTypeInternal(QualType ResultTy, ArrayRef<QualType> Args,
1968 bool OnlyWantCanonical) const;
1969
1970public:
1972 NestedNameSpecifier Qualifier,
1973 const TypeDecl *Decl) const;
1974
1975 /// Return the unique reference to the type for the specified type
1976 /// declaration.
1977 QualType getTypeDeclType(const TypeDecl *Decl) const;
1978
1979 /// Use the normal 'getFooBarType' constructors to obtain these types.
1980 QualType getTypeDeclType(const TagDecl *) const = delete;
1981 QualType getTypeDeclType(const TypedefDecl *) const = delete;
1982 QualType getTypeDeclType(const TypeAliasDecl *) const = delete;
1984
1986
1988 NestedNameSpecifier Qualifier, const UsingShadowDecl *D,
1989 QualType UnderlyingType = QualType()) const;
1990
1991 /// Return the unique reference to the type for the specified
1992 /// typedef-name decl.
1993 /// FIXME: TypeMatchesDeclOrNone is a workaround for a serialization issue:
1994 /// The decl underlying type might still not be available.
1997 const TypedefNameDecl *Decl, QualType UnderlyingType = QualType(),
1998 std::optional<bool> TypeMatchesDeclOrNone = std::nullopt) const;
1999
2000 CanQualType getCanonicalTagType(const TagDecl *TD) const;
2002 NestedNameSpecifier Qualifier, const TagDecl *TD,
2003 bool OwnsTag) const;
2004
2005private:
2006 UnresolvedUsingType *getUnresolvedUsingTypeInternal(
2008 const UnresolvedUsingTypenameDecl *D, llvm::FoldingSetInsertToken Token,
2009 const Type *CanonicalType) const;
2010
2011 TagType *getTagTypeInternal(ElaboratedTypeKeyword Keyword,
2012 NestedNameSpecifier Qualifier, const TagDecl *Tag,
2013 bool OwnsTag, bool IsInjected,
2014 const Type *CanonicalType,
2015 bool WithFoldingSetNode) const;
2016
2017public:
2018 /// Compute BestType and BestPromotionType for an enum based on the highest
2019 /// number of negative and positive bits of its elements.
2020 /// Returns true if enum width is too large.
2021 bool computeBestEnumTypes(bool IsPacked, unsigned NumNegativeBits,
2022 unsigned NumPositiveBits, QualType &BestType,
2023 QualType &BestPromotionType);
2024
2025 /// Determine whether the given integral value is representable within
2026 /// the given type T.
2027 bool isRepresentableIntegerValue(llvm::APSInt &Value, QualType T);
2028
2029 /// Compute NumNegativeBits and NumPositiveBits for an enum based on
2030 /// the constant values of its enumerators.
2031 template <typename RangeT>
2032 bool computeEnumBits(RangeT EnumConstants, unsigned &NumNegativeBits,
2033 unsigned &NumPositiveBits) {
2034 NumNegativeBits = 0;
2035 NumPositiveBits = 0;
2036 bool MembersRepresentableByInt = true;
2037 for (auto *Elem : EnumConstants) {
2038 EnumConstantDecl *ECD = cast_or_null<EnumConstantDecl>(Elem);
2039 if (!ECD)
2040 continue; // Already issued a diagnostic.
2041
2042 llvm::APSInt InitVal = ECD->getInitVal();
2043 if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
2044 // If the enumerator is zero that should still be counted as a positive
2045 // bit since we need a bit to store the value zero.
2046 unsigned ActiveBits = InitVal.getActiveBits();
2047 NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
2048 } else {
2049 NumNegativeBits =
2050 std::max(NumNegativeBits, InitVal.getSignificantBits());
2051 }
2052
2053 MembersRepresentableByInt &= isRepresentableIntegerValue(InitVal, IntTy);
2054 }
2055
2056 // If we have an empty set of enumerators we still need one bit.
2057 // From [dcl.enum]p8
2058 // If the enumerator-list is empty, the values of the enumeration are as if
2059 // the enumeration had a single enumerator with value 0
2060 if (!NumPositiveBits && !NumNegativeBits)
2061 NumPositiveBits = 1;
2062
2063 return MembersRepresentableByInt;
2064 }
2065
2069 NestedNameSpecifier Qualifier,
2070 const UnresolvedUsingTypenameDecl *D) const;
2071
2072 QualType getAttributedType(attr::Kind attrKind, QualType modifiedType,
2073 QualType equivalentType,
2074 const Attr *attr = nullptr) const;
2075
2076 QualType getAttributedType(const Attr *attr, QualType modifiedType,
2077 QualType equivalentType) const;
2078
2079 QualType getAttributedType(NullabilityKind nullability, QualType modifiedType,
2080 QualType equivalentType) const;
2081
2082 QualType getBTFTagAttributedType(const BTFTypeTagAttr *BTFAttr,
2083 QualType Wrapped) const;
2084
2085 QualType getOverflowBehaviorType(const OverflowBehaviorAttr *Attr,
2086 QualType Wrapped) const;
2087
2088 QualType
2089 getOverflowBehaviorType(OverflowBehaviorType::OverflowBehaviorKind Kind,
2090 QualType Wrapped) const;
2091
2093 QualType Wrapped, QualType Contained,
2094 const HLSLAttributedResourceType::Attributes &Attrs);
2095
2097 uint32_t Alignment,
2098 ArrayRef<SpirvOperand> Operands);
2099
2101 Decl *AssociatedDecl, unsigned Index,
2103 bool Final) const;
2105 unsigned Index, bool Final,
2106 const TemplateArgument &ArgPack);
2108
2109 QualType
2110 getTemplateTypeParmType(int Depth, int Index, bool ParameterPack,
2111 TemplateTypeParmDecl *ParmDecl = nullptr) const;
2112
2115 ArrayRef<TemplateArgument> CanonicalArgs) const;
2116
2117 QualType
2119 ArrayRef<TemplateArgument> SpecifiedArgs,
2120 ArrayRef<TemplateArgument> CanonicalArgs,
2121 QualType Underlying = QualType()) const;
2122
2123 QualType
2125 ArrayRef<TemplateArgumentLoc> SpecifiedArgs,
2126 ArrayRef<TemplateArgument> CanonicalArgs,
2127 QualType Canon = QualType()) const;
2128
2130 ElaboratedTypeKeyword Keyword, SourceLocation ElaboratedKeywordLoc,
2131 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKeywordLoc,
2133 const TemplateArgumentListInfo &SpecifiedArgs,
2134 ArrayRef<TemplateArgument> CanonicalArgs,
2135 QualType Canon = QualType()) const;
2136
2137 QualType getParenType(QualType NamedType) const;
2138
2140 const IdentifierInfo *MacroII) const;
2141
2144 const IdentifierInfo *Name) const;
2145
2147
2148 /// Form a pack expansion type with the given pattern.
2149 /// \param NumExpansions The number of expansions for the pack, if known.
2150 /// \param ExpectPackInType If \c false, we should not expect \p Pattern to
2151 /// contain an unexpanded pack. This only makes sense if the pack
2152 /// expansion is used in a context where the arity is inferred from
2153 /// elsewhere, such as if the pattern contains a placeholder type or
2154 /// if this is the canonical type of another pack expansion type.
2156 bool ExpectPackInType = true) const;
2157
2159 ObjCInterfaceDecl *PrevDecl = nullptr) const;
2160
2161 /// Legacy interface: cannot provide type arguments or __kindof.
2163 ObjCProtocolDecl * const *Protocols,
2164 unsigned NumProtocols) const;
2165
2167 ArrayRef<QualType> typeArgs,
2169 bool isKindOf) const;
2170
2172 ArrayRef<ObjCProtocolDecl *> protocols) const;
2174 ObjCTypeParamDecl *New) const;
2175
2177
2178 /// QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in
2179 /// QT's qualified-id protocol list adopt all protocols in IDecl's list
2180 /// of protocols.
2182 ObjCInterfaceDecl *IDecl);
2183
2184 /// Return a ObjCObjectPointerType type for the given ObjCObjectType.
2186
2187 /// C23 feature and GCC extension.
2188 QualType getTypeOfExprType(Expr *E, TypeOfKind Kind) const;
2189 QualType getTypeOfType(QualType QT, TypeOfKind Kind) const;
2190
2191 QualType getReferenceQualifiedType(const Expr *e) const;
2192
2193 /// C++11 decltype.
2194 QualType getDecltypeType(Expr *e, QualType UnderlyingType) const;
2195
2196 QualType getPackIndexingType(QualType Pattern, Expr *IndexExpr,
2197 bool FullySubstituted = false,
2198 ArrayRef<QualType> Expansions = {},
2199 UnsignedOrNone Index = std::nullopt) const;
2200
2201 /// Unary type transforms
2202 QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType,
2203 UnaryTransformType::UTTKind UKind) const;
2204
2205 /// C++11 deduced auto type.
2206 QualType
2207 getAutoType(DeducedKind DK, QualType DeducedAsType, AutoTypeKeyword Keyword,
2208 TemplateName TypeConstraintConcept = TemplateName(),
2209 ArrayRef<TemplateArgument> TypeConstraintArgs = {}) const;
2210
2211 /// C++11 deduction pattern for 'auto' type.
2212 QualType getAutoDeductType() const;
2213
2214 /// C++11 deduction pattern for 'auto &&' type.
2215 QualType getAutoRRefDeductType() const;
2216
2217 /// Remove any type constraints from a template parameter type, for
2218 /// equivalence comparison of template parameters.
2219 QualType getUnconstrainedType(QualType T) const;
2220
2221 /// C++17 deduced class template specialization type.
2223 QualType DeducedAsType,
2225 TemplateName Template) const;
2226
2227 /// Return the unique type for "size_t" (C99 7.17), defined in
2228 /// <stddef.h>.
2229 ///
2230 /// The sizeof operator requires this (C99 6.5.3.4p4).
2231 QualType getSizeType() const;
2232
2234
2235 /// Return the unique signed counterpart of
2236 /// the integer type corresponding to size_t.
2237 QualType getSignedSizeType() const;
2238
2239 /// Return the unique type for "intmax_t" (C99 7.18.1.5), defined in
2240 /// <stdint.h>.
2241 CanQualType getIntMaxType() const;
2242
2243 /// Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in
2244 /// <stdint.h>.
2246
2247 /// Return the unique wchar_t type available in C++ (and available as
2248 /// __wchar_t as a Microsoft extension).
2249 QualType getWCharType() const { return WCharTy; }
2250
2251 /// Return the type of wide characters. In C++, this returns the
2252 /// unique wchar_t type. In C99, this returns a type compatible with the type
2253 /// defined in <stddef.h> as defined by the target.
2255
2256 /// Return the type of "signed wchar_t".
2257 ///
2258 /// Used when in C++, as a GCC extension.
2260
2261 /// Return the type of "unsigned wchar_t".
2262 ///
2263 /// Used when in C++, as a GCC extension.
2265
2266 /// In C99, this returns a type compatible with the type
2267 /// defined in <stddef.h> as defined by the target.
2268 QualType getWIntType() const { return WIntTy; }
2269
2270 /// Return a type compatible with "intptr_t" (C99 7.18.1.4),
2271 /// as defined by the target.
2272 QualType getIntPtrType() const;
2273
2274 /// Return a type compatible with "uintptr_t" (C99 7.18.1.4),
2275 /// as defined by the target.
2276 QualType getUIntPtrType() const;
2277
2278 /// Return the unique type for "ptrdiff_t" (C99 7.17) defined in
2279 /// <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
2281
2282 /// Return the unique unsigned counterpart of "ptrdiff_t"
2283 /// integer type. The standard (C11 7.21.6.1p7) refers to this type
2284 /// in the definition of %tu format specifier.
2286
2287 /// Return the unique type for "pid_t" defined in
2288 /// <sys/types.h>. We need this to compute the correct type for vfork().
2289 QualType getProcessIDType() const;
2290
2291 /// Return the C structure type used to represent constant CFStrings.
2293
2294 /// Returns the C struct type for objc_super
2295 QualType getObjCSuperType() const;
2296 void setObjCSuperType(QualType ST) { ObjCSuperType = ST; }
2297
2298 /// Get the structure type used to representation CFStrings, or NULL
2299 /// if it hasn't yet been built.
2301 if (CFConstantStringTypeDecl)
2303 /*Qualifier=*/std::nullopt,
2304 CFConstantStringTypeDecl);
2305 return QualType();
2306 }
2310
2311 // This setter/getter represents the ObjC type for an NSConstantString.
2314 return ObjCConstantStringType;
2315 }
2316
2318 return ObjCNSStringType;
2319 }
2320
2322 ObjCNSStringType = T;
2323 }
2324
2325 /// Retrieve the type that \c id has been defined to, which may be
2326 /// different from the built-in \c id if \c id has been typedef'd.
2328 if (ObjCIdRedefinitionType.isNull())
2329 return getObjCIdType();
2330 return ObjCIdRedefinitionType;
2331 }
2332
2333 /// Set the user-written type that redefines \c id.
2335 ObjCIdRedefinitionType = RedefType;
2336 }
2337
2338 /// Retrieve the type that \c Class has been defined to, which may be
2339 /// different from the built-in \c Class if \c Class has been typedef'd.
2341 if (ObjCClassRedefinitionType.isNull())
2342 return getObjCClassType();
2343 return ObjCClassRedefinitionType;
2344 }
2345
2346 /// Set the user-written type that redefines 'SEL'.
2348 ObjCClassRedefinitionType = RedefType;
2349 }
2350
2351 /// Retrieve the type that 'SEL' has been defined to, which may be
2352 /// different from the built-in 'SEL' if 'SEL' has been typedef'd.
2354 if (ObjCSelRedefinitionType.isNull())
2355 return getObjCSelType();
2356 return ObjCSelRedefinitionType;
2357 }
2358
2359 /// Set the user-written type that redefines 'SEL'.
2361 ObjCSelRedefinitionType = RedefType;
2362 }
2363
2364 /// Retrieve the identifier 'NSObject'.
2366 if (!NSObjectName) {
2367 NSObjectName = &Idents.get("NSObject");
2368 }
2369
2370 return NSObjectName;
2371 }
2372
2373 /// Retrieve the identifier 'NSCopying'.
2375 if (!NSCopyingName) {
2376 NSCopyingName = &Idents.get("NSCopying");
2377 }
2378
2379 return NSCopyingName;
2380 }
2381
2383
2385
2386 /// Retrieve the identifier 'bool'.
2388 if (!BoolName)
2389 BoolName = &Idents.get("bool");
2390 return BoolName;
2391 }
2392
2393#define BuiltinTemplate(BTName) \
2394 IdentifierInfo *get##BTName##Name() const { \
2395 if (!Name##BTName) \
2396 Name##BTName = &Idents.get(#BTName); \
2397 return Name##BTName; \
2398 }
2399#include "clang/Basic/BuiltinTemplates.inc"
2400
2401 /// Retrieve the Objective-C "instancetype" type.
2404 /*Qualifier=*/std::nullopt,
2406 }
2407
2408 /// Retrieve the typedef declaration corresponding to the Objective-C
2409 /// "instancetype" type.
2411
2412 /// Set the type for the C FILE type.
2413 void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
2414
2415 /// Retrieve the C FILE type.
2417 if (FILEDecl)
2419 /*Qualifier=*/std::nullopt, FILEDecl);
2420 return QualType();
2421 }
2422
2423 /// Set the type for the C jmp_buf type.
2424 void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
2425 this->jmp_bufDecl = jmp_bufDecl;
2426 }
2427
2428 /// Retrieve the C jmp_buf type.
2430 if (jmp_bufDecl)
2432 /*Qualifier=*/std::nullopt, jmp_bufDecl);
2433 return QualType();
2434 }
2435
2436 /// Set the type for the C sigjmp_buf type.
2437 void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
2438 this->sigjmp_bufDecl = sigjmp_bufDecl;
2439 }
2440
2441 /// Retrieve the C sigjmp_buf type.
2443 if (sigjmp_bufDecl)
2445 /*Qualifier=*/std::nullopt, sigjmp_bufDecl);
2446 return QualType();
2447 }
2448
2449 /// Set the type for the C ucontext_t type.
2450 void setucontext_tDecl(TypeDecl *ucontext_tDecl) {
2451 this->ucontext_tDecl = ucontext_tDecl;
2452 }
2453
2454 /// Retrieve the C ucontext_t type.
2456 if (ucontext_tDecl)
2458 /*Qualifier=*/std::nullopt, ucontext_tDecl);
2459 return QualType();
2460 }
2461
2462 /// The result type of logical operations, '<', '>', '!=', etc.
2464 return getLangOpts().CPlusPlus ? BoolTy : IntTy;
2465 }
2466
2467 /// Emit the Objective-CC type encoding for the given type \p T into
2468 /// \p S.
2469 ///
2470 /// If \p Field is specified then record field names are also encoded.
2471 void getObjCEncodingForType(QualType T, std::string &S,
2472 const FieldDecl *Field=nullptr,
2473 QualType *NotEncodedT=nullptr) const;
2474
2475 /// Emit the Objective-C property type encoding for the given
2476 /// type \p T into \p S.
2477 void getObjCEncodingForPropertyType(QualType T, std::string &S) const;
2478
2480
2481 /// Put the string version of the type qualifiers \p QT into \p S.
2483 std::string &S) const;
2484
2485 /// Emit the encoded type for the function \p Decl into \p S.
2486 ///
2487 /// This is in the same format as Objective-C method encodings.
2488 ///
2489 /// \returns true if an error occurred (e.g., because one of the parameter
2490 /// types is incomplete), false otherwise.
2491 std::string getObjCEncodingForFunctionDecl(const FunctionDecl *Decl) const;
2492
2493 /// Emit the encoded type for the method declaration \p Decl into
2494 /// \p S.
2496 bool Extended = false) const;
2497
2498 /// Return the encoded type for this block declaration.
2499 std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const;
2500
2501 /// getObjCEncodingForPropertyDecl - Return the encoded type for
2502 /// this method declaration. If non-NULL, Container must be either
2503 /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
2504 /// only be NULL when getting encodings for protocol properties.
2506 const Decl *Container) const;
2507
2509 ObjCProtocolDecl *rProto) const;
2510
2512 const ObjCPropertyDecl *PD,
2513 const Decl *Container) const;
2514
2515 /// Return the size of type \p T for Objective-C encoding purpose,
2516 /// in characters.
2518
2519 /// Retrieve the typedef corresponding to the predefined \c id type
2520 /// in Objective-C.
2521 TypedefDecl *getObjCIdDecl() const;
2522
2523 /// Represents the Objective-CC \c id type.
2524 ///
2525 /// This is set up lazily, by Sema. \c id is always a (typedef for a)
2526 /// pointer type, a pointer to a struct.
2529 /*Qualifier=*/std::nullopt, getObjCIdDecl());
2530 }
2531
2532 /// Retrieve the typedef corresponding to the predefined 'SEL' type
2533 /// in Objective-C.
2534 TypedefDecl *getObjCSelDecl() const;
2535
2536 /// Retrieve the type that corresponds to the predefined Objective-C
2537 /// 'SEL' type.
2540 /*Qualifier=*/std::nullopt, getObjCSelDecl());
2541 }
2542
2544
2545 /// Retrieve the typedef declaration corresponding to the predefined
2546 /// Objective-C 'Class' type.
2548
2549 /// Represents the Objective-C \c Class type.
2550 ///
2551 /// This is set up lazily, by Sema. \c Class is always a (typedef for a)
2552 /// pointer type, a pointer to a struct.
2555 /*Qualifier=*/std::nullopt, getObjCClassDecl());
2556 }
2557
2558 /// Retrieve the Objective-C class declaration corresponding to
2559 /// the predefined \c Protocol class.
2561
2562 /// Retrieve declaration of 'BOOL' typedef
2564 return BOOLDecl;
2565 }
2566
2567 /// Save declaration of 'BOOL' typedef
2569 BOOLDecl = TD;
2570 }
2571
2572 /// type of 'BOOL' type.
2575 /*Qualifier=*/std::nullopt, getBOOLDecl());
2576 }
2577
2578 /// Retrieve the type of the Objective-C \c Protocol class.
2582
2583 /// Retrieve the C type declaration corresponding to the predefined
2584 /// \c __builtin_va_list type.
2586
2587 /// Retrieve the type of the \c __builtin_va_list type.
2590 /*Qualifier=*/std::nullopt, getBuiltinVaListDecl());
2591 }
2592
2593 /// Retrieve the C type declaration corresponding to the predefined
2594 /// \c __va_list_tag type used to help define the \c __builtin_va_list type
2595 /// for some targets.
2596 Decl *getVaListTagDecl() const;
2597
2598 /// Retrieve the C type declaration corresponding to the predefined
2599 /// \c __builtin_ms_va_list type.
2601
2602 /// Retrieve the type of the \c __builtin_ms_va_list type.
2605 /*Qualifier=*/std::nullopt, getBuiltinMSVaListDecl());
2606 }
2607
2608 /// Retrieve the implicitly-predeclared 'struct _GUID' declaration.
2610
2611 /// Retrieve the implicitly-predeclared 'struct _GUID' type.
2613 assert(MSGuidTagDecl && "asked for GUID type but MS extensions disabled");
2615 }
2616
2617 /// Retrieve the implicitly-predeclared 'struct type_info' declaration.
2619 // Lazily create this type on demand - it's only needed for MS builds.
2620 if (!MSTypeInfoTagDecl)
2622 return MSTypeInfoTagDecl;
2623 }
2624
2625 /// Retrieve the C type declaration corresponding to the predefined
2626 /// \c __builtin_zos_va_list type.
2628
2629 /// Retrieve the type of the \c __builtin_zos_va_list type.
2632 /*Qualifier=*/std::nullopt,
2634 }
2635
2636 /// Return whether a declaration to a builtin is allowed to be
2637 /// overloaded/redeclared.
2638 bool canBuiltinBeRedeclared(const FunctionDecl *) const;
2639
2640 /// Return a type with additional \c const, \c volatile, or
2641 /// \c restrict qualifiers.
2644 }
2645
2646 /// Un-split a SplitQualType.
2648 return getQualifiedType(split.Ty, split.Quals);
2649 }
2650
2651 /// Return a type with additional qualifiers.
2653 if (!Qs.hasNonFastQualifiers())
2654 return T.withFastQualifiers(Qs.getFastQualifiers());
2655 QualifierCollector Qc(Qs);
2656 const Type *Ptr = Qc.strip(T);
2657 return getExtQualType(Ptr, Qc);
2658 }
2659
2660 /// Return a type with additional qualifiers.
2662 if (!Qs.hasNonFastQualifiers())
2663 return QualType(T, Qs.getFastQualifiers());
2664 return getExtQualType(T, Qs);
2665 }
2666
2667 /// Return a type with the given lifetime qualifier.
2668 ///
2669 /// \pre Neither type.ObjCLifetime() nor \p lifetime may be \c OCL_None.
2671 Qualifiers::ObjCLifetime lifetime) {
2672 assert(type.getObjCLifetime() == Qualifiers::OCL_None);
2673 assert(lifetime != Qualifiers::OCL_None);
2674
2675 Qualifiers qs;
2676 qs.addObjCLifetime(lifetime);
2677 return getQualifiedType(type, qs);
2678 }
2679
2680 /// getUnqualifiedObjCPointerType - Returns version of
2681 /// Objective-C pointer type with lifetime qualifier removed.
2683 if (!type.getTypePtr()->isObjCObjectPointerType() ||
2684 !type.getQualifiers().hasObjCLifetime())
2685 return type;
2686 Qualifiers Qs = type.getQualifiers();
2687 Qs.removeObjCLifetime();
2688 return getQualifiedType(type.getUnqualifiedType(), Qs);
2689 }
2690
2691 /// \brief Return a type with the given __ptrauth qualifier.
2693 assert(!Ty.getPointerAuth());
2694 assert(PointerAuth);
2695
2696 Qualifiers Qs;
2697 Qs.setPointerAuth(PointerAuth);
2698 return getQualifiedType(Ty, Qs);
2699 }
2700
2701 unsigned char getFixedPointScale(QualType Ty) const;
2702 unsigned char getFixedPointIBits(QualType Ty) const;
2703 llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const;
2704 llvm::APFixedPoint getFixedPointMax(QualType Ty) const;
2705 llvm::APFixedPoint getFixedPointMin(QualType Ty) const;
2706
2708 SourceLocation NameLoc) const;
2709
2711 UnresolvedSetIterator End) const;
2713
2715 bool TemplateKeyword,
2716 TemplateName Template) const;
2719
2721 Decl *AssociatedDecl,
2722 unsigned Index,
2724 bool Final) const;
2726 Decl *AssociatedDecl,
2727 unsigned Index,
2728 bool Final) const;
2729
2731 getPackIndexingTemplateName(TemplateName Pattern, Expr *IndexExpr,
2732 bool FullySubstituted = false,
2733 ArrayRef<TemplateName> Expansions = {}) const;
2734
2735 /// Represents a TemplateName which had some of its default arguments
2736 /// deduced. This both represents this default argument deduction as sugar,
2737 /// and provides the support for it's equivalences through canonicalization.
2738 /// For example DeducedTemplateNames which have the same set of default
2739 /// arguments are equivalent, and are also equivalent to the underlying
2740 /// template when the deduced template arguments are the same.
2742 DefaultArguments DefaultArgs) const;
2743
2745 /// No error
2747
2748 /// Missing a type
2750
2751 /// Missing a type from <stdio.h>
2753
2754 /// Missing a type from <setjmp.h>
2756
2757 /// Missing a type from <ucontext.h>
2759 };
2760
2761 QualType DecodeTypeStr(const char *&Str, const ASTContext &Context,
2763 bool &RequireICE, bool AllowTypeModifiers) const;
2764
2765 /// Return the type for the specified builtin.
2766 ///
2767 /// If \p IntegerConstantArgs is non-null, it is filled in with a bitmask of
2768 /// arguments to the builtin that are required to be integer constant
2769 /// expressions.
2771 unsigned *IntegerConstantArgs = nullptr) const;
2772
2773 /// Types and expressions required to build C++2a three-way comparisons
2774 /// using operator<=>, including the values return by builtin <=> operators.
2776
2777private:
2778 CanQualType getFromTargetType(unsigned Type) const;
2779 TypeInfo getTypeInfoImpl(const Type *T) const;
2780
2781 //===--------------------------------------------------------------------===//
2782 // Type Predicates.
2783 //===--------------------------------------------------------------------===//
2784
2785public:
2786 /// Return one of the GCNone, Weak or Strong Objective-C garbage
2787 /// collection attributes.
2789
2790 /// Return true if the given vector types are of the same unqualified
2791 /// type or if they are equivalent to the same GCC vector type.
2792 ///
2793 /// \note This ignores whether they are target-specific (AltiVec or Neon)
2794 /// types.
2795 bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
2796
2797 /// Return true if two OverflowBehaviorTypes are compatible for assignment.
2798 /// This checks both the underlying type compatibility and the overflow
2799 /// behavior kind (trap vs wrap).
2801
2802 enum class OBTAssignResult {
2803 Compatible, // No OBT issues
2804 IncompatibleKinds, // __ob_trap vs __ob_wrap (error)
2805 Discards, // OBT -> non-OBT on integer types (warning)
2806 NotApplicable // Not both integers, fall through to normal checking
2807 };
2808
2809 /// Check overflow behavior type compatibility for assignments.
2810 /// Returns detailed information about OBT compatibility for assignment
2811 /// checking.
2813
2814 /// Return true if the given types are an RISC-V vector builtin type and a
2815 /// VectorType that is a fixed-length representation of the RISC-V vector
2816 /// builtin type for a specific vector-length.
2817 bool areCompatibleRVVTypes(QualType FirstType, QualType SecondType);
2818
2819 /// Return true if the given vector types are lax-compatible RISC-V vector
2820 /// types as defined by -flax-vector-conversions=, which permits implicit
2821 /// conversions between vectors with different number of elements and/or
2822 /// incompatible element types, false otherwise.
2823 bool areLaxCompatibleRVVTypes(QualType FirstType, QualType SecondType);
2824
2825 /// Return true if the type has been explicitly qualified with ObjC ownership.
2826 /// A type may be implicitly qualified with ownership under ObjC ARC, and in
2827 /// some cases the compiler treats these differently.
2829
2830 /// Return true if this is an \c NSObject object with its \c NSObject
2831 /// attribute set.
2833 return Ty->isObjCNSObjectType();
2834 }
2835
2836 //===--------------------------------------------------------------------===//
2837 // Type Sizing and Analysis
2838 //===--------------------------------------------------------------------===//
2839
2840 /// Return the APFloat 'semantics' for the specified scalar floating
2841 /// point type.
2842 const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
2843
2844 /// Get the size and alignment of the specified complete type in bits.
2845 TypeInfo getTypeInfo(const Type *T) const;
2846 TypeInfo getTypeInfo(QualType T) const { return getTypeInfo(T.getTypePtr()); }
2847
2848 /// Get default simd alignment of the specified complete type in bits.
2849 unsigned getOpenMPDefaultSimdAlign(QualType T) const;
2850
2851 /// Return the size of the specified (complete) type \p T, in bits.
2852 uint64_t getTypeSize(QualType T) const { return getTypeInfo(T).Width; }
2853 uint64_t getTypeSize(const Type *T) const { return getTypeInfo(T).Width; }
2854
2855 /// Return the size of the character type, in bits.
2856 uint64_t getCharWidth() const {
2857 return getTypeSize(CharTy);
2858 }
2859
2860 /// Convert a size in bits to a size in characters.
2861 CharUnits toCharUnitsFromBits(int64_t BitSize) const;
2862
2863 /// Convert a size in characters to a size in bits.
2864 int64_t toBits(CharUnits CharSize) const;
2865
2866 /// Return the size of the specified (complete) type \p T, in
2867 /// characters.
2869 CharUnits getTypeSizeInChars(const Type *T) const;
2870
2871 std::optional<CharUnits> getTypeSizeInCharsIfKnown(QualType Ty) const {
2872 if (Ty->isIncompleteType() || Ty->isDependentType() ||
2873 Ty->isUndeducedType() || Ty->isSizelessType())
2874 return std::nullopt;
2875 return getTypeSizeInChars(Ty);
2876 }
2877
2878 std::optional<CharUnits> getTypeSizeInCharsIfKnown(const Type *Ty) const {
2879 return getTypeSizeInCharsIfKnown(QualType(Ty, 0));
2880 }
2881
2882 /// Return the ABI-specified alignment of a (complete) type \p T, in
2883 /// bits.
2884 unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; }
2885 unsigned getTypeAlign(const Type *T) const { return getTypeInfo(T).Align; }
2886
2887 /// Return the ABI-specified natural alignment of a (complete) type \p T,
2888 /// before alignment adjustments, in bits.
2889 ///
2890 /// This alignment is currently used only by ARM and AArch64 when passing
2891 /// arguments of a composite type.
2893 return getTypeUnadjustedAlign(T.getTypePtr());
2894 }
2895 unsigned getTypeUnadjustedAlign(const Type *T) const;
2896
2897 /// Return the alignment of a type, in bits, or 0 if
2898 /// the type is incomplete and we cannot determine the alignment (for
2899 /// example, from alignment attributes). The returned alignment is the
2900 /// Preferred alignment if NeedsPreferredAlignment is true, otherwise is the
2901 /// ABI alignment.
2903 bool NeedsPreferredAlignment = false) const;
2904
2905 /// Return the ABI-specified alignment of a (complete) type \p T, in
2906 /// characters.
2908 CharUnits getTypeAlignInChars(const Type *T) const;
2909
2910 /// Return the PreferredAlignment of a (complete) type \p T, in
2911 /// characters.
2915
2916 /// getTypeUnadjustedAlignInChars - Return the ABI-specified alignment of a type,
2917 /// in characters, before alignment adjustments. This method does not work on
2918 /// incomplete types.
2921
2922 // getTypeInfoDataSizeInChars - Return the size of a type, in chars. If the
2923 // type is a record, its data size is returned.
2925
2926 TypeInfoChars getTypeInfoInChars(const Type *T) const;
2928
2929 /// Determine if the alignment the type has was required using an
2930 /// alignment attribute.
2931 bool isAlignmentRequired(const Type *T) const;
2932 bool isAlignmentRequired(QualType T) const;
2933
2934 /// More type predicates useful for type checking/promotion
2935 bool isPromotableIntegerType(QualType T) const; // C99 6.3.1.1p2
2936
2937 /// Return the "preferred" alignment of the specified type \p T for
2938 /// the current target, in bits.
2939 ///
2940 /// This can be different than the ABI alignment in cases where it is
2941 /// beneficial for performance or backwards compatibility preserving to
2942 /// overalign a data type. (Note: despite the name, the preferred alignment
2943 /// is ABI-impacting, and not an optimization.)
2945 return getPreferredTypeAlign(T.getTypePtr());
2946 }
2947 unsigned getPreferredTypeAlign(const Type *T) const;
2948
2949 /// Return the default alignment for __attribute__((aligned)) on
2950 /// this target, to be used if no alignment value is specified.
2952
2953 /// Return the alignment in bits that should be given to a
2954 /// global variable with type \p T. If \p VD is non-null it will be
2955 /// considered specifically for the query.
2956 unsigned getAlignOfGlobalVar(QualType T, const VarDecl *VD) const;
2957
2958 /// Return the alignment in characters that should be given to a
2959 /// global variable with type \p T. If \p VD is non-null it will be
2960 /// considered specifically for the query.
2962
2963 /// Return the minimum alignment as specified by the target. If \p VD is
2964 /// non-null it may be used to identify external or weak variables.
2965 unsigned getMinGlobalAlignOfVar(uint64_t Size, const VarDecl *VD) const;
2966
2967 /// Return a conservative estimate of the alignment of the specified
2968 /// decl \p D.
2969 ///
2970 /// \pre \p D must not be a bitfield type, as bitfields do not have a valid
2971 /// alignment.
2972 ///
2973 /// If \p ForAlignof, references are treated like their underlying type
2974 /// and large arrays don't get any special treatment. If not \p ForAlignof
2975 /// it computes the value expected by CodeGen: references are treated like
2976 /// pointers and large arrays get extra alignment.
2977 CharUnits getDeclAlign(const Decl *D, bool ForAlignof = false) const;
2978
2979 /// Return the alignment (in bytes) of the thrown exception object. This is
2980 /// only meaningful for targets that allocate C++ exceptions in a system
2981 /// runtime, such as those using the Itanium C++ ABI.
2983
2984 /// Return whether unannotated records are treated as if they have
2985 /// [[gnu::ms_struct]].
2986 bool defaultsToMsStruct() const;
2987
2988 /// Whether layout (offset and size) information can be queried for \p D.
2989 static bool hasLayout(const RecordDecl *D) {
2990 D = D->getDefinition();
2991 return D && !D->isInvalidDecl() && D->isCompleteDefinition();
2992 }
2993
2994 /// Get or compute information about the layout of the specified
2995 /// record (struct/union/class) \p D, which indicates its size and field
2996 /// position information.
2997 /// \pre hasLayout(D)
2998 const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const;
2999
3000 /// Get or compute information about the layout of the specified
3001 /// Objective-C interface.
3003 const;
3004
3005 void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS,
3006 bool Simple = false) const;
3007
3008 /// Get our current best idea for the key function of the
3009 /// given record decl, or nullptr if there isn't one.
3010 ///
3011 /// The key function is, according to the Itanium C++ ABI section 5.2.3:
3012 /// ...the first non-pure virtual function that is not inline at the
3013 /// point of class definition.
3014 ///
3015 /// Other ABIs use the same idea. However, the ARM C++ ABI ignores
3016 /// virtual functions that are defined 'inline', which means that
3017 /// the result of this computation can change.
3019
3020 /// Observe that the given method cannot be a key function.
3021 /// Checks the key-function cache for the method's class and clears it
3022 /// if matches the given declaration.
3023 ///
3024 /// This is used in ABIs where out-of-line definitions marked
3025 /// inline are not considered to be key functions.
3026 ///
3027 /// \param method should be the declaration from the class definition
3028 void setNonKeyFunction(const CXXMethodDecl *method);
3029
3030 /// Loading virtual member pointers using the virtual inheritance model
3031 /// always results in an adjustment using the vbtable even if the index is
3032 /// zero.
3033 ///
3034 /// This is usually OK because the first slot in the vbtable points
3035 /// backwards to the top of the MDC. However, the MDC might be reusing a
3036 /// vbptr from an nv-base. In this case, the first slot in the vbtable
3037 /// points to the start of the nv-base which introduced the vbptr and *not*
3038 /// the MDC. Modify the NonVirtualBaseAdjustment to account for this.
3040
3041 /// Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
3042 uint64_t getFieldOffset(const ValueDecl *FD) const;
3043
3044 /// Get the offset of an ObjCIvarDecl in bits.
3045 uint64_t lookupFieldBitOffset(const ObjCInterfaceDecl *OID,
3046 const ObjCIvarDecl *Ivar) const;
3047
3048 /// Find the 'this' offset for the member path in a pointer-to-member
3049 /// APValue.
3051
3052 bool isNearlyEmpty(const CXXRecordDecl *RD) const;
3053
3055
3056 /// If \p T is null pointer, assume the target in ASTContext.
3057 MangleContext *createMangleContext(const TargetInfo *T = nullptr);
3058
3059 /// Creates a device mangle context to correctly mangle lambdas in a mixed
3060 /// architecture compile by setting the lambda mangling number source to the
3061 /// DeviceLambdaManglingNumber. Currently this asserts that the TargetInfo
3062 /// (from the AuxTargetInfo) is a an itanium target.
3064
3066
3067 void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass,
3069
3070 unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const;
3071 void CollectInheritedProtocols(const Decl *CDecl,
3073
3074 /// Return true if the specified type has unique object representations
3075 /// according to (C++17 [meta.unary.prop]p9)
3076 bool
3078 bool CheckIfTriviallyCopyable = true) const;
3079
3080 //===--------------------------------------------------------------------===//
3081 // Type Operators
3082 //===--------------------------------------------------------------------===//
3083
3084 /// Return the canonical (structural) type corresponding to the
3085 /// specified potentially non-canonical type \p T.
3086 ///
3087 /// The non-canonical version of a type may have many "decorated" versions of
3088 /// types. Decorators can include typedefs, 'typeof' operators, etc. The
3089 /// returned type is guaranteed to be free of any of these, allowing two
3090 /// canonical types to be compared for exact equality with a simple pointer
3091 /// comparison.
3093 return CanQualType::CreateUnsafe(T.getCanonicalType());
3094 }
3095
3096 static const Type *getCanonicalType(const Type *T) {
3097 return T->getCanonicalTypeInternal().getTypePtr();
3098 }
3099
3100 /// Return the canonical parameter type corresponding to the specific
3101 /// potentially non-canonical one.
3102 ///
3103 /// Qualifiers are stripped off, functions are turned into function
3104 /// pointers, and arrays decay one level into pointers.
3106
3107 /// Determine whether the given types \p T1 and \p T2 are equivalent.
3108 static bool hasSameType(QualType T1, QualType T2) {
3109 return getCanonicalType(T1) == getCanonicalType(T2);
3110 }
3111 static bool hasSameType(const Type *T1, const Type *T2) {
3112 return getCanonicalType(T1) == getCanonicalType(T2);
3113 }
3114
3115 /// Determine whether the given expressions \p X and \p Y are equivalent.
3116 bool hasSameExpr(const Expr *X, const Expr *Y) const;
3117
3118 /// Return this type as a completely-unqualified array type,
3119 /// capturing the qualifiers in \p Quals.
3120 ///
3121 /// This will remove the minimal amount of sugaring from the types, similar
3122 /// to the behavior of QualType::getUnqualifiedType().
3123 ///
3124 /// \param T is the qualified type, which may be an ArrayType
3125 ///
3126 /// \param Quals will receive the full set of qualifiers that were
3127 /// applied to the array.
3128 ///
3129 /// \returns if this is an array type, the completely unqualified array type
3130 /// that corresponds to it. Otherwise, returns T.getUnqualifiedType().
3133 Qualifiers Quals;
3134 return getUnqualifiedArrayType(T, Quals);
3135 }
3136
3137 /// Determine whether the given types are equivalent after
3138 /// cvr-qualifiers have been removed.
3140 return getCanonicalType(T1).getTypePtr() ==
3142 }
3143
3145 bool IsParam) const {
3146 auto SubTnullability = SubT->getNullability();
3147 auto SuperTnullability = SuperT->getNullability();
3148 if (SubTnullability.has_value() == SuperTnullability.has_value()) {
3149 // Neither has nullability; return true
3150 if (!SubTnullability)
3151 return true;
3152 // Both have nullability qualifier.
3153 if (*SubTnullability == *SuperTnullability ||
3154 *SubTnullability == NullabilityKind::Unspecified ||
3155 *SuperTnullability == NullabilityKind::Unspecified)
3156 return true;
3157
3158 if (IsParam) {
3159 // Ok for the superclass method parameter to be "nonnull" and the subclass
3160 // method parameter to be "nullable"
3161 return (*SuperTnullability == NullabilityKind::NonNull &&
3162 *SubTnullability == NullabilityKind::Nullable);
3163 }
3164 // For the return type, it's okay for the superclass method to specify
3165 // "nullable" and the subclass method specify "nonnull"
3166 return (*SuperTnullability == NullabilityKind::Nullable &&
3167 *SubTnullability == NullabilityKind::NonNull);
3168 }
3169 return true;
3170 }
3171
3172 bool ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl,
3173 const ObjCMethodDecl *MethodImp);
3174
3175 bool UnwrapSimilarTypes(QualType &T1, QualType &T2,
3176 bool AllowPiMismatch = true) const;
3178 bool AllowPiMismatch = true) const;
3179
3180 /// Determine if two types are similar, according to the C++ rules. That is,
3181 /// determine if they are the same other than qualifiers on the initial
3182 /// sequence of pointer / pointer-to-member / array (and in Clang, object
3183 /// pointer) types and their element types.
3184 ///
3185 /// Clang offers a number of qualifiers in addition to the C++ qualifiers;
3186 /// those qualifiers are also ignored in the 'similarity' check.
3187 bool hasSimilarType(QualType T1, QualType T2) const;
3188
3189 /// Determine if two types are similar, ignoring only CVR qualifiers.
3190 bool hasCvrSimilarType(QualType T1, QualType T2);
3191
3192 /// Retrieves the default calling convention for the current context.
3193 ///
3194 /// The context's default calling convention may differ from the current
3195 /// target's default calling convention if the -fdefault-calling-conv option
3196 /// is used; to get the target's default calling convention, e.g. for built-in
3197 /// functions, call getTargetInfo().getDefaultCallingConv() instead.
3199 bool IsCXXMethod) const;
3200
3201 /// Retrieves the "canonical" template name that refers to a
3202 /// given template.
3203 ///
3204 /// The canonical template name is the simplest expression that can
3205 /// be used to refer to a given template. For most templates, this
3206 /// expression is just the template declaration itself. For example,
3207 /// the template std::vector can be referred to via a variety of
3208 /// names---std::vector, \::std::vector, vector (if vector is in
3209 /// scope), etc.---but all of these names map down to the same
3210 /// TemplateDecl, which is used to form the canonical template name.
3211 ///
3212 /// Dependent template names are more interesting. Here, the
3213 /// template name could be something like T::template apply or
3214 /// std::allocator<T>::template rebind, where the nested name
3215 /// specifier itself is dependent. In this case, the canonical
3216 /// template name uses the shortest form of the dependent
3217 /// nested-name-specifier, which itself contains all canonical
3218 /// types, values, and templates.
3220 bool IgnoreDeduced = false) const;
3221
3222 /// Return the default argument of a template parameter, if one exists.
3223 const TemplateArgument *
3225
3226 /// Determine whether the given template names refer to the same
3227 /// template.
3228 bool hasSameTemplateName(const TemplateName &X, const TemplateName &Y,
3229 bool IgnoreDeduced = false) const;
3230
3231 /// Determine whether the two declarations refer to the same entity.
3232 bool isSameEntity(const NamedDecl *X, const NamedDecl *Y) const;
3233
3234 /// Determine whether two template parameter lists are similar enough
3235 /// that they may be used in declarations of the same template.
3237 const TemplateParameterList *Y) const;
3238
3239 /// Determine whether two template parameters are similar enough
3240 /// that they may be used in declarations of the same template.
3241 bool isSameTemplateParameter(const NamedDecl *X, const NamedDecl *Y) const;
3242
3243 /// Determine whether two 'requires' expressions are similar enough that they
3244 /// may be used in re-declarations.
3245 ///
3246 /// Use of 'requires' isn't mandatory, works with constraints expressed in
3247 /// other ways too.
3249 const AssociatedConstraint &ACY) const;
3250
3251 /// Determine whether two 'requires' expressions are similar enough that they
3252 /// may be used in re-declarations.
3253 ///
3254 /// Use of 'requires' isn't mandatory, works with constraints expressed in
3255 /// other ways too.
3256 bool isSameConstraintExpr(const Expr *XCE, const Expr *YCE) const;
3257
3258 /// Determine whether two type contraint are similar enough that they could
3259 /// used in declarations of the same template.
3260 bool isSameTypeConstraint(const TypeConstraint *XTC,
3261 const TypeConstraint *YTC) const;
3262
3263 /// Determine whether two default template arguments are similar enough
3264 /// that they may be used in declarations of the same template.
3266 const NamedDecl *Y) const;
3267
3268 /// Retrieve the "canonical" template argument.
3269 ///
3270 /// The canonical template argument is the simplest template argument
3271 /// (which may be a type, value, expression, or declaration) that
3272 /// expresses the value of the argument.
3274 const;
3275
3276 /// Canonicalize the given template argument list.
3277 ///
3278 /// Returns true if any arguments were non-canonical, false otherwise.
3279 bool
3281
3282 /// Canonicalize the given TemplateTemplateParmDecl.
3285
3287 TemplateTemplateParmDecl *TTP) const;
3289 TemplateTemplateParmDecl *CanonTTP) const;
3290
3291 /// Determine whether the given template arguments \p Arg1 and \p Arg2 are
3292 /// equivalent.
3294 const TemplateArgument &Arg2) const;
3295
3296 /// Type Query functions. If the type is an instance of the specified class,
3297 /// return the Type pointer for the underlying maximally pretty type. This
3298 /// is a member of ASTContext because this may need to do some amount of
3299 /// canonicalization, e.g. to move type qualifiers into the element type.
3300 const ArrayType *getAsArrayType(QualType T) const;
3302 return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
3303 }
3305 return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
3306 }
3308 return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
3309 }
3311 const {
3312 return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
3313 }
3314
3315 /// Return the innermost element type of an array type.
3316 ///
3317 /// For example, will return "int" for int[m][n]
3318 QualType getBaseElementType(const ArrayType *VAT) const;
3319
3320 /// Return the innermost element type of a type (which needn't
3321 /// actually be an array type).
3323
3324 /// Return number of (potentially nested) constant array elements.
3325 static uint64_t getConstantArrayElementCount(const ConstantArrayType *CA);
3326
3327 /// Return number of elements initialized in a (potentially nested)
3328 /// ArrayInitLoopExpr.
3329 /// \c AILE may be null, in which case 0 is returned.
3330 static uint64_t
3332
3333 /// Perform adjustment on the parameter type of a function.
3334 ///
3335 /// This routine adjusts the given parameter type @p T to the actual
3336 /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8],
3337 /// C++ [dcl.fct]p3). The adjusted parameter type is returned.
3339
3340 /// Retrieve the parameter type as adjusted for use in the signature
3341 /// of a function, decaying array and function types and removing top-level
3342 /// cv-qualifiers.
3344
3346
3347 /// Return the properly qualified result of decaying the specified
3348 /// array type to a pointer.
3349 ///
3350 /// This operation is non-trivial when handling typedefs etc. The canonical
3351 /// type of \p T must be an array type, this returns a pointer to a properly
3352 /// qualified element of the array.
3353 ///
3354 /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
3356
3357 /// Return the type that \p PromotableType will promote to: C99
3358 /// 6.3.1.1p2, assuming that \p PromotableType is a promotable integer type.
3359 QualType getPromotedIntegerType(QualType PromotableType) const;
3360
3361 /// Recurses in pointer/array types until it finds an Objective-C
3362 /// retainable type and returns its ownership.
3364
3365 /// Whether this is a promotable bitfield reference according
3366 /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
3367 ///
3368 /// \returns the type this bit-field will promote to, or NULL if no
3369 /// promotion occurs.
3371
3372 /// Return the highest ranked integer type, see C99 6.3.1.8p1.
3373 ///
3374 /// If \p LHS > \p RHS, returns 1. If \p LHS == \p RHS, returns 0. If
3375 /// \p LHS < \p RHS, return -1.
3376 int getIntegerTypeOrder(QualType LHS, QualType RHS) const;
3377
3378 /// Compare the rank of the two specified floating point types,
3379 /// ignoring the domain of the type (i.e. 'double' == '_Complex double').
3380 ///
3381 /// If \p LHS > \p RHS, returns 1. If \p LHS == \p RHS, returns 0. If
3382 /// \p LHS < \p RHS, return -1.
3383 int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
3384
3385 /// Compare the rank of two floating point types as above, but compare equal
3386 /// if both types have the same floating-point semantics on the target (i.e.
3387 /// long double and double on AArch64 will return 0).
3389
3390 unsigned getTargetAddressSpace(LangAS AS) const;
3391
3392 LangAS getLangASForBuiltinAddressSpace(unsigned AS) const;
3393
3394 /// Get target-dependent integer value for null pointer which is used for
3395 /// constant folding.
3396 uint64_t getTargetNullPointerValue(QualType QT) const;
3397
3399 return AddrSpaceMapMangling || isTargetAddressSpace(AS);
3400 }
3401
3402 bool hasAnyFunctionEffects() const { return AnyFunctionEffects; }
3403
3404 // Merges two exception specifications, such that the resulting
3405 // exception spec is the union of both. For example, if either
3406 // of them can throw something, the result can throw it as well.
3410 SmallVectorImpl<QualType> &ExceptionTypeStorage,
3411 bool AcceptDependent) const;
3412
3413 // For two "same" types, return a type which has
3414 // the common sugar between them. If Unqualified is true,
3415 // both types need only be the same unqualified type.
3416 // The result will drop the qualifiers which do not occur
3417 // in both types.
3419 bool Unqualified = false) const;
3420
3421private:
3422 // Helper for integer ordering
3423 unsigned getIntegerRank(const Type *T) const;
3424
3425public:
3426 //===--------------------------------------------------------------------===//
3427 // Type Compatibility Predicates
3428 //===--------------------------------------------------------------------===//
3429
3430 /// Compatibility predicates used to check assignment expressions.
3432 bool CompareUnqualified = false); // C99 6.2.7p1
3433
3436
3437 bool isObjCIdType(QualType T) const { return T == getObjCIdType(); }
3438
3439 bool isObjCClassType(QualType T) const { return T == getObjCClassType(); }
3440
3441 bool isObjCSelType(QualType T) const { return T == getObjCSelType(); }
3442
3444 const ObjCObjectPointerType *RHS,
3445 bool ForCompare);
3446
3448 const ObjCObjectPointerType *RHS);
3449
3450 // Check the safety of assignment from LHS to RHS
3452 const ObjCObjectPointerType *RHSOPT);
3454 const ObjCObjectType *RHS);
3456 const ObjCObjectPointerType *LHSOPT,
3457 const ObjCObjectPointerType *RHSOPT,
3458 bool BlockReturnType);
3461 const ObjCObjectPointerType *RHSOPT);
3463
3464 // Functions for calculating composite types
3465 QualType mergeTypes(QualType, QualType, bool OfBlockPointer = false,
3466 bool Unqualified = false, bool BlockReturnType = false,
3467 bool IsConditionalOperator = false);
3468 QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer = false,
3469 bool Unqualified = false, bool AllowCXX = false,
3470 bool IsConditionalOperator = false);
3472 bool OfBlockPointer = false,
3473 bool Unqualified = false);
3475 bool OfBlockPointer=false,
3476 bool Unqualified = false);
3478
3480
3481 /// This function merges the ExtParameterInfo lists of two functions. It
3482 /// returns true if the lists are compatible. The merged list is returned in
3483 /// NewParamInfos.
3484 ///
3485 /// \param FirstFnType The type of the first function.
3486 ///
3487 /// \param SecondFnType The type of the second function.
3488 ///
3489 /// \param CanUseFirst This flag is set to true if the first function's
3490 /// ExtParameterInfo list can be used as the composite list of
3491 /// ExtParameterInfo.
3492 ///
3493 /// \param CanUseSecond This flag is set to true if the second function's
3494 /// ExtParameterInfo list can be used as the composite list of
3495 /// ExtParameterInfo.
3496 ///
3497 /// \param NewParamInfos The composite list of ExtParameterInfo. The list is
3498 /// empty if none of the flags are set.
3499 ///
3501 const FunctionProtoType *FirstFnType,
3502 const FunctionProtoType *SecondFnType,
3503 bool &CanUseFirst, bool &CanUseSecond,
3505
3506 void ResetObjCLayout(const ObjCInterfaceDecl *D);
3507
3509 const ObjCInterfaceDecl *SubClass) {
3510 ObjCSubClasses[D].push_back(SubClass);
3511 }
3512
3513 //===--------------------------------------------------------------------===//
3514 // Integer Predicates
3515 //===--------------------------------------------------------------------===//
3516
3517 // The width of an integer, as defined in C99 6.2.6.2. This is the number
3518 // of bits in an integer type excluding any padding bits.
3519 unsigned getIntWidth(QualType T) const;
3520
3521 // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
3522 // unsigned integer type. This method takes a signed type, and returns the
3523 // corresponding unsigned integer type.
3524 // With the introduction of fixed point types in ISO N1169, this method also
3525 // accepts fixed point types and returns the corresponding unsigned type for
3526 // a given fixed point type.
3528
3529 // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
3530 // unsigned integer type. This method takes an unsigned type, and returns the
3531 // corresponding signed integer type.
3532 // With the introduction of fixed point types in ISO N1169, this method also
3533 // accepts fixed point types and returns the corresponding signed type for
3534 // a given fixed point type.
3536
3537 // Per ISO N1169, this method accepts fixed point types and returns the
3538 // corresponding saturated type for a given fixed point type.
3540
3541 // Per ISO N1169, this method accepts fixed point types and returns the
3542 // corresponding non-saturated type for a given fixed point type.
3544
3545 // This method accepts fixed point types and returns the corresponding signed
3546 // type. Unlike getCorrespondingUnsignedType(), this only accepts unsigned
3547 // fixed point types because there are unsigned integer types like bool and
3548 // char8_t that don't have signed equivalents.
3550
3551 //===--------------------------------------------------------------------===//
3552 // Integer Values
3553 //===--------------------------------------------------------------------===//
3554
3555 /// Make an APSInt of the appropriate width and signedness for the
3556 /// given \p Value and integer \p Type.
3557 llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const {
3558 // If Type is a signed integer type larger than 64 bits, we need to be sure
3559 // to sign extend Res appropriately.
3560 llvm::APSInt Res(64, !Type->isSignedIntegerOrEnumerationType());
3561 Res = Value;
3562 unsigned Width = getIntWidth(Type);
3563 if (Width != Res.getBitWidth())
3564 return Res.extOrTrunc(Width);
3565 return Res;
3566 }
3567
3568 bool isSentinelNullExpr(const Expr *E);
3569
3570 /// Get the implementation of the ObjCInterfaceDecl \p D, or nullptr if
3571 /// none exists.
3573
3574 /// Get the implementation of the ObjCCategoryDecl \p D, or nullptr if
3575 /// none exists.
3577
3578 /// Return true if there is at least one \@implementation in the TU.
3580 return !ObjCImpls.empty();
3581 }
3582
3583 /// Set the implementation of ObjCInterfaceDecl.
3585 ObjCImplementationDecl *ImplD);
3586
3587 /// Set the implementation of ObjCCategoryDecl.
3589 ObjCCategoryImplDecl *ImplD);
3590
3591 /// Get the duplicate declaration of a ObjCMethod in the same
3592 /// interface, or null if none exists.
3593 const ObjCMethodDecl *
3595
3597 const ObjCMethodDecl *Redecl);
3598
3599 /// Returns the Objective-C interface that \p ND belongs to if it is
3600 /// an Objective-C method/property/ivar etc. that is part of an interface,
3601 /// otherwise returns null.
3603
3604 /// Set the copy initialization expression of a block var decl. \p CanThrow
3605 /// indicates whether the copy expression can throw or not.
3606 void setBlockVarCopyInit(const VarDecl* VD, Expr *CopyExpr, bool CanThrow);
3607
3608 /// Get the copy initialization expression of the VarDecl \p VD, or
3609 /// nullptr if none exists.
3611
3612 /// Allocate an uninitialized TypeSourceInfo.
3613 ///
3614 /// The caller should initialize the memory held by TypeSourceInfo using
3615 /// the TypeLoc wrappers.
3616 ///
3617 /// \param T the type that will be the basis for type source info. This type
3618 /// should refer to how the declarator was written in source code, not to
3619 /// what type semantic analysis resolved the declarator to.
3620 ///
3621 /// \param Size the size of the type info to create, or 0 if the size
3622 /// should be calculated based on the type.
3623 TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const;
3624
3625 /// Allocate a TypeSourceInfo where all locations have been
3626 /// initialized to a given location, which defaults to the empty
3627 /// location.
3630 SourceLocation Loc = SourceLocation()) const;
3631
3632 /// Add a deallocation callback that will be invoked when the
3633 /// ASTContext is destroyed.
3634 ///
3635 /// \param Callback A callback function that will be invoked on destruction.
3636 ///
3637 /// \param Data Pointer data that will be provided to the callback function
3638 /// when it is called.
3639 void AddDeallocation(void (*Callback)(void *), void *Data) const;
3640
3641 /// If T isn't trivially destructible, calls AddDeallocation to register it
3642 /// for destruction.
3643 template <typename T> void addDestruction(T *Ptr) const {
3644 if (!std::is_trivially_destructible<T>::value) {
3645 auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
3646 AddDeallocation(DestroyPtr, Ptr);
3647 }
3648 }
3649
3652
3653 /// Determines if the decl can be CodeGen'ed or deserialized from PCH
3654 /// lazily, only when used; this is only relevant for function or file scoped
3655 /// var definitions.
3656 ///
3657 /// \returns true if the function/var must be CodeGen'ed/deserialized even if
3658 /// it is not used.
3659 bool DeclMustBeEmitted(const Decl *D);
3660
3661 /// Visits all versions of a multiversioned function with the passed
3662 /// predicate.
3664 const FunctionDecl *FD,
3665 llvm::function_ref<void(FunctionDecl *)> Pred) const;
3666
3667 const CXXConstructorDecl *
3669
3671 CXXConstructorDecl *CD);
3672
3674
3676
3678
3680
3681 void setManglingNumber(const NamedDecl *ND, unsigned Number);
3682 unsigned getManglingNumber(const NamedDecl *ND,
3683 bool ForAuxTarget = false) const;
3684
3685 void setStaticLocalNumber(const VarDecl *VD, unsigned Number);
3686 unsigned getStaticLocalNumber(const VarDecl *VD) const;
3687
3688 /// Ordinal for the next TopLevelStmtDecl; counts created and loaded ones.
3690
3692 return !TypeAwareOperatorNewAndDeletes.empty();
3693 }
3694 void setIsDestroyingOperatorDelete(const FunctionDecl *FD, bool IsDestroying);
3695 bool isDestroyingOperatorDelete(const FunctionDecl *FD) const;
3697 bool IsTypeAware);
3698 bool isTypeAwareOperatorNewOrDelete(const FunctionDecl *FD) const;
3699
3701
3703 FunctionDecl *OperatorDelete,
3704 OperatorDeleteKind K) const;
3706 OperatorDeleteKind K) const;
3708 OperatorDeleteKind K) const;
3711
3712 /// Retrieve the context for computing mangling numbers in the given
3713 /// DeclContext.
3717 const Decl *D);
3718
3719 std::unique_ptr<MangleNumberingContext> createMangleNumberingContext() const;
3720
3721 /// Used by ParmVarDecl to store on the side the
3722 /// index of the parameter when it exceeds the size of the normal bitfield.
3723 void setParameterIndex(const ParmVarDecl *D, unsigned index);
3724
3725 /// Used by ParmVarDecl to retrieve on the side the
3726 /// index of the parameter when it exceeds the size of the normal bitfield.
3727 unsigned getParameterIndex(const ParmVarDecl *D) const;
3728
3729 /// Return a string representing the human readable name for the specified
3730 /// function declaration or file name. Used by SourceLocExpr and
3731 /// PredefinedExpr to cache evaluated results.
3733
3734 /// Return the next version number to be used for a string literal evaluated
3735 /// as part of constant evaluation.
3736 unsigned getNextStringLiteralVersion() { return NextStringLiteralVersion++; }
3737
3738 /// Return a declaration for the global GUID object representing the given
3739 /// GUID value.
3741
3742 /// Return a declaration for a uniquified anonymous global constant
3743 /// corresponding to a given APValue.
3746
3747 /// Return the template parameter object of the given type with the given
3748 /// value.
3750 const APValue &V) const;
3751
3752 /// Parses the target attributes passed in, and returns only the ones that are
3753 /// valid feature names.
3754 ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const;
3755
3756 void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
3757 const FunctionDecl *) const;
3758 void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
3759 GlobalDecl GD) const;
3760
3761 /// Generates and stores SYCL kernel metadata for the provided
3762 /// SYCL kernel entry point function. The provided function must have
3763 /// an attached sycl_kernel_entry_point attribute that specifies a unique
3764 /// type for the name of a SYCL kernel. Callers are required to detect
3765 /// conflicting SYCL kernel names and issue a diagnostic prior to calling
3766 /// this function.
3768
3769 /// Given a type used as a SYCL kernel name, returns a reference to the
3770 /// metadata generated from the corresponding SYCL kernel entry point.
3771 /// Aborts if the provided type is not a registered SYCL kernel name.
3773
3774 /// Returns a pointer to the metadata generated from the corresponding
3775 /// SYCLkernel entry point if the provided type corresponds to a registered
3776 /// SYCL kernel name. Returns a null pointer otherwise.
3778
3779 //===--------------------------------------------------------------------===//
3780 // Statistics
3781 //===--------------------------------------------------------------------===//
3782
3783 /// The number of implicitly-declared default constructors.
3785
3786 /// The number of implicitly-declared default constructors for
3787 /// which declarations were built.
3789
3790 /// The number of implicitly-declared copy constructors.
3792
3793 /// The number of implicitly-declared copy constructors for
3794 /// which declarations were built.
3796
3797 /// The number of implicitly-declared move constructors.
3799
3800 /// The number of implicitly-declared move constructors for
3801 /// which declarations were built.
3803
3804 /// The number of implicitly-declared copy assignment operators.
3806
3807 /// The number of implicitly-declared copy assignment operators for
3808 /// which declarations were built.
3810
3811 /// The number of implicitly-declared move assignment operators.
3813
3814 /// The number of implicitly-declared move assignment operators for
3815 /// which declarations were built.
3817
3818 /// The number of implicitly-declared destructors.
3820
3821 /// The number of implicitly-declared destructors for which
3822 /// declarations were built.
3824
3825public:
3826 /// Initialize built-in types.
3827 ///
3828 /// This routine may only be invoked once for a given ASTContext object.
3829 /// It is normally invoked after ASTContext construction.
3830 ///
3831 /// \param Target The target
3832 void InitBuiltinTypes(const TargetInfo &Target,
3833 const TargetInfo *AuxTarget = nullptr);
3834
3835private:
3836 void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
3837
3838 class ObjCEncOptions {
3839 unsigned Bits;
3840
3841 ObjCEncOptions(unsigned Bits) : Bits(Bits) {}
3842
3843 public:
3844 ObjCEncOptions() : Bits(0) {}
3845
3846#define OPT_LIST(V) \
3847 V(ExpandPointedToStructures, 0) \
3848 V(ExpandStructures, 1) \
3849 V(IsOutermostType, 2) \
3850 V(EncodingProperty, 3) \
3851 V(IsStructField, 4) \
3852 V(EncodeBlockParameters, 5) \
3853 V(EncodeClassNames, 6) \
3854
3855#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
3856OPT_LIST(V)
3857#undef V
3858
3859#define V(N,I) bool N() const { return Bits & 1 << I; }
3860OPT_LIST(V)
3861#undef V
3862
3863#undef OPT_LIST
3864
3865 [[nodiscard]] ObjCEncOptions keepingOnly(ObjCEncOptions Mask) const {
3866 return Bits & Mask.Bits;
3867 }
3868
3869 [[nodiscard]] ObjCEncOptions forComponentType() const {
3870 ObjCEncOptions Mask = ObjCEncOptions()
3871 .setIsOutermostType()
3872 .setIsStructField();
3873 return Bits & ~Mask.Bits;
3874 }
3875 };
3876
3877 // Return the Objective-C type encoding for a given type.
3878 void getObjCEncodingForTypeImpl(QualType t, std::string &S,
3879 ObjCEncOptions Options,
3880 const FieldDecl *Field,
3881 QualType *NotEncodedT = nullptr) const;
3882
3883 // Adds the encoding of the structure's members.
3884 void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S,
3885 const FieldDecl *Field,
3886 bool includeVBases = true,
3887 QualType *NotEncodedT=nullptr) const;
3888
3889public:
3890 // Adds the encoding of a method parameter or return type.
3892 QualType T, std::string& S,
3893 bool Extended) const;
3894
3895 /// Returns true if this is an inline-initialized static data member
3896 /// which is treated as a definition for MSVC compatibility.
3897 bool isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const;
3898
3900 /// Not an inline variable.
3901 None,
3902
3903 /// Weak definition of inline variable.
3905
3906 /// Weak for now, might become strong later in this TU.
3908
3909 /// Strong definition.
3911 };
3912
3913 /// Determine whether a definition of this inline variable should
3914 /// be treated as a weak or strong definition. For compatibility with
3915 /// C++14 and before, for a constexpr static data member, if there is an
3916 /// out-of-line declaration of the member, we may promote it from weak to
3917 /// strong.
3920
3921private:
3923 friend class DeclContext;
3924
3925 const ASTRecordLayout &getObjCLayout(const ObjCInterfaceDecl *D) const;
3926
3927 /// A set of deallocations that should be performed when the
3928 /// ASTContext is destroyed.
3929 // FIXME: We really should have a better mechanism in the ASTContext to
3930 // manage running destructors for types which do variable sized allocation
3931 // within the AST. In some places we thread the AST bump pointer allocator
3932 // into the datastructures which avoids this mess during deallocation but is
3933 // wasteful of memory, and here we require a lot of error prone book keeping
3934 // in order to track and run destructors while we're tearing things down.
3935 using DeallocationFunctionsAndArguments =
3936 llvm::SmallVector<std::pair<void (*)(void *), void *>, 16>;
3937 mutable DeallocationFunctionsAndArguments Deallocations;
3938
3939 // FIXME: This currently contains the set of StoredDeclMaps used
3940 // by DeclContext objects. This probably should not be in ASTContext,
3941 // but we include it here so that ASTContext can quickly deallocate them.
3942 llvm::PointerIntPair<StoredDeclsMap *, 1> LastSDM;
3943
3944 std::vector<Decl *> TraversalScope;
3945
3946 std::unique_ptr<VTableContextBase> VTContext;
3947
3948 void ReleaseDeclContextMaps();
3949
3950public:
3951 enum PragmaSectionFlag : unsigned {
3958 PSF_Invalid = 0x80000000U,
3959 };
3960
3972
3973 llvm::StringMap<SectionInfo> SectionInfos;
3974
3975 /// Return a new OMPTraitInfo object owned by this context.
3977
3978 /// Whether a C++ static variable or CUDA/HIP kernel may be externalized.
3979 bool mayExternalize(const Decl *D) const;
3980
3981 /// Whether a C++ static variable or CUDA/HIP kernel should be externalized.
3982 bool shouldExternalize(const Decl *D) const;
3983
3984 /// Resolve the root record to be used to derive the vtable pointer
3985 /// authentication policy for the specified record.
3986 const CXXRecordDecl *
3987 baseForVTableAuthentication(const CXXRecordDecl *ThisClass) const;
3988
3989 bool useAbbreviatedThunkName(GlobalDecl VirtualMethodDecl,
3990 StringRef MangledName);
3991
3992 StringRef getCUIDHash() const;
3993
3994 /// Returns a list of PFP fields for the given type, including subfields in
3995 /// bases or other fields, except for fields contained within fields of union
3996 /// type.
3997 std::vector<PFPField> findPFPFields(QualType Ty) const;
3998
3999 bool hasPFPFields(QualType Ty) const;
4000 static bool isPFPField(const FieldDecl *Field);
4001
4002 /// Returns whether this record's PFP fields (if any) are trivially
4003 /// copyable (i.e. may be memcpy'd). This may also return true if the
4004 /// record does not have any PFP fields, so it may be necessary for the caller
4005 /// to check for PFP fields, e.g. by calling hasPFPFields().
4006 bool arePFPFieldsTriviallyCopyable(const RecordDecl *RD) const;
4007
4008 llvm::SetVector<const FieldDecl *> PFPFieldsWithEvaluatedOffset;
4011
4012private:
4013 /// All OMPTraitInfo objects live in this collection, one per
4014 /// `pragma omp [begin] declare variant` directive.
4015 SmallVector<std::unique_ptr<OMPTraitInfo>, 4> OMPTraitInfoVector;
4016
4017 llvm::DenseMap<GlobalDecl, llvm::StringSet<>> ThunksToBeAbbreviated;
4018};
4019
4020/// Insertion operator for diagnostics.
4022 const ASTContext::SectionInfo &Section);
4023
4024/// Utility function for constructing a nullary selector.
4025inline Selector GetNullarySelector(StringRef name, ASTContext &Ctx) {
4026 const IdentifierInfo *II = &Ctx.Idents.get(name);
4027 return Ctx.Selectors.getSelector(0, &II);
4028}
4029
4030/// Utility function for constructing an unary selector.
4031inline Selector GetUnarySelector(StringRef name, ASTContext &Ctx) {
4032 const IdentifierInfo *II = &Ctx.Idents.get(name);
4033 return Ctx.Selectors.getSelector(1, &II);
4034}
4035
4036} // namespace clang
4037
4038// operator new and delete aren't allowed inside namespaces.
4039
4040/// Placement new for using the ASTContext's allocator.
4041///
4042/// This placement form of operator new uses the ASTContext's allocator for
4043/// obtaining memory.
4044///
4045/// IMPORTANT: These are also declared in clang/AST/ASTContextAllocate.h!
4046/// Any changes here need to also be made there.
4047///
4048/// We intentionally avoid using a nothrow specification here so that the calls
4049/// to this operator will not perform a null check on the result -- the
4050/// underlying allocator never returns null pointers.
4051///
4052/// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
4053/// @code
4054/// // Default alignment (8)
4055/// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
4056/// // Specific alignment
4057/// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
4058/// @endcode
4059/// Memory allocated through this placement new operator does not need to be
4060/// explicitly freed, as ASTContext will free all of this memory when it gets
4061/// destroyed. Please note that you cannot use delete on the pointer.
4062///
4063/// @param Bytes The number of bytes to allocate. Calculated by the compiler.
4064/// @param C The ASTContext that provides the allocator.
4065/// @param Alignment The alignment of the allocated memory (if the underlying
4066/// allocator supports it).
4067/// @return The allocated memory. Could be nullptr.
4068inline void *operator new(size_t Bytes, const clang::ASTContext &C,
4069 size_t Alignment /* = 8 */) {
4070 return C.Allocate(Bytes, Alignment);
4071}
4072
4073/// Placement delete companion to the new above.
4074///
4075/// This operator is just a companion to the new above. There is no way of
4076/// invoking it directly; see the new operator for more details. This operator
4077/// is called implicitly by the compiler if a placement new expression using
4078/// the ASTContext throws in the object constructor.
4079inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) {
4080 C.Deallocate(Ptr);
4081}
4082
4083/// This placement form of operator new[] uses the ASTContext's allocator for
4084/// obtaining memory.
4085///
4086/// We intentionally avoid using a nothrow specification here so that the calls
4087/// to this operator will not perform a null check on the result -- the
4088/// underlying allocator never returns null pointers.
4089///
4090/// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
4091/// @code
4092/// // Default alignment (8)
4093/// char *data = new (Context) char[10];
4094/// // Specific alignment
4095/// char *data = new (Context, 4) char[10];
4096/// @endcode
4097/// Memory allocated through this placement new[] operator does not need to be
4098/// explicitly freed, as ASTContext will free all of this memory when it gets
4099/// destroyed. Please note that you cannot use delete on the pointer.
4100///
4101/// @param Bytes The number of bytes to allocate. Calculated by the compiler.
4102/// @param C The ASTContext that provides the allocator.
4103/// @param Alignment The alignment of the allocated memory (if the underlying
4104/// allocator supports it).
4105/// @return The allocated memory. Could be nullptr.
4106inline void *operator new[](size_t Bytes, const clang::ASTContext& C,
4107 size_t Alignment /* = 8 */) {
4108 return C.Allocate(Bytes, Alignment);
4109}
4110
4111/// Placement delete[] companion to the new[] above.
4112///
4113/// This operator is just a companion to the new[] above. There is no way of
4114/// invoking it directly; see the new[] operator for more details. This operator
4115/// is called implicitly by the compiler if a placement new[] expression using
4116/// the ASTContext throws in the object constructor.
4117inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) {
4118 C.Deallocate(Ptr);
4119}
4120
4121template <> struct llvm::DenseMapInfo<llvm::FoldingSetNodeID> {
4122 static unsigned getHashValue(const FoldingSetNodeID &Val) {
4123 return Val.computeHash();
4124 }
4125
4126 static bool isEqual(const FoldingSetNodeID &LHS,
4127 const FoldingSetNodeID &RHS) {
4128 return LHS == RHS;
4129 }
4130};
4131template <> struct llvm::DenseMapInfo<llvm::FoldingSetNodeIDRef> {
4132 static unsigned getHashValue(FoldingSetNodeIDRef Val) {
4133 return Val.computeHash();
4134 }
4135 static bool isEqual(FoldingSetNodeIDRef LHS, FoldingSetNodeIDRef RHS) {
4136 return LHS == RHS;
4137 }
4138 static unsigned getHashValue(const FoldingSetNodeID &Val) {
4139 return Val.computeHash();
4140 }
4141 static bool isEqual(const FoldingSetNodeID &LHS, FoldingSetNodeIDRef RHS) {
4142 return LHS == RHS;
4143 }
4144};
4145
4146#endif // LLVM_CLANG_AST_ASTCONTEXT_H
#define OPT_LIST(V)
#define V(N, I)
Forward declaration of all AST node types.
static bool CanThrow(Expr *E, ASTContext &Ctx)
Definition CFG.cpp:2852
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, clang::CharUnits CU)
Definition CharUnits.h:192
#define X(type, name)
Definition Value.h:97
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Forward-declares types that need PointerLikeTypeTraits.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
This file declares types used to describe SYCL kernels.
Defines the clang::SourceLocation class and associated facilities.
#define CXXABI(Name, Str)
Allows QualTypes to be sorted and hence used in maps and sets.
C Language Family Type Representation.
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:239
ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents, SelectorTable &sels, Builtin::Context &builtins, TranslationUnitKind TUKind)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:124
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:239
bool getByrefLifetime(QualType Ty, Qualifiers::ObjCLifetime &Lifetime, bool &HasByrefExtendedLayout) const
Returns true, if given type has a known lifetime.
MSGuidDecl * getMSGuidDecl(MSGuidDeclParts Parts) const
Return a declaration for the global GUID object representing the given GUID value.
CanQualType AccumTy
BuiltinVectorTypeInfo getBuiltinVectorTypeInfo(const BuiltinType *VecTy) const
Returns the element type, element count and number of vectors (in case of tuple) for a builtin vector...
bool ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl, const ObjCMethodDecl *MethodImp)
CanQualType ObjCBuiltinSelTy
SourceManager & getSourceManager()
Definition ASTContext.h:911
TranslationUnitDecl * getTranslationUnitDecl() const
const ConstantArrayType * getAsConstantArrayType(QualType T) const
CanQualType getCanonicalFunctionResultType(QualType ResultType) const
Adjust the given function result type.
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
llvm::SmallPtrSet< const FunctionDecl *, 4 > CUDADeviceInvalidFuncs
Functions whose device body should be replaced with a trap stub.
QualType getBuiltinZOSVaListType() const
Retrieve the type of the __builtin_zos_va_list type.
LangAS getOpenCLTypeAddrSpace(const Type *T) const
Get address space for OpenCL type.
friend class ASTWriter
Definition ASTContext.h:611
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
void InitBuiltinTypes(const TargetInfo &Target, const TargetInfo *AuxTarget=nullptr)
Initialize built-in types.
ParentMapContext & getParentMapContext()
Returns the dynamic AST node parent map context.
QualType getParenType(QualType NamedType) const
size_t getSideTableAllocatedMemory() const
Return the total memory used for various side tables.
MemberSpecializationInfo * getInstantiatedFromStaticDataMember(const VarDecl *Var)
If this variable is an instantiated static data member of a class template specialization,...
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
CanQualType ARCUnbridgedCastTy
uint64_t getTypeSize(const Type *T) const
QualType getDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, SourceLocation AttrLoc) const
Return the unique reference to the matrix type of the specified element type and size.
QualType getBTFTagAttributedType(const BTFTypeTagAttr *BTFAttr, QualType Wrapped) const
llvm::DenseMap< const Decl *, comments::FullComment * > ParsedComments
Mapping from declarations to parsed comments attached to any redeclaration.
unsigned getManglingNumber(const NamedDecl *ND, bool ForAuxTarget=false) const
static const Type * getCanonicalType(const Type *T)
CanQualType LongTy
const SmallVectorImpl< Type * > & getTypes() const
unsigned getIntWidth(QualType T) const
CanQualType getCanonicalParamType(QualType T) const
Return the canonical parameter type corresponding to the specific potentially non-canonical one.
const FunctionType * adjustFunctionType(const FunctionType *Fn, FunctionType::ExtInfo EInfo)
Change the ExtInfo on a function type.
TemplateOrSpecializationInfo getTemplateOrSpecializationInfo(const VarDecl *Var)
CanQualType WIntTy
@ Weak
Weak definition of inline variable.
@ WeakUnknown
Weak for now, might become strong later in this TU.
bool dtorHasOperatorDelete(const CXXDestructorDecl *Dtor, OperatorDeleteKind K) const
const ProfileList & getProfileList() const
void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl)
TypedefDecl * getObjCClassDecl() const
Retrieve the typedef declaration corresponding to the predefined Objective-C 'Class' type.
TypedefNameDecl * getTypedefNameForUnnamedTagDecl(const TagDecl *TD)
QualType getTypeDeclType(const UnresolvedUsingTypenameDecl *) const =delete
TypedefDecl * getCFConstantStringDecl() const
CanQualType Int128Ty
CanQualType SatUnsignedFractTy
CanQualType getAdjustedType(CanQualType Orig, CanQualType New) const
void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern)
Remember that the using decl Inst is an instantiation of the using decl Pattern of a class template.
bool areCompatibleRVVTypes(QualType FirstType, QualType SecondType)
Return true if the given types are an RISC-V vector builtin type and a VectorType that is a fixed-len...
QualType getConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns, std::optional< MatrixType::LayoutKind > Layout=std::nullopt) const
Return the unique reference to the matrix type of the specified element type and size.
ExternCContextDecl * getExternCContextDecl() const
const llvm::fltSemantics & getFloatTypeSemantics(QualType T) const
Return the APFloat 'semantics' for the specified scalar floating point type.
ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const
Parses the target attributes passed in, and returns only the ones that are valid feature names.
QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT, const ObjCObjectPointerType *RHSOPT)
TypedefDecl * getObjCSelDecl() const
Retrieve the typedef corresponding to the predefined 'SEL' type in Objective-C.
llvm::iterator_range< import_iterator > import_range
bool AnyObjCImplementation()
Return true if there is at least one @implementation in the TU.
CanQualType UnsignedShortAccumTy
TypedefDecl * getObjCInstanceTypeDecl()
Retrieve the typedef declaration corresponding to the Objective-C "instancetype" type.
uint64_t getFieldOffset(const ValueDecl *FD) const
Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
void DeallocateDeclListNode(DeclListNode *N)
Deallocates a DeclListNode by returning it to the ListNodeFreeList pool.
Definition ASTContext.h:951
unsigned NumTopLevelStmtDecls
Ordinal for the next TopLevelStmtDecl; counts created and loaded ones.
DeclListNode * AllocateDeclListNode(clang::NamedDecl *ND)
Allocates a DeclListNode or returns one from the ListNodeFreeList pool.
Definition ASTContext.h:940
QualType adjustFunctionResultType(QualType FunctionType, QualType NewResultType)
Change the result type of a function type, preserving sugar such as attributed types.
void setTemplateOrSpecializationInfo(VarDecl *Inst, TemplateOrSpecializationInfo TSI)
bool isTypeAwareOperatorNewOrDelete(const FunctionDecl *FD) const
bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, ObjCProtocolDecl *rProto) const
ProtocolCompatibleWithProtocol - return 'true' if 'lProto' is in the inheritance hierarchy of 'rProto...
TypedefDecl * buildImplicitTypedef(QualType T, StringRef Name) const
Create a new implicit TU-level typedef declaration.
unsigned getTypeAlign(const Type *T) const
QualType getCanonicalTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName T, ArrayRef< TemplateArgument > CanonicalArgs) const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
void adjustObjCTypeParamBoundType(const ObjCTypeParamDecl *Orig, ObjCTypeParamDecl *New) const
llvm::StringMap< SectionInfo > SectionInfos
QualType getAutoType(DeducedKind DK, QualType DeducedAsType, AutoTypeKeyword Keyword, TemplateName TypeConstraintConcept=TemplateName(), ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) const
Retrieve the "canonical" template argument.
QualType getAutoRRefDeductType() const
C++11 deduction pattern for 'auto &&' type.
TypedefDecl * getBuiltinMSVaListDecl() const
Retrieve the C type declaration corresponding to the predefined __builtin_ms_va_list type.
bool ObjCQualifiedIdTypesAreCompatible(const ObjCObjectPointerType *LHS, const ObjCObjectPointerType *RHS, bool ForCompare)
ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an ObjCQualifiedIDType.
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
QualType getBuiltinVaListType() const
Retrieve the type of the __builtin_va_list type.
QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false, bool Unqualified=false, bool AllowCXX=false, bool IsConditionalOperator=false)
NamedDecl * getInstantiatedFromUsingDecl(NamedDecl *Inst)
If the given using decl Inst is an instantiation of another (possibly unresolved) using decl,...
DeclarationNameTable DeclarationNames
Definition ASTContext.h:854
comments::FullComment * cloneFullComment(comments::FullComment *FC, const Decl *D) const
bool containsNonRelocatablePointerAuth(QualType T)
Examines a given type, and returns whether the type itself or any data it transitively contains has a...
Definition ASTContext.h:766
CharUnits getObjCEncodingTypeSize(QualType T) const
Return the size of type T for Objective-C encoding purpose, in characters.
int getIntegerTypeOrder(QualType LHS, QualType RHS) const
Return the highest ranked integer type, see C99 6.3.1.8p1.
QualType getObjCClassType() const
Represents the Objective-C Class type.
const TemplateArgument * getDefaultTemplateArgumentOrNone(const NamedDecl *P) const
Return the default argument of a template parameter, if one exists.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
TypedefDecl * getObjCIdDecl() const
Retrieve the typedef corresponding to the predefined id type in Objective-C.
void setCurrentNamedModule(Module *M)
Set the (C++20) module we are building.
QualType getRawCFConstantStringType() const
Get the structure type used to representation CFStrings, or NULL if it hasn't yet been built.
QualType getProcessIDType() const
Return the unique type for "pid_t" defined in <sys/types.h>.
CharUnits getMemberPointerPathAdjustment(const APValue &MP) const
Find the 'this' offset for the member path in a pointer-to-member APValue.
bool mayExternalize(const Decl *D) const
Whether a C++ static variable or CUDA/HIP kernel may be externalized.
std::unique_ptr< MangleNumberingContext > createMangleNumberingContext() const
CanQualType SatAccumTy
ArrayRef< CXXDefaultArgExpr * > getCtorClosureDefaultArgs(const CXXConstructorDecl *CD)
QualType getUnsignedPointerDiffType() const
Return the unique unsigned counterpart of "ptrdiff_t" integer type.
QualType getucontext_tType() const
Retrieve the C ucontext_t type.
std::optional< CharUnits > getTypeSizeInCharsIfKnown(const Type *Ty) const
QualType getScalableVectorType(QualType EltTy, unsigned NumElts, unsigned NumFields=1) const
Return the unique reference to a scalable vector type of the specified element type and scalable numb...
bool hasSameExpr(const Expr *X, const Expr *Y) const
Determine whether the given expressions X and Y are equivalent.
TemplateName getPackIndexingTemplateName(TemplateName Pattern, Expr *IndexExpr, bool FullySubstituted=false, ArrayRef< TemplateName > Expansions={}) const
void getObjCEncodingForType(QualType T, std::string &S, const FieldDecl *Field=nullptr, QualType *NotEncodedT=nullptr) const
Emit the Objective-CC type encoding for the given type T into S.
QualType getBuiltinMSVaListType() const
Retrieve the type of the __builtin_ms_va_list type.
MangleContext * createMangleContext(const TargetInfo *T=nullptr)
If T is null pointer, assume the target in ASTContext.
RawComment * getRawCommentNoCache(RawCommentLookupKey Key) const
Return the documentation comment attached to a given declaration or macro, without looking into cache...
QualType getRealTypeForBitwidth(unsigned DestWidth, FloatModeKind ExplicitType) const
getRealTypeForBitwidth - sets floating point QualTy according to specified bitwidth.
ArrayRef< Decl * > getTraversalScope() const
Definition ASTContext.h:896
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
CanQualType ShortAccumTy
ASTMutationListener * getASTMutationListener() const
Retrieve a pointer to the AST mutation listener associated with this AST context, if any.
unsigned NumImplicitCopyAssignmentOperatorsDeclared
The number of implicitly-declared copy assignment operators for which declarations were built.
uint64_t getTargetNullPointerValue(QualType QT) const
Get target-dependent integer value for null pointer which is used for constant folding.
unsigned getTypeUnadjustedAlign(QualType T) const
Return the ABI-specified natural alignment of a (complete) type T, before alignment adjustments,...
unsigned char getFixedPointIBits(QualType Ty) const
QualType getSubstBuiltinTemplatePack(const TemplateArgument &ArgPack)
QualType getCorrespondingSignedFixedPointType(QualType Ty) const
IntrusiveRefCntPtr< ExternalASTSource > ExternalSource
Definition ASTContext.h:855
CanQualType FloatTy
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
QualType getCountAttributedType(QualType T, Expr *CountExpr, bool CountInBytes, bool OrNull, ArrayRef< TypeCoupledDeclRefInfo > DependentDecls) const
void setObjCIdRedefinitionType(QualType RedefType)
Set the user-written type that redefines id.
bool isObjCIdType(QualType T) const
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
DynTypedNodeList getParents(const NodeT &Node)
Forwards to get node parents from the ParentMapContext.
friend class IncrementalParser
Definition ASTContext.h:614
unsigned NumImplicitDestructorsDeclared
The number of implicitly-declared destructors for which declarations were built.
bool isObjCClassType(QualType T) const
void setObjCNSStringType(QualType T)
bool mergeExtParameterInfo(const FunctionProtoType *FirstFnType, const FunctionProtoType *SecondFnType, bool &CanUseFirst, bool &CanUseSecond, SmallVectorImpl< FunctionProtoType::ExtParameterInfo > &NewParamInfos)
This function merges the ExtParameterInfo lists of two functions.
bool ObjCQualifiedClassTypesAreCompatible(const ObjCObjectPointerType *LHS, const ObjCObjectPointerType *RHS)
ObjCQualifiedClassTypesAreCompatible - compare Class<pr,...> and Class<pr1, ...>.
bool shouldExternalize(const Decl *D) const
Whether a C++ static variable or CUDA/HIP kernel should be externalized.
FullSourceLoc getFullLoc(SourceLocation Loc) const
bool propertyTypesAreCompatible(QualType, QualType)
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern)
CanQualType DoubleTy
QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc, VectorKind VecKind) const
Return the unique reference to the type for a dependently sized vector of the specified element type.
comments::CommandTraits & getCommentCommandTraits() const
CanQualType SatLongAccumTy
const XRayFunctionFilter & getXRayFilter() const
CanQualType getIntMaxType() const
Return the unique type for "intmax_t" (C99 7.18.1.5), defined in <stdint.h>.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
OpenCLTypeKind getOpenCLTypeKind(const Type *T) const
Map an AST Type to an OpenCLTypeKind enum value.
FunctionDecl * getcudaGetParameterBufferDecl()
TemplateName getDependentTemplateName(const DependentTemplateStorage &Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template operat...
QualType getFILEType() const
Retrieve the C FILE type.
ArrayRef< Decl * > getModuleInitializers(Module *M)
Get the initializations to perform when importing a module, if any.
void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, std::string &S) const
Put the string version of the type qualifiers QT into S.
unsigned getPreferredTypeAlign(QualType T) const
Return the "preferred" alignment of the specified type T for the current target, in bits.
void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl)
Set the type for the C sigjmp_buf type.
std::string getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, bool Extended=false) const
Emit the encoded type for the method declaration Decl into S.
void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS, bool Simple=false) const
bool DeclMustBeEmitted(const Decl *D)
Determines if the decl can be CodeGen'ed or deserialized from PCH lazily, only when used; this is onl...
CanQualType LongDoubleTy
CanQualType OMPArrayShapingTy
ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents, SelectorTable &sels, Builtin::Context &builtins, TranslationUnitKind TUKind)
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
std::string getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, const Decl *Container) const
getObjCEncodingForPropertyDecl - Return the encoded type for this method declaration.
CanQualType Char16Ty
TemplateName getCanonicalTemplateName(TemplateName Name, bool IgnoreDeduced=false) const
Retrieves the "canonical" template name that refers to a given template.
unsigned getStaticLocalNumber(const VarDecl *VD) const
QualType getObjCSelRedefinitionType() const
Retrieve the type that 'SEL' has been defined to, which may be different from the built-in 'SEL' if '...
void addComment(const RawComment &RC)
void getLegacyIntegralTypeEncoding(QualType &t) const
getLegacyIntegralTypeEncoding - Another legacy compatibility encoding: 32-bit longs are encoded as 'l...
bool isSameTypeConstraint(const TypeConstraint *XTC, const TypeConstraint *YTC) const
Determine whether two type contraint are similar enough that they could used in declarations of the s...
void setRelocationInfoForCXXRecord(const CXXRecordDecl *, CXXRecordDeclRelocationInfo)
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, UnsignedOrNone PackIndex, bool Final) const
Retrieve a substitution-result type.
RecordDecl * buildImplicitRecord(StringRef Name, RecordDecl::TagKind TK=RecordDecl::TagKind::Struct) const
Create a new implicit TU-level CXXRecordDecl or RecordDecl declaration.
void setObjCSelRedefinitionType(QualType RedefType)
Set the user-written type that redefines 'SEL'.
void setFILEDecl(TypeDecl *FILEDecl)
Set the type for the C FILE type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
bool defaultsToMsStruct() const
Return whether unannotated records are treated as if they have [[gnu::ms_struct]].
const CXXMethodDecl * getCurrentKeyFunction(const CXXRecordDecl *RD)
Get our current best idea for the key function of the given record decl, or nullptr if there isn't on...
void completeCountAttributedType(CountAttributedType *CATy, Expr *CountExpr, ArrayRef< TypeCoupledDeclRefInfo > DependentDecls) const
Supply the count expression and coupled declarations for a type created by getIncompleteCountAttribut...
CanQualType UnsignedLongFractTy
QualType mergeTagDefinitions(QualType, QualType)
void setClassMaybeNeedsVectorDeletingDestructor(const CXXRecordDecl *RD)
overridden_method_range overridden_methods(const CXXMethodDecl *Method) const
void setIsTypeAwareOperatorNewOrDelete(const FunctionDecl *FD, bool IsTypeAware)
bool hasSeenTypeAwareOperatorNewOrDelete() const
QualType getDependentBitIntType(bool Unsigned, Expr *BitsExpr) const
Return a dependent bit-precise integer type with the specified signedness and bit count.
void setObjCImplementation(ObjCInterfaceDecl *IFaceD, ObjCImplementationDecl *ImplD)
Set the implementation of ObjCInterfaceDecl.
StringRef getCUIDHash() const
bool isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const
Returns true if this is an inline-initialized static data member which is treated as a definition for...
bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, const ObjCObjectPointerType *RHSOPT)
canAssignObjCInterfaces - Return true if the two interface types are compatible for assignment from R...
CanQualType VoidPtrTy
QualType getReferenceQualifiedType(const Expr *e) const
getReferenceQualifiedType - Given an expr, will return the type for that expression,...
bool hasSameFunctionTypeIgnoringExceptionSpec(QualType T, QualType U) const
Determine whether two function types are the same, ignoring exception specifications in cases where t...
bool isObjCSelType(QualType T) const
QualType getBlockDescriptorExtendedType() const
Gets the struct used to keep track of the extended descriptor for pointer to blocks.
void Deallocate(void *Ptr) const
Definition ASTContext.h:930
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
CanQualType DependentTy
bool QIdProtocolsAdoptObjCObjectProtocols(QualType QT, ObjCInterfaceDecl *IDecl)
QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in QT's qualified-id protocol list adopt...
FunctionProtoType::ExceptionSpecInfo mergeExceptionSpecs(FunctionProtoType::ExceptionSpecInfo ESI1, FunctionProtoType::ExceptionSpecInfo ESI2, SmallVectorImpl< QualType > &ExceptionTypeStorage, bool AcceptDependent) const
llvm::PointerUnion< const Decl *, const MacroInfo * > RawCommentLookupKey
Key used to look up the raw comment attached to a declaration or macro.
void addLazyModuleInitializers(Module *M, ArrayRef< GlobalDeclID > IDs)
bool isSameConstraintExpr(const Expr *XCE, const Expr *YCE) const
Determine whether two 'requires' expressions are similar enough that they may be used in re-declarati...
bool BlockRequiresCopying(QualType Ty, const VarDecl *D)
Returns true iff we need copy/dispose helpers for the given type.
QualType getTypeDeclType(const TypeAliasDecl *) const =delete
CanQualType NullPtrTy
QualType getUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const UsingShadowDecl *D, QualType UnderlyingType=QualType()) const
std::optional< QualType > tryMergeOverflowBehaviorTypes(QualType LHS, QualType RHS, bool OfBlockPointer, bool Unqualified, bool BlockReturnType, bool IsConditionalOperator)
Attempts to merge two types that may be OverflowBehaviorTypes.
CanQualType WideCharTy
CanQualType OMPIteratorTy
IdentifierTable & Idents
Definition ASTContext.h:850
Builtin::Context & BuiltinInfo
Definition ASTContext.h:852
bool computeEnumBits(RangeT EnumConstants, unsigned &NumNegativeBits, unsigned &NumPositiveBits)
Compute NumNegativeBits and NumPositiveBits for an enum based on the constant values of its enumerato...
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
void addModuleInitializer(Module *M, Decl *Init)
Add a declaration to the list of declarations that are initialized for a module.
const LangOptions & getLangOpts() const
QualType getConstType(QualType T) const
Return the uniqued reference to the type for a const qualified type.
bool containsAddressDiscriminatedPointerAuth(QualType T) const
Examines a given type, and returns whether the type itself is address discriminated,...
Definition ASTContext.h:755
QualType getFunctionTypeWithoutPtrSizes(QualType T)
Get a function type and produce the equivalent function type where pointer size address spaces in the...
uint64_t lookupFieldBitOffset(const ObjCInterfaceDecl *OID, const ObjCIvarDecl *Ivar) const
Get the offset of an ObjCIvarDecl in bits.
CanQualType getLogicalOperationType() const
The result type of logical operations, '<', '>', '!=', etc.
SelectorTable & Selectors
Definition ASTContext.h:851
bool isTypeIgnoredBySanitizer(const SanitizerMask &Mask, const QualType &Ty) const
Check if a type can have its sanitizer instrumentation elided based on its presence within an ignorel...
unsigned getMinGlobalAlignOfVar(uint64_t Size, const VarDecl *VD) const
Return the minimum alignment as specified by the target.
RawCommentList Comments
All comments in this translation unit.
bool isSameDefaultTemplateArgument(const NamedDecl *X, const NamedDecl *Y) const
Determine whether two default template arguments are similar enough that they may be used in declarat...
QualType applyObjCProtocolQualifiers(QualType type, ArrayRef< ObjCProtocolDecl * > protocols, bool &hasError, bool allowOnPointerType=false) const
Apply Objective-C protocol qualifiers to the given type.
QualType getMacroQualifiedType(QualType UnderlyingTy, const IdentifierInfo *MacroII) const
QualType getLateParsedAttrType(QualType Wrapped, LateParsedTypeAttribute *LateParsedAttr) const
Return a placeholder type for a late-parsed type attribute.
QualType removePtrSizeAddrSpace(QualType T) const
Remove the existing address space on the type if it is a pointer size address space and return the ty...
bool areLaxCompatibleRVVTypes(QualType FirstType, QualType SecondType)
Return true if the given vector types are lax-compatible RISC-V vector types as defined by -flax-vect...
llvm::ArrayRef< BitInterval > getPaddingIntervals(QualType Ty) const
void setObjCSuperType(QualType ST)
TagDecl * MSTypeInfoTagDecl
TypedefDecl * getBOOLDecl() const
Retrieve declaration of 'BOOL' typedef.
CanQualType SatShortFractTy
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current context.
bool canBindObjCObjectType(QualType To, QualType From)
unsigned getNextStringLiteralVersion()
Return the next version number to be used for a string literal evaluated as part of constant evaluati...
TemplateTemplateParmDecl * insertCanonicalTemplateTemplateParmDeclInternal(TemplateTemplateParmDecl *CanonTTP) const
int getFloatingTypeSemanticOrder(QualType LHS, QualType RHS) const
Compare the rank of two floating point types as above, but compare equal if both types have the same ...
QualType getUIntPtrType() const
Return a type compatible with "uintptr_t" (C99 7.18.1.4), as defined by the target.
void setParameterIndex(const ParmVarDecl *D, unsigned index)
Used by ParmVarDecl to store on the side the index of the parameter when it exceeds the size of the n...
QualType getFunctionTypeWithExceptionSpec(QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI) const
Get a function type and produce the equivalent function type with the specified exception specificati...
QualType getObjCInstanceType()
Retrieve the Objective-C "instancetype" type.
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier NNS, const IdentifierInfo *Name) const
Qualifiers::GC getObjCGCAttrKind(QualType Ty) const
Return one of the GCNone, Weak or Strong Objective-C garbage collection attributes.
PartialDiagnostic::DiagStorageAllocator & getDiagAllocator()
Definition ASTContext.h:965
static bool hasSameType(const Type *T1, const Type *T2)
CanQualType Ibm128Ty
void setASTMutationListener(ASTMutationListener *Listener)
Attach an AST mutation listener to the AST context.
static bool hasLayout(const RecordDecl *D)
Whether layout (offset and size) information can be queried for D.
bool hasUniqueObjectRepresentations(QualType Ty, bool CheckIfTriviallyCopyable=true) const
Return true if the specified type has unique object representations according to (C++17 [meta....
const QualType GetHigherPrecisionFPType(QualType ElementType) const
Definition ASTContext.h:972
CanQualType getCanonicalSizeType() const
bool typesAreBlockPointerCompatible(QualType, QualType)
CanQualType SatUnsignedAccumTy
bool useAbbreviatedThunkName(GlobalDecl VirtualMethodDecl, StringRef MangledName)
const ASTRecordLayout & getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) const
Get or compute information about the layout of the specified Objective-C interface.
friend class ASTReader
Definition ASTContext.h:610
QualType getObjCProtoType() const
Retrieve the type of the Objective-C Protocol class.
void forEachMultiversionedFunctionVersion(const FunctionDecl *FD, llvm::function_ref< void(FunctionDecl *)> Pred) const
Visits all versions of a multiversioned function with the passed predicate.
void setInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst, UsingEnumDecl *Pattern)
Remember that the using enum decl Inst is an instantiation of the using enum decl Pattern of a class ...
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
llvm::SetVector< const VarDecl * > CUDADeviceVarODRUsedByHost
Keep track of CUDA/HIP device-side variables ODR-used by host code.
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
Decl * getPrimaryMergedDecl(Decl *D)
QualType getSignatureParameterType(QualType T) const
Retrieve the parameter type as adjusted for use in the signature of a function, decaying array and fu...
CanQualType ArraySectionTy
CanQualType ObjCBuiltinIdTy
overridden_cxx_method_iterator overridden_methods_end(const CXXMethodDecl *Method) const
VTableContextBase * getVTableContext()
void setBOOLDecl(TypedefDecl *TD)
Save declaration of 'BOOL' typedef.
llvm::SetVector< const ValueDecl * > CUDAExternalDeviceDeclODRUsedByHost
Keep track of CUDA/HIP external kernels or device variables ODR-used by host code.
ComparisonCategories CompCategories
Types and expressions required to build C++2a three-way comparisons using operator<=>,...
int getFloatingTypeOrder(QualType LHS, QualType RHS) const
Compare the rank of the two specified floating point types, ignoring the domain of the type (i....
unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const
ASTContext(const ASTContext &)=delete
ObjCPropertyImplDecl * getObjCPropertyImplDeclForPropertyDecl(const ObjCPropertyDecl *PD, const Decl *Container) const
bool isNearlyEmpty(const CXXRecordDecl *RD) const
PointerAuthQualifier getObjCMemberSelTypePtrAuth()
QualType AutoDeductTy
CanQualType BoolTy
void setcudaLaunchDeviceDecl(FunctionDecl *FD)
void attachCommentsToJustParsedDecls(ArrayRef< Decl * > Decls, const Preprocessor *PP)
Searches existing comments for doc comments that should be attached to Decls.
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth,...
llvm::BumpPtrAllocator & getAllocator() const
Definition ASTContext.h:920
void setStaticLocalNumber(const VarDecl *VD, unsigned Number)
friend class ASTDeclReader
Definition ASTContext.h:609
QualType getCFConstantStringType() const
Return the C structure type used to represent constant CFStrings.
void eraseDeclAttrs(const Decl *D)
Erase the attributes corresponding to the given declaration.
const NoSanitizeList & getNoSanitizeList() const
struct clang::ASTContext::CUDAConstantEvalContext CUDAConstantEvalCtx
IdentifierInfo * getNSObjectName() const
Retrieve the identifier 'NSObject'.
UsingEnumDecl * getInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst)
If the given using-enum decl Inst is an instantiation of another using-enum decl, return it.
RecordDecl * getCFConstantStringTagDecl() const
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
std::string getObjCEncodingForFunctionDecl(const FunctionDecl *Decl) const
Emit the encoded type for the function Decl into S.
TypeSourceInfo * getTemplateSpecializationTypeInfo(ElaboratedTypeKeyword Keyword, SourceLocation ElaboratedKeywordLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKeywordLoc, TemplateName T, SourceLocation TLoc, const TemplateArgumentListInfo &SpecifiedArgs, ArrayRef< TemplateArgument > CanonicalArgs, QualType Canon=QualType()) const
CanQualType MetaInfoTy
bool addressSpaceMapManglingFor(LangAS AS) const
CanQualType UnsignedFractTy
QualType getjmp_bufType() const
Retrieve the C jmp_buf type.
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
QualType mergeFunctionParameterTypes(QualType, QualType, bool OfBlockPointer=false, bool Unqualified=false)
mergeFunctionParameterTypes - merge two types which appear as function parameter types
QualType getsigjmp_bufType() const
Retrieve the C sigjmp_buf type.
void addOverriddenMethod(const CXXMethodDecl *Method, const CXXMethodDecl *Overridden)
Note that the given C++ Method overrides the given Overridden method.
TemplateTemplateParmDecl * findCanonicalTemplateTemplateParmDeclInternal(TemplateTemplateParmDecl *TTP) const
const TargetInfo * getAuxTargetInfo() const
Definition ASTContext.h:970
CanQualType Float128Ty
CanQualType ObjCBuiltinClassTy
unsigned NumImplicitDefaultConstructorsDeclared
The number of implicitly-declared default constructors for which declarations were built.
CanQualType UnresolvedTemplateTy
void setucontext_tDecl(TypeDecl *ucontext_tDecl)
Set the type for the C ucontext_t type.
OMPTraitInfo & getNewOMPTraitInfo()
Return a new OMPTraitInfo object owned by this context.
friend class CXXRecordDecl
Definition ASTContext.h:613
CanQualType UnsignedLongTy
llvm::DenseSet< const FunctionDecl * > CUDAImplicitHostDeviceFunUsedByDevice
Keep track of CUDA/HIP implicit host device functions used on device side in device compilation.
void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass, SmallVectorImpl< const ObjCIvarDecl * > &Ivars) const
DeepCollectObjCIvars - This routine first collects all declared, but not synthesized,...
bool computeBestEnumTypes(bool IsPacked, unsigned NumNegativeBits, unsigned NumPositiveBits, QualType &BestType, QualType &BestPromotionType)
Compute BestType and BestPromotionType for an enum based on the highest number of negative and positi...
llvm::APFixedPoint getFixedPointMin(QualType Ty) const
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType adjustType(QualType OldType, llvm::function_ref< QualType(QualType)> Adjust) const
Rebuild a type, preserving any existing type sugar.
void addedLocalImportDecl(ImportDecl *Import)
Notify the AST context that a new import declaration has been parsed or implicitly created within thi...
bool hasAnyFunctionEffects() const
const TranslationUnitKind TUKind
Definition ASTContext.h:853
QualType getQualifiedType(const Type *T, Qualifiers Qs) const
Return a type with additional qualifiers.
CanQualType UnsignedLongAccumTy
QualType AutoRRefDeductTy
QualType getRestrictType(QualType T) const
Return the uniqued reference to the type for a restrict qualified type.
RawComment * getRawCommentNoCacheImpl(RawCommentLookupKey Key, const SourceLocation RepresentativeLoc, const std::map< unsigned, RawComment * > &CommentsInFile) const
CountAttributedType * getIncompleteCountAttributedType(QualType WrappedTy, bool CountInBytes, bool OrNull) const
Return a CountAttributedType whose count expression has not been parsed yet, for use by a late-parsed...
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
CanQualType ShortFractTy
QualType getStringLiteralArrayType(QualType EltTy, unsigned Length) const
Return a type for a constant array for a string literal of the specified element type and length.
QualType getCorrespondingSaturatedType(QualType Ty) const
bool arePFPFieldsTriviallyCopyable(const RecordDecl *RD) const
Returns whether this record's PFP fields (if any) are trivially copyable (i.e.
bool isSameEntity(const NamedDecl *X, const NamedDecl *Y) const
Determine whether the two declarations refer to the same entity.
QualType getBOOLType() const
type of 'BOOL' type.
QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl, unsigned Index, bool Final, const TemplateArgument &ArgPack)
llvm::DenseMap< const CXXMethodDecl *, CXXCastPath > LambdaCastPaths
For capturing lambdas with an explicit object parameter whose type is derived from the lambda type,...
CanQualType BoundMemberTy
CanQualType SatUnsignedShortFractTy
CanQualType CharTy
QualType removeAddrSpaceQualType(QualType T) const
Remove any existing address space on the type and returns the type with qualifiers intact (or that's ...
bool hasSameFunctionTypeIgnoringParamABI(QualType T, QualType U) const
Determine if two function types are the same, ignoring parameter ABI annotations.
TypedefDecl * getInt128Decl() const
Retrieve the declaration for the 128-bit signed integer type.
unsigned getOpenMPDefaultSimdAlign(QualType T) const
Get default simd alignment of the specified complete type in bits.
QualType getObjCSuperType() const
Returns the C struct type for objc_super.
QualType getBlockDescriptorType() const
Gets the struct used to keep track of the descriptor for pointer to blocks.
bool CommentsLoaded
True if comments are already loaded from ExternalASTSource.
BlockVarCopyInit getBlockVarCopyInit(const VarDecl *VD) const
Get the copy initialization expression of the VarDecl VD, or nullptr if none exists.
QualType getHLSLInlineSpirvType(uint32_t Opcode, uint32_t Size, uint32_t Alignment, ArrayRef< SpirvOperand > Operands)
unsigned NumImplicitMoveConstructorsDeclared
The number of implicitly-declared move constructors for which declarations were built.
bool isInSameModule(const Module *M1, const Module *M2) const
If the two module M1 and M2 are in the same module.
unsigned NumImplicitCopyConstructorsDeclared
The number of implicitly-declared copy constructors for which declarations were built.
QualType getLeastIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
CanQualType IntTy
CanQualType PseudoObjectTy
QualType getWebAssemblyExternrefType() const
Return a WebAssembly externref type.
void setTraversalScope(const std::vector< Decl * > &)
CharUnits getTypeUnadjustedAlignInChars(QualType T) const
getTypeUnadjustedAlignInChars - Return the ABI-specified alignment of a type, in characters,...
QualType getAdjustedType(QualType Orig, QualType New) const
Return the uniqued reference to a type adjusted from the original type to a new type.
CanQualType getComplexType(CanQualType T) const
friend class NestedNameSpecifier
Definition ASTContext.h:240
void PrintStats() const
MangleContext * cudaNVInitDeviceMC()
unsigned getAlignOfGlobalVar(QualType T, const VarDecl *VD) const
Return the alignment in bits that should be given to a global variable with type T.
bool areCompatibleOverflowBehaviorTypes(QualType LHS, QualType RHS)
Return true if two OverflowBehaviorTypes are compatible for assignment.
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
MangleNumberingContext & getManglingNumberContext(const DeclContext *DC)
Retrieve the context for computing mangling numbers in the given DeclContext.
comments::FullComment * getLocalCommentForDeclUncached(const Decl *D) const
Return parsed documentation comment attached to a given declaration.
unsigned NumImplicitDestructors
The number of implicitly-declared destructors.
CanQualType Float16Ty
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
bool isAlignmentRequired(const Type *T) const
Determine if the alignment the type has was required using an alignment attribute.
TagDecl * MSGuidTagDecl
bool areComparableObjCPointerTypes(QualType LHS, QualType RHS)
MangleContext * createDeviceMangleContext(const TargetInfo &T)
Creates a device mangle context to correctly mangle lambdas in a mixed architecture compile by settin...
CharUnits getExnObjectAlignment() const
Return the alignment (in bytes) of the thrown exception object.
CanQualType SignedCharTy
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
ASTMutationListener * Listener
Definition ASTContext.h:856
void setNonKeyFunction(const CXXMethodDecl *method)
Observe that the given method cannot be a key function.
CanQualType ObjCBuiltinBoolTy
TypeInfoChars getTypeInfoInChars(const Type *T) const
QualType getPredefinedSugarType(PredefinedSugarType::Kind KD) const
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
LangAS getDefaultOpenCLPointeeAddrSpace()
Returns default address space based on OpenCL version and enabled features.
TemplateParamObjectDecl * getTemplateParamObjectDecl(QualType T, const APValue &V) const
Return the template parameter object of the given type with the given value.
interp::Context & getInterpContext() const
Returns the clang bytecode interpreter context.
const SourceManager & getSourceManager() const
Definition ASTContext.h:912
CanQualType OverloadTy
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
TemplateTemplateParmDecl * getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const
Canonicalize the given TemplateTemplateParmDecl.
CanQualType OCLClkEventTy
void adjustExceptionSpec(FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI, bool AsWritten=false)
Change the exception specification on a function once it is delay-parsed, instantiated,...
TypedefDecl * getUInt128Decl() const
Retrieve the declaration for the 128-bit unsigned integer type.
CharUnits getPreferredTypeAlignInChars(QualType T) const
Return the PreferredAlignment of a (complete) type T, in characters.
bool hasPFPFields(QualType Ty) const
const clang::PrintingPolicy & getPrintingPolicy() const
Definition ASTContext.h:903
void ResetObjCLayout(const ObjCInterfaceDecl *D)
ArrayRef< Module * > getModulesWithMergedDefinition(const NamedDecl *Def)
Get the additional modules in which the definition Def has been merged.
static ImportDecl * getNextLocalImport(ImportDecl *Import)
void setCtorClosureDefaultArgs(const CXXConstructorDecl *CD, ArrayRef< CXXDefaultArgExpr * > Args)
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
CanQualType SatUnsignedShortAccumTy
QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, bool Unqualified=false, bool BlockReturnType=false, bool IsConditionalOperator=false)
CharUnits getAlignOfGlobalVarInChars(QualType T, const VarDecl *VD) const
Return the alignment in characters that should be given to a global variable with type T.
const ObjCMethodDecl * getObjCMethodRedeclaration(const ObjCMethodDecl *MD) const
Get the duplicate declaration of a ObjCMethod in the same interface, or null if none exists.
QualType getPackIndexingType(QualType Pattern, Expr *IndexExpr, bool FullySubstituted=false, ArrayRef< QualType > Expansions={}, UnsignedOrNone Index=std::nullopt) const
static bool isObjCNSObjectType(QualType Ty)
Return true if this is an NSObject object with its NSObject attribute set.
GVALinkage GetGVALinkageForVariable(const VarDecl *VD) const
llvm::PointerUnion< VarTemplateDecl *, MemberSpecializationInfo * > TemplateOrSpecializationInfo
A type synonym for the TemplateOrInstantiation mapping.
Definition ASTContext.h:605
UsingShadowDecl * getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst)
QualType getWCharType() const
Return the unique wchar_t type available in C++ (and available as __wchar_t as a Microsoft extension)...
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a non-unique reference to the type for a variable array of the specified element type.
QualType getObjCIdType() const
Represents the Objective-CC id type.
Decl * getVaListTagDecl() const
Retrieve the C type declaration corresponding to the predefined __va_list_tag type used to help defin...
QualType getUnsignedWCharType() const
Return the type of "unsigned wchar_t".
QualType getFunctionTypeWithoutParamABIs(QualType T) const
Get or construct a function type that is equivalent to the input type except that the parameter ABI a...
QualType getCorrespondingUnsaturatedType(QualType Ty) const
comments::FullComment * getCommentForDecl(const Decl *D, const Preprocessor *PP) const
Return parsed documentation comment attached to a given declaration.
TemplateArgument getInjectedTemplateArg(NamedDecl *ParamDecl) const
unsigned getTargetDefaultAlignForAttributeAligned() const
Return the default alignment for attribute((aligned)) on this target, to be used if no alignment valu...
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
llvm::DenseMap< CanQualType, SYCLKernelInfo > SYCLKernels
Map of SYCL kernels indexed by the unique type used to name the kernel.
bool isSameTemplateParameterList(const TemplateParameterList *X, const TemplateParameterList *Y) const
Determine whether two template parameter lists are similar enough that they may be used in declaratio...
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
QualType getTypeDeclType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypeDecl *Decl) const
bool isDestroyingOperatorDelete(const FunctionDecl *FD) const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CanQualType UnsignedInt128Ty
CanQualType BuiltinFnTy
ObjCInterfaceDecl * getObjCProtocolDecl() const
Retrieve the Objective-C class declaration corresponding to the predefined Protocol class.
unsigned NumImplicitDefaultConstructors
The number of implicitly-declared default constructors.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
llvm::iterator_range< overridden_cxx_method_iterator > overridden_method_range
unsigned NumImplicitMoveAssignmentOperatorsDeclared
The number of implicitly-declared move assignment operators for which declarations were built.
void setManglingNumber(const NamedDecl *ND, unsigned Number)
CanQualType OCLSamplerTy
TypedefDecl * getBuiltinVaListDecl() const
Retrieve the C type declaration corresponding to the predefined __builtin_va_list type.
TypeInfo getTypeInfo(QualType T) const
CanQualType getCanonicalTypeDeclType(const TypeDecl *TD) const
CanQualType VoidTy
QualType getPackExpansionType(QualType Pattern, UnsignedOrNone NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
CanQualType UnsignedCharTy
CanQualType UnsignedShortFractTy
BuiltinTemplateDecl * buildBuiltinTemplateDecl(BuiltinTemplateKind BTK, const IdentifierInfo *II) const
void * Allocate(size_t Size, unsigned Align=8) const
Definition ASTContext.h:924
ArrayRef< ExplicitInstantiationDecl * > getExplicitInstantiationDecls(const NamedDecl *Spec) const
Get all ExplicitInstantiationDecls for a given specialization.
bool canBuiltinBeRedeclared(const FunctionDecl *) const
Return whether a declaration to a builtin is allowed to be overloaded/redeclared.
CanQualType UnsignedIntTy
unsigned NumImplicitMoveConstructors
The number of implicitly-declared move constructors.
QualType getTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypedefNameDecl *Decl, QualType UnderlyingType=QualType(), std::optional< bool > TypeMatchesDeclOrNone=std::nullopt) const
Return the unique reference to the type for the specified typedef-name decl.
QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl, ArrayRef< ObjCProtocolDecl * > protocols) const
QualType getVolatileType(QualType T) const
Return the uniqued reference to the type for a volatile qualified type.
void getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT, QualType T, std::string &S, bool Extended) const
getObjCEncodingForMethodParameter - Return the encoded type for a single method parameter or return t...
static bool isPFPField(const FieldDecl *Field)
void addDeclaratorForUnnamedTagDecl(TagDecl *TD, DeclaratorDecl *DD)
unsigned overridden_methods_size(const CXXMethodDecl *Method) const
std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const
Return the encoded type for this block declaration.
QualType getTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName T, ArrayRef< TemplateArgument > SpecifiedArgs, ArrayRef< TemplateArgument > CanonicalArgs, QualType Underlying=QualType()) const
TypeSourceInfo * CreateTypeSourceInfo(QualType T, unsigned Size=0) const
Allocate an uninitialized TypeSourceInfo.
TagDecl * getMSTypeInfoTagDecl() const
Retrieve the implicitly-predeclared 'struct type_info' declaration.
TemplateName getQualifiedTemplateName(NestedNameSpecifier Qualifier, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getObjCClassRedefinitionType() const
Retrieve the type that Class has been defined to, which may be different from the built-in Class if C...
TagDecl * getMSGuidTagDecl() const
Retrieve the implicitly-predeclared 'struct _GUID' declaration.
bool isSameAssociatedConstraint(const AssociatedConstraint &ACX, const AssociatedConstraint &ACY) const
Determine whether two 'requires' expressions are similar enough that they may be used in re-declarati...
QualType getExceptionObjectType(QualType T) const
CanQualType UnknownAnyTy
void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Note that the static data member Inst is an instantiation of the static data member template Tmpl of ...
FieldDecl * getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field) const
DeclaratorDecl * getDeclaratorForUnnamedTagDecl(const TagDecl *TD)
bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl)
ObjCObjectAdoptsQTypeProtocols - Checks that protocols in IC's protocol list adopt all protocols in Q...
QualType getFunctionNoProtoType(QualType ResultTy) const
CanQualType UnsignedLongLongTy
QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, unsigned *IntegerConstantArgs=nullptr) const
Return the type for the specified builtin.
CanQualType OCLReserveIDTy
bool isSameTemplateParameter(const NamedDecl *X, const NamedDecl *Y) const
Determine whether two template parameters are similar enough that they may be used in declarations of...
void registerSYCLEntryPointFunction(FunctionDecl *FD)
Generates and stores SYCL kernel metadata for the provided SYCL kernel entry point function.
QualType getTypeDeclType(const TagDecl *) const =delete
Use the normal 'getFooBarType' constructors to obtain these types.
size_t getASTAllocatedMemory() const
Return the total amount of physical memory allocated for representing AST nodes and type information.
Definition ASTContext.h:958
QualType getArrayDecayedType(QualType T) const
Return the properly qualified result of decaying the specified array type to a pointer.
overridden_cxx_method_iterator overridden_methods_begin(const CXXMethodDecl *Method) const
CanQualType UnsignedShortTy
FunctionDecl * getOperatorDeleteForVDtor(const CXXDestructorDecl *Dtor, OperatorDeleteKind K) const
unsigned getTypeAlignIfKnown(QualType T, bool NeedsPreferredAlignment=false) const
Return the alignment of a type, in bits, or 0 if the type is incomplete and we cannot determine the a...
void UnwrapSimilarArrayTypes(QualType &T1, QualType &T2, bool AllowPiMismatch=true) const
Attempt to unwrap two types that may both be array types with the same bound (or both be array types ...
QualType getObjCConstantStringInterface() const
bool isRepresentableIntegerValue(llvm::APSInt &Value, QualType T)
Determine whether the given integral value is representable within the given type T.
bool AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
llvm::DenseMap< RawCommentLookupKey, const RawComment * > RawComments
Mapping from declaration or macro to directly attached comment.
const SYCLKernelInfo & getSYCLKernelInfo(QualType T) const
Given a type used as a SYCL kernel name, returns a reference to the metadata generated from the corre...
bool canAssignObjCInterfacesInBlockPointer(const ObjCObjectPointerType *LHSOPT, const ObjCObjectPointerType *RHSOPT, bool BlockReturnType)
canAssignObjCInterfacesInBlockPointer - This routine is specifically written for providing type-safet...
CanQualType SatUnsignedLongFractTy
QualType getMemberPointerType(QualType T, NestedNameSpecifier Qualifier, const CXXRecordDecl *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
void setcudaConfigureCallDecl(FunctionDecl *FD)
CanQualType getDecayedType(CanQualType T) const
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
QualType getObjCIdRedefinitionType() const
Retrieve the type that id has been defined to, which may be different from the built-in id if id has ...
const CXXConstructorDecl * getCopyConstructorForExceptionObject(CXXRecordDecl *RD)
QualType getDependentAddressSpaceType(QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttrLoc) const
QualType getTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TagDecl *TD, bool OwnsTag) const
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const
Make an APSInt of the appropriate width and signedness for the given Value and integer Type.
CanQualType getMSGuidType() const
Retrieve the implicitly-predeclared 'struct _GUID' type.
const VariableArrayType * getAsVariableArrayType(QualType T) const
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
void setExternalSource(IntrusiveRefCntPtr< ExternalASTSource > Source)
Attach an external AST source to the AST context.
const ObjCInterfaceDecl * getObjContainingInterface(const NamedDecl *ND) const
Returns the Objective-C interface that ND belongs to if it is an Objective-C method/property/ivar etc...
CanQualType ShortTy
StringLiteral * getPredefinedStringLiteralFromCache(StringRef Key) const
Return a string representing the human readable name for the specified function declaration or file n...
CanQualType getCanonicalUnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) const
bool hasSimilarType(QualType T1, QualType T2) const
Determine if two types are similar, according to the C++ rules.
llvm::APFixedPoint getFixedPointMax(QualType Ty) const
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
void setObjCClassRedefinitionType(QualType RedefType)
Set the user-written type that redefines 'SEL'.
bool classMaybeNeedsVectorDeletingDestructor(const CXXRecordDecl *RD)
QualType getTemplateTypeParmType(int Depth, int Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
bool hasDirectOwnershipQualifier(QualType Ty) const
Return true if the type has been explicitly qualified with ObjC ownership.
CanQualType FractTy
Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const
Recurses in pointer/array types until it finds an Objective-C retainable type and returns its ownersh...
void addCopyConstructorForExceptionObject(CXXRecordDecl *RD, CXXConstructorDecl *CD)
void deduplicateMergedDefinitionsFor(NamedDecl *ND)
Clean up the merged definition list.
FunctionDecl * getcudaConfigureCallDecl()
static uint64_t getConstantArrayElementCount(const ConstantArrayType *CA)
Return number of (potentially nested) constant array elements.
DiagnosticsEngine & getDiagnostics() const
llvm::StringRef backupStr(llvm::StringRef S) const
Definition ASTContext.h:932
QualType getAdjustedParameterType(QualType T) const
Perform adjustment on the parameter type of a function.
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
CanQualType LongAccumTy
CanQualType Char32Ty
void recordOffsetOfEvaluation(const OffsetOfExpr *E)
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
QualType getCVRQualifiedType(QualType T, unsigned CVR) const
Return a type with additional const, volatile, or restrict qualifiers.
UnnamedGlobalConstantDecl * getUnnamedGlobalConstantDecl(QualType Ty, const APValue &Value) const
Return a declaration for a uniquified anonymous global constant corresponding to a given APValue.
CanQualType SatFractTy
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
QualType getUnresolvedUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const UnresolvedUsingTypenameDecl *D) const
bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec)
Return true if the given vector types are of the same unqualified type or if they are equivalent to t...
void getOverriddenMethods(const NamedDecl *Method, SmallVectorImpl< const NamedDecl * > &Overridden) const
Return C++ or ObjC overridden methods for the given Method.
DeclarationNameInfo getNameForTemplate(TemplateName Name, SourceLocation NameLoc) const
bool hasSameTemplateName(const TemplateName &X, const TemplateName &Y, bool IgnoreDeduced=false) const
Determine whether the given template names refer to the same template.
CanQualType SatLongFractTy
const TargetInfo & getTargetInfo() const
Definition ASTContext.h:969
void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl)
CanQualType OCLQueueTy
CanQualType LongFractTy
OBTAssignResult checkOBTAssignmentCompatibility(QualType LHS, QualType RHS)
Check overflow behavior type compatibility for assignments.
CanQualType SatShortAccumTy
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
CanQualType BFloat16Ty
unsigned NumImplicitCopyConstructors
The number of implicitly-declared copy constructors.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
static uint64_t getArrayInitLoopExprElementCount(const ArrayInitLoopExpr *AILE)
Return number of elements initialized in a (potentially nested) ArrayInitLoopExpr.
void addExplicitInstantiationDecl(const NamedDecl *Spec, ExplicitInstantiationDecl *EID)
Add an ExplicitInstantiationDecl for a given specialization.
QualType getOverflowBehaviorType(const OverflowBehaviorAttr *Attr, QualType Wrapped) const
CanQualType IncompleteMatrixIdxTy
std::optional< CharUnits > getTypeSizeInCharsIfKnown(QualType Ty) const
CXXRecordDecl *& getLambdaDeclarationSlotForMerging(const Decl *ContextDecl, int IndexInContext)
Definition ASTContext.h:744
friend class DeclarationNameTable
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *) const
CanQualType getNSIntegerType() const
QualType getCorrespondingUnsignedType(QualType T) const
void setBlockVarCopyInit(const VarDecl *VD, Expr *CopyExpr, bool CanThrow)
Set the copy initialization expression of a block var decl.
QualType getLifetimeQualifiedType(QualType type, Qualifiers::ObjCLifetime lifetime)
Return a type with the given lifetime qualifier.
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
bool typesAreCompatible(QualType T1, QualType T2, bool CompareUnqualified=false)
Compatibility predicates used to check assignment expressions.
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
QualType getObjCNSStringType() const
TargetCXXABI::Kind getCXXABIKind() const
Return the C++ ABI kind that should be used.
void setjmp_bufDecl(TypeDecl *jmp_bufDecl)
Set the type for the C jmp_buf type.
QualType getHLSLAttributedResourceType(QualType Wrapped, QualType Contained, const HLSLAttributedResourceType::Attributes &Attrs)
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
bool UnwrapSimilarTypes(QualType &T1, QualType &T2, bool AllowPiMismatch=true) const
Attempt to unwrap two types that may be similar (C++ [conv.qual]).
IntrusiveRefCntPtr< ExternalASTSource > getExternalSourcePtr() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
QualType getSignedSizeType() const
Return the unique signed counterpart of the integer type corresponding to size_t.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
void setcudaGetParameterBufferDecl(FunctionDecl *FD)
CanQualType SatUnsignedLongAccumTy
QualType getUnconstrainedType(QualType T) const
Remove any type constraints from a template parameter type, for equivalence comparison of template pa...
CanQualType LongLongTy
CanQualType getCanonicalTagType(const TagDecl *TD) const
bool isSameTemplateArgument(const TemplateArgument &Arg1, const TemplateArgument &Arg2) const
Determine whether the given template arguments Arg1 and Arg2 are equivalent.
QualType getTypeOfType(QualType QT, TypeOfKind Kind) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes.
QualType getCorrespondingSignedType(QualType T) const
QualType mergeObjCGCQualifiers(QualType, QualType)
mergeObjCGCQualifiers - This routine merges ObjC's GC attribute of 'LHS' and 'RHS' attributes and ret...
QualType getQualifiedType(QualType T, Qualifiers Qs) const
Return a type with additional qualifiers.
llvm::DenseMap< const Decl *, const Decl * > CommentlessRedeclChains
Keeps track of redeclaration chains that don't have any comment attached.
unsigned getTargetAddressSpace(LangAS AS) const
std::vector< PFPField > findPFPFields(QualType Ty) const
Returns a list of PFP fields for the given type, including subfields in bases or other fields,...
QualType getWideCharType() const
Return the type of wide characters.
QualType getIntPtrType() const
Return a type compatible with "intptr_t" (C99 7.18.1.4), as defined by the target.
void mergeDefinitionIntoModule(NamedDecl *ND, Module *M, bool NotifyListeners=true)
Note that the definition ND has been merged into module M, and should be visible whenever M is visibl...
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
void addTranslationUnitDecl()
CanQualType WCharTy
bool hasSameNullabilityTypeQualifier(QualType SubT, QualType SuperT, bool IsParam) const
void getObjCEncodingForPropertyType(QualType T, std::string &S) const
Emit the Objective-C property type encoding for the given type T into S.
unsigned NumImplicitCopyAssignmentOperators
The number of implicitly-declared copy assignment operators.
void CollectInheritedProtocols(const Decl *CDecl, llvm::SmallPtrSet< ObjCProtocolDecl *, 8 > &Protocols)
CollectInheritedProtocols - Collect all protocols in current class and those inherited by it.
bool isPromotableIntegerType(QualType T) const
More type predicates useful for type checking/promotion.
T * Allocate(size_t Num=1) const
Definition ASTContext.h:927
llvm::DenseMap< const Decl *, const Decl * > RedeclChainComments
Mapping from canonical declaration to the first redeclaration in chain that has a comment attached.
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType)
Change the result type of a function type once it is deduced.
QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const
Return the uniqued reference to the type for an Objective-C gc-qualified type.
QualType getPointerAuthType(QualType Ty, PointerAuthQualifier PointerAuth)
Return a type with the given __ptrauth qualifier.
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
std::optional< CXXRecordDeclRelocationInfo > getRelocationInfoForCXXRecord(const CXXRecordDecl *) const
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
InlineVariableDefinitionKind getInlineVariableDefinitionKind(const VarDecl *VD) const
Determine whether a definition of this inline variable should be treated as a weak or strong definiti...
const RawComment * getRawCommentForAnyRedecl(RawCommentLookupKey Key, const Decl **OriginalDecl=nullptr) const
Return the documentation comment attached to a given declaration or macro.
void setPrimaryMergedDecl(Decl *D, Decl *Primary)
TemplateName getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl, unsigned Index, UnsignedOrNone PackIndex, bool Final) const
CanQualType getUIntMaxType() const
Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in <stdint.h>.
IdentifierInfo * getBoolName() const
Retrieve the identifier 'bool'.
friend class DeclContext
CharUnits getOffsetOfBaseWithVBPtr(const CXXRecordDecl *RD) const
Loading virtual member pointers using the virtual inheritance model always results in an adjustment u...
LangAS getLangASForBuiltinAddressSpace(unsigned AS) const
bool hasSameFunctionTypeIgnoringPtrSizes(QualType T, QualType U)
Determine whether two function types are the same, ignoring pointer sizes in the return type and para...
void addOperatorDeleteForVDtor(const CXXDestructorDecl *Dtor, FunctionDecl *OperatorDelete, OperatorDeleteKind K) const
unsigned char getFixedPointScale(QualType Ty) const
QualType getIncompleteArrayType(QualType EltTy, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a unique reference to the type for an incomplete array of the specified element type.
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
QualType DecodeTypeStr(const char *&Str, const ASTContext &Context, ASTContext::GetBuiltinTypeError &Error, bool &RequireICE, bool AllowTypeModifiers) const
void addObjCSubClass(const ObjCInterfaceDecl *D, const ObjCInterfaceDecl *SubClass)
TemplateName getAssumedTemplateName(DeclarationName Name) const
Retrieve a template name representing an unqualified-id that has been assumed to name a template for ...
@ GE_None
No error.
@ GE_Missing_stdio
Missing a type from <stdio.h>
@ GE_Missing_type
Missing a type.
@ GE_Missing_ucontext
Missing a type from <ucontext.h>
@ GE_Missing_setjmp
Missing a type from <setjmp.h>
QualType adjustStringLiteralBaseType(QualType StrLTy) const
uint16_t getPointerAuthTypeDiscriminator(QualType T)
Return the "other" type-specific discriminator for the given type.
llvm::SetVector< const FieldDecl * > PFPFieldsWithEvaluatedOffset
uint16_t getPointerAuthVTablePointerDiscriminator(const CXXRecordDecl *RD, bool IsVTTEntry)
Return the "other" discriminator used for the pointer auth schema used for vtable pointers using the ...
bool canonicalizeTemplateArguments(MutableArrayRef< TemplateArgument > Args) const
Canonicalize the given template argument list.
QualType getTypeOfExprType(Expr *E, TypeOfKind Kind) const
C23 feature and GCC extension.
QualType getMatrixTypeWithLayout(QualType T, MatrixType::LayoutKind Layout) const
CanQualType Char8Ty
bool isUnaryOverflowPatternExcluded(const UnaryOperator *UO)
QualType getSignedWCharType() const
Return the type of "signed wchar_t".
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals) const
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals.
QualType getTypeDeclType(const TypedefDecl *) const =delete
bool hasCvrSimilarType(QualType T1, QualType T2)
Determine if two types are similar, ignoring only CVR qualifiers.
TemplateName getDeducedTemplateName(TemplateName Underlying, DefaultArguments DefaultArgs) const
Represents a TemplateName which had some of its default arguments deduced.
ObjCImplementationDecl * getObjCImplementation(ObjCInterfaceDecl *D)
Get the implementation of the ObjCInterfaceDecl D, or nullptr if none exists.
CanQualType HalfTy
CanQualType UnsignedAccumTy
void setObjCMethodRedeclaration(const ObjCMethodDecl *MD, const ObjCMethodDecl *Redecl)
void addTypedefNameForUnnamedTagDecl(TagDecl *TD, TypedefNameDecl *TND)
bool isDependenceAllowed() const
QualType getWIntType() const
In C99, this returns a type compatible with the type defined in <stddef.h> as defined by the target.
const CXXRecordDecl * baseForVTableAuthentication(const CXXRecordDecl *ThisClass) const
Resolve the root record to be used to derive the vtable pointer authentication policy for the specifi...
void cacheRawComment(RawCommentLookupKey Original, const RawComment &Comment) const
Attaches Comment to Original (a declaration or macro), and to its redeclaration chain when Original i...
QualType getVariableArrayDecayedType(QualType Ty) const
Returns a vla type where known sizes are replaced with [*].
void setCFConstantStringType(QualType T)
const SYCLKernelInfo * findSYCLKernelInfo(QualType T) const
Returns a pointer to the metadata generated from the corresponding SYCLkernel entry point if the prov...
ASTContext & operator=(const ASTContext &)=delete
Module * getCurrentNamedModule() const
Get module under construction, nullptr if this is not a C++20 module.
unsigned getParameterIndex(const ParmVarDecl *D) const
Used by ParmVarDecl to retrieve on the side the index of the parameter when it exceeds the size of th...
QualType getCommonSugaredType(QualType X, QualType Y, bool Unqualified=false) const
CanQualType OCLEventTy
void setPrintingPolicy(const clang::PrintingPolicy &Policy)
Definition ASTContext.h:907
void AddDeallocation(void(*Callback)(void *), void *Data) const
Add a deallocation callback that will be invoked when the ASTContext is destroyed.
AttrVec & getDeclAttrs(const Decl *D)
Retrieve the attributes for the given declaration.
QualType getDeducedTemplateSpecializationType(DeducedKind DK, QualType DeducedAsType, ElaboratedTypeKeyword Keyword, TemplateName Template) const
C++17 deduced class template specialization type.
CXXMethodVector::const_iterator overridden_cxx_method_iterator
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
QualType mergeTransparentUnionType(QualType, QualType, bool OfBlockPointer=false, bool Unqualified=false)
mergeTransparentUnionType - if T is a transparent union type and a member of T is compatible with Sub...
QualType isPromotableBitField(Expr *E) const
Whether this is a promotable bitfield reference according to C99 6.3.1.1p2, bullet 2 (and GCC extensi...
bool isSentinelNullExpr(const Expr *E)
CanQualType getNSUIntegerType() const
IdentifierInfo * getNSCopyingName()
Retrieve the identifier 'NSCopying'.
void setIsDestroyingOperatorDelete(const FunctionDecl *FD, bool IsDestroying)
TypedefDecl * getBuiltinZOSVaListDecl() const
Retrieve the C type declaration corresponding to the predefined __builtin_zos_va_list type.
void recordMemberDataPointerEvaluation(const ValueDecl *VD)
uint64_t getCharWidth() const
Return the size of the character type, in bits.
CanQualType getPointerType(CanQualType T) const
QualType getUnqualifiedArrayType(QualType T) const
import_range local_imports() const
QualType getBitIntType(bool Unsigned, unsigned NumBits) const
Return a bit-precise integer type with the specified signedness and bit count.
const DependentSizedArrayType * getAsDependentSizedArrayType(QualType T) const
unsigned NumImplicitMoveAssignmentOperators
The number of implicitly-declared move assignment operators.
FunctionDecl * getcudaLaunchDeviceDecl()
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Represents a loop initializing the elements of an array.
Definition Expr.h:6018
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3820
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6978
Attr - This represents one attribute.
Definition Attr.h:46
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6722
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
This class is used for builtin types like 'int'.
Definition TypeBase.h:3245
Holds information about both target-independent and target-specific builtins, allowing easy queries b...
Definition Builtins.h:236
Implements C++ ABI-specific semantic analysis functions.
Definition CXXABI.h:29
Represents a C++ constructor within a class.
Definition DeclCXX.h:2642
Represents a C++ destructor within a class.
Definition DeclCXX.h:2907
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
static CanQual< Type > CreateUnsafe(QualType Other)
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
Declaration of a C++20 concept.
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3858
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition TypeBase.h:3509
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
A list storing NamedDecls in the lookup tables.
Definition DeclBase.h:1346
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
Definition DeclBase.h:198
bool isInvalidDecl() const
Definition DeclBase.h:596
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:995
The name of a declaration.
Represents a ValueDecl that came out of a declarator.
Definition Decl.h:781
Represents an array type in C++ whose size is a value-dependent expression.
Definition TypeBase.h:4109
Represents a dependent template name that cannot be resolved prior to template instantiation.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:232
Container for either a single DynTypedNode or for an ArrayRef to DynTypedNode.
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3558
llvm::APSInt getInitVal() const
Definition Decl.h:3578
Represents an explicit instantiation of a template entity in source code.
This represents one expression.
Definition Expr.h:113
Declaration context for names declared as extern "C" in C++.
Definition Decl.h:248
Abstract interface for external sources of AST nodes.
Represents a member of a struct/union/class.
Definition Decl.h:3295
A SourceLocation and its associated SourceManager.
Represents a function declaration or definition.
Definition Decl.h:2059
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5416
A class which abstracts out some details necessary for making a call.
Definition TypeBase.h:4723
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition TypeBase.h:4612
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:60
One of these records is kept for each identifier that is lexed.
Implements an efficient mapping from strings to IdentifierInfo nodes.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5191
Represents a C array with an unspecified size.
Definition TypeBase.h:4007
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A global _GUID constant.
Definition DeclCXX.h:4451
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
Definition Mangle.h:56
Keeps track of the mangled names of lambda expressions and block literals within a particular context...
Provides information a specialization of a member of a class template, which may be a member function...
Describes a module or submodule.
Definition Module.h:340
This represents a decl that may have a name.
Definition Decl.h:275
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2335
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition DeclObjC.h:2551
ObjCContainerDecl - Represents a container for method declarations.
Definition DeclObjC.h:954
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition DeclObjC.h:2603
Represents an ObjC class declaration.
Definition DeclObjC.h:1160
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1958
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Represents a pointer to an Objective C object.
Definition TypeBase.h:8087
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:734
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition DeclObjC.h:2811
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2090
Represents the declaration of an Objective-C type parameter.
Definition DeclObjC.h:581
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2571
Represents a parameter to a function.
Definition Decl.h:1820
Pointer-authentication qualifiers.
Definition TypeBase.h:153
PredefinedSugarKind Kind
Definition TypeBase.h:8357
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
A (possibly-)qualified type.
Definition TypeBase.h:938
PointerAuthQualifier getPointerAuth() const
Definition TypeBase.h:1469
A qualifier set is used to build a set of qualifiers.
Definition TypeBase.h:8386
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Definition TypeBase.h:8393
The collection of all-type qualifiers we support.
Definition TypeBase.h:332
@ OCL_None
There is no lifetime qualification on this type.
Definition TypeBase.h:351
void removeObjCLifetime()
Definition TypeBase.h:552
bool hasNonFastQualifiers() const
Return true if the set contains any qualifiers which require an ExtQuals node to be allocated.
Definition TypeBase.h:639
unsigned getFastQualifiers() const
Definition TypeBase.h:620
static Qualifiers fromCVRMask(unsigned CVR)
Definition TypeBase.h:436
void setPointerAuth(PointerAuthQualifier Q)
Definition TypeBase.h:607
void addObjCLifetime(ObjCLifetime type)
Definition TypeBase.h:553
This class represents all comments included in the translation unit, sorted in order of appearance in...
Represents a struct/union/class.
Definition Decl.h:4460
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4644
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition Decl.h:5468
This table allows us to fully hide how we implement multi-keyword caching.
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
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.
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
clang::DiagStorageAllocator DiagStorageAllocator
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1819
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3852
TagTypeKind TagKind
Definition Decl.h:3857
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3953
Kind
The basic C++ ABI kind.
Exposes information about the current target.
Definition TargetInfo.h:226
A convenient class for passing around template argument information.
Represents a template argument.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Represents a C++ template name within the type system.
A template parameter object.
Stores a list of template parameters for a TemplateDecl and its derived classes.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Declaration of a template type parameter.
Token - This structure provides full information about a lexed token.
Definition Token.h:36
The top declaration context.
Definition Decl.h:106
static TranslationUnitDecl * Create(ASTContext &C)
Definition Decl.cpp:5560
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition Decl.h:3823
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition ASTConcept.h:227
Represents a declaration of a type.
Definition Decl.h:3648
A container of type source information.
Definition TypeBase.h:8417
The base class of the type hierarchy.
Definition TypeBase.h:1879
bool isSizelessType() const
As an extension, we classify types as one of "sized" or "sizeless"; every type is one or the other.
Definition Type.cpp:2787
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
Definition Type.cpp:2413
bool isObjCNSObjectType() const
Definition Type.cpp:5597
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2863
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Definition TypeBase.h:9215
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2653
NullabilityKindOrNone getNullability() const
Determine the nullability of the given type.
Definition Type.cpp:5325
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3802
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3697
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2288
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition DeclCXX.h:4508
The iterator over UnresolvedSets.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition TypeBase.h:6131
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4067
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
Declaration of a variable template.
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:4064
Represents a GCC generic vector type.
Definition TypeBase.h:4273
This class provides information about commands that can be used in comments.
A full comment attached to a declaration, contains block content.
Definition Comment.h:1097
Holds all information required to evaluate constexpr code in a module.
Definition Context.h:49
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Stmt, BlockExpr > blockExpr
Matches a reference to a block.
llvm::FixedPointSemantics FixedPointSemantics
Definition Interp.h:57
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition Linkage.h:72
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition TypeBase.h:1838
bool isTargetAddressSpace(LangAS AS)
OpenCLTypeKind
OpenCL type kinds.
Definition TargetInfo.h:212
Stmt Stmt * Callback
Definition StmtOpenMP.h:919
NullabilityKind
Describes the nullability of a particular type.
Definition Specifiers.h:350
@ Nullable
Values of this type can be null.
Definition Specifiers.h:354
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
Definition Specifiers.h:359
@ NonNull
Values of this type can never be null.
Definition Specifiers.h:352
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
TypeOfKind
The kind of 'typeof' expression we're after.
Definition TypeBase.h:919
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition Linkage.h:54
Selector GetUnarySelector(StringRef name, ASTContext &Ctx)
Utility function for constructing an unary selector.
@ Result
The result type of a method or function.
Definition TypeBase.h:906
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition TypeBase.h:3817
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
Definition Parser.h:81
Selector GetNullarySelector(StringRef name, ASTContext &Ctx)
Utility function for constructing a nullary selector.
@ Class
The "class" keyword.
Definition TypeBase.h:6050
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
Definition Builtins.h:491
@ Keyword
The name has been typo-corrected to a keyword.
Definition Sema.h:556
LangAS
Defines the address space values used by the address space qualifier of QualType.
TranslationUnitKind
Describes the kind of translation unit being processed.
@ TU_Incremental
The translation unit is a is a complete translation unit that we might incrementally extend later.
DeducedKind
Definition TypeBase.h:1811
FloatModeKind
Definition TargetInfo.h:74
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
Definition ASTContext.h:147
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition Specifiers.h:192
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:282
U cast(CodeGen::Address addr)
Definition Address.h:327
AlignRequirementKind
Definition ASTContext.h:174
@ None
The alignment was not explicit in code.
Definition ASTContext.h:176
@ RequiredByEnum
The alignment comes from an alignment attribute on a enum type.
Definition ASTContext.h:185
@ RequiredByTypedef
The alignment comes from an alignment attribute on a typedef.
Definition ASTContext.h:179
@ RequiredByRecord
The alignment comes from an alignment attribute on a record type.
Definition ASTContext.h:182
@ PackIndex
Index of a pack indexing expression or specifier.
Definition Sema.h:845
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:6014
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:6035
@ Other
Other implicit parameter.
Definition Decl.h:1775
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
int32_t uint32_t
int32_t uint32_t uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
int32_t uint32_t uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 uint16_t
BuiltinVectorTypeInfo(QualType ElementType, llvm::ElementCount EC, unsigned NumVectors)
CUDAConstantEvalContextRAII(ASTContext &Ctx_, bool NoWrongSidedVars)
Definition ASTContext.h:868
BuiltinVectorTypeInfo(QualType ElementType, llvm::ElementCount EC, unsigned NumVectors)
CUDAConstantEvalContextRAII(ASTContext &Ctx_, bool NoWrongSidedVars)
Definition ASTContext.h:868
bool NoWrongSidedVars
Do not allow wrong-sided variables in constant expressions.
Definition ASTContext.h:863
SourceLocation PragmaSectionLocation
SectionInfo(NamedDecl *Decl, SourceLocation PragmaSectionLocation, int SectionFlags)
Copy initialization expr of a __block variable and a boolean flag that indicates whether the expressi...
Definition Expr.h:6768
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Holds information about the various types of exception specification.
Definition TypeBase.h:5473
Extra information about a function prototype.
Definition TypeBase.h:5501
A late-parsed attribute that will be applied as a type attribute.
Definition Parser.h:233
Parts of a decomposed MSGuidDecl.
Definition DeclCXX.h:4426
FieldDecl * Field
Definition ASTContext.h:218
CharUnits Offset
Definition ASTContext.h:217
Contains information gathered from parsing the contents of TargetAttr.
Definition TargetInfo.h:59
Describes how types, statements, expressions, and declarations should be printed.
UniquingSet info for pools keyed on a QualType and a bool.
Definition ASTContext.h:223
static unsigned getHashValue(const KeyTy &Key)
Definition ASTContext.h:228
static KeyTy getKey(const T &N)
Definition ASTContext.h:226
static bool isEqual(const KeyTy &Key, const T &N)
Definition ASTContext.h:232
std::pair< QualType, bool > KeyTy
Definition ASTContext.h:224
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition TypeBase.h:871
const Type * Ty
The locally-unqualified type.
Definition TypeBase.h:873
Qualifiers Quals
The local qualifiers.
Definition TypeBase.h:876
AlignRequirementKind AlignRequirement
Definition ASTContext.h:205
TypeInfoChars(CharUnits Width, CharUnits Align, AlignRequirementKind AlignRequirement)
Definition ASTContext.h:208
bool isAlignRequired()
Definition ASTContext.h:197
AlignRequirementKind AlignRequirement
Definition ASTContext.h:191
TypeInfo(uint64_t Width, unsigned Align, AlignRequirementKind AlignRequirement)
Definition ASTContext.h:194
static bool isEqual(const ScalableVecTyKey &LHS, const ScalableVecTyKey &RHS)
Definition ASTContext.h:77
static unsigned getHashValue(const ScalableVecTyKey &Val)
Definition ASTContext.h:73
static bool isEqual(FoldingSetNodeIDRef LHS, FoldingSetNodeIDRef RHS)
static unsigned getHashValue(FoldingSetNodeIDRef Val)
static bool isEqual(const FoldingSetNodeID &LHS, FoldingSetNodeIDRef RHS)
static unsigned getHashValue(const FoldingSetNodeID &Val)
static bool isEqual(const FoldingSetNodeID &LHS, const FoldingSetNodeID &RHS)
static unsigned getHashValue(const FoldingSetNodeID &Val)
clang::QualType EltTy
Definition ASTContext.h:60
bool operator==(const ScalableVecTyKey &RHS) const
Definition ASTContext.h:64