diff options
Diffstat (limited to 'clang/include/clang/AST/ASTContext.h')
-rw-r--r-- | clang/include/clang/AST/ASTContext.h | 161 |
1 files changed, 139 insertions, 22 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index ce47d54e44b0..34299581d89d 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -34,12 +34,13 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/Linkage.h" +#include "clang/Basic/NoSanitizeList.h" #include "clang/Basic/OperatorKinds.h" #include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/ProfileList.h" -#include "clang/Basic/SanitizerBlacklist.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/Specifiers.h" +#include "clang/Basic/TargetCXXABI.h" #include "clang/Basic/XRayLists.h" #include "llvm/ADT/APSInt.h" #include "llvm/ADT/ArrayRef.h" @@ -102,6 +103,7 @@ class DynTypedNode; class DynTypedNodeList; class Expr; class GlobalDecl; +class ItaniumMangleContext; class MangleContext; class MangleNumberingContext; class MaterializeTemporaryExpr; @@ -299,6 +301,10 @@ class ASTContext : public RefCountedBase<ASTContext> { /// This is lazily created. This is intentionally not serialized. mutable llvm::StringMap<StringLiteral *> StringLiteralCache; + /// MD5 hash of CUID. It is calculated when first used and cached by this + /// data member. + mutable std::string CUIDHash; + /// Representation of a "canonical" template template parameter that /// is used in canonical template names. class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode { @@ -453,6 +459,7 @@ private: friend class ASTWriter; template <class> friend class serialization::AbstractTypeReader; friend class CXXRecordDecl; + friend class IncrementalParser; /// A mapping to contain the template or declaration that /// a variable declaration describes or was instantiated from, @@ -512,6 +519,17 @@ private: /// B<int> to the UnresolvedUsingDecl in B<T>. llvm::DenseMap<NamedDecl *, NamedDecl *> InstantiatedFromUsingDecl; + /// Like InstantiatedFromUsingDecl, but for using-enum-declarations. Maps + /// from the instantiated using-enum to the templated decl from whence it + /// came. + /// Note that using-enum-declarations cannot be dependent and + /// thus will never be instantiated from an "unresolved" + /// version thereof (as with using-declarations), so each mapping is from + /// a (resolved) UsingEnumDecl to a (resolved) UsingEnumDecl. + llvm::DenseMap<UsingEnumDecl *, UsingEnumDecl *> + InstantiatedFromUsingEnumDecl; + + /// Simlarly maps instantiated UsingShadowDecls to their origin. llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*> InstantiatedFromUsingShadowDecl; @@ -538,6 +556,9 @@ private: /// need them (like static local vars). llvm::MapVector<const NamedDecl *, unsigned> MangleNumbers; llvm::MapVector<const VarDecl *, unsigned> StaticLocalNumbers; + /// Mapping the associated device lambda mangling number if present. + mutable llvm::DenseMap<const CXXRecordDecl *, unsigned> + DeviceLambdaManglingNumbers; /// Mapping that stores parameterIndex values for ParmVarDecls when /// that value exceeds the bitfield size of ParmVarDeclBits.ParameterIndex. @@ -547,7 +568,7 @@ private: ImportDecl *FirstLocalImport = nullptr; ImportDecl *LastLocalImport = nullptr; - TranslationUnitDecl *TUDecl; + TranslationUnitDecl *TUDecl = nullptr; mutable ExternCContextDecl *ExternCContext = nullptr; mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr; mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr; @@ -559,9 +580,9 @@ private: /// this ASTContext object. LangOptions &LangOpts; - /// Blacklist object that is used by sanitizers to decide which + /// NoSanitizeList object that is used by sanitizers to decide which /// entities should not be instrumented. - std::unique_ptr<SanitizerBlacklist> SanitizerBL; + std::unique_ptr<NoSanitizeList> NoSanitizeL; /// Function filtering mechanism to determine whether a given function /// should be imbued with the XRay "always" or "never" attributes. @@ -597,10 +618,14 @@ private: std::unique_ptr<interp::Context> InterpContext; std::unique_ptr<ParentMapContext> ParentMapCtx; + /// Keeps track of the deallocated DeclListNodes for future reuse. + DeclListNode *ListNodeFreeList = nullptr; + public: IdentifierTable &Idents; SelectorTable &Selectors; Builtin::Context &BuiltinInfo; + const TranslationUnitKind TUKind; mutable DeclarationNameTable DeclarationNames; IntrusiveRefCntPtr<ExternalASTSource> ExternalSource; ASTMutationListener *Listener = nullptr; @@ -612,11 +637,22 @@ public: ParentMapContext &getParentMapContext(); // A traversal scope limits the parts of the AST visible to certain analyses. - // RecursiveASTVisitor::TraverseAST will only visit reachable nodes, and + // RecursiveASTVisitor only visits specified children of TranslationUnitDecl. // getParents() will only observe reachable parent edges. // - // The scope is defined by a set of "top-level" declarations. - // Initially, it is the entire TU: {getTranslationUnitDecl()}. + // The scope is defined by a set of "top-level" declarations which will be + // visible under the TranslationUnitDecl. + // Initially, it is the entire TU, represented by {getTranslationUnitDecl()}. + // + // After setTraversalScope({foo, bar}), the exposed AST looks like: + // TranslationUnitDecl + // - foo + // - ... + // - bar + // - ... + // All other siblings of foo and bar are pruned from the tree. + // (However they are still accessible via TranslationUnitDecl->decls()) + // // Changing the scope clears the parent cache, which is expensive to rebuild. std::vector<Decl *> getTraversalScope() const { return TraversalScope; } void setTraversalScope(const std::vector<Decl *> &); @@ -648,6 +684,24 @@ public: } void Deallocate(void *Ptr) const {} + /// Allocates a \c DeclListNode or returns one from the \c ListNodeFreeList + /// pool. + DeclListNode *AllocateDeclListNode(clang::NamedDecl *ND) { + if (DeclListNode *Alloc = ListNodeFreeList) { + ListNodeFreeList = Alloc->Rest.dyn_cast<DeclListNode*>(); + Alloc->D = ND; + Alloc->Rest = nullptr; + return Alloc; + } + return new (*this) DeclListNode(ND); + } + /// Deallcates a \c DeclListNode by returning it to the \c ListNodeFreeList + /// pool. + void DeallocateDeclListNode(DeclListNode *N) { + N->Rest = ListNodeFreeList; + ListNodeFreeList = N; + } + /// Return the total amount of physical memory allocated for representing /// AST nodes and type information. size_t getASTAllocatedMemory() const { @@ -688,9 +742,7 @@ public: return LangOpts.CPlusPlus || LangOpts.RecoveryAST; } - const SanitizerBlacklist &getSanitizerBlacklist() const { - return *SanitizerBL; - } + const NoSanitizeList &getNoSanitizeList() const { return *NoSanitizeL; } const XRayFunctionFilter &getXRayFilter() const { return *XRayFilter; @@ -704,6 +756,11 @@ public: return FullSourceLoc(Loc,SourceMgr); } + /// Return the C++ ABI kind that should be used. The C++ ABI can be overriden + /// at compile time with `-fc++-abi=`. If this is not provided, we instead use + /// the default ABI set by the target. + TargetCXXABI::Kind getCXXABIKind() const; + /// All comments in this translation unit. RawCommentList Comments; @@ -853,30 +910,38 @@ public: MemberSpecializationInfo *getInstantiatedFromStaticDataMember( const VarDecl *Var); - TemplateOrSpecializationInfo - getTemplateOrSpecializationInfo(const VarDecl *Var); - /// Note that the static data member \p Inst is an instantiation of /// the static data member template \p Tmpl of a class template. void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation = SourceLocation()); + TemplateOrSpecializationInfo + getTemplateOrSpecializationInfo(const VarDecl *Var); + void setTemplateOrSpecializationInfo(VarDecl *Inst, TemplateOrSpecializationInfo TSI); - /// If the given using decl \p Inst is an instantiation of a - /// (possibly unresolved) using decl from a template instantiation, - /// return it. + /// If the given using decl \p Inst is an instantiation of + /// another (possibly unresolved) using decl, return it. NamedDecl *getInstantiatedFromUsingDecl(NamedDecl *Inst); /// Remember that the using decl \p Inst is an instantiation /// of the using decl \p Pattern of a class template. void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern); + /// If the given using-enum decl \p Inst is an instantiation of + /// another using-enum decl, return it. + UsingEnumDecl *getInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst); + + /// Remember that the using enum decl \p Inst is an instantiation + /// of the using enum decl \p Pattern of a class template. + void setInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst, + UsingEnumDecl *Pattern); + + UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst); void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern); - UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst); FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field); @@ -959,7 +1024,18 @@ public: /// Get the initializations to perform when importing a module, if any. ArrayRef<Decl*> getModuleInitializers(Module *M); - TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; } + TranslationUnitDecl *getTranslationUnitDecl() const { + return TUDecl->getMostRecentDecl(); + } + void addTranslationUnitDecl() { + assert(!TUDecl || TUKind == TU_Incremental); + TranslationUnitDecl *NewTUDecl = TranslationUnitDecl::Create(*this); + if (TraversalScope.empty() || TraversalScope.back() == TUDecl) + TraversalScope = {NewTUDecl}; + if (TUDecl) + NewTUDecl->setPreviousDecl(TUDecl); + TUDecl = NewTUDecl; + } ExternCContextDecl *getExternCContextDecl() const; BuiltinTemplateDecl *getMakeIntegerSeqDecl() const; @@ -1017,6 +1093,9 @@ public: #define PPC_VECTOR_TYPE(Name, Id, Size) \ CanQualType Id##Ty; #include "clang/Basic/PPCTypes.def" +#define RVV_TYPE(Name, Id, SingletonId) \ + CanQualType SingletonId; +#include "clang/Basic/RISCVVTypes.def" // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. @@ -1029,11 +1108,12 @@ public: // Implicitly-declared type 'struct _GUID'. mutable TagDecl *MSGuidTagDecl = nullptr; - /// Keep track of CUDA/HIP static device variables referenced by host code. - llvm::DenseSet<const VarDecl *> CUDAStaticDeviceVarReferencedByHost; + /// Keep track of CUDA/HIP device-side variables ODR-used by host code. + llvm::DenseSet<const VarDecl *> CUDADeviceVarODRUsedByHost; ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents, - SelectorTable &sels, Builtin::Context &builtins); + SelectorTable &sels, Builtin::Context &builtins, + TranslationUnitKind TUKind); ASTContext(const ASTContext &) = delete; ASTContext &operator=(const ASTContext &) = delete; ~ASTContext(); @@ -2320,6 +2400,12 @@ public: /// If \p T is null pointer, assume the target in ASTContext. MangleContext *createMangleContext(const TargetInfo *T = nullptr); + /// Creates a device mangle context to correctly mangle lambdas in a mixed + /// architecture compile by setting the lambda mangling number source to the + /// DeviceLambdaManglingNumber. Currently this asserts that the TargetInfo + /// (from the AuxTargetInfo) is a an itanium target. + MangleContext *createDeviceMangleContext(const TargetInfo &T); + void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass, SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const; @@ -2420,7 +2506,7 @@ public: const ObjCMethodDecl *MethodImp); bool UnwrapSimilarTypes(QualType &T1, QualType &T2); - bool UnwrapSimilarArrayTypes(QualType &T1, QualType &T2); + void UnwrapSimilarArrayTypes(QualType &T1, QualType &T2); /// Determine if two types are similar, according to the C++ rules. That is, /// determine if they are the same other than qualifiers on the initial @@ -2719,6 +2805,14 @@ public: // a given fixed point type. QualType getCorrespondingUnsignedType(QualType T) const; + // Per C99 6.2.5p6, for every signed integer type, there is a corresponding + // unsigned integer type. This method takes an unsigned type, and returns the + // corresponding signed integer type. + // With the introduction of fixed point types in ISO N1169, this method also + // accepts fixed point types and returns the corresponding signed type for + // a given fixed point type. + QualType getCorrespondingSignedType(QualType T) const; + // Per ISO N1169, this method accepts fixed point types and returns the // corresponding saturated type for a given fixed point type. QualType getCorrespondingSaturatedType(QualType Ty) const; @@ -3113,10 +3207,33 @@ public: /// Whether a C++ static variable should be externalized. bool shouldExternalizeStaticVar(const Decl *D) const; + StringRef getCUIDHash() const; + + void AddSYCLKernelNamingDecl(const CXXRecordDecl *RD); + bool IsSYCLKernelNamingDecl(const NamedDecl *RD) const; + unsigned GetSYCLKernelNamingIndex(const NamedDecl *RD); + /// A SourceLocation to store whether we have evaluated a kernel name already, + /// and where it happened. If so, we need to diagnose an illegal use of the + /// builtin. + llvm::MapVector<const SYCLUniqueStableNameExpr *, std::string> + SYCLUniqueStableNameEvaluatedValues; + private: /// All OMPTraitInfo objects live in this collection, one per /// `pragma omp [begin] declare variant` directive. SmallVector<std::unique_ptr<OMPTraitInfo>, 4> OMPTraitInfoVector; + + /// A list of the (right now just lambda decls) declarations required to + /// name all the SYCL kernels in the translation unit, so that we can get the + /// correct kernel name, as well as implement + /// __builtin_sycl_unique_stable_name. + llvm::DenseMap<const DeclContext *, + llvm::SmallPtrSet<const CXXRecordDecl *, 4>> + SYCLKernelNamingTypes; + std::unique_ptr<ItaniumMangleContext> SYCLKernelFilterContext; + void FilterSYCLKernelNamingDecls( + const CXXRecordDecl *RD, + llvm::SmallVectorImpl<const CXXRecordDecl *> &Decls); }; /// Insertion operator for diagnostics. |