diff options
Diffstat (limited to 'include/clang/AST')
107 files changed, 5739 insertions, 1390 deletions
diff --git a/include/clang/AST/APValue.h b/include/clang/AST/APValue.h index d4057c9da5f3..6943479831ec 100644 --- a/include/clang/AST/APValue.h +++ b/include/clang/AST/APValue.h @@ -1,9 +1,8 @@ //===--- APValue.h - Union class for APFloat/APSInt/Complex -----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -14,6 +13,7 @@ #ifndef LLVM_CLANG_AST_APVALUE_H #define LLVM_CLANG_AST_APVALUE_H +#include "clang/Basic/FixedPoint.h" #include "clang/Basic/LLVM.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APSInt.h" @@ -24,14 +24,52 @@ namespace clang { class AddrLabelExpr; class ASTContext; class CharUnits; + class CXXRecordDecl; + class Decl; class DiagnosticBuilder; class Expr; class FieldDecl; - class Decl; + struct PrintingPolicy; + class Type; class ValueDecl; - class CXXRecordDecl; - class QualType; +/// Symbolic representation of typeid(T) for some type T. +class TypeInfoLValue { + const Type *T; + +public: + TypeInfoLValue() : T() {} + explicit TypeInfoLValue(const Type *T); + + const Type *getType() const { return T; } + explicit operator bool() const { return T; } + + void *getOpaqueValue() { return const_cast<Type*>(T); } + static TypeInfoLValue getFromOpaqueValue(void *Value) { + TypeInfoLValue V; + V.T = reinterpret_cast<const Type*>(Value); + return V; + } + + void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const; +}; +} + +namespace llvm { +template<> struct PointerLikeTypeTraits<clang::TypeInfoLValue> { + static void *getAsVoidPointer(clang::TypeInfoLValue V) { + return V.getOpaqueValue(); + } + static clang::TypeInfoLValue getFromVoidPointer(void *P) { + return clang::TypeInfoLValue::getFromOpaqueValue(P); + } + // Validated by static_assert in APValue.cpp; hardcoded to avoid needing + // to include Type.h. + static constexpr int NumLowBitsAvailable = 3; +}; +} + +namespace clang { /// APValue - This class implements a discriminated union of [uninitialized] /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset], /// [Vector: N * APValue], [Array: N * APValue] @@ -40,9 +78,13 @@ class APValue { typedef llvm::APFloat APFloat; public: enum ValueKind { - Uninitialized, + /// There is no such object (it's outside its lifetime). + None, + /// This object has an indeterminate value (C++ [basic.indet]). + Indeterminate, Int, Float, + FixedPoint, ComplexInt, ComplexFloat, LValue, @@ -55,14 +97,14 @@ public: }; class LValueBase { - public: - typedef llvm::PointerUnion<const ValueDecl *, const Expr *> PtrTy; + typedef llvm::PointerUnion<const ValueDecl *, const Expr *, TypeInfoLValue> + PtrTy; - LValueBase() : CallIndex(0), Version(0) {} - - template <class T> - LValueBase(T P, unsigned I = 0, unsigned V = 0) - : Ptr(P), CallIndex(I), Version(V) {} + public: + LValueBase() : Local{} {} + LValueBase(const ValueDecl *P, unsigned I = 0, unsigned V = 0); + LValueBase(const Expr *P, unsigned I = 0, unsigned V = 0); + static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo); template <class T> bool is() const { return Ptr.is<T>(); } @@ -77,45 +119,73 @@ public: bool isNull() const; - explicit operator bool () const; + explicit operator bool() const; - PtrTy getPointer() const { - return Ptr; - } + unsigned getCallIndex() const; + unsigned getVersion() const; + QualType getTypeInfoType() const; - unsigned getCallIndex() const { - return CallIndex; - } - - void setCallIndex(unsigned Index) { - CallIndex = Index; - } - - unsigned getVersion() const { - return Version; - } - - bool operator==(const LValueBase &Other) const { - return Ptr == Other.Ptr && CallIndex == Other.CallIndex && - Version == Other.Version; + friend bool operator==(const LValueBase &LHS, const LValueBase &RHS); + friend bool operator!=(const LValueBase &LHS, const LValueBase &RHS) { + return !(LHS == RHS); } + friend llvm::hash_code hash_value(const LValueBase &Base); private: PtrTy Ptr; - unsigned CallIndex, Version; + struct LocalState { + unsigned CallIndex, Version; + }; + union { + LocalState Local; + /// The type std::type_info, if this is a TypeInfoLValue. + void *TypeInfoType; + }; }; + /// A FieldDecl or CXXRecordDecl, along with a flag indicating whether we + /// mean a virtual or non-virtual base class subobject. typedef llvm::PointerIntPair<const Decl *, 1, bool> BaseOrMemberType; - union LValuePathEntry { - /// BaseOrMember - The FieldDecl or CXXRecordDecl indicating the next item - /// in the path. An opaque value of type BaseOrMemberType. - void *BaseOrMember; - /// ArrayIndex - The array index of the next item in the path. - uint64_t ArrayIndex; + + /// A non-discriminated union of a base, field, or array index. + class LValuePathEntry { + static_assert(sizeof(uintptr_t) <= sizeof(uint64_t), + "pointer doesn't fit in 64 bits?"); + uint64_t Value; + + public: + LValuePathEntry() : Value() {} + LValuePathEntry(BaseOrMemberType BaseOrMember) + : Value{reinterpret_cast<uintptr_t>(BaseOrMember.getOpaqueValue())} {} + static LValuePathEntry ArrayIndex(uint64_t Index) { + LValuePathEntry Result; + Result.Value = Index; + return Result; + } + + BaseOrMemberType getAsBaseOrMember() const { + return BaseOrMemberType::getFromOpaqueValue( + reinterpret_cast<void *>(Value)); + } + uint64_t getAsArrayIndex() const { return Value; } + + friend bool operator==(LValuePathEntry A, LValuePathEntry B) { + return A.Value == B.Value; + } + friend bool operator!=(LValuePathEntry A, LValuePathEntry B) { + return A.Value != B.Value; + } + friend llvm::hash_code hash_value(LValuePathEntry A) { + return llvm::hash_value(A.Value); + } }; struct NoLValuePath {}; struct UninitArray {}; struct UninitStruct {}; + + friend class ASTReader; + friend class ASTWriter; + private: ValueKind Kind; @@ -168,55 +238,64 @@ private: DataType Data; public: - APValue() : Kind(Uninitialized) {} - explicit APValue(APSInt I) : Kind(Uninitialized) { + APValue() : Kind(None) {} + explicit APValue(APSInt I) : Kind(None) { MakeInt(); setInt(std::move(I)); } - explicit APValue(APFloat F) : Kind(Uninitialized) { + explicit APValue(APFloat F) : Kind(None) { MakeFloat(); setFloat(std::move(F)); } - explicit APValue(const APValue *E, unsigned N) : Kind(Uninitialized) { + explicit APValue(APFixedPoint FX) : Kind(None) { + MakeFixedPoint(std::move(FX)); + } + explicit APValue(const APValue *E, unsigned N) : Kind(None) { MakeVector(); setVector(E, N); } - APValue(APSInt R, APSInt I) : Kind(Uninitialized) { + APValue(APSInt R, APSInt I) : Kind(None) { MakeComplexInt(); setComplexInt(std::move(R), std::move(I)); } - APValue(APFloat R, APFloat I) : Kind(Uninitialized) { + APValue(APFloat R, APFloat I) : Kind(None) { MakeComplexFloat(); setComplexFloat(std::move(R), std::move(I)); } APValue(const APValue &RHS); - APValue(APValue &&RHS) : Kind(Uninitialized) { swap(RHS); } + APValue(APValue &&RHS) : Kind(None) { swap(RHS); } APValue(LValueBase B, const CharUnits &O, NoLValuePath N, bool IsNullPtr = false) - : Kind(Uninitialized) { + : Kind(None) { MakeLValue(); setLValue(B, O, N, IsNullPtr); } APValue(LValueBase B, const CharUnits &O, ArrayRef<LValuePathEntry> Path, bool OnePastTheEnd, bool IsNullPtr = false) - : Kind(Uninitialized) { + : Kind(None) { MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, IsNullPtr); } - APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(Uninitialized) { + APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(None) { MakeArray(InitElts, Size); } - APValue(UninitStruct, unsigned B, unsigned M) : Kind(Uninitialized) { + APValue(UninitStruct, unsigned B, unsigned M) : Kind(None) { MakeStruct(B, M); } explicit APValue(const FieldDecl *D, const APValue &V = APValue()) - : Kind(Uninitialized) { + : Kind(None) { MakeUnion(); setUnion(D, V); } APValue(const ValueDecl *Member, bool IsDerivedMember, - ArrayRef<const CXXRecordDecl*> Path) : Kind(Uninitialized) { + ArrayRef<const CXXRecordDecl*> Path) : Kind(None) { MakeMemberPointer(Member, IsDerivedMember, Path); } APValue(const AddrLabelExpr* LHSExpr, const AddrLabelExpr* RHSExpr) - : Kind(Uninitialized) { + : Kind(None) { MakeAddrLabelDiff(); setAddrLabelDiff(LHSExpr, RHSExpr); } + static APValue IndeterminateValue() { + APValue Result; + Result.Kind = Indeterminate; + return Result; + } ~APValue() { - MakeUninit(); + if (Kind != None && Kind != Indeterminate) + DestroyDataAndMakeUninit(); } /// Returns whether the object performed allocations. @@ -230,9 +309,14 @@ public: void swap(APValue &RHS); ValueKind getKind() const { return Kind; } - bool isUninit() const { return Kind == Uninitialized; } + + bool isAbsent() const { return Kind == None; } + bool isIndeterminate() const { return Kind == Indeterminate; } + bool hasValue() const { return Kind != None && Kind != Indeterminate; } + bool isInt() const { return Kind == Int; } bool isFloat() const { return Kind == Float; } + bool isFixedPoint() const { return Kind == FixedPoint; } bool isComplexInt() const { return Kind == ComplexInt; } bool isComplexFloat() const { return Kind == ComplexFloat; } bool isLValue() const { return Kind == LValue; } @@ -246,8 +330,8 @@ public: void dump() const; void dump(raw_ostream &OS) const; - void printPretty(raw_ostream &OS, ASTContext &Ctx, QualType Ty) const; - std::string getAsString(ASTContext &Ctx, QualType Ty) const; + void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const; + std::string getAsString(const ASTContext &Ctx, QualType Ty) const; APSInt &getInt() { assert(isInt() && "Invalid accessor"); @@ -257,6 +341,12 @@ public: return const_cast<APValue*>(this)->getInt(); } + /// Try to convert this value to an integral constant. This works if it's an + /// integer, null pointer, or offset from a null pointer. Returns true on + /// success. + bool toIntegralConstant(APSInt &Result, QualType SrcTy, + const ASTContext &Ctx) const; + APFloat &getFloat() { assert(isFloat() && "Invalid accessor"); return *(APFloat*)(char*)Data.buffer; @@ -265,6 +355,14 @@ public: return const_cast<APValue*>(this)->getFloat(); } + APFixedPoint &getFixedPoint() { + assert(isFixedPoint() && "Invalid accessor"); + return *(APFixedPoint *)(char *)Data.buffer; + } + const APFixedPoint &getFixedPoint() const { + return const_cast<APValue *>(this)->getFixedPoint(); + } + APSInt &getComplexIntReal() { assert(isComplexInt() && "Invalid accessor"); return ((ComplexAPSInt*)(char*)Data.buffer)->Real; @@ -406,6 +504,10 @@ public: assert(isFloat() && "Invalid accessor"); *(APFloat *)(char *)Data.buffer = std::move(F); } + void setFixedPoint(APFixedPoint FX) { + assert(isFixedPoint() && "Invalid accessor"); + *(APFixedPoint *)(char *)Data.buffer = std::move(FX); + } void setVector(const APValue *E, unsigned N) { assert(isVector() && "Invalid accessor"); ((Vec*)(char*)Data.buffer)->Elts = new APValue[N]; @@ -451,51 +553,52 @@ public: private: void DestroyDataAndMakeUninit(); - void MakeUninit() { - if (Kind != Uninitialized) - DestroyDataAndMakeUninit(); - } void MakeInt() { - assert(isUninit() && "Bad state change"); + assert(isAbsent() && "Bad state change"); new ((void*)Data.buffer) APSInt(1); Kind = Int; } void MakeFloat() { - assert(isUninit() && "Bad state change"); + assert(isAbsent() && "Bad state change"); new ((void*)(char*)Data.buffer) APFloat(0.0); Kind = Float; } + void MakeFixedPoint(APFixedPoint &&FX) { + assert(isAbsent() && "Bad state change"); + new ((void *)(char *)Data.buffer) APFixedPoint(std::move(FX)); + Kind = FixedPoint; + } void MakeVector() { - assert(isUninit() && "Bad state change"); + assert(isAbsent() && "Bad state change"); new ((void*)(char*)Data.buffer) Vec(); Kind = Vector; } void MakeComplexInt() { - assert(isUninit() && "Bad state change"); + assert(isAbsent() && "Bad state change"); new ((void*)(char*)Data.buffer) ComplexAPSInt(); Kind = ComplexInt; } void MakeComplexFloat() { - assert(isUninit() && "Bad state change"); + assert(isAbsent() && "Bad state change"); new ((void*)(char*)Data.buffer) ComplexAPFloat(); Kind = ComplexFloat; } void MakeLValue(); void MakeArray(unsigned InitElts, unsigned Size); void MakeStruct(unsigned B, unsigned M) { - assert(isUninit() && "Bad state change"); + assert(isAbsent() && "Bad state change"); new ((void*)(char*)Data.buffer) StructData(B, M); Kind = Struct; } void MakeUnion() { - assert(isUninit() && "Bad state change"); + assert(isAbsent() && "Bad state change"); new ((void*)(char*)Data.buffer) UnionData(); Kind = Union; } void MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember, ArrayRef<const CXXRecordDecl*> Path); void MakeAddrLabelDiff() { - assert(isUninit() && "Bad state change"); + assert(isAbsent() && "Bad state change"); new ((void*)(char*)Data.buffer) AddrLabelDiffData(); Kind = AddrLabelDiff; } diff --git a/include/clang/AST/AST.h b/include/clang/AST/AST.h index 6db351d1064b..6d0f274121b2 100644 --- a/include/clang/AST/AST.h +++ b/include/clang/AST/AST.h @@ -1,9 +1,8 @@ //===--- AST.h - "Umbrella" header for AST library --------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/ASTConsumer.h b/include/clang/AST/ASTConsumer.h index 1167c566a35f..dc216a89c205 100644 --- a/include/clang/AST/ASTConsumer.h +++ b/include/clang/AST/ASTConsumer.h @@ -1,9 +1,8 @@ //===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 13870116c7fd..1d1aaf4fb115 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -1,9 +1,8 @@ //===- ASTContext.h - Context to hold long-lived AST nodes ------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -266,17 +265,21 @@ private: /// Mapping from __block VarDecls to BlockVarCopyInit. llvm::DenseMap<const VarDecl *, BlockVarCopyInit> BlockVarCopyInits; - /// Mapping from class scope functions specialization to their - /// template patterns. - llvm::DenseMap<const FunctionDecl*, FunctionDecl*> - ClassScopeSpecializationPattern; - /// Mapping from materialized temporaries with static storage duration /// that appear in constant initializers to their evaluated values. These are /// allocated in a std::map because their address must be stable. llvm::DenseMap<const MaterializeTemporaryExpr *, APValue *> MaterializedTemporaryValues; + /// Used to cleanups APValues stored in the AST. + mutable llvm::SmallVector<APValue *, 0> APValueCleanups; + + /// A cache mapping a string value to a StringLiteral object with the same + /// value. + /// + /// This is lazily created. This is intentionally not serialized. + mutable llvm::StringMap<StringLiteral *> StringLiteralCache; + /// Representation of a "canonical" template template parameter that /// is used in canonical template names. class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode { @@ -892,11 +895,6 @@ public: TemplateOrSpecializationInfo getTemplateOrSpecializationInfo(const VarDecl *Var); - FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD); - - void setClassScopeSpecializationPattern(FunctionDecl *FD, - FunctionDecl *Pattern); - /// 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, @@ -1334,6 +1332,10 @@ public: ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const; + /// Return a type for a constant array for a string literal of the + /// specified element type and length. + QualType getStringLiteralArrayType(QualType EltTy, unsigned Length) const; + /// Returns a vla type where known sizes are replaced with [*]. QualType getVariableArrayDecayedType(QualType Ty) const; @@ -1452,6 +1454,9 @@ public: QualType getParenType(QualType NamedType) const; + QualType getMacroQualifiedType(QualType UnderlyingTy, + const IdentifierInfo *MacroII) const; + QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl = nullptr) const; @@ -1520,7 +1525,7 @@ public: /// C++11 deduced auto type. QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, - bool IsDependent) const; + bool IsDependent, bool IsPack = false) const; /// C++11 deduction pattern for 'auto' type. QualType getAutoDeductType() const; @@ -1985,6 +1990,7 @@ public: TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const; + TemplateName getAssumedTemplateName(DeclarationName Name) const; TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, @@ -2003,6 +2009,9 @@ public: /// No error GE_None, + /// Missing a type + GE_Missing_type, + /// Missing a type from <stdio.h> GE_Missing_stdio, @@ -2086,6 +2095,16 @@ public: CharUnits getTypeSizeInChars(QualType T) const; CharUnits getTypeSizeInChars(const Type *T) const; + Optional<CharUnits> getTypeSizeInCharsIfKnown(QualType Ty) const { + if (Ty->isIncompleteType() || Ty->isDependentType()) + return None; + return getTypeSizeInChars(Ty); + } + + Optional<CharUnits> getTypeSizeInCharsIfKnown(const Type *Ty) const { + return getTypeSizeInCharsIfKnown(QualType(Ty, 0)); + } + /// Return the ABI-specified alignment of a (complete) type \p T, in /// bits. unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; } @@ -2160,6 +2179,13 @@ public: /// pointers and large arrays get extra alignment. CharUnits getDeclAlign(const Decl *D, bool ForAlignof = false) const; + /// Return the alignment (in bytes) of the thrown exception object. This is + /// only meaningful for targets that allocate C++ exceptions in a system + /// runtime, such as those using the Itanium C++ ABI. + CharUnits getExnObjectAlignment() const { + return toCharUnitsFromBits(Target->getExnObjectAlignment()); + } + /// Get or compute information about the layout of the specified /// record (struct/union/class) \p D, which indicates its size and field /// position information. @@ -2225,7 +2251,8 @@ public: VTableContextBase *getVTableContext(); - MangleContext *createMangleContext(); + /// If \p T is null pointer, assume the target in ASTContext. + MangleContext *createMangleContext(const TargetInfo *T = nullptr); void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass, SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const; @@ -2371,7 +2398,8 @@ public: /// Retrieves the default calling convention for the current target. CallingConv getDefaultCallingConvention(bool IsVariadic, - bool IsCXXMethod) const; + bool IsCXXMethod, + bool IsBuiltin = false) const; /// Retrieves the "canonical" template name that refers to a /// given template. @@ -2488,6 +2516,11 @@ public: /// \p LHS < \p RHS, return -1. int getFloatingTypeOrder(QualType LHS, QualType RHS) const; + /// Compare the rank of two floating point types as above, but compare equal + /// if both types have the same floating-point semantics on the target (i.e. + /// long double and double on AArch64 will return 0). + int getFloatingTypeSemanticOrder(QualType LHS, QualType RHS) const; + /// Return a real floating point or a complex type (based on /// \p typeDomain/\p typeSize). /// @@ -2624,6 +2657,12 @@ public: // corresponding saturated type for a given fixed point type. QualType getCorrespondingSaturatedType(QualType Ty) const; + // This method accepts fixed point types and returns the corresponding signed + // type. Unlike getCorrespondingUnsignedType(), this only accepts unsigned + // fixed point types because there are unsigned integer types like bool and + // char8_t that don't have signed equivalents. + QualType getCorrespondingSignedFixedPointType(QualType Ty) const; + //===--------------------------------------------------------------------===// // Integer Values //===--------------------------------------------------------------------===// @@ -2677,7 +2716,7 @@ public: /// otherwise returns null. const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) const; - /// Set the copy inialization expression of a block var decl. \p CanThrow + /// Set the copy initialization expression of a block var decl. \p CanThrow /// indicates whether the copy expression can throw or not. void setBlockVarCopyInit(const VarDecl* VD, Expr *CopyExpr, bool CanThrow); @@ -2712,12 +2751,11 @@ public: /// /// \param Data Pointer data that will be provided to the callback function /// when it is called. - void AddDeallocation(void (*Callback)(void*), void *Data); + void AddDeallocation(void (*Callback)(void *), void *Data) const; /// If T isn't trivially destructible, calls AddDeallocation to register it /// for destruction. - template <typename T> - void addDestruction(T *Ptr) { + template <typename T> void addDestruction(T *Ptr) const { if (!std::is_trivially_destructible<T>::value) { auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); }; AddDeallocation(DestroyPtr, Ptr); @@ -2780,51 +2818,56 @@ public: APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E, bool MayCreate); + /// Return a string representing the human readable name for the specified + /// function declaration or file name. Used by SourceLocExpr and + /// PredefinedExpr to cache evaluated results. + StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const; + //===--------------------------------------------------------------------===// // Statistics //===--------------------------------------------------------------------===// /// The number of implicitly-declared default constructors. - static unsigned NumImplicitDefaultConstructors; + unsigned NumImplicitDefaultConstructors = 0; /// The number of implicitly-declared default constructors for /// which declarations were built. - static unsigned NumImplicitDefaultConstructorsDeclared; + unsigned NumImplicitDefaultConstructorsDeclared = 0; /// The number of implicitly-declared copy constructors. - static unsigned NumImplicitCopyConstructors; + unsigned NumImplicitCopyConstructors = 0; /// The number of implicitly-declared copy constructors for /// which declarations were built. - static unsigned NumImplicitCopyConstructorsDeclared; + unsigned NumImplicitCopyConstructorsDeclared = 0; /// The number of implicitly-declared move constructors. - static unsigned NumImplicitMoveConstructors; + unsigned NumImplicitMoveConstructors = 0; /// The number of implicitly-declared move constructors for /// which declarations were built. - static unsigned NumImplicitMoveConstructorsDeclared; + unsigned NumImplicitMoveConstructorsDeclared = 0; /// The number of implicitly-declared copy assignment operators. - static unsigned NumImplicitCopyAssignmentOperators; + unsigned NumImplicitCopyAssignmentOperators = 0; /// The number of implicitly-declared copy assignment operators for /// which declarations were built. - static unsigned NumImplicitCopyAssignmentOperatorsDeclared; + unsigned NumImplicitCopyAssignmentOperatorsDeclared = 0; /// The number of implicitly-declared move assignment operators. - static unsigned NumImplicitMoveAssignmentOperators; + unsigned NumImplicitMoveAssignmentOperators = 0; /// The number of implicitly-declared move assignment operators for /// which declarations were built. - static unsigned NumImplicitMoveAssignmentOperatorsDeclared; + unsigned NumImplicitMoveAssignmentOperatorsDeclared = 0; /// The number of implicitly-declared destructors. - static unsigned NumImplicitDestructors; + unsigned NumImplicitDestructors = 0; /// The number of implicitly-declared destructors for which /// declarations were built. - static unsigned NumImplicitDestructorsDeclared; + unsigned NumImplicitDestructorsDeclared = 0; public: /// Initialize built-in types. @@ -2839,18 +2882,51 @@ public: private: void InitBuiltinType(CanQualType &R, BuiltinType::Kind K); + class ObjCEncOptions { + unsigned Bits; + + ObjCEncOptions(unsigned Bits) : Bits(Bits) {} + + public: + ObjCEncOptions() : Bits(0) {} + ObjCEncOptions(const ObjCEncOptions &RHS) : Bits(RHS.Bits) {} + +#define OPT_LIST(V) \ + V(ExpandPointedToStructures, 0) \ + V(ExpandStructures, 1) \ + V(IsOutermostType, 2) \ + V(EncodingProperty, 3) \ + V(IsStructField, 4) \ + V(EncodeBlockParameters, 5) \ + V(EncodeClassNames, 6) \ + +#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; } +OPT_LIST(V) +#undef V + +#define V(N,I) bool N() const { return Bits & 1 << I; } +OPT_LIST(V) +#undef V + +#undef OPT_LIST + + LLVM_NODISCARD ObjCEncOptions keepingOnly(ObjCEncOptions Mask) const { + return Bits & Mask.Bits; + } + + LLVM_NODISCARD ObjCEncOptions forComponentType() const { + ObjCEncOptions Mask = ObjCEncOptions() + .setIsOutermostType() + .setIsStructField(); + return Bits & ~Mask.Bits; + } + }; + // Return the Objective-C type encoding for a given type. void getObjCEncodingForTypeImpl(QualType t, std::string &S, - bool ExpandPointedToStructures, - bool ExpandStructures, + ObjCEncOptions Options, const FieldDecl *Field, - bool OutermostType = false, - bool EncodingProperty = false, - bool StructField = false, - bool EncodeBlockParameters = false, - bool EncodeClassNames = false, - bool EncodePointerToObjCTypedef = false, - QualType *NotEncodedT=nullptr) const; + QualType *NotEncodedT = nullptr) const; // Adds the encoding of the structure's members. void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S, @@ -2908,7 +2984,7 @@ private: // in order to track and run destructors while we're tearing things down. using DeallocationFunctionsAndArguments = llvm::SmallVector<std::pair<void (*)(void *), void *>, 16>; - DeallocationFunctionsAndArguments Deallocations; + mutable DeallocationFunctionsAndArguments Deallocations; // FIXME: This currently contains the set of StoredDeclMaps used // by DeclContext objects. This probably should not be in ASTContext, diff --git a/include/clang/AST/ASTContextAllocate.h b/include/clang/AST/ASTContextAllocate.h index 5b9eed208a4d..70c8e24f9185 100644 --- a/include/clang/AST/ASTContextAllocate.h +++ b/include/clang/AST/ASTContextAllocate.h @@ -1,9 +1,8 @@ //===- ASTContextAllocate.h - ASTContext allocate functions -----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/ASTDiagnostic.h b/include/clang/AST/ASTDiagnostic.h index fe92604587ef..d6549e12d92a 100644 --- a/include/clang/AST/ASTDiagnostic.h +++ b/include/clang/AST/ASTDiagnostic.h @@ -1,9 +1,8 @@ //===--- ASTDiagnostic.h - Diagnostics for the AST library ------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/clang/AST/ASTDumper.h b/include/clang/AST/ASTDumper.h new file mode 100644 index 000000000000..61202f057a80 --- /dev/null +++ b/include/clang/AST/ASTDumper.h @@ -0,0 +1,56 @@ +//===--- ASTDumper.h - Dumping implementation for ASTs --------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ASTDUMPER_H +#define LLVM_CLANG_AST_ASTDUMPER_H + +#include "clang/AST/ASTNodeTraverser.h" +#include "clang/AST/TextNodeDumper.h" + +namespace clang { + +class ASTDumper : public ASTNodeTraverser<ASTDumper, TextNodeDumper> { + + TextNodeDumper NodeDumper; + + raw_ostream &OS; + + const bool ShowColors; + +public: + ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits, + const SourceManager *SM) + : ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) {} + + ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits, + const SourceManager *SM, bool ShowColors) + : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {} + ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits, + const SourceManager *SM, bool ShowColors, + const PrintingPolicy &PrintPolicy) + : NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS), + ShowColors(ShowColors) {} + + TextNodeDumper &doGetNodeDelegate() { return NodeDumper; } + + void dumpLookups(const DeclContext *DC, bool DumpDecls); + + template <typename SpecializationDecl> + void dumpTemplateDeclSpecialization(const SpecializationDecl *D, + bool DumpExplicitInst, bool DumpRefOnly); + template <typename TemplateDecl> + void dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst); + + void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D); + void VisitClassTemplateDecl(const ClassTemplateDecl *D); + void VisitVarTemplateDecl(const VarTemplateDecl *D); +}; + +} // namespace clang + +#endif diff --git a/include/clang/AST/ASTDumperUtils.h b/include/clang/AST/ASTDumperUtils.h index 5e62e902b423..55a085449a9b 100644 --- a/include/clang/AST/ASTDumperUtils.h +++ b/include/clang/AST/ASTDumperUtils.h @@ -1,9 +1,8 @@ //===--- ASTDumperUtils.h - Printing of AST nodes -------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -18,6 +17,12 @@ namespace clang { +/// Used to specify the format for printing AST dump information. +enum ASTDumpOutputFormat { + ADOF_Default, + ADOF_JSON +}; + // Colors used for various parts of the AST dump // Do not use bold yellow for any text. It is hard to read on white screens. diff --git a/include/clang/AST/ASTFwd.h b/include/clang/AST/ASTFwd.h index 038d5c3d3611..93919bbdd52f 100644 --- a/include/clang/AST/ASTFwd.h +++ b/include/clang/AST/ASTFwd.h @@ -1,9 +1,8 @@ //===--- ASTFwd.h ----------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===--------------------------------------------------------------===// /// diff --git a/include/clang/AST/ASTImporter.h b/include/clang/AST/ASTImporter.h index dbb9cf35ddea..4a55c120a457 100644 --- a/include/clang/AST/ASTImporter.h +++ b/include/clang/AST/ASTImporter.h @@ -1,9 +1,8 @@ //===- ASTImporter.h - Importing ASTs from other Contexts -------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -15,6 +14,7 @@ #ifndef LLVM_CLANG_AST_ASTIMPORTER_H #define LLVM_CLANG_AST_ASTIMPORTER_H +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/TemplateName.h" @@ -33,7 +33,8 @@ namespace clang { class ASTContext; -class ASTImporterLookupTable; +class ASTImporterSharedState; +class Attr; class CXXBaseSpecifier; class CXXCtorInitializer; class Decl; @@ -43,8 +44,8 @@ class FileManager; class NamedDecl; class Stmt; class TagDecl; +class TranslationUnitDecl; class TypeSourceInfo; -class Attr; class ImportError : public llvm::ErrorInfo<ImportError> { public: @@ -87,14 +88,140 @@ class Attr; using ImportedCXXBaseSpecifierMap = llvm::DenseMap<const CXXBaseSpecifier *, CXXBaseSpecifier *>; - private: + // An ImportPath is the list of the AST nodes which we visit during an + // Import call. + // If node `A` depends on node `B` then the path contains an `A`->`B` edge. + // From the call stack of the import functions we can read the very same + // path. + // + // Now imagine the following AST, where the `->` represents dependency in + // therms of the import. + // ``` + // A->B->C->D + // `->E + // ``` + // We would like to import A. + // The import behaves like a DFS, so we will visit the nodes in this order: + // ABCDE. + // During the visitation we will have the following ImportPaths: + // ``` + // A + // AB + // ABC + // ABCD + // ABC + // AB + // ABE + // AB + // A + // ``` + // If during the visit of E there is an error then we set an error for E, + // then as the call stack shrinks for B, then for A: + // ``` + // A + // AB + // ABC + // ABCD + // ABC + // AB + // ABE // Error! Set an error to E + // AB // Set an error to B + // A // Set an error to A + // ``` + // However, during the import we could import C and D without any error and + // they are independent from A,B and E. + // We must not set up an error for C and D. + // So, at the end of the import we have an entry in `ImportDeclErrors` for + // A,B,E but not for C,D. + // + // Now what happens if there is a cycle in the import path? + // Let's consider this AST: + // ``` + // A->B->C->A + // `->E + // ``` + // During the visitation we will have the below ImportPaths and if during + // the visit of E there is an error then we will set up an error for E,B,A. + // But what's up with C? + // ``` + // A + // AB + // ABC + // ABCA + // ABC + // AB + // ABE // Error! Set an error to E + // AB // Set an error to B + // A // Set an error to A + // ``` + // This time we know that both B and C are dependent on A. + // This means we must set up an error for C too. + // As the call stack reverses back we get to A and we must set up an error + // to all nodes which depend on A (this includes C). + // But C is no longer on the import path, it just had been previously. + // Such situation can happen only if during the visitation we had a cycle. + // If we didn't have any cycle, then the normal way of passing an Error + // object through the call stack could handle the situation. + // This is why we must track cycles during the import process for each + // visited declaration. + class ImportPathTy { + public: + using VecTy = llvm::SmallVector<Decl *, 32>; + + void push(Decl *D) { + Nodes.push_back(D); + ++Aux[D]; + } + + void pop() { + if (Nodes.empty()) + return; + --Aux[Nodes.back()]; + Nodes.pop_back(); + } + + /// Returns true if the last element can be found earlier in the path. + bool hasCycleAtBack() const { + auto Pos = Aux.find(Nodes.back()); + return Pos != Aux.end() && Pos->second > 1; + } + + using Cycle = llvm::iterator_range<VecTy::const_reverse_iterator>; + Cycle getCycleAtBack() const { + assert(Nodes.size() >= 2); + return Cycle(Nodes.rbegin(), + std::find(Nodes.rbegin() + 1, Nodes.rend(), Nodes.back()) + + 1); + } + + /// Returns the copy of the cycle. + VecTy copyCycleAtBack() const { + auto R = getCycleAtBack(); + return VecTy(R.begin(), R.end()); + } + + private: + // All nodes of the path. + VecTy Nodes; + // Auxiliary container to be able to answer "Do we have a cycle ending + // at last element?" as fast as possible. + // We count each Decl's occurrence over the path. + llvm::SmallDenseMap<Decl *, int, 32> Aux; + }; - /// Pointer to the import specific lookup table, which may be shared - /// amongst several ASTImporter objects. - /// This is an externally managed resource (and should exist during the - /// lifetime of the ASTImporter object) - /// If not set then the original C/C++ lookup is used. - ASTImporterLookupTable *LookupTable = nullptr; + private: + std::shared_ptr<ASTImporterSharedState> SharedState = nullptr; + + /// The path which we go through during the import of a given AST node. + ImportPathTy ImportPath; + /// Sometimes we have to save some part of an import path, so later we can + /// set up properties to the saved nodes. + /// We may have several of these import paths associated to one Decl. + using SavedImportPathsForOneDecl = + llvm::SmallVector<ImportPathTy::VecTy, 32>; + using SavedImportPathsTy = + llvm::SmallDenseMap<Decl *, SavedImportPathsForOneDecl, 32>; + SavedImportPathsTy SavedImportPaths; /// The contexts we're importing to and from. ASTContext &ToContext, &FromContext; @@ -116,6 +243,18 @@ class Attr; /// context to the corresponding declarations in the "to" context. llvm::DenseMap<Decl *, Decl *> ImportedDecls; + /// Mapping from the already-imported declarations in the "from" + /// context to the error status of the import of that declaration. + /// This map contains only the declarations that were not correctly + /// imported. The same declaration may or may not be included in + /// ImportedDecls. This map is updated continuously during imports and never + /// cleared (like ImportedDecls). + llvm::DenseMap<Decl *, ImportError> ImportDeclErrors; + + /// Mapping from the already-imported declarations in the "to" + /// context to the corresponding declarations in the "from" context. + llvm::DenseMap<Decl *, Decl *> ImportedFromDecls; + /// Mapping from the already-imported statements in the "from" /// context to the corresponding statements in the "to" context. llvm::DenseMap<Stmt *, Stmt *> ImportedStmts; @@ -138,6 +277,15 @@ class Attr; void AddToLookupTable(Decl *ToD); + protected: + /// Can be overwritten by subclasses to implement their own import logic. + /// The overwritten method should call this method if it didn't import the + /// decl on its own. + virtual Expected<Decl *> ImportImpl(Decl *From); + + /// Used only in unittests to verify the behaviour of the error handling. + virtual bool returnWithErrorInTest() { return false; }; + public: /// \param ToContext The context we'll be importing into. @@ -152,13 +300,13 @@ class Attr; /// as little as it can, e.g., by importing declarations as forward /// declarations that can be completed at a later point. /// - /// \param LookupTable The importer specific lookup table which may be + /// \param SharedState The importer specific lookup table which may be /// shared amongst several ASTImporter objects. /// If not set then the original C/C++ lookup is used. ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, - ASTImporterLookupTable *LookupTable = nullptr); + std::shared_ptr<ASTImporterSharedState> SharedState = nullptr); virtual ~ASTImporter(); @@ -173,63 +321,51 @@ class Attr; /// \return Error information (success or error). template <typename ImportT> LLVM_NODISCARD llvm::Error importInto(ImportT &To, const ImportT &From) { - To = Import(From); - if (From && !To) - return llvm::make_error<ImportError>(); - return llvm::Error::success(); - // FIXME: this should be the final code - //auto ToOrErr = Import(From); - //if (ToOrErr) - // To = *ToOrErr; - //return ToOrErr.takeError(); + auto ToOrErr = Import(From); + if (ToOrErr) + To = *ToOrErr; + return ToOrErr.takeError(); } /// Import the given type from the "from" context into the "to" /// context. A null type is imported as a null type (no error). /// /// \returns The equivalent type in the "to" context, or the import error. - llvm::Expected<QualType> Import_New(QualType FromT); - // FIXME: Remove this version. - QualType Import(QualType FromT); + llvm::Expected<QualType> Import(QualType FromT); /// Import the given type source information from the /// "from" context into the "to" context. /// /// \returns The equivalent type source information in the "to" /// context, or the import error. - llvm::Expected<TypeSourceInfo *> Import_New(TypeSourceInfo *FromTSI); - // FIXME: Remove this version. - TypeSourceInfo *Import(TypeSourceInfo *FromTSI); + llvm::Expected<TypeSourceInfo *> Import(TypeSourceInfo *FromTSI); /// Import the given attribute from the "from" context into the /// "to" context. /// /// \returns The equivalent attribute in the "to" context, or the import /// error. - llvm::Expected<Attr *> Import_New(const Attr *FromAttr); - // FIXME: Remove this version. - Attr *Import(const Attr *FromAttr); + llvm::Expected<Attr *> Import(const Attr *FromAttr); /// Import the given declaration from the "from" context into the /// "to" context. /// /// \returns The equivalent declaration in the "to" context, or the import /// error. - llvm::Expected<Decl *> Import_New(Decl *FromD); - llvm::Expected<Decl *> Import_New(const Decl *FromD) { - return Import_New(const_cast<Decl *>(FromD)); - } - // FIXME: Remove this version. - Decl *Import(Decl *FromD); - Decl *Import(const Decl *FromD) { + llvm::Expected<Decl *> Import(Decl *FromD); + llvm::Expected<const Decl *> Import(const Decl *FromD) { return Import(const_cast<Decl *>(FromD)); } /// Return the copy of the given declaration in the "to" context if /// it has already been imported from the "from" context. Otherwise return - /// NULL. + /// nullptr. Decl *GetAlreadyImportedOrNull(const Decl *FromD) const; + /// Return the translation unit from where the declaration was + /// imported. If it does not exist nullptr is returned. + TranslationUnitDecl *GetFromTU(Decl *ToD); + /// Import the given declaration context from the "from" /// AST context into the "to" AST context. /// @@ -242,28 +378,21 @@ class Attr; /// /// \returns The equivalent expression in the "to" context, or the import /// error. - llvm::Expected<Expr *> Import_New(Expr *FromE); - // FIXME: Remove this version. - Expr *Import(Expr *FromE); + llvm::Expected<Expr *> Import(Expr *FromE); /// Import the given statement from the "from" context into the /// "to" context. /// /// \returns The equivalent statement in the "to" context, or the import /// error. - llvm::Expected<Stmt *> Import_New(Stmt *FromS); - // FIXME: Remove this version. - Stmt *Import(Stmt *FromS); + llvm::Expected<Stmt *> Import(Stmt *FromS); /// Import the given nested-name-specifier from the "from" /// context into the "to" context. /// /// \returns The equivalent nested-name-specifier in the "to" /// context, or the import error. - llvm::Expected<NestedNameSpecifier *> - Import_New(NestedNameSpecifier *FromNNS); - // FIXME: Remove this version. - NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS); + llvm::Expected<NestedNameSpecifier *> Import(NestedNameSpecifier *FromNNS); /// Import the given nested-name-specifier-loc from the "from" /// context into the "to" context. @@ -271,42 +400,32 @@ class Attr; /// \returns The equivalent nested-name-specifier-loc in the "to" /// context, or the import error. llvm::Expected<NestedNameSpecifierLoc> - Import_New(NestedNameSpecifierLoc FromNNS); - // FIXME: Remove this version. - NestedNameSpecifierLoc Import(NestedNameSpecifierLoc FromNNS); + Import(NestedNameSpecifierLoc FromNNS); /// Import the given template name from the "from" context into the /// "to" context, or the import error. - llvm::Expected<TemplateName> Import_New(TemplateName From); - // FIXME: Remove this version. - TemplateName Import(TemplateName From); + llvm::Expected<TemplateName> Import(TemplateName From); /// Import the given source location from the "from" context into /// the "to" context. /// /// \returns The equivalent source location in the "to" context, or the /// import error. - llvm::Expected<SourceLocation> Import_New(SourceLocation FromLoc); - // FIXME: Remove this version. - SourceLocation Import(SourceLocation FromLoc); + llvm::Expected<SourceLocation> Import(SourceLocation FromLoc); /// Import the given source range from the "from" context into /// the "to" context. /// /// \returns The equivalent source range in the "to" context, or the import /// error. - llvm::Expected<SourceRange> Import_New(SourceRange FromRange); - // FIXME: Remove this version. - SourceRange Import(SourceRange FromRange); + llvm::Expected<SourceRange> Import(SourceRange FromRange); /// Import the given declaration name from the "from" /// context into the "to" context. /// /// \returns The equivalent declaration name in the "to" context, or the /// import error. - llvm::Expected<DeclarationName> Import_New(DeclarationName FromName); - // FIXME: Remove this version. - DeclarationName Import(DeclarationName FromName); + llvm::Expected<DeclarationName> Import(DeclarationName FromName); /// Import the given identifier from the "from" context /// into the "to" context. @@ -320,46 +439,32 @@ class Attr; /// /// \returns The equivalent selector in the "to" context, or the import /// error. - llvm::Expected<Selector> Import_New(Selector FromSel); - // FIXME: Remove this version. - Selector Import(Selector FromSel); + llvm::Expected<Selector> Import(Selector FromSel); /// Import the given file ID from the "from" context into the /// "to" context. /// /// \returns The equivalent file ID in the source manager of the "to" /// context, or the import error. - llvm::Expected<FileID> Import_New(FileID); - // FIXME: Remove this version. - FileID Import(FileID); + llvm::Expected<FileID> Import(FileID, bool IsBuiltin = false); /// Import the given C++ constructor initializer from the "from" /// context into the "to" context. /// /// \returns The equivalent initializer in the "to" context, or the import /// error. - llvm::Expected<CXXCtorInitializer *> - Import_New(CXXCtorInitializer *FromInit); - // FIXME: Remove this version. - CXXCtorInitializer *Import(CXXCtorInitializer *FromInit); + llvm::Expected<CXXCtorInitializer *> Import(CXXCtorInitializer *FromInit); /// Import the given CXXBaseSpecifier from the "from" context into /// the "to" context. /// /// \returns The equivalent CXXBaseSpecifier in the source manager of the /// "to" context, or the import error. - llvm::Expected<CXXBaseSpecifier *> - Import_New(const CXXBaseSpecifier *FromSpec); - // FIXME: Remove this version. - CXXBaseSpecifier *Import(const CXXBaseSpecifier *FromSpec); + llvm::Expected<CXXBaseSpecifier *> Import(const CXXBaseSpecifier *FromSpec); /// Import the definition of the given declaration, including all of /// the declarations it contains. - LLVM_NODISCARD llvm::Error ImportDefinition_New(Decl *From); - - // FIXME: Compatibility function. - // Usages of this should be changed to ImportDefinition_New. - void ImportDefinition(Decl *From); + LLVM_NODISCARD llvm::Error ImportDefinition(Decl *From); /// Cope with a name conflict when importing a declaration into the /// given context. @@ -422,9 +527,13 @@ class Attr; /// Subclasses can override this function to observe all of the \c From -> /// \c To declaration mappings as they are imported. - virtual Decl *Imported(Decl *From, Decl *To) { return To; } + virtual void Imported(Decl *From, Decl *To) {} + + void RegisterImportedDecl(Decl *FromD, Decl *ToD); /// Store and assign the imported declaration to its counterpart. + /// It may happen that several decls from the 'from' context are mapped to + /// the same decl in the 'to' context. Decl *MapImported(Decl *From, Decl *To); /// Called by StructuralEquivalenceContext. If a RecordDecl is @@ -435,6 +544,14 @@ class Attr; /// importation, eliminating this loop. virtual Decl *GetOriginalDecl(Decl *To) { return nullptr; } + /// Return if import of the given declaration has failed and if yes + /// the kind of the problem. This gives the first error encountered with + /// the node. + llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *FromD) const; + + /// Mark (newly) imported declaration with error. + void setImportDeclError(Decl *From, ImportError Error); + /// Determine whether the given types are structurally /// equivalent. bool IsStructurallyEquivalent(QualType From, QualType To, @@ -445,7 +562,6 @@ class Attr; /// \returns The index of the field in its parent context (starting from 0). /// On error `None` is returned (parent context is non-record). static llvm::Optional<unsigned> getFieldIndex(Decl *F); - }; } // namespace clang diff --git a/include/clang/AST/ASTImporterLookupTable.h b/include/clang/AST/ASTImporterLookupTable.h index 14cafe817ddc..407478a51058 100644 --- a/include/clang/AST/ASTImporterLookupTable.h +++ b/include/clang/AST/ASTImporterLookupTable.h @@ -1,9 +1,8 @@ //===- ASTImporterLookupTable.h - ASTImporter specific lookup--*- C++ -*---===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/ASTImporterSharedState.h b/include/clang/AST/ASTImporterSharedState.h new file mode 100644 index 000000000000..3635a62deef0 --- /dev/null +++ b/include/clang/AST/ASTImporterSharedState.h @@ -0,0 +1,81 @@ +//===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the ASTImporter specific state, which may be shared +// amongst several ASTImporter objects. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H +#define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H + +#include "clang/AST/ASTImporterLookupTable.h" +#include "clang/AST/Decl.h" +#include "llvm/ADT/DenseMap.h" +// FIXME We need this because of ImportError. +#include "clang/AST/ASTImporter.h" + +namespace clang { + +class TranslationUnitDecl; + +/// Importer specific state, which may be shared amongst several ASTImporter +/// objects. +class ASTImporterSharedState { + + /// Pointer to the import specific lookup table. + std::unique_ptr<ASTImporterLookupTable> LookupTable; + + /// Mapping from the already-imported declarations in the "to" + /// context to the error status of the import of that declaration. + /// This map contains only the declarations that were not correctly + /// imported. The same declaration may or may not be included in + /// ImportedFromDecls. This map is updated continuously during imports and + /// never cleared (like ImportedFromDecls). + llvm::DenseMap<Decl *, ImportError> ImportErrors; + + // FIXME put ImportedFromDecls here! + // And from that point we can better encapsulate the lookup table. + +public: + ASTImporterSharedState() = default; + + ASTImporterSharedState(TranslationUnitDecl &ToTU) { + LookupTable = llvm::make_unique<ASTImporterLookupTable>(ToTU); + } + + ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); } + + void addDeclToLookup(Decl *D) { + if (LookupTable) + if (auto *ND = dyn_cast<NamedDecl>(D)) + LookupTable->add(ND); + } + + void removeDeclFromLookup(Decl *D) { + if (LookupTable) + if (auto *ND = dyn_cast<NamedDecl>(D)) + LookupTable->remove(ND); + } + + llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *ToD) const { + auto Pos = ImportErrors.find(ToD); + if (Pos != ImportErrors.end()) + return Pos->second; + else + return Optional<ImportError>(); + } + + void setImportDeclError(Decl *To, ImportError Error) { + ImportErrors[To] = Error; + } +}; + +} // namespace clang +#endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H diff --git a/include/clang/AST/ASTLambda.h b/include/clang/AST/ASTLambda.h index 6fedcb8d3801..c1153168e41b 100644 --- a/include/clang/AST/ASTLambda.h +++ b/include/clang/AST/ASTLambda.h @@ -1,9 +1,8 @@ //===--- ASTLambda.h - Lambda Helper Functions --------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// diff --git a/include/clang/AST/ASTMutationListener.h b/include/clang/AST/ASTMutationListener.h index 80184e1cc740..8879f9f3229f 100644 --- a/include/clang/AST/ASTMutationListener.h +++ b/include/clang/AST/ASTMutationListener.h @@ -1,9 +1,8 @@ //===--- ASTMutationListener.h - AST Mutation Interface --------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -128,6 +127,11 @@ public: virtual void DeclarationMarkedOpenMPDeclareTarget(const Decl *D, const Attr *Attr) {} + /// A declaration is marked as a variable with OpenMP allocator. + /// + /// \param D the declaration marked as a variable with OpenMP allocator. + virtual void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) {} + /// A definition has been made visible by being redefined locally. /// /// \param D The definition that was previously not visible. diff --git a/include/clang/AST/ASTNodeTraverser.h b/include/clang/AST/ASTNodeTraverser.h new file mode 100644 index 000000000000..e43eacef86c6 --- /dev/null +++ b/include/clang/AST/ASTNodeTraverser.h @@ -0,0 +1,654 @@ +//===--- ASTNodeTraverser.h - Traversal of AST nodes ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements the AST traversal facilities. Other users +// of this class may make use of the same traversal logic by inheriting it, +// similar to RecursiveASTVisitor. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ASTNODETRAVERSER_H +#define LLVM_CLANG_AST_ASTNODETRAVERSER_H + +#include "clang/AST/AttrVisitor.h" +#include "clang/AST/CommentVisitor.h" +#include "clang/AST/DeclVisitor.h" +#include "clang/AST/LocInfoType.h" +#include "clang/AST/StmtVisitor.h" +#include "clang/AST/TemplateArgumentVisitor.h" +#include "clang/AST/TypeVisitor.h" + +namespace clang { + +/** + +ASTNodeTraverser traverses the Clang AST for dumping purposes. + +The `Derived::doGetNodeDelegate()` method is required to be an accessible member +which returns a reference of type `NodeDelegateType &` which implements the +following interface: + +struct { + template <typename Fn> void AddChild(Fn DoAddChild); + template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild); + + void Visit(const comments::Comment *C, const comments::FullComment *FC); + void Visit(const Attr *A); + void Visit(const TemplateArgument &TA, SourceRange R = {}, + const Decl *From = nullptr, StringRef Label = {}); + void Visit(const Stmt *Node); + void Visit(const Type *T); + void Visit(QualType T); + void Visit(const Decl *D); + void Visit(const CXXCtorInitializer *Init); + void Visit(const OMPClause *C); + void Visit(const BlockDecl::Capture &C); + void Visit(const GenericSelectionExpr::ConstAssociation &A); +}; +*/ +template <typename Derived, typename NodeDelegateType> +class ASTNodeTraverser + : public ConstDeclVisitor<Derived>, + public ConstStmtVisitor<Derived>, + public comments::ConstCommentVisitor<Derived, void, + const comments::FullComment *>, + public TypeVisitor<Derived>, + public ConstAttrVisitor<Derived>, + public ConstTemplateArgumentVisitor<Derived> { + + /// Indicates whether we should trigger deserialization of nodes that had + /// not already been loaded. + bool Deserialize = false; + + NodeDelegateType &getNodeDelegate() { + return getDerived().doGetNodeDelegate(); + } + Derived &getDerived() { return *static_cast<Derived *>(this); } + +public: + void setDeserialize(bool D) { Deserialize = D; } + bool getDeserialize() const { return Deserialize; } + + void Visit(const Decl *D) { + getNodeDelegate().AddChild([=] { + getNodeDelegate().Visit(D); + if (!D) + return; + + ConstDeclVisitor<Derived>::Visit(D); + + for (const auto &A : D->attrs()) + Visit(A); + + if (const comments::FullComment *Comment = + D->getASTContext().getLocalCommentForDeclUncached(D)) + Visit(Comment, Comment); + + // Decls within functions are visited by the body. + if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D)) { + if (const auto *DC = dyn_cast<DeclContext>(D)) + dumpDeclContext(DC); + } + }); + } + + void Visit(const Stmt *S, StringRef Label = {}) { + getNodeDelegate().AddChild(Label, [=] { + getNodeDelegate().Visit(S); + + if (!S) { + return; + } + + ConstStmtVisitor<Derived>::Visit(S); + + // Some statements have custom mechanisms for dumping their children. + if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S)) { + return; + } + + for (const Stmt *SubStmt : S->children()) + Visit(SubStmt); + }); + } + + void Visit(QualType T) { + SplitQualType SQT = T.split(); + if (!SQT.Quals.hasQualifiers()) + return Visit(SQT.Ty); + + getNodeDelegate().AddChild([=] { + getNodeDelegate().Visit(T); + Visit(T.split().Ty); + }); + } + + void Visit(const Type *T) { + getNodeDelegate().AddChild([=] { + getNodeDelegate().Visit(T); + if (!T) + return; + TypeVisitor<Derived>::Visit(T); + + QualType SingleStepDesugar = + T->getLocallyUnqualifiedSingleStepDesugaredType(); + if (SingleStepDesugar != QualType(T, 0)) + Visit(SingleStepDesugar); + }); + } + + void Visit(const Attr *A) { + getNodeDelegate().AddChild([=] { + getNodeDelegate().Visit(A); + ConstAttrVisitor<Derived>::Visit(A); + }); + } + + void Visit(const CXXCtorInitializer *Init) { + getNodeDelegate().AddChild([=] { + getNodeDelegate().Visit(Init); + Visit(Init->getInit()); + }); + } + + void Visit(const TemplateArgument &A, SourceRange R = {}, + const Decl *From = nullptr, const char *Label = nullptr) { + getNodeDelegate().AddChild([=] { + getNodeDelegate().Visit(A, R, From, Label); + ConstTemplateArgumentVisitor<Derived>::Visit(A); + }); + } + + void Visit(const BlockDecl::Capture &C) { + getNodeDelegate().AddChild([=] { + getNodeDelegate().Visit(C); + if (C.hasCopyExpr()) + Visit(C.getCopyExpr()); + }); + } + + void Visit(const OMPClause *C) { + getNodeDelegate().AddChild([=] { + getNodeDelegate().Visit(C); + for (const auto *S : C->children()) + Visit(S); + }); + } + + void Visit(const GenericSelectionExpr::ConstAssociation &A) { + getNodeDelegate().AddChild([=] { + getNodeDelegate().Visit(A); + if (const TypeSourceInfo *TSI = A.getTypeSourceInfo()) + Visit(TSI->getType()); + Visit(A.getAssociationExpr()); + }); + } + + void Visit(const comments::Comment *C, const comments::FullComment *FC) { + getNodeDelegate().AddChild([=] { + getNodeDelegate().Visit(C, FC); + if (!C) { + return; + } + comments::ConstCommentVisitor<Derived, void, + const comments::FullComment *>::visit(C, + FC); + for (comments::Comment::child_iterator I = C->child_begin(), + E = C->child_end(); + I != E; ++I) + Visit(*I, FC); + }); + } + + void Visit(const ast_type_traits::DynTypedNode &N) { + // FIXME: Improve this with a switch or a visitor pattern. + if (const auto *D = N.get<Decl>()) + Visit(D); + else if (const auto *S = N.get<Stmt>()) + Visit(S); + else if (const auto *QT = N.get<QualType>()) + Visit(*QT); + else if (const auto *T = N.get<Type>()) + Visit(T); + else if (const auto *C = N.get<CXXCtorInitializer>()) + Visit(C); + else if (const auto *C = N.get<OMPClause>()) + Visit(C); + else if (const auto *T = N.get<TemplateArgument>()) + Visit(*T); + } + + void dumpDeclContext(const DeclContext *DC) { + if (!DC) + return; + + for (const auto *D : (Deserialize ? DC->decls() : DC->noload_decls())) + Visit(D); + } + + void dumpTemplateParameters(const TemplateParameterList *TPL) { + if (!TPL) + return; + + for (const auto &TP : *TPL) + Visit(TP); + } + + void + dumpASTTemplateArgumentListInfo(const ASTTemplateArgumentListInfo *TALI) { + if (!TALI) + return; + + for (const auto &TA : TALI->arguments()) + dumpTemplateArgumentLoc(TA); + } + + void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A, + const Decl *From = nullptr, + const char *Label = nullptr) { + Visit(A.getArgument(), A.getSourceRange(), From, Label); + } + + void dumpTemplateArgumentList(const TemplateArgumentList &TAL) { + for (unsigned i = 0, e = TAL.size(); i < e; ++i) + Visit(TAL[i]); + } + + void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) { + if (!typeParams) + return; + + for (const auto &typeParam : *typeParams) { + Visit(typeParam); + } + } + + void VisitComplexType(const ComplexType *T) { Visit(T->getElementType()); } + void VisitLocInfoType(const LocInfoType *T) { + Visit(T->getTypeSourceInfo()->getType()); + } + void VisitPointerType(const PointerType *T) { Visit(T->getPointeeType()); } + void VisitBlockPointerType(const BlockPointerType *T) { + Visit(T->getPointeeType()); + } + void VisitReferenceType(const ReferenceType *T) { + Visit(T->getPointeeType()); + } + void VisitMemberPointerType(const MemberPointerType *T) { + Visit(T->getClass()); + Visit(T->getPointeeType()); + } + void VisitArrayType(const ArrayType *T) { Visit(T->getElementType()); } + void VisitVariableArrayType(const VariableArrayType *T) { + VisitArrayType(T); + Visit(T->getSizeExpr()); + } + void VisitDependentSizedArrayType(const DependentSizedArrayType *T) { + Visit(T->getElementType()); + Visit(T->getSizeExpr()); + } + void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T) { + Visit(T->getElementType()); + Visit(T->getSizeExpr()); + } + void VisitVectorType(const VectorType *T) { Visit(T->getElementType()); } + void VisitFunctionType(const FunctionType *T) { Visit(T->getReturnType()); } + void VisitFunctionProtoType(const FunctionProtoType *T) { + VisitFunctionType(T); + for (const QualType &PT : T->getParamTypes()) + Visit(PT); + } + void VisitTypeOfExprType(const TypeOfExprType *T) { + Visit(T->getUnderlyingExpr()); + } + void VisitDecltypeType(const DecltypeType *T) { + Visit(T->getUnderlyingExpr()); + } + void VisitUnaryTransformType(const UnaryTransformType *T) { + Visit(T->getBaseType()); + } + void VisitAttributedType(const AttributedType *T) { + // FIXME: AttrKind + Visit(T->getModifiedType()); + } + void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) { + Visit(T->getReplacedParameter()); + } + void + VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T) { + Visit(T->getReplacedParameter()); + Visit(T->getArgumentPack()); + } + void VisitTemplateSpecializationType(const TemplateSpecializationType *T) { + for (const auto &Arg : *T) + Visit(Arg); + if (T->isTypeAlias()) + Visit(T->getAliasedType()); + } + void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { + Visit(T->getPointeeType()); + } + void VisitAtomicType(const AtomicType *T) { Visit(T->getValueType()); } + void VisitPipeType(const PipeType *T) { Visit(T->getElementType()); } + void VisitAdjustedType(const AdjustedType *T) { Visit(T->getOriginalType()); } + void VisitPackExpansionType(const PackExpansionType *T) { + if (!T->isSugared()) + Visit(T->getPattern()); + } + // FIXME: ElaboratedType, DependentNameType, + // DependentTemplateSpecializationType, ObjCObjectType + + void VisitTypedefDecl(const TypedefDecl *D) { Visit(D->getUnderlyingType()); } + + void VisitEnumConstantDecl(const EnumConstantDecl *D) { + if (const Expr *Init = D->getInitExpr()) + Visit(Init); + } + + void VisitFunctionDecl(const FunctionDecl *D) { + if (const auto *FTSI = D->getTemplateSpecializationInfo()) + dumpTemplateArgumentList(*FTSI->TemplateArguments); + + if (D->param_begin()) + for (const auto *Parameter : D->parameters()) + Visit(Parameter); + + if (const auto *C = dyn_cast<CXXConstructorDecl>(D)) + for (const auto *I : C->inits()) + Visit(I); + + if (D->doesThisDeclarationHaveABody()) + Visit(D->getBody()); + } + + void VisitFieldDecl(const FieldDecl *D) { + if (D->isBitField()) + Visit(D->getBitWidth()); + if (Expr *Init = D->getInClassInitializer()) + Visit(Init); + } + + void VisitVarDecl(const VarDecl *D) { + if (D->hasInit()) + Visit(D->getInit()); + } + + void VisitDecompositionDecl(const DecompositionDecl *D) { + VisitVarDecl(D); + for (const auto *B : D->bindings()) + Visit(B); + } + + void VisitBindingDecl(const BindingDecl *D) { + if (const auto *E = D->getBinding()) + Visit(E); + } + + void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) { + Visit(D->getAsmString()); + } + + void VisitCapturedDecl(const CapturedDecl *D) { Visit(D->getBody()); } + + void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) { + for (const auto *E : D->varlists()) + Visit(E); + } + + void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) { + Visit(D->getCombiner()); + if (const auto *Initializer = D->getInitializer()) + Visit(Initializer); + } + + void VisitOMPDeclareMapperDecl(const OMPDeclareMapperDecl *D) { + for (const auto *C : D->clauselists()) + Visit(C); + } + + void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) { + Visit(D->getInit()); + } + + void VisitOMPAllocateDecl(const OMPAllocateDecl *D) { + for (const auto *E : D->varlists()) + Visit(E); + for (const auto *C : D->clauselists()) + Visit(C); + } + + template <typename SpecializationDecl> + void dumpTemplateDeclSpecialization(const SpecializationDecl *D) { + for (const auto *RedeclWithBadType : D->redecls()) { + // FIXME: The redecls() range sometimes has elements of a less-specific + // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives + // us TagDecls, and should give CXXRecordDecls). + auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType); + if (!Redecl) { + // Found the injected-class-name for a class template. This will be + // dumped as part of its surrounding class so we don't need to dump it + // here. + assert(isa<CXXRecordDecl>(RedeclWithBadType) && + "expected an injected-class-name"); + continue; + } + Visit(Redecl); + } + } + + template <typename TemplateDecl> + void dumpTemplateDecl(const TemplateDecl *D) { + dumpTemplateParameters(D->getTemplateParameters()); + + Visit(D->getTemplatedDecl()); + + for (const auto *Child : D->specializations()) + dumpTemplateDeclSpecialization(Child); + } + + void VisitTypeAliasDecl(const TypeAliasDecl *D) { + Visit(D->getUnderlyingType()); + } + + void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) { + dumpTemplateParameters(D->getTemplateParameters()); + Visit(D->getTemplatedDecl()); + } + + void VisitStaticAssertDecl(const StaticAssertDecl *D) { + Visit(D->getAssertExpr()); + Visit(D->getMessage()); + } + + void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { + dumpTemplateDecl(D); + } + + void VisitClassTemplateDecl(const ClassTemplateDecl *D) { + dumpTemplateDecl(D); + } + + void VisitClassTemplateSpecializationDecl( + const ClassTemplateSpecializationDecl *D) { + dumpTemplateArgumentList(D->getTemplateArgs()); + } + + void VisitClassTemplatePartialSpecializationDecl( + const ClassTemplatePartialSpecializationDecl *D) { + VisitClassTemplateSpecializationDecl(D); + dumpTemplateParameters(D->getTemplateParameters()); + } + + void VisitClassScopeFunctionSpecializationDecl( + const ClassScopeFunctionSpecializationDecl *D) { + Visit(D->getSpecialization()); + dumpASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten()); + } + void VisitVarTemplateDecl(const VarTemplateDecl *D) { dumpTemplateDecl(D); } + + void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) { + dumpTemplateParameters(D->getTemplateParameters()); + } + + void + VisitVarTemplateSpecializationDecl(const VarTemplateSpecializationDecl *D) { + dumpTemplateArgumentList(D->getTemplateArgs()); + VisitVarDecl(D); + } + + void VisitVarTemplatePartialSpecializationDecl( + const VarTemplatePartialSpecializationDecl *D) { + dumpTemplateParameters(D->getTemplateParameters()); + VisitVarTemplateSpecializationDecl(D); + } + + void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) { + if (D->hasDefaultArgument()) + Visit(D->getDefaultArgument(), SourceRange(), + D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" : "previous"); + } + + void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { + if (D->hasDefaultArgument()) + Visit(D->getDefaultArgument(), SourceRange(), + D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" : "previous"); + } + + void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) { + dumpTemplateParameters(D->getTemplateParameters()); + if (D->hasDefaultArgument()) + dumpTemplateArgumentLoc( + D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" : "previous"); + } + + void VisitConceptDecl(const ConceptDecl *D) { + dumpTemplateParameters(D->getTemplateParameters()); + Visit(D->getConstraintExpr()); + } + + void VisitUsingShadowDecl(const UsingShadowDecl *D) { + if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl())) + Visit(TD->getTypeForDecl()); + } + + void VisitFriendDecl(const FriendDecl *D) { + if (!D->getFriendType()) + Visit(D->getFriendDecl()); + } + + void VisitObjCMethodDecl(const ObjCMethodDecl *D) { + if (D->isThisDeclarationADefinition()) + dumpDeclContext(D); + else + for (const ParmVarDecl *Parameter : D->parameters()) + Visit(Parameter); + + if (D->hasBody()) + Visit(D->getBody()); + } + + void VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { + dumpObjCTypeParamList(D->getTypeParamList()); + } + + void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { + dumpObjCTypeParamList(D->getTypeParamListAsWritten()); + } + + void VisitObjCImplementationDecl(const ObjCImplementationDecl *D) { + for (const auto &I : D->inits()) + Visit(I); + } + + void VisitBlockDecl(const BlockDecl *D) { + for (const auto &I : D->parameters()) + Visit(I); + + for (const auto &I : D->captures()) + Visit(I); + Visit(D->getBody()); + } + + void VisitDeclStmt(const DeclStmt *Node) { + for (const auto &D : Node->decls()) + Visit(D); + } + + void VisitAttributedStmt(const AttributedStmt *Node) { + for (const auto *A : Node->getAttrs()) + Visit(A); + } + + void VisitCXXCatchStmt(const CXXCatchStmt *Node) { + Visit(Node->getExceptionDecl()); + } + + void VisitCapturedStmt(const CapturedStmt *Node) { + Visit(Node->getCapturedDecl()); + } + + void VisitOMPExecutableDirective(const OMPExecutableDirective *Node) { + for (const auto *C : Node->clauses()) + Visit(C); + } + + void VisitInitListExpr(const InitListExpr *ILE) { + if (auto *Filler = ILE->getArrayFiller()) { + Visit(Filler, "array_filler"); + } + } + + void VisitBlockExpr(const BlockExpr *Node) { Visit(Node->getBlockDecl()); } + + void VisitOpaqueValueExpr(const OpaqueValueExpr *Node) { + if (Expr *Source = Node->getSourceExpr()) + Visit(Source); + } + + void VisitGenericSelectionExpr(const GenericSelectionExpr *E) { + Visit(E->getControllingExpr()); + Visit(E->getControllingExpr()->getType()); // FIXME: remove + + for (const auto &Assoc : E->associations()) { + Visit(Assoc); + } + } + + void VisitLambdaExpr(const LambdaExpr *Node) { + Visit(Node->getLambdaClass()); + } + + void VisitSizeOfPackExpr(const SizeOfPackExpr *Node) { + if (Node->isPartiallySubstituted()) + for (const auto &A : Node->getPartialArguments()) + Visit(A); + } + + void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) { + if (const VarDecl *CatchParam = Node->getCatchParamDecl()) + Visit(CatchParam); + } + + void VisitExpressionTemplateArgument(const TemplateArgument &TA) { + Visit(TA.getAsExpr()); + } + void VisitPackTemplateArgument(const TemplateArgument &TA) { + for (const auto &TArg : TA.pack_elements()) + Visit(TArg); + } + + // Implements Visit methods for Attrs. +#include "clang/AST/AttrNodeTraverse.inc" +}; + +} // namespace clang + +#endif // LLVM_CLANG_AST_ASTNODETRAVERSER_H diff --git a/include/clang/AST/ASTStructuralEquivalence.h b/include/clang/AST/ASTStructuralEquivalence.h index f8847505bc72..70e0daa08a9a 100644 --- a/include/clang/AST/ASTStructuralEquivalence.h +++ b/include/clang/AST/ASTStructuralEquivalence.h @@ -1,9 +1,8 @@ //===- ASTStructuralEquivalence.h -------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -112,6 +111,10 @@ struct StructuralEquivalenceContext { static llvm::Optional<unsigned> findUntaggedStructOrUnionIndex(RecordDecl *Anon); + // If ErrorOnTagTypeMismatch is set, return the the error, otherwise get the + // relevant warning for the input error diagnostic. + unsigned getApplicableDiagnostic(unsigned ErrorDiagnostic); + private: /// Finish checking all of the structural equivalences. /// diff --git a/include/clang/AST/ASTTypeTraits.h b/include/clang/AST/ASTTypeTraits.h index 9df9793370c4..a29a04e5d242 100644 --- a/include/clang/AST/ASTTypeTraits.h +++ b/include/clang/AST/ASTTypeTraits.h @@ -1,9 +1,8 @@ //===--- ASTTypeTraits.h ----------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -19,6 +18,7 @@ #include "clang/AST/ASTFwd.h" #include "clang/AST/Decl.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OpenMPClause.h" #include "clang/AST/Stmt.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TypeLoc.h" @@ -38,6 +38,17 @@ struct PrintingPolicy; namespace ast_type_traits { +/// Defines how we descend a level in the AST when we pass +/// through expressions. +enum TraversalKind { + /// Will traverse all child nodes. + TK_AsIs, + + /// Will not traverse implicit casts and parentheses. + /// Corresponds to Expr::IgnoreParenImpCasts() + TK_IgnoreImplicitCastsAndParentheses +}; + /// Kind identifier. /// /// It can be constructed from any node kind and allows for runtime type @@ -59,6 +70,7 @@ public: static ASTNodeKind getFromNode(const Decl &D); static ASTNodeKind getFromNode(const Stmt &S); static ASTNodeKind getFromNode(const Type &T); + static ASTNodeKind getFromNode(const OMPClause &C); /// \} /// Returns \c true if \c this and \c Other represent the same kind. @@ -137,6 +149,9 @@ private: NKI_Type, #define TYPE(DERIVED, BASE) NKI_##DERIVED##Type, #include "clang/AST/TypeNodes.def" + NKI_OMPClause, +#define OPENMP_CLAUSE(TextualSpelling, Class) NKI_##Class, +#include "clang/Basic/OpenMPKinds.def" NKI_NumberOfKinds }; @@ -184,12 +199,15 @@ KIND_TO_KIND_ID(TypeLoc) KIND_TO_KIND_ID(Decl) KIND_TO_KIND_ID(Stmt) KIND_TO_KIND_ID(Type) +KIND_TO_KIND_ID(OMPClause) #define DECL(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Decl) #include "clang/AST/DeclNodes.inc" #define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED) #include "clang/AST/StmtNodes.inc" #define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type) #include "clang/AST/TypeNodes.def" +#define OPENMP_CLAUSE(TextualSpelling, Class) KIND_TO_KIND_ID(Class) +#include "clang/Basic/OpenMPKinds.def" #undef KIND_TO_KIND_ID inline raw_ostream &operator<<(raw_ostream &OS, ASTNodeKind K) { @@ -460,6 +478,11 @@ struct DynTypedNode::BaseConverter< T, typename std::enable_if<std::is_base_of<Type, T>::value>::type> : public DynCastPtrConverter<T, Type> {}; +template <typename T> +struct DynTypedNode::BaseConverter< + T, typename std::enable_if<std::is_base_of<OMPClause, T>::value>::type> + : public DynCastPtrConverter<T, OMPClause> {}; + template <> struct DynTypedNode::BaseConverter< NestedNameSpecifier, void> : public PtrConverter<NestedNameSpecifier> {}; diff --git a/include/clang/AST/ASTUnresolvedSet.h b/include/clang/AST/ASTUnresolvedSet.h index 9bf63bb6e2d7..8d2b23b3539a 100644 --- a/include/clang/AST/ASTUnresolvedSet.h +++ b/include/clang/AST/ASTUnresolvedSet.h @@ -1,9 +1,8 @@ //===- ASTUnresolvedSet.h - Unresolved sets of declarations -----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/ASTVector.h b/include/clang/AST/ASTVector.h index 51de119f080e..d5a04767ca13 100644 --- a/include/clang/AST/ASTVector.h +++ b/include/clang/AST/ASTVector.h @@ -1,9 +1,8 @@ //===- ASTVector.h - Vector that uses ASTContext for allocation ---*- C++ -*-=// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index 3a319326d269..1fbed7ceebfa 100644 --- a/include/clang/AST/Attr.h +++ b/include/clang/AST/Attr.h @@ -1,9 +1,8 @@ //===--- Attr.h - Classes for representing attributes ----------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/AttrIterator.h b/include/clang/AST/AttrIterator.h index 43ad1c931967..78ce9314a2bb 100644 --- a/include/clang/AST/AttrIterator.h +++ b/include/clang/AST/AttrIterator.h @@ -1,9 +1,8 @@ //===- AttrIterator.h - Classes for attribute iteration ---------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/AttrVisitor.h b/include/clang/AST/AttrVisitor.h index 867f9e7ad18d..d271db010ed1 100644 --- a/include/clang/AST/AttrVisitor.h +++ b/include/clang/AST/AttrVisitor.h @@ -1,9 +1,8 @@ //===- AttrVisitor.h - Visitor for Attr subclasses --------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/Availability.h b/include/clang/AST/Availability.h index 28f3c3c01d20..527fc4b59a5f 100644 --- a/include/clang/AST/Availability.h +++ b/include/clang/AST/Availability.h @@ -1,9 +1,8 @@ //===--- Availability.h - Classes for availability --------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/BaseSubobject.h b/include/clang/AST/BaseSubobject.h index 8fd4ac69ebd6..15600f02fcef 100644 --- a/include/clang/AST/BaseSubobject.h +++ b/include/clang/AST/BaseSubobject.h @@ -1,9 +1,8 @@ //===- BaseSubobject.h - BaseSubobject class --------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -81,11 +80,6 @@ template<> struct DenseMapInfo<clang::BaseSubobject> { } }; -// It's OK to treat BaseSubobject as a POD type. -template <> struct isPodLike<clang::BaseSubobject> { - static const bool value = true; -}; - } // namespace llvm #endif // LLVM_CLANG_AST_BASESUBOBJECT_H diff --git a/include/clang/AST/BuiltinTypes.def b/include/clang/AST/BuiltinTypes.def index 400efcb1981f..74a45ee4ccc0 100644 --- a/include/clang/AST/BuiltinTypes.def +++ b/include/clang/AST/BuiltinTypes.def @@ -1,9 +1,8 @@ //===-- BuiltinTypes.def - Metadata about BuiltinTypes ----------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/CXXInheritance.h b/include/clang/AST/CXXInheritance.h index f5e23f8e8505..bb2ad9c64d3b 100644 --- a/include/clang/AST/CXXInheritance.h +++ b/include/clang/AST/CXXInheritance.h @@ -1,9 +1,8 @@ //===- CXXInheritance.h - C++ Inheritance -----------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/CanonicalType.h b/include/clang/AST/CanonicalType.h index c2f01e7d5460..2e00d344533d 100644 --- a/include/clang/AST/CanonicalType.h +++ b/include/clang/AST/CanonicalType.h @@ -1,9 +1,8 @@ //===- CanonicalType.h - C Language Family Type Representation --*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -510,7 +509,7 @@ struct CanProxyAdaptor<FunctionProtoType> } LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariadic) - LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Qualifiers, getTypeQuals) + LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Qualifiers, getMethodQuals) using param_type_iterator = CanTypeIterator<FunctionProtoType::param_type_iterator>; diff --git a/include/clang/AST/CharUnits.h b/include/clang/AST/CharUnits.h index 0aadf06fffc9..37f489c7708a 100644 --- a/include/clang/AST/CharUnits.h +++ b/include/clang/AST/CharUnits.h @@ -1,9 +1,8 @@ //===--- CharUnits.h - Character units for sizes and offsets ----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -238,10 +237,6 @@ template<> struct DenseMapInfo<clang::CharUnits> { } }; -template <> struct isPodLike<clang::CharUnits> { - static const bool value = true; -}; - } // end namespace llvm #endif // LLVM_CLANG_AST_CHARUNITS_H diff --git a/include/clang/AST/Comment.h b/include/clang/AST/Comment.h index 1b590562e152..2c284a271bb7 100644 --- a/include/clang/AST/Comment.h +++ b/include/clang/AST/Comment.h @@ -1,9 +1,8 @@ //===--- Comment.h - Comment AST nodes --------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/CommentBriefParser.h b/include/clang/AST/CommentBriefParser.h index baa22930539e..cfd2137bd68c 100644 --- a/include/clang/AST/CommentBriefParser.h +++ b/include/clang/AST/CommentBriefParser.h @@ -1,9 +1,8 @@ //===--- CommentBriefParser.h - Dumb comment parser -------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/CommentCommandTraits.h b/include/clang/AST/CommentCommandTraits.h index 4fd007872c01..83a29a540d42 100644 --- a/include/clang/AST/CommentCommandTraits.h +++ b/include/clang/AST/CommentCommandTraits.h @@ -1,9 +1,8 @@ //===--- CommentCommandTraits.h - Comment command properties ----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/CommentDiagnostic.h b/include/clang/AST/CommentDiagnostic.h index b9816f1a8e62..2e498d5db386 100644 --- a/include/clang/AST/CommentDiagnostic.h +++ b/include/clang/AST/CommentDiagnostic.h @@ -1,9 +1,8 @@ //===--- CommentDiagnostic.h - Diagnostics for the AST library --*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/clang/AST/CommentLexer.h b/include/clang/AST/CommentLexer.h index 3ef5b7c8c998..9ddbb7d31d99 100644 --- a/include/clang/AST/CommentLexer.h +++ b/include/clang/AST/CommentLexer.h @@ -1,9 +1,8 @@ //===--- CommentLexer.h - Lexer for structured comments ---------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/CommentParser.h b/include/clang/AST/CommentParser.h index fa8862899c14..1a0cfb06e52b 100644 --- a/include/clang/AST/CommentParser.h +++ b/include/clang/AST/CommentParser.h @@ -1,9 +1,8 @@ //===--- CommentParser.h - Doxygen comment parser ---------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/CommentSema.h b/include/clang/AST/CommentSema.h index 632eba782b92..307618fa5363 100644 --- a/include/clang/AST/CommentSema.h +++ b/include/clang/AST/CommentSema.h @@ -1,9 +1,8 @@ //===--- CommentSema.h - Doxygen comment semantic analysis ------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/CommentVisitor.h b/include/clang/AST/CommentVisitor.h index e37e9d6cd299..d9a7439f7cc0 100644 --- a/include/clang/AST/CommentVisitor.h +++ b/include/clang/AST/CommentVisitor.h @@ -1,9 +1,8 @@ //===- CommentVisitor.h - Visitor for Comment subclasses --------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/clang/AST/ComparisonCategories.h b/include/clang/AST/ComparisonCategories.h index 23bfd708e7eb..9d591cc81495 100644 --- a/include/clang/AST/ComparisonCategories.h +++ b/include/clang/AST/ComparisonCategories.h @@ -1,9 +1,8 @@ //===- ComparisonCategories.h - Three Way Comparison Data -------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/CurrentSourceLocExprScope.h b/include/clang/AST/CurrentSourceLocExprScope.h new file mode 100644 index 000000000000..4ebbdf63abb5 --- /dev/null +++ b/include/clang/AST/CurrentSourceLocExprScope.h @@ -0,0 +1,75 @@ +//===--- CurrentSourceLocExprScope.h ----------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines types used to track the current context needed to evaluate +// a SourceLocExpr. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H +#define LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H + +#include <cassert> + +namespace clang { +class Expr; + +/// Represents the current source location and context used to determine the +/// value of the source location builtins (ex. __builtin_LINE), including the +/// context of default argument and default initializer expressions. +class CurrentSourceLocExprScope { + /// The CXXDefaultArgExpr or CXXDefaultInitExpr we're currently evaluating. + const Expr *DefaultExpr = nullptr; + +public: + /// A RAII style scope guard used for tracking the current source + /// location and context as used by the source location builtins + /// (ex. __builtin_LINE). + class SourceLocExprScopeGuard; + + const Expr *getDefaultExpr() const { return DefaultExpr; } + + explicit CurrentSourceLocExprScope() = default; + +private: + explicit CurrentSourceLocExprScope(const Expr *DefaultExpr) + : DefaultExpr(DefaultExpr) {} + + CurrentSourceLocExprScope(CurrentSourceLocExprScope const &) = default; + CurrentSourceLocExprScope & + operator=(CurrentSourceLocExprScope const &) = default; +}; + +class CurrentSourceLocExprScope::SourceLocExprScopeGuard { +public: + SourceLocExprScopeGuard(const Expr *DefaultExpr, + CurrentSourceLocExprScope &Current) + : Current(Current), OldVal(Current), Enable(false) { + assert(DefaultExpr && "the new scope should not be empty"); + if ((Enable = (Current.getDefaultExpr() == nullptr))) + Current = CurrentSourceLocExprScope(DefaultExpr); + } + + ~SourceLocExprScopeGuard() { + if (Enable) + Current = OldVal; + } + +private: + SourceLocExprScopeGuard(SourceLocExprScopeGuard const &) = delete; + SourceLocExprScopeGuard &operator=(SourceLocExprScopeGuard const &) = delete; + + CurrentSourceLocExprScope &Current; + CurrentSourceLocExprScope OldVal; + bool Enable; +}; + +} // end namespace clang + +#endif // LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H diff --git a/include/clang/AST/DataCollection.h b/include/clang/AST/DataCollection.h index 8b2a8345d941..37f101793ecc 100644 --- a/include/clang/AST/DataCollection.h +++ b/include/clang/AST/DataCollection.h @@ -1,9 +1,8 @@ //===--- DatatCollection.h --------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// \file diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index de2765391f0f..02742801f37c 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1,9 +1,8 @@ //===- Decl.h - Classes for representing declarations -----------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -1227,10 +1226,15 @@ public: void setInit(Expr *I); - /// Determine whether this variable's value can be used in a + /// Determine whether this variable's value might be usable in a /// constant expression, according to the relevant language standard. /// This only checks properties of the declaration, and does not check /// whether the initializer is in fact a constant expression. + bool mightBeUsableInConstantExpressions(ASTContext &C) const; + + /// Determine whether this variable's value can be used in a + /// constant expression, according to the relevant language standard, + /// including checking whether it was initialized by a constant expression. bool isUsableInConstantExpressions(ASTContext &C) const; EvaluatedStmt *ensureEvaluatedStmt() const; @@ -1396,6 +1400,10 @@ public: NonParmVarDeclBits.IsInitCapture = IC; } + /// Determine whether this variable is actually a function parameter pack or + /// init-capture pack. + bool isParameterPack() const; + /// Whether this local extern variable declaration's previous declaration /// was declared in the same block scope. Only correct in C++. bool isPreviousDeclInSameBlockScope() const { @@ -1435,6 +1443,12 @@ public: /// template specialization or instantiation this is. TemplateSpecializationKind getTemplateSpecializationKind() const; + /// Get the template specialization kind of this variable for the purposes of + /// template instantiation. This differs from getTemplateSpecializationKind() + /// for an instantiation of a class-scope explicit specialization. + TemplateSpecializationKind + getTemplateSpecializationKindForInstantiation() const; + /// If this variable is an instantiation of a variable template or a /// static data member of a class template, determine its point of /// instantiation. @@ -1683,10 +1697,6 @@ public: QualType getOriginalType() const; - /// Determine whether this parameter is actually a function - /// parameter pack. - bool isParameterPack() const; - /// Sets the function declaration that owns this /// ParmVarDecl. Since ParmVarDecls are often created before the /// FunctionDecls that own them, this routine is required to update @@ -1743,10 +1753,19 @@ class FunctionDecl : public DeclaratorDecl, public: /// The kind of templated function a FunctionDecl can be. enum TemplatedKind { + // Not templated. TK_NonTemplate, + // The pattern in a function template declaration. TK_FunctionTemplate, + // A non-template function that is an instantiation or explicit + // specialization of a member of a templated class. TK_MemberSpecialization, + // An instantiation or explicit specialization of a function template. + // Note: this might have been instantiated from a templated class if it + // is a class-scope explicit specialization. TK_FunctionTemplateSpecialization, + // A function template specialization that hasn't yet been resolved to a + // particular specialized function template. TK_DependentFunctionTemplateSpecialization }; @@ -1842,7 +1861,7 @@ protected: FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass S, bool isInlineSpecified, - bool isConstexprSpecified); + ConstexprSpecKind ConstexprKind); using redeclarable_base = Redeclarable<FunctionDecl>; @@ -1872,29 +1891,24 @@ public: using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; - static FunctionDecl *Create(ASTContext &C, DeclContext *DC, - SourceLocation StartLoc, SourceLocation NLoc, - DeclarationName N, QualType T, - TypeSourceInfo *TInfo, - StorageClass SC, - bool isInlineSpecified = false, - bool hasWrittenPrototype = true, - bool isConstexprSpecified = false) { + static FunctionDecl * + Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, + SourceLocation NLoc, DeclarationName N, QualType T, + TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified = false, + bool hasWrittenPrototype = true, + ConstexprSpecKind ConstexprKind = CSK_unspecified) { DeclarationNameInfo NameInfo(N, NLoc); - return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, - SC, + return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC, isInlineSpecified, hasWrittenPrototype, - isConstexprSpecified); + ConstexprKind); } static FunctionDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, - const DeclarationNameInfo &NameInfo, - QualType T, TypeSourceInfo *TInfo, - StorageClass SC, - bool isInlineSpecified, - bool hasWrittenPrototype, - bool isConstexprSpecified = false); + const DeclarationNameInfo &NameInfo, QualType T, + TypeSourceInfo *TInfo, StorageClass SC, + bool isInlineSpecified, bool hasWrittenPrototype, + ConstexprSpecKind ConstexprKind); static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID); @@ -2091,8 +2105,21 @@ public: } /// Whether this is a (C++11) constexpr function or constexpr constructor. - bool isConstexpr() const { return FunctionDeclBits.IsConstexpr; } - void setConstexpr(bool IC) { FunctionDeclBits.IsConstexpr = IC; } + bool isConstexpr() const { + return FunctionDeclBits.ConstexprKind != CSK_unspecified; + } + void setConstexprKind(ConstexprSpecKind CSK) { + FunctionDeclBits.ConstexprKind = CSK; + } + ConstexprSpecKind getConstexprKind() const { + return static_cast<ConstexprSpecKind>(FunctionDeclBits.ConstexprKind); + } + bool isConstexprSpecified() const { + return FunctionDeclBits.ConstexprKind == CSK_constexpr; + } + bool isConsteval() const { + return FunctionDeclBits.ConstexprKind == CSK_consteval; + } /// Whether the instantiation of this function is pending. /// This bit is set when the decision to instantiate this function is made @@ -2256,7 +2283,7 @@ public: return const_cast<FunctionDecl*>(this)->getCanonicalDecl(); } - unsigned getBuiltinID() const; + unsigned getBuiltinID(bool ConsiderWrapperFunctions = false) const; // ArrayRef interface to parameters. ArrayRef<ParmVarDecl *> parameters() const { @@ -2316,6 +2343,14 @@ public: return T->castAs<FunctionType>()->getReturnType(); } + /// Gets the ExceptionSpecificationType as declared. + ExceptionSpecificationType getExceptionSpecType() const { + auto *TSI = getTypeSourceInfo(); + QualType T = TSI ? TSI->getType() : getType(); + const auto *FPT = T->getAs<FunctionProtoType>(); + return FPT ? FPT->getExceptionSpecType() : EST_None; + } + /// Attempt to compute an informative source range covering the /// function exception specification, if any. SourceRange getExceptionSpecSourceRange() const; @@ -2355,22 +2390,14 @@ public: /// that was defined in the class body. bool isInlined() const { return FunctionDeclBits.IsInline; } - /// Whether this function is marked as explicit explicitly. - bool isExplicitSpecified() const { - return FunctionDeclBits.IsExplicitSpecified; - } - - /// State that this function is marked as explicit explicitly. - void setExplicitSpecified(bool ExpSpec = true) { - FunctionDeclBits.IsExplicitSpecified = ExpSpec; - } - bool isInlineDefinitionExternallyVisible() const; bool isMSExternInline() const; bool doesDeclarationForceExternallyVisibleDefinition() const; + bool isStatic() const { return getStorageClass() == SC_Static; } + /// Whether this function declaration represents an C++ overloaded /// operator, e.g., "operator+". bool isOverloadedOperator() const { @@ -2441,10 +2468,6 @@ public: return getPrimaryTemplate() != nullptr; } - /// Retrieve the class scope template pattern that this function - /// template specialization is instantiated from. - FunctionDecl *getClassScopeSpecializationPattern() const; - /// If this function is actually a function template specialization, /// retrieve information about this function template specialization. /// Otherwise, returns NULL. @@ -2531,6 +2554,11 @@ public: /// represents. TemplateSpecializationKind getTemplateSpecializationKind() const; + /// Determine the kind of template specialization this function represents + /// for the purpose of template instantiation. + TemplateSpecializationKind + getTemplateSpecializationKindForInstantiation() const; + /// Determine what kind of template instantiation this function /// represents. void setTemplateSpecializationKind(TemplateSpecializationKind TSK, @@ -2703,6 +2731,11 @@ public: /// bit-fields. bool isZeroLengthBitField(const ASTContext &Ctx) const; + /// Determine if this field is a subobject of zero size, that is, either a + /// zero-length bit-field or a field of empty class type with the + /// [[no_unique_address]] attribute. + bool isZeroSize(const ASTContext &Ctx) const; + /// Get the kind of (C++11) default member initializer that this field has. InClassInitStyle getInClassInitStyle() const { InitStorageKind storageKind = InitStorage.getInt(); @@ -3713,6 +3746,30 @@ public: RecordDeclBits.NonTrivialToPrimitiveDestroy = V; } + bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const { + return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion; + } + + void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V) { + RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V; + } + + bool hasNonTrivialToPrimitiveDestructCUnion() const { + return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion; + } + + void setHasNonTrivialToPrimitiveDestructCUnion(bool V) { + RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V; + } + + bool hasNonTrivialToPrimitiveCopyCUnion() const { + return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion; + } + + void setHasNonTrivialToPrimitiveCopyCUnion(bool V) { + RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V; + } + /// Determine whether this class can be passed in registers. In C++ mode, /// it must have at least one trivial, non-deleted copy or move constructor. /// FIXME: This should be set as part of completeDefinition. @@ -3852,7 +3909,7 @@ public: static bool classofKind(Kind K) { return K == FileScopeAsm; } }; -/// Pepresents a block literal declaration, which is like an +/// Represents a block literal declaration, which is like an /// unnamed FunctionDecl. For example: /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } class BlockDecl : public Decl, public DeclContext { @@ -4009,6 +4066,13 @@ public: bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; } void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; } + bool canAvoidCopyToHeap() const { + return BlockDeclBits.CanAvoidCopyToHeap; + } + void setCanAvoidCopyToHeap(bool B = true) { + BlockDeclBits.CanAvoidCopyToHeap = B; + } + bool capturesVariable(const VarDecl *var) const; void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures, @@ -4233,8 +4297,10 @@ public: SourceLocation getRBraceLoc() const { return RBraceLoc; } void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } + bool hasBraces() const { return RBraceLoc.isValid(); } + SourceLocation getEndLoc() const LLVM_READONLY { - if (RBraceLoc.isValid()) + if (hasBraces()) return RBraceLoc; // No braces: get the end location of the (only) declaration in context // (if present). diff --git a/include/clang/AST/DeclAccessPair.h b/include/clang/AST/DeclAccessPair.h index 3c5056c6e55b..805342c2910a 100644 --- a/include/clang/AST/DeclAccessPair.h +++ b/include/clang/AST/DeclAccessPair.h @@ -1,9 +1,8 @@ //===--- DeclAccessPair.h - A decl bundled with its path access -*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -61,12 +60,4 @@ public: }; } -// Take a moment to tell SmallVector that DeclAccessPair is POD. -namespace llvm { -template<typename> struct isPodLike; -template<> struct isPodLike<clang::DeclAccessPair> { - static const bool value = true; -}; -} - #endif diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 8405a43fa098..d64d0cb425db 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -1,9 +1,8 @@ //===- DeclBase.h - Base Classes for representing declarations --*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -14,6 +13,7 @@ #ifndef LLVM_CLANG_AST_DECLBASE_H #define LLVM_CLANG_AST_DECLBASE_H +#include "clang/AST/ASTDumperUtils.h" #include "clang/AST/AttrIterator.h" #include "clang/AST/DeclarationName.h" #include "clang/Basic/IdentifierTable.h" @@ -42,6 +42,7 @@ namespace clang { class ASTContext; class ASTMutationListener; class Attr; +class BlockDecl; class DeclContext; class ExternalSourceSymbolAttr; class FunctionDecl; @@ -176,7 +177,10 @@ public: IDNS_LocalExtern = 0x0800, /// This declaration is an OpenMP user defined reduction construction. - IDNS_OMPReduction = 0x1000 + IDNS_OMPReduction = 0x1000, + + /// This declaration is an OpenMP user defined mapper. + IDNS_OMPMapper = 0x2000, }; /// ObjCDeclQualifier - 'Qualifiers' written next to the return and @@ -324,7 +328,7 @@ protected: unsigned FromASTFile : 1; /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. - unsigned IdentifierNamespace : 13; + unsigned IdentifierNamespace : 14; /// If 0, we have not computed the linkage of this declaration. /// Otherwise, it is the linkage + 1. @@ -364,6 +368,13 @@ private: return ModuleOwnershipKind::Unowned; } +public: + Decl() = delete; + Decl(const Decl&) = delete; + Decl(Decl &&) = delete; + Decl &operator=(const Decl&) = delete; + Decl &operator=(Decl&&) = delete; + protected: Decl(Kind DK, DeclContext *DC, SourceLocation L) : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)), @@ -597,10 +608,6 @@ public: return getModuleOwnershipKind() == ModuleOwnershipKind::ModulePrivate; } - /// Whether this declaration is exported (by virtue of being lexically - /// within an ExportDecl or by being a NamespaceDecl). - bool isExported() const; - /// Return true if this declaration has an attribute which acts as /// definition of the entity, such as 'alias' or 'ifunc'. bool hasDefiningAttr() const; @@ -1135,7 +1142,8 @@ public: // Same as dump(), but forces color printing. void dumpColor() const; - void dump(raw_ostream &Out, bool Deserialize = false) const; + void dump(raw_ostream &Out, bool Deserialize = false, + ASTDumpOutputFormat OutputFormat = ADOF_Default) const; /// \return Unique reproducible object identifier int64_t getID() const; @@ -1252,6 +1260,7 @@ public: /// NamespaceDecl /// TagDecl /// OMPDeclareReductionDecl +/// OMPDeclareMapperDecl /// FunctionDecl /// ObjCMethodDecl /// ObjCContainerDecl @@ -1431,6 +1440,13 @@ class DeclContext { uint64_t NonTrivialToPrimitiveCopy : 1; uint64_t NonTrivialToPrimitiveDestroy : 1; + /// The following bits indicate whether this is or contains a C union that + /// is non-trivial to default-initialize, destruct, or copy. These bits + /// imply the associated basic non-triviality predicates declared above. + uint64_t HasNonTrivialToPrimitiveDefaultInitializeCUnion : 1; + uint64_t HasNonTrivialToPrimitiveDestructCUnion : 1; + uint64_t HasNonTrivialToPrimitiveCopyCUnion : 1; + /// Indicates whether this struct is destroyed in the callee. uint64_t ParamDestroyedInCallee : 1; @@ -1439,7 +1455,7 @@ class DeclContext { }; /// Number of non-inherited bits in RecordDeclBitfields. - enum { NumRecordDeclBits = 11 }; + enum { NumRecordDeclBits = 14 }; /// Stores the bits used by OMPDeclareReductionDecl. /// If modified NumOMPDeclareReductionDeclBits and the accessor @@ -1472,10 +1488,6 @@ class DeclContext { uint64_t IsInline : 1; uint64_t IsInlineSpecified : 1; - /// This is shared by CXXConstructorDecl, - /// CXXConversionDecl, and CXXDeductionGuideDecl. - uint64_t IsExplicitSpecified : 1; - uint64_t IsVirtualAsWritten : 1; uint64_t IsPure : 1; uint64_t HasInheritedPrototype : 1; @@ -1495,7 +1507,9 @@ class DeclContext { uint64_t IsExplicitlyDefaulted : 1; uint64_t HasImplicitReturnZero : 1; uint64_t IsLateTemplateParsed : 1; - uint64_t IsConstexpr : 1; + + /// Kind of contexpr specifier as defined by ConstexprSpecKind. + uint64_t ConstexprKind : 2; uint64_t InstantiationIsPending : 1; /// Indicates if the function uses __try. @@ -1535,17 +1549,25 @@ class DeclContext { /// For the bits in FunctionDeclBitfields. uint64_t : NumFunctionDeclBits; - /// 25 bits to fit in the remaining availible space. + /// 24 bits to fit in the remaining available space. /// Note that this makes CXXConstructorDeclBitfields take /// exactly 64 bits and thus the width of NumCtorInitializers /// will need to be shrunk if some bit is added to NumDeclContextBitfields, /// NumFunctionDeclBitfields or CXXConstructorDeclBitfields. - uint64_t NumCtorInitializers : 25; + uint64_t NumCtorInitializers : 23; uint64_t IsInheritingConstructor : 1; + + /// Whether this constructor has a trail-allocated explicit specifier. + uint64_t HasTrailingExplicitSpecifier : 1; + /// If this constructor does't have a trail-allocated explicit specifier. + /// Whether this constructor is explicit specified. + uint64_t IsSimpleExplicit : 1; }; /// Number of non-inherited bits in CXXConstructorDeclBitfields. - enum { NumCXXConstructorDeclBits = 26 }; + enum { + NumCXXConstructorDeclBits = 64 - NumDeclContextBits - NumFunctionDeclBits + }; /// Stores the bits used by ObjCMethodDecl. /// If modified NumObjCMethodDeclBits and the accessor @@ -1662,6 +1684,11 @@ class DeclContext { /// A bit that indicates this block is passed directly to a function as a /// non-escaping parameter. uint64_t DoesNotEscape : 1; + + /// A bit that indicates whether it's possible to avoid coying this block to + /// the heap when it initializes or is assigned to a local variable with + /// automatic storage. + uint64_t CanAvoidCopyToHeap : 1; }; /// Number of non-inherited bits in BlockDeclBitfields. @@ -1784,6 +1811,10 @@ public: bool isClosure() const { return getDeclKind() == Decl::Block; } + /// Return this DeclContext if it is a BlockDecl. Otherwise, return the + /// innermost enclosing BlockDecl or null if there are no enclosing blocks. + const BlockDecl *getInnermostBlockDecl() const; + bool isObjCContainer() const { switch (getDeclKind()) { case Decl::ObjCCategory: diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index d3357c245d86..7add83f89624 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -1,9 +1,8 @@ //===- DeclCXX.h - Classes for representing C++ declarations --*- C++ -*-=====// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -64,6 +63,7 @@ class CXXDestructorDecl; class CXXFinalOverriderMap; class CXXIndirectPrimaryBaseSet; class CXXMethodDecl; +class DecompositionDecl; class DiagnosticBuilder; class FriendDecl; class FunctionTemplateDecl; @@ -334,10 +334,12 @@ class CXXRecordDecl : public RecordDecl { /// True when this class is a POD-type. unsigned PlainOldData : 1; - /// true when this class is empty for traits purposes, - /// i.e. has no data members other than 0-width bit-fields, has no - /// virtual function/base, and doesn't inherit from a non-empty - /// class. Doesn't take union-ness into account. + /// True when this class is empty for traits purposes, that is: + /// * has no data members other than 0-width bit-fields and empty fields + /// marked [[no_unique_address]] + /// * has no virtual function/base, and + /// * doesn't inherit from a non-empty class. + /// Doesn't take union-ness into account. unsigned Empty : 1; /// True when this class is polymorphic, i.e., has at @@ -1222,6 +1224,9 @@ public: /// lambda. TemplateParameterList *getGenericLambdaTemplateParameterList() const; + /// Retrieve the lambda template parameters that were specified explicitly. + ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const; + LambdaCaptureDefault getLambdaCaptureDefault() const { assert(isLambda()); return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault); @@ -1326,6 +1331,14 @@ public: /// \note This does NOT include a check for union-ness. bool isEmpty() const { return data().Empty; } + bool hasPrivateFields() const { + return data().HasPrivateFields; + } + + bool hasProtectedFields() const { + return data().HasProtectedFields; + } + /// Determine whether this class has direct non-static data members. bool hasDirectFields() const { auto &D = data(); @@ -1829,6 +1842,14 @@ public: CXXBasePath &Path, DeclarationName Name); /// Base-class lookup callback that determines whether there exists + /// an OpenMP declare mapper member with the given name. + /// + /// This callback can be used with \c lookupInBases() to find members + /// of the given name within a C++ class hierarchy. + static bool FindOMPMapperMember(const CXXBaseSpecifier *Specifier, + CXXBasePath &Path, DeclarationName Name); + + /// Base-class lookup callback that determines whether there exists /// a member with the given name that can be used in a nested-name-specifier. /// /// This callback can be used with \c lookupInBases() to find members of @@ -1975,6 +1996,53 @@ public: } }; +/// Store information needed for an explicit specifier. +/// used by CXXDeductionGuideDecl, CXXConstructorDecl and CXXConversionDecl. +class ExplicitSpecifier { + llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{ + nullptr, ExplicitSpecKind::ResolvedFalse}; + +public: + ExplicitSpecifier() = default; + ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind) + : ExplicitSpec(Expression, Kind) {} + ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); } + const Expr *getExpr() const { return ExplicitSpec.getPointer(); } + Expr *getExpr() { return ExplicitSpec.getPointer(); } + + /// Return true if the ExplicitSpecifier isn't defaulted. + bool isSpecified() const { + return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse || + ExplicitSpec.getPointer(); + } + + /// Check for Equivalence of explicit specifiers. + /// Return True if the explicit specifier are equivalent false otherwise. + bool isEquivalent(const ExplicitSpecifier Other) const; + /// Return true if the explicit specifier is already resolved to be explicit. + bool isExplicit() const { + return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue; + } + /// Return true if the ExplicitSpecifier isn't valid. + /// This state occurs after a substitution failures. + bool isInvalid() const { + return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved && + !ExplicitSpec.getPointer(); + } + void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); } + void setExpr(Expr *E) { ExplicitSpec.setPointer(E); } + // getFromDecl - retrieve the explicit specifier in the given declaration. + // if the given declaration has no explicit. the returned explicit specifier + // is defaulted. .isSpecified() will be false. + static ExplicitSpecifier getFromDecl(FunctionDecl *Function); + static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) { + return getFromDecl(const_cast<FunctionDecl *>(Function)); + } + static ExplicitSpecifier Invalid() { + return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved); + } +}; + /// Represents a C++ deduction guide declaration. /// /// \code @@ -1990,31 +2058,36 @@ class CXXDeductionGuideDecl : public FunctionDecl { private: CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, - bool IsExplicit, const DeclarationNameInfo &NameInfo, - QualType T, TypeSourceInfo *TInfo, - SourceLocation EndLocation) + ExplicitSpecifier ES, + const DeclarationNameInfo &NameInfo, QualType T, + TypeSourceInfo *TInfo, SourceLocation EndLocation) : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo, - SC_None, false, false) { + SC_None, false, CSK_unspecified), + ExplicitSpec(ES) { if (EndLocation.isValid()) setRangeEnd(EndLocation); - setExplicitSpecified(IsExplicit); setIsCopyDeductionCandidate(false); } + ExplicitSpecifier ExplicitSpec; + void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } + public: friend class ASTDeclReader; friend class ASTDeclWriter; - static CXXDeductionGuideDecl *Create(ASTContext &C, DeclContext *DC, - SourceLocation StartLoc, bool IsExplicit, - const DeclarationNameInfo &NameInfo, - QualType T, TypeSourceInfo *TInfo, - SourceLocation EndLocation); + static CXXDeductionGuideDecl * + Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, + ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, + TypeSourceInfo *TInfo, SourceLocation EndLocation); static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID); - /// Whether this deduction guide is explicit. - bool isExplicit() const { return isExplicitSpecified(); } + ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; } + const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; } + + /// Return true if the declartion is already resolved to be explicit. + bool isExplicit() const { return ExplicitSpec.isExplicit(); } /// Get the template for which this guide performs deduction. TemplateDecl *getDeducedTemplate() const { @@ -2044,11 +2117,11 @@ class CXXMethodDecl : public FunctionDecl { protected: CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, - QualType T, TypeSourceInfo *TInfo, - StorageClass SC, bool isInline, - bool isConstexpr, SourceLocation EndLocation) - : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, - SC, isInline, isConstexpr) { + QualType T, TypeSourceInfo *TInfo, StorageClass SC, + bool isInline, ConstexprSpecKind ConstexprKind, + SourceLocation EndLocation) + : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, isInline, + ConstexprKind) { if (EndLocation.isValid()) setRangeEnd(EndLocation); } @@ -2056,11 +2129,9 @@ protected: public: static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, - const DeclarationNameInfo &NameInfo, - QualType T, TypeSourceInfo *TInfo, - StorageClass SC, - bool isInline, - bool isConstexpr, + const DeclarationNameInfo &NameInfo, QualType T, + TypeSourceInfo *TInfo, StorageClass SC, + bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation); static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); @@ -2161,20 +2232,20 @@ public: overridden_method_range overridden_methods() const; - /// Returns the parent of this method declaration, which + /// Return the parent of this method declaration, which /// is the class in which this method is defined. const CXXRecordDecl *getParent() const { return cast<CXXRecordDecl>(FunctionDecl::getParent()); } - /// Returns the parent of this method declaration, which + /// Return the parent of this method declaration, which /// is the class in which this method is defined. CXXRecordDecl *getParent() { return const_cast<CXXRecordDecl *>( cast<CXXRecordDecl>(FunctionDecl::getParent())); } - /// Returns the type of the \c this pointer. + /// Return the type of the \c this pointer. /// /// Should only be called for instance (i.e., non-static) methods. Note /// that for the call operator of a lambda closure type, this returns the @@ -2182,11 +2253,19 @@ public: /// 'this' type. QualType getThisType() const; + /// Return the type of the object pointed by \c this. + /// + /// See getThisType() for usage restriction. + QualType getThisObjectType() const; + static QualType getThisType(const FunctionProtoType *FPT, const CXXRecordDecl *Decl); - Qualifiers getTypeQualifiers() const { - return getType()->getAs<FunctionProtoType>()->getTypeQuals(); + static QualType getThisObjectType(const FunctionProtoType *FPT, + const CXXRecordDecl *Decl); + + Qualifiers getMethodQualifiers() const { + return getType()->getAs<FunctionProtoType>()->getMethodQuals(); } /// Retrieve the ref-qualifier associated with this method. @@ -2231,6 +2310,17 @@ public: ->getCorrespondingMethodInClass(RD, MayBeBase); } + /// Find if \p RD declares a function that overrides this function, and if so, + /// return it. Does not search base classes. + CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, + bool MayBeBase = false); + const CXXMethodDecl * + getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, + bool MayBeBase = false) const { + return const_cast<CXXMethodDecl *>(this) + ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase); + } + // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { @@ -2483,7 +2573,8 @@ public: /// \endcode class CXXConstructorDecl final : public CXXMethodDecl, - private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor> { + private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor, + ExplicitSpecifier> { // This class stores some data in DeclContext::CXXConstructorDeclBits // to save some space. Use the provided accessors to access it. @@ -2493,28 +2584,74 @@ class CXXConstructorDecl final LazyCXXCtorInitializersPtr CtorInitializers; CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, - const DeclarationNameInfo &NameInfo, - QualType T, TypeSourceInfo *TInfo, - bool isExplicitSpecified, bool isInline, - bool isImplicitlyDeclared, bool isConstexpr, + const DeclarationNameInfo &NameInfo, QualType T, + TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline, + bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited); void anchor() override; + size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const { + return CXXConstructorDeclBits.IsInheritingConstructor; + } + size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const { + return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; + } + + ExplicitSpecifier getExplicitSpecifierInternal() const { + if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier) + return *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>(); + return ExplicitSpecifier( + nullptr, getCanonicalDecl()->CXXConstructorDeclBits.IsSimpleExplicit + ? ExplicitSpecKind::ResolvedTrue + : ExplicitSpecKind::ResolvedFalse); + } + + void setExplicitSpecifier(ExplicitSpecifier ES) { + assert((!ES.getExpr() || + CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && + "cannot set this explicit specifier. no trail-allocated space for " + "explicit"); + if (ES.getExpr()) + *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES; + else + CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit(); + } + + enum TraillingAllocKind { + TAKInheritsConstructor = 1, + TAKHasTailExplicit = 1 << 1, + }; + + uint64_t getTraillingAllocKind() const { + return numTrailingObjects(OverloadToken<InheritedConstructor>()) | + (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1); + } + public: friend class ASTDeclReader; friend class ASTDeclWriter; friend TrailingObjects; static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID, - bool InheritsConstructor); + uint64_t AllocKind); static CXXConstructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, - bool isExplicit, bool isInline, bool isImplicitlyDeclared, - bool isConstexpr, + ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, + ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited = InheritedConstructor()); + ExplicitSpecifier getExplicitSpecifier() { + return getExplicitSpecifierInternal(); + } + const ExplicitSpecifier getExplicitSpecifier() const { + return getExplicitSpecifierInternal(); + } + + /// Return true if the declartion is already resolved to be explicit. + bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } + /// Iterates through the member/base initializer list. using init_iterator = CXXCtorInitializer **; @@ -2585,11 +2722,6 @@ public: CtorInitializers = Initializers; } - /// Whether this function is explicit. - bool isExplicit() const { - return getCanonicalDecl()->isExplicitSpecified(); - } - /// Determine whether this constructor is a delegating constructor. bool isDelegatingConstructor() const { return (getNumCtorInitializers() == 1) && @@ -2713,12 +2845,11 @@ class CXXDestructorDecl : public CXXMethodDecl { Expr *OperatorDeleteThisArg = nullptr; CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, - const DeclarationNameInfo &NameInfo, - QualType T, TypeSourceInfo *TInfo, - bool isInline, bool isImplicitlyDeclared) - : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo, - SC_None, isInline, /*isConstexpr=*/false, SourceLocation()) - { + const DeclarationNameInfo &NameInfo, QualType T, + TypeSourceInfo *TInfo, bool isInline, + bool isImplicitlyDeclared) + : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo, + SC_None, isInline, CSK_unspecified, SourceLocation()) { setImplicit(isImplicitlyDeclared); } @@ -2768,34 +2899,39 @@ public: class CXXConversionDecl : public CXXMethodDecl { CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, - TypeSourceInfo *TInfo, bool isInline, - bool isExplicitSpecified, bool isConstexpr, - SourceLocation EndLocation) + TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES, + ConstexprSpecKind ConstexprKind, SourceLocation EndLocation) : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo, - SC_None, isInline, isConstexpr, EndLocation) { - setExplicitSpecified(isExplicitSpecified); - } - + SC_None, isInline, ConstexprKind, EndLocation), + ExplicitSpec(ES) {} void anchor() override; + ExplicitSpecifier ExplicitSpec; + + void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } + public: friend class ASTDeclReader; friend class ASTDeclWriter; - static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, - SourceLocation StartLoc, - const DeclarationNameInfo &NameInfo, - QualType T, TypeSourceInfo *TInfo, - bool isInline, bool isExplicit, - bool isConstexpr, - SourceLocation EndLocation); + static CXXConversionDecl * + Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, + const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, + bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, + SourceLocation EndLocation); static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); - /// Whether this function is explicit. - bool isExplicit() const { - return getCanonicalDecl()->isExplicitSpecified(); + ExplicitSpecifier getExplicitSpecifier() { + return getCanonicalDecl()->ExplicitSpec; + } + + const ExplicitSpecifier getExplicitSpecifier() const { + return getCanonicalDecl()->ExplicitSpec; } + /// Return true if the declartion is already resolved to be explicit. + bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } + /// Returns the type that this conversion function is converting to. QualType getConversionType() const { return getType()->getAs<FunctionType>()->getReturnType(); @@ -3793,6 +3929,8 @@ public: /// x[0], x[1], and x[2] respectively, where x is the implicit /// DecompositionDecl of type 'int (&)[3]'. class BindingDecl : public ValueDecl { + /// The declaration that this binding binds to part of. + LazyDeclPtr Decomp; /// The binding represented by this declaration. References to this /// declaration are effectively equivalent to this expression (except /// that it is only evaluated once at the point of declaration of the @@ -3816,6 +3954,10 @@ public: /// decomposition declaration, and when the initializer is type-dependent. Expr *getBinding() const { return Binding; } + /// Get the decomposition declaration that this binding represents a + /// decomposition of. + ValueDecl *getDecomposedDecl() const; + /// Get the variable (if any) that holds the value of evaluating the binding. /// Only present for user-defined bindings for tuple-like types. VarDecl *getHoldingVar() const; @@ -3828,6 +3970,9 @@ public: this->Binding = Binding; } + /// Set the decomposed variable for this BindingDecl. + void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; } + static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == Decl::Binding; } }; @@ -3855,6 +4000,8 @@ class DecompositionDecl final NumBindings(Bindings.size()) { std::uninitialized_copy(Bindings.begin(), Bindings.end(), getTrailingObjects<BindingDecl *>()); + for (auto *B : Bindings) + B->setDecomposedDecl(this); } void anchor() override; diff --git a/include/clang/AST/DeclContextInternals.h b/include/clang/AST/DeclContextInternals.h index ccd82d2cf0d2..e6a4cd4381e4 100644 --- a/include/clang/AST/DeclContextInternals.h +++ b/include/clang/AST/DeclContextInternals.h @@ -1,9 +1,8 @@ //===- DeclContextInternals.h - DeclContext Representation ------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -114,12 +113,11 @@ public: } DeclsTy &Vec = *getAsVector(); - DeclsTy::iterator I = std::find(Vec.begin(), Vec.end(), D); + DeclsTy::iterator I = llvm::find(Vec, D); assert(I != Vec.end() && "list does not contain decl"); Vec.erase(I); - assert(std::find(Vec.begin(), Vec.end(), D) - == Vec.end() && "list still contains decl"); + assert(llvm::find(Vec, D) == Vec.end() && "list still contains decl"); } /// Remove any declarations which were imported from an external diff --git a/include/clang/AST/DeclFriend.h b/include/clang/AST/DeclFriend.h index b5808f23de6f..6f8306c6025e 100644 --- a/include/clang/AST/DeclFriend.h +++ b/include/clang/AST/DeclFriend.h @@ -1,9 +1,8 @@ //===- DeclFriend.h - Classes for C++ friend declarations -------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/DeclGroup.h b/include/clang/AST/DeclGroup.h index 6d5aaadf529c..2be9dae9431e 100644 --- a/include/clang/AST/DeclGroup.h +++ b/include/clang/AST/DeclGroup.h @@ -1,9 +1,8 @@ //===- DeclGroup.h - Classes for representing groups of Decls ---*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/DeclLookups.h b/include/clang/AST/DeclLookups.h index 9627f440d406..41c8999736ea 100644 --- a/include/clang/AST/DeclLookups.h +++ b/include/clang/AST/DeclLookups.h @@ -1,9 +1,8 @@ //===- DeclLookups.h - Low-level interface to all names in a DC -*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 5b57411f9785..8d85ac36d861 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -1,9 +1,8 @@ //===- DeclObjC.h - Classes for representing declarations -------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/DeclOpenMP.h b/include/clang/AST/DeclOpenMP.h index 8540cc5b25b6..437feaba28fb 100644 --- a/include/clang/AST/DeclOpenMP.h +++ b/include/clang/AST/DeclOpenMP.h @@ -1,9 +1,8 @@ //===- DeclOpenMP.h - Classes for representing OpenMP directives -*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// @@ -207,6 +206,102 @@ public: } }; +/// This represents '#pragma omp declare mapper ...' directive. Map clauses are +/// allowed to use with this directive. The following example declares a user +/// defined mapper for the type 'struct vec'. This example instructs the fields +/// 'len' and 'data' should be mapped when mapping instances of 'struct vec'. +/// +/// \code +/// #pragma omp declare mapper(mid: struct vec v) map(v.len, v.data[0:N]) +/// \endcode +class OMPDeclareMapperDecl final : public ValueDecl, public DeclContext { + friend class ASTDeclReader; + + /// Clauses associated with this mapper declaration + MutableArrayRef<OMPClause *> Clauses; + + /// Mapper variable, which is 'v' in the example above + Expr *MapperVarRef = nullptr; + + /// Name of the mapper variable + DeclarationName VarName; + + LazyDeclPtr PrevDeclInScope; + + virtual void anchor(); + + OMPDeclareMapperDecl(Kind DK, DeclContext *DC, SourceLocation L, + DeclarationName Name, QualType Ty, + DeclarationName VarName, + OMPDeclareMapperDecl *PrevDeclInScope) + : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), VarName(VarName), + PrevDeclInScope(PrevDeclInScope) {} + + void setPrevDeclInScope(OMPDeclareMapperDecl *Prev) { + PrevDeclInScope = Prev; + } + + /// Sets an array of clauses to this mapper declaration + void setClauses(ArrayRef<OMPClause *> CL); + +public: + /// Creates declare mapper node. + static OMPDeclareMapperDecl *Create(ASTContext &C, DeclContext *DC, + SourceLocation L, DeclarationName Name, + QualType T, DeclarationName VarName, + OMPDeclareMapperDecl *PrevDeclInScope); + /// Creates deserialized declare mapper node. + static OMPDeclareMapperDecl *CreateDeserialized(ASTContext &C, unsigned ID, + unsigned N); + + /// Creates an array of clauses to this mapper declaration and intializes + /// them. + void CreateClauses(ASTContext &C, ArrayRef<OMPClause *> CL); + + using clauselist_iterator = MutableArrayRef<OMPClause *>::iterator; + using clauselist_const_iterator = ArrayRef<const OMPClause *>::iterator; + using clauselist_range = llvm::iterator_range<clauselist_iterator>; + using clauselist_const_range = + llvm::iterator_range<clauselist_const_iterator>; + + unsigned clauselist_size() const { return Clauses.size(); } + bool clauselist_empty() const { return Clauses.empty(); } + + clauselist_range clauselists() { + return clauselist_range(clauselist_begin(), clauselist_end()); + } + clauselist_const_range clauselists() const { + return clauselist_const_range(clauselist_begin(), clauselist_end()); + } + clauselist_iterator clauselist_begin() { return Clauses.begin(); } + clauselist_iterator clauselist_end() { return Clauses.end(); } + clauselist_const_iterator clauselist_begin() const { return Clauses.begin(); } + clauselist_const_iterator clauselist_end() const { return Clauses.end(); } + + /// Get the variable declared in the mapper + Expr *getMapperVarRef() { return MapperVarRef; } + const Expr *getMapperVarRef() const { return MapperVarRef; } + /// Set the variable declared in the mapper + void setMapperVarRef(Expr *MapperVarRefE) { MapperVarRef = MapperVarRefE; } + + /// Get the name of the variable declared in the mapper + DeclarationName getVarName() { return VarName; } + + /// Get reference to previous declare mapper construct in the same + /// scope with the same name. + OMPDeclareMapperDecl *getPrevDeclInScope(); + const OMPDeclareMapperDecl *getPrevDeclInScope() const; + + static bool classof(const Decl *D) { return classofKind(D->getKind()); } + static bool classofKind(Kind K) { return K == OMPDeclareMapper; } + static DeclContext *castToDeclContext(const OMPDeclareMapperDecl *D) { + return static_cast<DeclContext *>(const_cast<OMPDeclareMapperDecl *>(D)); + } + static OMPDeclareMapperDecl *castFromDeclContext(const DeclContext *DC) { + return static_cast<OMPDeclareMapperDecl *>(const_cast<DeclContext *>(DC)); + } +}; + /// Pseudo declaration for capturing expressions. Also is used for capturing of /// non-static data members in non-static member functions. /// @@ -310,6 +405,119 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == OMPRequires; } }; + +/// This represents '#pragma omp allocate ...' directive. +/// For example, in the following, the default allocator is used for both 'a' +/// and 'A::b': +/// +/// \code +/// int a; +/// #pragma omp allocate(a) +/// struct A { +/// static int b; +/// #pragma omp allocate(b) +/// }; +/// \endcode +/// +class OMPAllocateDecl final + : public Decl, + private llvm::TrailingObjects<OMPAllocateDecl, Expr *, OMPClause *> { + friend class ASTDeclReader; + friend TrailingObjects; + + /// Number of variable within the allocate directive. + unsigned NumVars = 0; + /// Number of clauses associated with the allocate directive. + unsigned NumClauses = 0; + + size_t numTrailingObjects(OverloadToken<Expr *>) const { + return NumVars; + } + size_t numTrailingObjects(OverloadToken<OMPClause *>) const { + return NumClauses; + } + + virtual void anchor(); + + OMPAllocateDecl(Kind DK, DeclContext *DC, SourceLocation L) + : Decl(DK, DC, L) {} + + ArrayRef<const Expr *> getVars() const { + return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumVars); + } + + MutableArrayRef<Expr *> getVars() { + return MutableArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumVars); + } + + void setVars(ArrayRef<Expr *> VL); + + /// Returns an array of immutable clauses associated with this directive. + ArrayRef<OMPClause *> getClauses() const { + return llvm::makeArrayRef(getTrailingObjects<OMPClause *>(), NumClauses); + } + + /// Returns an array of clauses associated with this directive. + MutableArrayRef<OMPClause *> getClauses() { + return MutableArrayRef<OMPClause *>(getTrailingObjects<OMPClause *>(), + NumClauses); + } + + /// Sets an array of clauses to this requires declaration + void setClauses(ArrayRef<OMPClause *> CL); + +public: + static OMPAllocateDecl *Create(ASTContext &C, DeclContext *DC, + SourceLocation L, ArrayRef<Expr *> VL, + ArrayRef<OMPClause *> CL); + static OMPAllocateDecl *CreateDeserialized(ASTContext &C, unsigned ID, + unsigned NVars, unsigned NClauses); + + typedef MutableArrayRef<Expr *>::iterator varlist_iterator; + typedef ArrayRef<const Expr *>::iterator varlist_const_iterator; + typedef llvm::iterator_range<varlist_iterator> varlist_range; + typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range; + using clauselist_iterator = MutableArrayRef<OMPClause *>::iterator; + using clauselist_const_iterator = ArrayRef<const OMPClause *>::iterator; + using clauselist_range = llvm::iterator_range<clauselist_iterator>; + using clauselist_const_range = llvm::iterator_range<clauselist_const_iterator>; + + + unsigned varlist_size() const { return NumVars; } + bool varlist_empty() const { return NumVars == 0; } + unsigned clauselist_size() const { return NumClauses; } + bool clauselist_empty() const { return NumClauses == 0; } + + varlist_range varlists() { + return varlist_range(varlist_begin(), varlist_end()); + } + varlist_const_range varlists() const { + return varlist_const_range(varlist_begin(), varlist_end()); + } + varlist_iterator varlist_begin() { return getVars().begin(); } + varlist_iterator varlist_end() { return getVars().end(); } + varlist_const_iterator varlist_begin() const { return getVars().begin(); } + varlist_const_iterator varlist_end() const { return getVars().end(); } + + clauselist_range clauselists() { + return clauselist_range(clauselist_begin(), clauselist_end()); + } + clauselist_const_range clauselists() const { + return clauselist_const_range(clauselist_begin(), clauselist_end()); + } + clauselist_iterator clauselist_begin() { return getClauses().begin(); } + clauselist_iterator clauselist_end() { return getClauses().end(); } + clauselist_const_iterator clauselist_begin() const { + return getClauses().begin(); + } + clauselist_const_iterator clauselist_end() const { + return getClauses().end(); + } + + static bool classof(const Decl *D) { return classofKind(D->getKind()); } + static bool classofKind(Kind K) { return K == OMPAllocate; } +}; + } // end namespace clang #endif diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index f6e3d8f300ba..235b31c1c312 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -1,9 +1,8 @@ //===- DeclTemplate.h - Classes for representing C++ templates --*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -177,6 +176,11 @@ public: return SourceRange(TemplateLoc, RAngleLoc); } + void print(raw_ostream &Out, const ASTContext &Context, + bool OmitTemplateKW = false) const; + void print(raw_ostream &Out, const ASTContext &Context, + const PrintingPolicy &Policy, bool OmitTemplateKW = false) const; + public: // FIXME: workaround for MSVC 2013; remove when no longer needed using FixedSizeStorageOwner = TrailingObjects::FixedSizeStorageOwner; @@ -505,29 +509,13 @@ public: /// Provides information about a function template specialization, /// which is a FunctionDecl that has been explicitly specialization or /// instantiated from a function template. -class FunctionTemplateSpecializationInfo : public llvm::FoldingSetNode { - FunctionTemplateSpecializationInfo(FunctionDecl *FD, - FunctionTemplateDecl *Template, - TemplateSpecializationKind TSK, - const TemplateArgumentList *TemplateArgs, - const ASTTemplateArgumentListInfo *TemplateArgsAsWritten, - SourceLocation POI) - : Function(FD), Template(Template, TSK - 1), - TemplateArguments(TemplateArgs), - TemplateArgumentsAsWritten(TemplateArgsAsWritten), - PointOfInstantiation(POI) {} - -public: - static FunctionTemplateSpecializationInfo * - Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, - TemplateSpecializationKind TSK, - const TemplateArgumentList *TemplateArgs, - const TemplateArgumentListInfo *TemplateArgsAsWritten, - SourceLocation POI); - - /// The function template specialization that this structure - /// describes. - FunctionDecl *Function; +class FunctionTemplateSpecializationInfo final + : public llvm::FoldingSetNode, + private llvm::TrailingObjects<FunctionTemplateSpecializationInfo, + MemberSpecializationInfo *> { + /// The function template specialization that this structure describes and a + /// flag indicating if the function is a member specialization. + llvm::PointerIntPair<FunctionDecl *, 1, bool> Function; /// The function template from which this function template /// specialization was generated. @@ -535,17 +523,50 @@ public: /// The two bits contain the top 4 values of TemplateSpecializationKind. llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template; +public: /// The template arguments used to produce the function template /// specialization from the function template. const TemplateArgumentList *TemplateArguments; /// The template arguments as written in the sources, if provided. + /// FIXME: Normally null; tail-allocate this. const ASTTemplateArgumentListInfo *TemplateArgumentsAsWritten; /// The point at which this function template specialization was /// first instantiated. SourceLocation PointOfInstantiation; +private: + FunctionTemplateSpecializationInfo( + FunctionDecl *FD, FunctionTemplateDecl *Template, + TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs, + const ASTTemplateArgumentListInfo *TemplateArgsAsWritten, + SourceLocation POI, MemberSpecializationInfo *MSInfo) + : Function(FD, MSInfo ? 1 : 0), Template(Template, TSK - 1), + TemplateArguments(TemplateArgs), + TemplateArgumentsAsWritten(TemplateArgsAsWritten), + PointOfInstantiation(POI) { + if (MSInfo) + getTrailingObjects<MemberSpecializationInfo *>()[0] = MSInfo; + } + + size_t numTrailingObjects(OverloadToken<MemberSpecializationInfo*>) const { + return Function.getInt(); + } + +public: + friend TrailingObjects; + + static FunctionTemplateSpecializationInfo * + Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, + TemplateSpecializationKind TSK, + const TemplateArgumentList *TemplateArgs, + const TemplateArgumentListInfo *TemplateArgsAsWritten, + SourceLocation POI, MemberSpecializationInfo *MSInfo); + + /// Retrieve the declaration of the function template specialization. + FunctionDecl *getFunction() const { return Function.getPointer(); } + /// Retrieve the template from which this function was specialized. FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); } @@ -588,9 +609,44 @@ public: PointOfInstantiation = POI; } + /// Get the specialization info if this function template specialization is + /// also a member specialization: + /// + /// \code + /// template<typename> struct A { + /// template<typename> void f(); + /// template<> void f<int>(); // ClassScopeFunctionSpecializationDecl + /// }; + /// \endcode + /// + /// Here, A<int>::f<int> is a function template specialization that is + /// an explicit specialization of A<int>::f, but it's also a member + /// specialization (an implicit instantiation in this case) of A::f<int>. + /// Further: + /// + /// \code + /// template<> template<> void A<int>::f<int>() {} + /// \endcode + /// + /// ... declares a function template specialization that is an explicit + /// specialization of A<int>::f, and is also an explicit member + /// specialization of A::f<int>. + /// + /// Note that the TemplateSpecializationKind of the MemberSpecializationInfo + /// need not be the same as that returned by getTemplateSpecializationKind(), + /// and represents the relationship between the function and the class-scope + /// explicit specialization in the original templated class -- whereas our + /// TemplateSpecializationKind represents the relationship between the + /// function and the function template, and should always be + /// TSK_ExplicitSpecialization whenever we have MemberSpecializationInfo. + MemberSpecializationInfo *getMemberSpecializationInfo() const { + return numTrailingObjects(OverloadToken<MemberSpecializationInfo *>()) + ? getTrailingObjects<MemberSpecializationInfo *>()[0] + : nullptr; + } + void Profile(llvm::FoldingSetNodeID &ID) { - Profile(ID, TemplateArguments->asArray(), - Function->getASTContext()); + Profile(ID, TemplateArguments->asArray(), getFunction()->getASTContext()); } static void @@ -956,7 +1012,7 @@ SpecEntryTraits<FunctionTemplateSpecializationInfo> { using DeclType = FunctionDecl; static DeclType *getDecl(FunctionTemplateSpecializationInfo *I) { - return I->Function; + return I->getFunction(); } static ArrayRef<TemplateArgument> @@ -1747,6 +1803,20 @@ public: return getSpecializationKind() == TSK_ExplicitSpecialization; } + /// Is this an explicit specialization at class scope (within the class that + /// owns the primary template)? For example: + /// + /// \code + /// template<typename T> struct Outer { + /// template<typename U> struct Inner; + /// template<> struct Inner; // class-scope explicit specialization + /// }; + /// \endcode + bool isClassScopeExplicitSpecialization() const { + return isExplicitSpecialization() && + isa<CXXRecordDecl>(getLexicalDeclContext()); + } + /// True if this declaration is an explicit specialization, /// explicit instantiation declaration, or explicit instantiation /// definition. @@ -2395,8 +2465,6 @@ public: /// Declaration of a function specialization at template class scope. /// -/// This is a non-standard extension needed to support MSVC. -/// /// For example: /// \code /// template <class T> @@ -2409,17 +2477,18 @@ public: /// "template<> foo(int a)" will be saved in Specialization as a normal /// CXXMethodDecl. Then during an instantiation of class A, it will be /// transformed into an actual function specialization. +/// +/// FIXME: This is redundant; we could store the same information directly on +/// the CXXMethodDecl as a DependentFunctionTemplateSpecializationInfo. class ClassScopeFunctionSpecializationDecl : public Decl { CXXMethodDecl *Specialization; - bool HasExplicitTemplateArgs; - TemplateArgumentListInfo TemplateArgs; + const ASTTemplateArgumentListInfo *TemplateArgs; - ClassScopeFunctionSpecializationDecl(DeclContext *DC, SourceLocation Loc, - CXXMethodDecl *FD, bool Args, - TemplateArgumentListInfo TemplArgs) + ClassScopeFunctionSpecializationDecl( + DeclContext *DC, SourceLocation Loc, CXXMethodDecl *FD, + const ASTTemplateArgumentListInfo *TemplArgs) : Decl(Decl::ClassScopeFunctionSpecialization, DC, Loc), - Specialization(FD), HasExplicitTemplateArgs(Args), - TemplateArgs(std::move(TemplArgs)) {} + Specialization(FD), TemplateArgs(TemplArgs) {} ClassScopeFunctionSpecializationDecl(EmptyShell Empty) : Decl(Decl::ClassScopeFunctionSpecialization, Empty) {} @@ -2431,17 +2500,20 @@ public: friend class ASTDeclWriter; CXXMethodDecl *getSpecialization() const { return Specialization; } - bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } - const TemplateArgumentListInfo& templateArgs() const { return TemplateArgs; } - - static ClassScopeFunctionSpecializationDecl *Create(ASTContext &C, - DeclContext *DC, - SourceLocation Loc, - CXXMethodDecl *FD, - bool HasExplicitTemplateArgs, - TemplateArgumentListInfo TemplateArgs) { + bool hasExplicitTemplateArgs() const { return TemplateArgs; } + const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const { + return TemplateArgs; + } + + static ClassScopeFunctionSpecializationDecl * + Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, CXXMethodDecl *FD, + bool HasExplicitTemplateArgs, + const TemplateArgumentListInfo &TemplateArgs) { return new (C, DC) ClassScopeFunctionSpecializationDecl( - DC, Loc, FD, HasExplicitTemplateArgs, std::move(TemplateArgs)); + DC, Loc, FD, + HasExplicitTemplateArgs + ? ASTTemplateArgumentListInfo::Create(C, TemplateArgs) + : nullptr); } static ClassScopeFunctionSpecializationDecl * @@ -2582,6 +2654,11 @@ public: return getSpecializationKind() == TSK_ExplicitSpecialization; } + bool isClassScopeExplicitSpecialization() const { + return isExplicitSpecialization() && + isa<CXXRecordDecl>(getLexicalDeclContext()); + } + /// True if this declaration is an explicit specialization, /// explicit instantiation declaration, or explicit instantiation /// definition. @@ -3013,6 +3090,42 @@ public: static bool classofKind(Kind K) { return K == VarTemplate; } }; +// \brief Declaration of a C++2a concept. +class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> { +protected: + Expr *ConstraintExpr; + + ConceptDecl(DeclContext *DC, + SourceLocation L, DeclarationName Name, + TemplateParameterList *Params, + Expr *ConstraintExpr) + : TemplateDecl(nullptr, Concept, DC, L, Name, Params), + ConstraintExpr(ConstraintExpr) {}; +public: + static ConceptDecl *Create(ASTContext &C, DeclContext *DC, + SourceLocation L, DeclarationName Name, + TemplateParameterList *Params, + Expr *ConstraintExpr); + static ConceptDecl *CreateDeserialized(ASTContext &C, unsigned ID); + + Expr *getConstraintExpr() const { + return ConstraintExpr; + } + + SourceRange getSourceRange() const override LLVM_READONLY { + return SourceRange(getTemplateParameters()->getTemplateLoc(), + ConstraintExpr->getEndLoc()); + } + + // Implement isa/cast/dyncast/etc. + static bool classof(const Decl *D) { return classofKind(D->getKind()); } + static bool classofKind(Kind K) { return K == Concept; } + + friend class ASTReader; + friend class ASTDeclReader; + friend class ASTDeclWriter; +}; + inline NamedDecl *getAsNamedDecl(TemplateParameter P) { if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>()) return PD; diff --git a/include/clang/AST/DeclVisitor.h b/include/clang/AST/DeclVisitor.h index c6cbc9ff7faa..8690cdda4bb7 100644 --- a/include/clang/AST/DeclVisitor.h +++ b/include/clang/AST/DeclVisitor.h @@ -1,9 +1,8 @@ //===- DeclVisitor.h - Visitor for Decl subclasses --------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/DeclarationName.h b/include/clang/AST/DeclarationName.h index 62afae23ec79..90449147637d 100644 --- a/include/clang/AST/DeclarationName.h +++ b/include/clang/AST/DeclarationName.h @@ -1,9 +1,8 @@ //===- DeclarationName.h - Representation of declaration names --*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -862,9 +861,26 @@ struct DenseMapInfo<clang::DeclarationName> { } }; -template <> -struct isPodLike<clang::DeclarationName> { static const bool value = true; }; - } // namespace llvm +// The definition of AssumedTemplateStorage is factored out of TemplateName to +// resolve a cyclic dependency between it and DeclarationName (via Type). +namespace clang { + +/// A structure for storing the information associated with a name that has +/// been assumed to be a template name (despite finding no TemplateDecls). +class AssumedTemplateStorage : public UncommonTemplateNameStorage { + friend class ASTContext; + + AssumedTemplateStorage(DeclarationName Name) + : UncommonTemplateNameStorage(Assumed, 0), Name(Name) {} + DeclarationName Name; + +public: + /// Get the name of the template. + DeclarationName getDeclName() const { return Name; } +}; + +} // namespace clang + #endif // LLVM_CLANG_AST_DECLARATIONNAME_H diff --git a/include/clang/AST/DependentDiagnostic.h b/include/clang/AST/DependentDiagnostic.h index c21ef7907b8a..0a98dec0c25e 100644 --- a/include/clang/AST/DependentDiagnostic.h +++ b/include/clang/AST/DependentDiagnostic.h @@ -1,9 +1,8 @@ //==- DependentDiagnostic.h - Dependently-generated diagnostics --*- C++ -*-==// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/EvaluatedExprVisitor.h b/include/clang/AST/EvaluatedExprVisitor.h index f356584144e6..2f6c314b4111 100644 --- a/include/clang/AST/EvaluatedExprVisitor.h +++ b/include/clang/AST/EvaluatedExprVisitor.h @@ -1,9 +1,8 @@ //===--- EvaluatedExprVisitor.h - Evaluated expression visitor --*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 3de73428829b..d44a815c8699 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1,9 +1,8 @@ //===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -23,11 +22,14 @@ #include "clang/AST/TemplateBase.h" #include "clang/AST/Type.h" #include "clang/Basic/CharInfo.h" +#include "clang/Basic/FixedPoint.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/SyncScope.h" #include "clang/Basic/TypeTraits.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APSInt.h" +#include "llvm/ADT/iterator.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/AtomicOrdering.h" @@ -103,13 +105,20 @@ struct SubobjectAdjustment { /// This represents one expression. Note that Expr's are subclasses of Stmt. /// This allows an expression to be transparently used any place a Stmt is /// required. -class Expr : public Stmt { +class Expr : public ValueStmt { QualType TR; +public: + Expr() = delete; + Expr(const Expr&) = delete; + Expr(Expr &&) = delete; + Expr &operator=(const Expr&) = delete; + Expr &operator=(Expr&&) = delete; + protected: Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack) - : Stmt(SC) + : ValueStmt(SC) { ExprBits.TypeDependent = TD; ExprBits.ValueDependent = VD; @@ -122,7 +131,7 @@ protected: } /// Construct an empty expression. - explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } + explicit Expr(StmtClass SC, EmptyShell) : ValueStmt(SC) { } public: QualType getType() const { return TR; } @@ -590,7 +599,8 @@ public: /// which we can fold and convert to a boolean condition using /// any crazy technique that we want to, even if the expression has /// side-effects. - bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; + bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx, + bool InConstantContext = false) const; enum SideEffectsKind { SE_NoSideEffects, ///< Strictly evaluate the expression. @@ -602,14 +612,21 @@ public: /// EvaluateAsInt - Return true if this is a constant which we can fold and /// convert to an integer, using any crazy technique that we want to. bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, - SideEffectsKind AllowSideEffects = SE_NoSideEffects) const; + SideEffectsKind AllowSideEffects = SE_NoSideEffects, + bool InConstantContext = false) const; /// EvaluateAsFloat - Return true if this is a constant which we can fold and /// convert to a floating point value, using any crazy technique that we /// want to. - bool - EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx, - SideEffectsKind AllowSideEffects = SE_NoSideEffects) const; + bool EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx, + SideEffectsKind AllowSideEffects = SE_NoSideEffects, + bool InConstantContext = false) const; + + /// EvaluateAsFloat - Return true if this is a constant which we can fold and + /// convert to a fixed point value. + bool EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx, + SideEffectsKind AllowSideEffects = SE_NoSideEffects, + bool InConstantContext = false) const; /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be /// constant folded without side-effects, but discard the result. @@ -645,7 +662,8 @@ public: /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an /// lvalue with link time known address, with no side-effects. - bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; + bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, + bool InConstantContext = false) const; /// EvaluateAsInitializer - Evaluate an expression as if it were the /// initializer of the given declaration. Returns true if the initializer @@ -738,67 +756,110 @@ public: /// member expression. static QualType findBoundMemberType(const Expr *expr); - /// IgnoreImpCasts - Skip past any implicit casts which might - /// surround this expression. Only skips ImplicitCastExprs. + /// Skip past any implicit casts which might surround this expression until + /// reaching a fixed point. Skips: + /// * ImplicitCastExpr + /// * FullExpr Expr *IgnoreImpCasts() LLVM_READONLY; - - /// IgnoreImplicit - Skip past any implicit AST nodes which might - /// surround this expression. - Expr *IgnoreImplicit() LLVM_READONLY { - return cast<Expr>(Stmt::IgnoreImplicit()); - } - - const Expr *IgnoreImplicit() const LLVM_READONLY { - return const_cast<Expr*>(this)->IgnoreImplicit(); + const Expr *IgnoreImpCasts() const { + return const_cast<Expr *>(this)->IgnoreImpCasts(); } - /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return - /// its subexpression. If that subexpression is also a ParenExpr, - /// then this method recursively returns its subexpression, and so forth. - /// Otherwise, the method returns the current Expr. - Expr *IgnoreParens() LLVM_READONLY; - - /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr - /// or CastExprs, returning their operand. - Expr *IgnoreParenCasts() LLVM_READONLY; - - /// Ignore casts. Strip off any CastExprs, returning their operand. + /// Skip past any casts which might surround this expression until reaching + /// a fixed point. Skips: + /// * CastExpr + /// * FullExpr + /// * MaterializeTemporaryExpr + /// * SubstNonTypeTemplateParmExpr Expr *IgnoreCasts() LLVM_READONLY; - - /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off - /// any ParenExpr or ImplicitCastExprs, returning their operand. + const Expr *IgnoreCasts() const { + return const_cast<Expr *>(this)->IgnoreCasts(); + } + + /// Skip past any implicit AST nodes which might surround this expression + /// until reaching a fixed point. Skips: + /// * What IgnoreImpCasts() skips + /// * MaterializeTemporaryExpr + /// * CXXBindTemporaryExpr + Expr *IgnoreImplicit() LLVM_READONLY; + const Expr *IgnoreImplicit() const { + return const_cast<Expr *>(this)->IgnoreImplicit(); + } + + /// Skip past any parentheses which might surround this expression until + /// reaching a fixed point. Skips: + /// * ParenExpr + /// * UnaryOperator if `UO_Extension` + /// * GenericSelectionExpr if `!isResultDependent()` + /// * ChooseExpr if `!isConditionDependent()` + /// * ConstantExpr + Expr *IgnoreParens() LLVM_READONLY; + const Expr *IgnoreParens() const { + return const_cast<Expr *>(this)->IgnoreParens(); + } + + /// Skip past any parentheses and implicit casts which might surround this + /// expression until reaching a fixed point. + /// FIXME: IgnoreParenImpCasts really ought to be equivalent to + /// IgnoreParens() + IgnoreImpCasts() until reaching a fixed point. However + /// this is currently not the case. Instead IgnoreParenImpCasts() skips: + /// * What IgnoreParens() skips + /// * What IgnoreImpCasts() skips + /// * MaterializeTemporaryExpr + /// * SubstNonTypeTemplateParmExpr Expr *IgnoreParenImpCasts() LLVM_READONLY; - - /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a - /// call to a conversion operator, return the argument. - Expr *IgnoreConversionOperator() LLVM_READONLY; - - const Expr *IgnoreConversionOperator() const LLVM_READONLY { - return const_cast<Expr*>(this)->IgnoreConversionOperator(); + const Expr *IgnoreParenImpCasts() const { + return const_cast<Expr *>(this)->IgnoreParenImpCasts(); } - const Expr *IgnoreParenImpCasts() const LLVM_READONLY { - return const_cast<Expr*>(this)->IgnoreParenImpCasts(); + /// Skip past any parentheses and casts which might surround this expression + /// until reaching a fixed point. Skips: + /// * What IgnoreParens() skips + /// * What IgnoreCasts() skips + Expr *IgnoreParenCasts() LLVM_READONLY; + const Expr *IgnoreParenCasts() const { + return const_cast<Expr *>(this)->IgnoreParenCasts(); } - /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and - /// CastExprs that represent lvalue casts, returning their operand. + /// Skip conversion operators. If this Expr is a call to a conversion + /// operator, return the argument. + Expr *IgnoreConversionOperator() LLVM_READONLY; + const Expr *IgnoreConversionOperator() const { + return const_cast<Expr *>(this)->IgnoreConversionOperator(); + } + + /// Skip past any parentheses and lvalue casts which might surround this + /// expression until reaching a fixed point. Skips: + /// * What IgnoreParens() skips + /// * What IgnoreCasts() skips, except that only lvalue-to-rvalue + /// casts are skipped + /// FIXME: This is intended purely as a temporary workaround for code + /// that hasn't yet been rewritten to do the right thing about those + /// casts, and may disappear along with the last internal use. Expr *IgnoreParenLValueCasts() LLVM_READONLY; - - const Expr *IgnoreParenLValueCasts() const LLVM_READONLY { - return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); - } - - /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the - /// value (including ptr->int casts of the same size). Strip off any - /// ParenExpr or CastExprs, returning their operand. - Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY; - - /// Ignore parentheses and derived-to-base casts. + const Expr *IgnoreParenLValueCasts() const { + return const_cast<Expr *>(this)->IgnoreParenLValueCasts(); + } + + /// Skip past any parenthese and casts which do not change the value + /// (including ptr->int casts of the same size) until reaching a fixed point. + /// Skips: + /// * What IgnoreParens() skips + /// * CastExpr which do not change the value + /// * SubstNonTypeTemplateParmExpr + Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY; + const Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) const { + return const_cast<Expr *>(this)->IgnoreParenNoopCasts(Ctx); + } + + /// Skip past any parentheses and derived-to-base casts until reaching a + /// fixed point. Skips: + /// * What IgnoreParens() skips + /// * CastExpr which represent a derived-to-base cast (CK_DerivedToBase, + /// CK_UncheckedDerivedToBase and CK_NoOp) Expr *ignoreParenBaseCasts() LLVM_READONLY; - - const Expr *ignoreParenBaseCasts() const LLVM_READONLY { - return const_cast<Expr*>(this)->ignoreParenBaseCasts(); + const Expr *ignoreParenBaseCasts() const { + return const_cast<Expr *>(this)->ignoreParenBaseCasts(); } /// Determine whether this expression is a default function argument. @@ -817,24 +878,6 @@ public: /// Whether this expression is an implicit reference to 'this' in C++. bool isImplicitCXXThis() const; - const Expr *IgnoreImpCasts() const LLVM_READONLY { - return const_cast<Expr*>(this)->IgnoreImpCasts(); - } - const Expr *IgnoreParens() const LLVM_READONLY { - return const_cast<Expr*>(this)->IgnoreParens(); - } - const Expr *IgnoreParenCasts() const LLVM_READONLY { - return const_cast<Expr*>(this)->IgnoreParenCasts(); - } - /// Strip off casts, but keep parentheses. - const Expr *IgnoreCasts() const LLVM_READONLY { - return const_cast<Expr*>(this)->IgnoreCasts(); - } - - const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY { - return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); - } - static bool hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs); /// For an expression of class type or pointer to class type, @@ -900,20 +943,63 @@ public: } }; -/// ConstantExpr - An expression that occurs in a constant context. -class ConstantExpr : public FullExpr { - ConstantExpr(Expr *subexpr) - : FullExpr(ConstantExprClass, subexpr) {} +/// ConstantExpr - An expression that occurs in a constant context and +/// optionally the result of evaluating the expression. +class ConstantExpr final + : public FullExpr, + private llvm::TrailingObjects<ConstantExpr, APValue, uint64_t> { + static_assert(std::is_same<uint64_t, llvm::APInt::WordType>::value, + "this class assumes llvm::APInt::WordType is uint64_t for " + "trail-allocated storage"); public: - static ConstantExpr *Create(const ASTContext &Context, Expr *E) { - assert(!isa<ConstantExpr>(E)); - return new (Context) ConstantExpr(E); + /// Describes the kind of result that can be trail-allocated. + enum ResultStorageKind { RSK_None, RSK_Int64, RSK_APValue }; + +private: + size_t numTrailingObjects(OverloadToken<APValue>) const { + return ConstantExprBits.ResultKind == ConstantExpr::RSK_APValue; + } + size_t numTrailingObjects(OverloadToken<uint64_t>) const { + return ConstantExprBits.ResultKind == ConstantExpr::RSK_Int64; } - /// Build an empty constant expression wrapper. - explicit ConstantExpr(EmptyShell Empty) - : FullExpr(ConstantExprClass, Empty) {} + void DefaultInit(ResultStorageKind StorageKind); + uint64_t &Int64Result() { + assert(ConstantExprBits.ResultKind == ConstantExpr::RSK_Int64 && + "invalid accessor"); + return *getTrailingObjects<uint64_t>(); + } + const uint64_t &Int64Result() const { + return const_cast<ConstantExpr *>(this)->Int64Result(); + } + APValue &APValueResult() { + assert(ConstantExprBits.ResultKind == ConstantExpr::RSK_APValue && + "invalid accessor"); + return *getTrailingObjects<APValue>(); + } + const APValue &APValueResult() const { + return const_cast<ConstantExpr *>(this)->APValueResult(); + } + + ConstantExpr(Expr *subexpr, ResultStorageKind StorageKind); + ConstantExpr(ResultStorageKind StorageKind, EmptyShell Empty); + +public: + friend TrailingObjects; + friend class ASTStmtReader; + friend class ASTStmtWriter; + static ConstantExpr *Create(const ASTContext &Context, Expr *E, + const APValue &Result); + static ConstantExpr *Create(const ASTContext &Context, Expr *E, + ResultStorageKind Storage = RSK_None); + static ConstantExpr *CreateEmpty(const ASTContext &Context, + ResultStorageKind StorageKind, + EmptyShell Empty); + + static ResultStorageKind getStorageKind(const APValue &Value); + static ResultStorageKind getStorageKind(const Type *T, + const ASTContext &Context); SourceLocation getBeginLoc() const LLVM_READONLY { return SubExpr->getBeginLoc(); @@ -926,6 +1012,20 @@ public: return T->getStmtClass() == ConstantExprClass; } + void SetResult(APValue Value, const ASTContext &Context) { + MoveIntoResult(Value, Context); + } + void MoveIntoResult(APValue &Value, const ASTContext &Context); + + APValue::ValueKind getResultAPValueKind() const { + return static_cast<APValue::ValueKind>(ConstantExprBits.APValueKind); + } + ResultStorageKind getResultStorageKind() const { + return static_cast<ResultStorageKind>(ConstantExprBits.ResultKind); + } + APValue getAPValueResult() const; + const APValue &getResultAsAPValue() const { return APValueResult(); } + llvm::APSInt getResultAsAPSInt() const; // Iterators child_range children() { return child_range(&SubExpr, &SubExpr+1); } const_child_range children() const { @@ -1075,7 +1175,7 @@ class DeclRefExpr final bool RefersToEnlosingVariableOrCapture, const DeclarationNameInfo &NameInfo, NamedDecl *FoundD, const TemplateArgumentListInfo *TemplateArgs, QualType T, - ExprValueKind VK); + ExprValueKind VK, NonOdrUseReason NOUR); /// Construct an empty declaration reference expression. explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {} @@ -1088,14 +1188,16 @@ public: DeclRefExpr(const ASTContext &Ctx, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, QualType T, ExprValueKind VK, SourceLocation L, - const DeclarationNameLoc &LocInfo = DeclarationNameLoc()); + const DeclarationNameLoc &LocInfo = DeclarationNameLoc(), + NonOdrUseReason NOUR = NOUR_None); static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr, - const TemplateArgumentListInfo *TemplateArgs = nullptr); + const TemplateArgumentListInfo *TemplateArgs = nullptr, + NonOdrUseReason NOUR = NOUR_None); static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, @@ -1103,7 +1205,8 @@ public: bool RefersToEnclosingVariableOrCapture, const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr, - const TemplateArgumentListInfo *TemplateArgs = nullptr); + const TemplateArgumentListInfo *TemplateArgs = nullptr, + NonOdrUseReason NOUR = NOUR_None); /// Construct an empty declaration reference expression. static DeclRefExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier, @@ -1234,6 +1337,11 @@ public: DeclRefExprBits.HadMultipleCandidates = V; } + /// Is this expression a non-odr-use reference, and if so, why? + NonOdrUseReason isNonOdrUse() const { + return static_cast<NonOdrUseReason>(DeclRefExprBits.NonOdrUseReason); + } + /// Does this DeclRefExpr refer to an enclosing local or a captured /// variable? bool refersToEnclosingVariableOrCapture() const { @@ -1466,21 +1574,28 @@ public: /// Get a raw enumeration value representing the floating-point semantics of /// this literal (32-bit IEEE, x87, ...), suitable for serialisation. - APFloatSemantics getRawSemantics() const { - return static_cast<APFloatSemantics>(FloatingLiteralBits.Semantics); + llvm::APFloatBase::Semantics getRawSemantics() const { + return static_cast<llvm::APFloatBase::Semantics>( + FloatingLiteralBits.Semantics); } /// Set the raw enumeration value representing the floating-point semantics of /// this literal (32-bit IEEE, x87, ...), suitable for serialisation. - void setRawSemantics(APFloatSemantics Sem) { + void setRawSemantics(llvm::APFloatBase::Semantics Sem) { FloatingLiteralBits.Semantics = Sem; } /// Return the APFloat semantics this literal uses. - const llvm::fltSemantics &getSemantics() const; + const llvm::fltSemantics &getSemantics() const { + return llvm::APFloatBase::EnumToSemantics( + static_cast<llvm::APFloatBase::Semantics>( + FloatingLiteralBits.Semantics)); + } /// Set the APFloat semantics this literal uses. - void setSemantics(const llvm::fltSemantics &Sem); + void setSemantics(const llvm::fltSemantics &Sem) { + FloatingLiteralBits.Semantics = llvm::APFloatBase::SemanticsToEnum(Sem); + } bool isExact() const { return FloatingLiteralBits.IsExact; } void setExact(bool E) { FloatingLiteralBits.IsExact = E; } @@ -1837,6 +1952,11 @@ public: return child_range(getTrailingObjects<Stmt *>(), getTrailingObjects<Stmt *>() + hasFunctionName()); } + + const_child_range children() const { + return const_child_range(getTrailingObjects<Stmt *>(), + getTrailingObjects<Stmt *>() + hasFunctionName()); + } }; /// ParenExpr - This represents a parethesized expression, e.g. "(1)". This @@ -2577,6 +2697,11 @@ public: NumArgs = NewNumArgs; } + /// Bluntly set a new number of arguments without doing any checks whatsoever. + /// Only used during construction of a CallExpr in a few places in Sema. + /// FIXME: Find a way to remove it. + void setNumArgsUnsafe(unsigned NewNumArgs) { NumArgs = NewNumArgs; } + typedef ExprIterator arg_iterator; typedef ConstExprIterator const_arg_iterator; typedef llvm::iterator_range<arg_iterator> arg_range; @@ -2685,6 +2810,7 @@ class MemberExpr final ASTTemplateKWAndArgsInfo, TemplateArgumentLoc> { friend class ASTReader; + friend class ASTStmtReader; friend class ASTStmtWriter; friend TrailingObjects; @@ -2719,49 +2845,40 @@ class MemberExpr final return MemberExprBits.HasTemplateKWAndArgsInfo; } + MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc, + ValueDecl *MemberDecl, const DeclarationNameInfo &NameInfo, + QualType T, ExprValueKind VK, ExprObjectKind OK, + NonOdrUseReason NOUR); + MemberExpr(EmptyShell Empty) + : Expr(MemberExprClass, Empty), Base(), MemberDecl() {} + public: - MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc, - ValueDecl *memberdecl, const DeclarationNameInfo &NameInfo, - QualType ty, ExprValueKind VK, ExprObjectKind OK) - : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(), - base->isValueDependent(), base->isInstantiationDependent(), - base->containsUnexpandedParameterPack()), - Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()), - MemberLoc(NameInfo.getLoc()) { - assert(memberdecl->getDeclName() == NameInfo.getName()); - MemberExprBits.IsArrow = isarrow; - MemberExprBits.HasQualifierOrFoundDecl = false; - MemberExprBits.HasTemplateKWAndArgsInfo = false; - MemberExprBits.HadMultipleCandidates = false; - MemberExprBits.OperatorLoc = operatorloc; - } - - // NOTE: this constructor should be used only when it is known that - // the member name can not provide additional syntactic info - // (i.e., source locations for C++ operator names or type source info - // for constructors, destructors and conversion operators). - MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc, - ValueDecl *memberdecl, SourceLocation l, QualType ty, - ExprValueKind VK, ExprObjectKind OK) - : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(), - base->isValueDependent(), base->isInstantiationDependent(), - base->containsUnexpandedParameterPack()), - Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l) { - MemberExprBits.IsArrow = isarrow; - MemberExprBits.HasQualifierOrFoundDecl = false; - MemberExprBits.HasTemplateKWAndArgsInfo = false; - MemberExprBits.HadMultipleCandidates = false; - MemberExprBits.OperatorLoc = operatorloc; - } - - static MemberExpr *Create(const ASTContext &C, Expr *base, bool isarrow, + static MemberExpr *Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, - SourceLocation TemplateKWLoc, ValueDecl *memberdecl, - DeclAccessPair founddecl, + SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, + DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, - const TemplateArgumentListInfo *targs, QualType ty, - ExprValueKind VK, ExprObjectKind OK); + const TemplateArgumentListInfo *TemplateArgs, + QualType T, ExprValueKind VK, ExprObjectKind OK, + NonOdrUseReason NOUR); + + /// Create an implicit MemberExpr, with no location, qualifier, template + /// arguments, and so on. Suitable only for non-static member access. + static MemberExpr *CreateImplicit(const ASTContext &C, Expr *Base, + bool IsArrow, ValueDecl *MemberDecl, + QualType T, ExprValueKind VK, + ExprObjectKind OK) { + return Create(C, Base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(), + SourceLocation(), MemberDecl, + DeclAccessPair::make(MemberDecl, MemberDecl->getAccess()), + DeclarationNameInfo(), nullptr, T, VK, OK, NOUR_None); + } + + static MemberExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier, + bool HasFoundDecl, + bool HasTemplateKWAndArgsInfo, + unsigned NumTemplateArgs); void setBase(Expr *E) { Base = E; } Expr *getBase() const { return cast<Expr>(Base); } @@ -2909,6 +3026,12 @@ public: return LO.AppleKext || !hasQualifier(); } + /// Is this expression a non-odr-use reference, and if so, why? + /// This is only meaningful if the named member is a static member. + NonOdrUseReason isNonOdrUse() const { + return static_cast<NonOdrUseReason>(MemberExprBits.NonOdrUseReason); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == MemberExprClass; } @@ -3072,6 +3195,13 @@ public: path_const_iterator path_begin() const { return path_buffer(); } path_const_iterator path_end() const { return path_buffer() + path_size(); } + llvm::iterator_range<path_iterator> path() { + return llvm::make_range(path_begin(), path_end()); + } + llvm::iterator_range<path_const_iterator> path() const { + return llvm::make_range(path_begin(), path_end()); + } + const FieldDecl *getTargetUnionField() const { assert(getCastKind() == CK_ToUnion); return getTargetFieldForToUnionCast(getType(), getSubExpr()->getType()); @@ -3159,18 +3289,6 @@ public: friend class CastExpr; }; -inline Expr *Expr::IgnoreImpCasts() { - Expr *e = this; - while (true) - if (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) - e = ice->getSubExpr(); - else if (FullExpr *fe = dyn_cast<FullExpr>(e)) - e = fe->getSubExpr(); - else - break; - return e; -} - /// ExplicitCastExpr - An explicit cast written in the source /// code. /// @@ -3377,6 +3495,9 @@ public: static bool isComparisonOp(Opcode Opc) { return Opc >= BO_Cmp && Opc<=BO_NE; } bool isComparisonOp() const { return isComparisonOp(getOpcode()); } + static bool isCommaOp(Opcode Opc) { return Opc == BO_Comma; } + bool isCommaOp() const { return isCommaOp(getOpcode()); } + static Opcode negateComparisonOp(Opcode Opc) { switch (Opc) { default: @@ -4137,6 +4258,71 @@ public: } }; +/// Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), +/// __builtin_FUNCTION(), or __builtin_FILE(). +class SourceLocExpr final : public Expr { + SourceLocation BuiltinLoc, RParenLoc; + DeclContext *ParentContext; + +public: + enum IdentKind { Function, File, Line, Column }; + + SourceLocExpr(const ASTContext &Ctx, IdentKind Type, SourceLocation BLoc, + SourceLocation RParenLoc, DeclContext *Context); + + /// Build an empty call expression. + explicit SourceLocExpr(EmptyShell Empty) : Expr(SourceLocExprClass, Empty) {} + + /// Return the result of evaluating this SourceLocExpr in the specified + /// (and possibly null) default argument or initialization context. + APValue EvaluateInContext(const ASTContext &Ctx, + const Expr *DefaultExpr) const; + + /// Return a string representing the name of the specific builtin function. + StringRef getBuiltinStr() const; + + IdentKind getIdentKind() const { + return static_cast<IdentKind>(SourceLocExprBits.Kind); + } + + bool isStringType() const { + switch (getIdentKind()) { + case File: + case Function: + return true; + case Line: + case Column: + return false; + } + llvm_unreachable("unknown source location expression kind"); + } + bool isIntType() const LLVM_READONLY { return !isStringType(); } + + /// If the SourceLocExpr has been resolved return the subexpression + /// representing the resolved value. Otherwise return null. + const DeclContext *getParentContext() const { return ParentContext; } + DeclContext *getParentContext() { return ParentContext; } + + SourceLocation getLocation() const { return BuiltinLoc; } + SourceLocation getBeginLoc() const { return BuiltinLoc; } + SourceLocation getEndLoc() const { return RParenLoc; } + + child_range children() { + return child_range(child_iterator(), child_iterator()); + } + + const_child_range children() const { + return const_child_range(child_iterator(), child_iterator()); + } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == SourceLocExprClass; + } + +private: + friend class ASTStmtReader; +}; + /// Describes an C or C++ initializer list. /// /// InitListExpr describes an initializer list, which can be used to @@ -5007,99 +5193,277 @@ public: /// which names a dependent type in its association list is result-dependent, /// which means that the choice of result expression is dependent. /// Result-dependent generic associations are both type- and value-dependent. -class GenericSelectionExpr : public Expr { - enum { CONTROLLING, END_EXPR }; - TypeSourceInfo **AssocTypes; - Stmt **SubExprs; +class GenericSelectionExpr final + : public Expr, + private llvm::TrailingObjects<GenericSelectionExpr, Stmt *, + TypeSourceInfo *> { + friend class ASTStmtReader; + friend class ASTStmtWriter; + friend TrailingObjects; + + /// The number of association expressions and the index of the result + /// expression in the case where the generic selection expression is not + /// result-dependent. The result index is equal to ResultDependentIndex + /// if and only if the generic selection expression is result-dependent. unsigned NumAssocs, ResultIndex; - SourceLocation GenericLoc, DefaultLoc, RParenLoc; + enum : unsigned { + ResultDependentIndex = std::numeric_limits<unsigned>::max(), + ControllingIndex = 0, + AssocExprStartIndex = 1 + }; -public: - GenericSelectionExpr(const ASTContext &Context, - SourceLocation GenericLoc, Expr *ControllingExpr, - ArrayRef<TypeSourceInfo*> AssocTypes, - ArrayRef<Expr*> AssocExprs, - SourceLocation DefaultLoc, SourceLocation RParenLoc, + /// The location of the "default" and of the right parenthesis. + SourceLocation DefaultLoc, RParenLoc; + + // GenericSelectionExpr is followed by several trailing objects. + // They are (in order): + // + // * A single Stmt * for the controlling expression. + // * An array of getNumAssocs() Stmt * for the association expressions. + // * An array of getNumAssocs() TypeSourceInfo *, one for each of the + // association expressions. + unsigned numTrailingObjects(OverloadToken<Stmt *>) const { + // Add one to account for the controlling expression; the remainder + // are the associated expressions. + return 1 + getNumAssocs(); + } + + unsigned numTrailingObjects(OverloadToken<TypeSourceInfo *>) const { + return getNumAssocs(); + } + + template <bool Const> class AssociationIteratorTy; + /// Bundle together an association expression and its TypeSourceInfo. + /// The Const template parameter is for the const and non-const versions + /// of AssociationTy. + template <bool Const> class AssociationTy { + friend class GenericSelectionExpr; + template <bool OtherConst> friend class AssociationIteratorTy; + using ExprPtrTy = + typename std::conditional<Const, const Expr *, Expr *>::type; + using TSIPtrTy = typename std::conditional<Const, const TypeSourceInfo *, + TypeSourceInfo *>::type; + ExprPtrTy E; + TSIPtrTy TSI; + bool Selected; + AssociationTy(ExprPtrTy E, TSIPtrTy TSI, bool Selected) + : E(E), TSI(TSI), Selected(Selected) {} + + public: + ExprPtrTy getAssociationExpr() const { return E; } + TSIPtrTy getTypeSourceInfo() const { return TSI; } + QualType getType() const { return TSI ? TSI->getType() : QualType(); } + bool isSelected() const { return Selected; } + AssociationTy *operator->() { return this; } + const AssociationTy *operator->() const { return this; } + }; // class AssociationTy + + /// Iterator over const and non-const Association objects. The Association + /// objects are created on the fly when the iterator is dereferenced. + /// This abstract over how exactly the association expressions and the + /// corresponding TypeSourceInfo * are stored. + template <bool Const> + class AssociationIteratorTy + : public llvm::iterator_facade_base< + AssociationIteratorTy<Const>, std::input_iterator_tag, + AssociationTy<Const>, std::ptrdiff_t, AssociationTy<Const>, + AssociationTy<Const>> { + friend class GenericSelectionExpr; + // FIXME: This iterator could conceptually be a random access iterator, and + // it would be nice if we could strengthen the iterator category someday. + // However this iterator does not satisfy two requirements of forward + // iterators: + // a) reference = T& or reference = const T& + // b) If It1 and It2 are both dereferenceable, then It1 == It2 if and only + // if *It1 and *It2 are bound to the same objects. + // An alternative design approach was discussed during review; + // store an Association object inside the iterator, and return a reference + // to it when dereferenced. This idea was discarded beacuse of nasty + // lifetime issues: + // AssociationIterator It = ...; + // const Association &Assoc = *It++; // Oops, Assoc is dangling. + using BaseTy = typename AssociationIteratorTy::iterator_facade_base; + using StmtPtrPtrTy = + typename std::conditional<Const, const Stmt *const *, Stmt **>::type; + using TSIPtrPtrTy = + typename std::conditional<Const, const TypeSourceInfo *const *, + TypeSourceInfo **>::type; + StmtPtrPtrTy E; // = nullptr; FIXME: Once support for gcc 4.8 is dropped. + TSIPtrPtrTy TSI; // Kept in sync with E. + unsigned Offset = 0, SelectedOffset = 0; + AssociationIteratorTy(StmtPtrPtrTy E, TSIPtrPtrTy TSI, unsigned Offset, + unsigned SelectedOffset) + : E(E), TSI(TSI), Offset(Offset), SelectedOffset(SelectedOffset) {} + + public: + AssociationIteratorTy() : E(nullptr), TSI(nullptr) {} + typename BaseTy::reference operator*() const { + return AssociationTy<Const>(cast<Expr>(*E), *TSI, + Offset == SelectedOffset); + } + typename BaseTy::pointer operator->() const { return **this; } + using BaseTy::operator++; + AssociationIteratorTy &operator++() { + ++E; + ++TSI; + ++Offset; + return *this; + } + bool operator==(AssociationIteratorTy Other) const { return E == Other.E; } + }; // class AssociationIterator + + /// Build a non-result-dependent generic selection expression. + GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc, + Expr *ControllingExpr, + ArrayRef<TypeSourceInfo *> AssocTypes, + ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc, + SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex); - /// This constructor is used in the result-dependent case. - GenericSelectionExpr(const ASTContext &Context, - SourceLocation GenericLoc, Expr *ControllingExpr, - ArrayRef<TypeSourceInfo*> AssocTypes, - ArrayRef<Expr*> AssocExprs, - SourceLocation DefaultLoc, SourceLocation RParenLoc, + /// Build a result-dependent generic selection expression. + GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc, + Expr *ControllingExpr, + ArrayRef<TypeSourceInfo *> AssocTypes, + ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc, + SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack); - explicit GenericSelectionExpr(EmptyShell Empty) - : Expr(GenericSelectionExprClass, Empty) { } + /// Build an empty generic selection expression for deserialization. + explicit GenericSelectionExpr(EmptyShell Empty, unsigned NumAssocs); +public: + /// Create a non-result-dependent generic selection expression. + static GenericSelectionExpr * + Create(const ASTContext &Context, SourceLocation GenericLoc, + Expr *ControllingExpr, ArrayRef<TypeSourceInfo *> AssocTypes, + ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc, + SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, + unsigned ResultIndex); + + /// Create a result-dependent generic selection expression. + static GenericSelectionExpr * + Create(const ASTContext &Context, SourceLocation GenericLoc, + Expr *ControllingExpr, ArrayRef<TypeSourceInfo *> AssocTypes, + ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc, + SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack); + + /// Create an empty generic selection expression for deserialization. + static GenericSelectionExpr *CreateEmpty(const ASTContext &Context, + unsigned NumAssocs); + + using Association = AssociationTy<false>; + using ConstAssociation = AssociationTy<true>; + using AssociationIterator = AssociationIteratorTy<false>; + using ConstAssociationIterator = AssociationIteratorTy<true>; + using association_range = llvm::iterator_range<AssociationIterator>; + using const_association_range = + llvm::iterator_range<ConstAssociationIterator>; + + /// The number of association expressions. unsigned getNumAssocs() const { return NumAssocs; } - SourceLocation getGenericLoc() const { return GenericLoc; } - SourceLocation getDefaultLoc() const { return DefaultLoc; } - SourceLocation getRParenLoc() const { return RParenLoc; } - - const Expr *getAssocExpr(unsigned i) const { - return cast<Expr>(SubExprs[END_EXPR+i]); - } - Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } - ArrayRef<Expr *> getAssocExprs() const { - return NumAssocs - ? llvm::makeArrayRef( - &reinterpret_cast<Expr **>(SubExprs)[END_EXPR], NumAssocs) - : None; - } - const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { - return AssocTypes[i]; - } - TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } - ArrayRef<TypeSourceInfo *> getAssocTypeSourceInfos() const { - return NumAssocs ? llvm::makeArrayRef(&AssocTypes[0], NumAssocs) : None; - } - - QualType getAssocType(unsigned i) const { - if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) - return TS->getType(); - else - return QualType(); - } - - const Expr *getControllingExpr() const { - return cast<Expr>(SubExprs[CONTROLLING]); - } - Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } - - /// Whether this generic selection is result-dependent. - bool isResultDependent() const { return ResultIndex == -1U; } - /// The zero-based index of the result expression's generic association in /// the generic selection's association list. Defined only if the /// generic selection is not result-dependent. unsigned getResultIndex() const { - assert(!isResultDependent() && "Generic selection is result-dependent"); + assert(!isResultDependent() && + "Generic selection is result-dependent but getResultIndex called!"); return ResultIndex; } - /// The generic selection's result expression. Defined only if the - /// generic selection is not result-dependent. - const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } - Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } + /// Whether this generic selection is result-dependent. + bool isResultDependent() const { return ResultIndex == ResultDependentIndex; } - SourceLocation getBeginLoc() const LLVM_READONLY { return GenericLoc; } - SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } + /// Return the controlling expression of this generic selection expression. + Expr *getControllingExpr() { + return cast<Expr>(getTrailingObjects<Stmt *>()[ControllingIndex]); + } + const Expr *getControllingExpr() const { + return cast<Expr>(getTrailingObjects<Stmt *>()[ControllingIndex]); + } + + /// Return the result expression of this controlling expression. Defined if + /// and only if the generic selection expression is not result-dependent. + Expr *getResultExpr() { + return cast<Expr>( + getTrailingObjects<Stmt *>()[AssocExprStartIndex + getResultIndex()]); + } + const Expr *getResultExpr() const { + return cast<Expr>( + getTrailingObjects<Stmt *>()[AssocExprStartIndex + getResultIndex()]); + } + + ArrayRef<Expr *> getAssocExprs() const { + return {reinterpret_cast<Expr *const *>(getTrailingObjects<Stmt *>() + + AssocExprStartIndex), + NumAssocs}; + } + ArrayRef<TypeSourceInfo *> getAssocTypeSourceInfos() const { + return {getTrailingObjects<TypeSourceInfo *>(), NumAssocs}; + } + + /// Return the Ith association expression with its TypeSourceInfo, + /// bundled together in GenericSelectionExpr::(Const)Association. + Association getAssociation(unsigned I) { + assert(I < getNumAssocs() && + "Out-of-range index in GenericSelectionExpr::getAssociation!"); + return Association( + cast<Expr>(getTrailingObjects<Stmt *>()[AssocExprStartIndex + I]), + getTrailingObjects<TypeSourceInfo *>()[I], + !isResultDependent() && (getResultIndex() == I)); + } + ConstAssociation getAssociation(unsigned I) const { + assert(I < getNumAssocs() && + "Out-of-range index in GenericSelectionExpr::getAssociation!"); + return ConstAssociation( + cast<Expr>(getTrailingObjects<Stmt *>()[AssocExprStartIndex + I]), + getTrailingObjects<TypeSourceInfo *>()[I], + !isResultDependent() && (getResultIndex() == I)); + } + + association_range associations() { + AssociationIterator Begin(getTrailingObjects<Stmt *>() + + AssocExprStartIndex, + getTrailingObjects<TypeSourceInfo *>(), + /*Offset=*/0, ResultIndex); + AssociationIterator End(Begin.E + NumAssocs, Begin.TSI + NumAssocs, + /*Offset=*/NumAssocs, ResultIndex); + return llvm::make_range(Begin, End); + } + + const_association_range associations() const { + ConstAssociationIterator Begin(getTrailingObjects<Stmt *>() + + AssocExprStartIndex, + getTrailingObjects<TypeSourceInfo *>(), + /*Offset=*/0, ResultIndex); + ConstAssociationIterator End(Begin.E + NumAssocs, Begin.TSI + NumAssocs, + /*Offset=*/NumAssocs, ResultIndex); + return llvm::make_range(Begin, End); + } + + SourceLocation getGenericLoc() const { + return GenericSelectionExprBits.GenericLoc; + } + SourceLocation getDefaultLoc() const { return DefaultLoc; } + SourceLocation getRParenLoc() const { return RParenLoc; } + SourceLocation getBeginLoc() const { return getGenericLoc(); } + SourceLocation getEndLoc() const { return getRParenLoc(); } static bool classof(const Stmt *T) { return T->getStmtClass() == GenericSelectionExprClass; } child_range children() { - return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); + return child_range(getTrailingObjects<Stmt *>(), + getTrailingObjects<Stmt *>() + + numTrailingObjects(OverloadToken<Stmt *>())); } const_child_range children() const { - return const_child_range(SubExprs, SubExprs + END_EXPR + NumAssocs); + return const_child_range(getTrailingObjects<Stmt *>(), + getTrailingObjects<Stmt *>() + + numTrailingObjects(OverloadToken<Stmt *>())); } - friend class ASTStmtReader; }; //===----------------------------------------------------------------------===// diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 6ef837a2fc40..28ed6cdfde14 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1,9 +1,8 @@ //===- ExprCXX.h - Classes for representing expressions ---------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -217,6 +216,8 @@ public: /// Represents a call to a CUDA kernel function. class CUDAKernelCallExpr final : public CallExpr { + friend class ASTStmtReader; + enum { CONFIG, END_PREARG }; // CUDAKernelCallExpr has some trailing objects belonging @@ -242,20 +243,6 @@ public: } CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } - /// Sets the kernel configuration expression. - /// - /// Note that this method cannot be called if config has already been set to a - /// non-null value. - void setConfig(CallExpr *E) { - assert(!getConfig() && - "Cannot call setConfig if config is not null"); - setPreArg(CONFIG, E); - setInstantiationDependent(isInstantiationDependent() || - E->isInstantiationDependent()); - setContainsUnexpandedParameterPack(containsUnexpandedParameterPack() || - E->containsUnexpandedParameterPack()); - } - static bool classof(const Stmt *T) { return T->getStmtClass() == CUDAKernelCallExprClass; } @@ -588,6 +575,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// The null pointer literal (C++11 [lex.nullptr]) @@ -617,6 +608,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Implicit construction of a std::initializer_list<T> object from an @@ -659,6 +654,10 @@ public: } child_range children() { return child_range(&SubExpr, &SubExpr + 1); } + + const_child_range children() const { + return const_child_range(&SubExpr, &SubExpr + 1); + } }; /// A C++ \c typeid expression (C++ [expr.typeid]), which gets @@ -749,6 +748,15 @@ public: auto **begin = reinterpret_cast<Stmt **>(&Operand); return child_range(begin, begin + 1); } + + const_child_range children() const { + if (isTypeOperand()) + return const_child_range(const_child_iterator(), const_child_iterator()); + + auto **begin = + reinterpret_cast<Stmt **>(&const_cast<CXXTypeidExpr *>(this)->Operand); + return const_child_range(begin, begin + 1); + } }; /// A member reference to an MSPropertyDecl. @@ -803,6 +811,11 @@ public: return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1); } + const_child_range children() const { + auto Children = const_cast<MSPropertyRefExpr *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == MSPropertyRefExprClass; } @@ -878,6 +891,10 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS); } + + const_child_range children() const { + return const_child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS); + } }; /// A Microsoft C++ @c __uuidof expression, which gets @@ -959,6 +976,14 @@ public: auto **begin = reinterpret_cast<Stmt **>(&Operand); return child_range(begin, begin + 1); } + + const_child_range children() const { + if (isTypeOperand()) + return const_child_range(const_child_iterator(), const_child_iterator()); + auto **begin = + reinterpret_cast<Stmt **>(&const_cast<CXXUuidofExpr *>(this)->Operand); + return const_child_range(begin, begin + 1); + } }; /// Represents the \c this expression in C++. @@ -1005,6 +1030,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// A C++ throw-expression (C++ [except.throw]). @@ -1063,6 +1092,10 @@ public: child_range children() { return child_range(&Operand, Operand ? &Operand + 1 : &Operand); } + + const_child_range children() const { + return const_child_range(&Operand, Operand ? &Operand + 1 : &Operand); + } }; /// A default argument (C++ [dcl.fct.default]). @@ -1076,7 +1109,11 @@ class CXXDefaultArgExpr final : public Expr { /// The parameter whose default is being used. ParmVarDecl *Param; - CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param) + /// The context where the default argument expression was used. + DeclContext *UsedContext; + + CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param, + DeclContext *UsedContext) : Expr(SC, Param->hasUnparsedDefaultArg() ? Param->getType().getNonReferenceType() @@ -1084,7 +1121,7 @@ class CXXDefaultArgExpr final : public Expr { Param->getDefaultArg()->getValueKind(), Param->getDefaultArg()->getObjectKind(), false, false, false, false), - Param(Param) { + Param(Param), UsedContext(UsedContext) { CXXDefaultArgExprBits.Loc = Loc; } @@ -1094,8 +1131,10 @@ public: // \p Param is the parameter whose default argument is used by this // expression. static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc, - ParmVarDecl *Param) { - return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); + ParmVarDecl *Param, + DeclContext *UsedContext) { + return new (C) + CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, UsedContext); } // Retrieve the parameter that the argument was created from. @@ -1106,6 +1145,9 @@ public: const Expr *getExpr() const { return getParam()->getDefaultArg(); } Expr *getExpr() { return getParam()->getDefaultArg(); } + const DeclContext *getUsedContext() const { return UsedContext; } + DeclContext *getUsedContext() { return UsedContext; } + /// Retrieve the location where this default argument was actually used. SourceLocation getUsedLocation() const { return CXXDefaultArgExprBits.Loc; } @@ -1124,6 +1166,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// A use of a default initializer in a constructor or in aggregate @@ -1141,8 +1187,11 @@ class CXXDefaultInitExpr : public Expr { /// The field whose default is being used. FieldDecl *Field; + /// The context where the default initializer expression was used. + DeclContext *UsedContext; + CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc, - FieldDecl *Field, QualType Ty); + FieldDecl *Field, QualType Ty, DeclContext *UsedContext); CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {} @@ -1150,8 +1199,8 @@ public: /// \p Field is the non-static data member whose default initializer is used /// by this expression. static CXXDefaultInitExpr *Create(const ASTContext &Ctx, SourceLocation Loc, - FieldDecl *Field) { - return new (Ctx) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType()); + FieldDecl *Field, DeclContext *UsedContext) { + return new (Ctx) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType(), UsedContext); } /// Get the field whose initializer will be used. @@ -1168,6 +1217,13 @@ public: return Field->getInClassInitializer(); } + const DeclContext *getUsedContext() const { return UsedContext; } + DeclContext *getUsedContext() { return UsedContext; } + + /// Retrieve the location where this default initializer expression was + /// actually used. + SourceLocation getUsedLocation() const { return getBeginLoc(); } + SourceLocation getBeginLoc() const { return CXXDefaultInitExprBits.Loc; } SourceLocation getEndLoc() const { return CXXDefaultInitExprBits.Loc; } @@ -1179,6 +1235,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents a C++ temporary. @@ -1256,6 +1316,10 @@ public: // Iterators child_range children() { return child_range(&SubExpr, &SubExpr + 1); } + + const_child_range children() const { + return const_child_range(&SubExpr, &SubExpr + 1); + } }; /// Represents a call to a C++ constructor. @@ -1439,6 +1503,11 @@ public: child_range children() { return child_range(getTrailingArgs(), getTrailingArgs() + getNumArgs()); } + + const_child_range children() const { + auto Children = const_cast<CXXConstructExpr *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } }; /// Represents a call to an inherited base class constructor from an @@ -1507,6 +1576,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents an explicit C++ type conversion that uses "functional" @@ -1833,6 +1906,10 @@ public: /// parameter list associated with it, or else return null. TemplateParameterList *getTemplateParameterList() const; + /// Get the template parameters were explicitly specified (as opposed to being + /// invented by use of an auto parameter). + ArrayRef<NamedDecl *> getExplicitTemplateParameters() const; + /// Whether this is a generic lambda. bool isGenericLambda() const { return getTemplateParameterList(); } @@ -1864,6 +1941,11 @@ public: // Includes initialization exprs plus body stmt return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); } + + const_child_range children() const { + return const_child_range(getStoredStmts(), + getStoredStmts() + NumCaptures + 1); + } }; /// An expression "T()" which creates a value-initialized rvalue of type @@ -1907,6 +1989,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents a new-expression for memory allocation and constructor @@ -1979,7 +2065,7 @@ private: CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, - SourceRange TypeIdParens, Expr *ArraySize, + SourceRange TypeIdParens, Optional<Expr *> ArraySize, InitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -1994,7 +2080,7 @@ public: Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, - SourceRange TypeIdParens, Expr *ArraySize, + SourceRange TypeIdParens, Optional<Expr *> ArraySize, InitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -2037,15 +2123,15 @@ public: bool isArray() const { return CXXNewExprBits.IsArray; } - Expr *getArraySize() { - return isArray() - ? cast<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]) - : nullptr; + Optional<Expr *> getArraySize() { + if (!isArray()) + return None; + return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]); } - const Expr *getArraySize() const { - return isArray() - ? cast<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]) - : nullptr; + Optional<const Expr *> getArraySize() const { + if (!isArray()) + return None; + return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]); } unsigned getNumPlacementArgs() const { @@ -2163,6 +2249,10 @@ public: // Iterators child_range children() { return child_range(raw_arg_begin(), raw_arg_end()); } + + const_child_range children() const { + return const_child_range(const_cast<CXXNewExpr *>(this)->children()); + } }; /// Represents a \c delete expression for memory deallocation and @@ -2229,6 +2319,10 @@ public: // Iterators child_range children() { return child_range(&Argument, &Argument + 1); } + + const_child_range children() const { + return const_child_range(&Argument, &Argument + 1); + } }; /// Stores the type being destroyed by a pseudo-destructor expression. @@ -2417,6 +2511,10 @@ public: // Iterators child_range children() { return child_range(&Base, &Base + 1); } + + const_child_range children() const { + return const_child_range(&Base, &Base + 1); + } }; /// A type trait used in the implementation of various C++11 and @@ -2501,6 +2599,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// An Embarcadero array type trait, as used in the implementation of @@ -2568,6 +2670,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// An expression trait intrinsic. @@ -2628,6 +2734,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// A reference to an overloaded function set, either an @@ -2920,6 +3030,10 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == UnresolvedLookupExprClass; } @@ -3074,6 +3188,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents an expression -- generally a full-expression -- that @@ -3143,6 +3261,10 @@ public: // Iterators child_range children() { return child_range(&SubExpr, &SubExpr + 1); } + + const_child_range children() const { + return const_child_range(&SubExpr, &SubExpr + 1); + } }; /// Describes an explicit type conversion that uses functional @@ -3272,6 +3394,12 @@ public: auto **begin = reinterpret_cast<Stmt **>(arg_begin()); return child_range(begin, begin + arg_size()); } + + const_child_range children() const { + auto **begin = reinterpret_cast<Stmt **>( + const_cast<CXXUnresolvedConstructExpr *>(this)->arg_begin()); + return const_child_range(begin, begin + arg_size()); + } }; /// Represents a C++ member access expression where the actual @@ -3518,6 +3646,12 @@ public: return child_range(child_iterator(), child_iterator()); return child_range(&Base, &Base + 1); } + + const_child_range children() const { + if (isImplicitAccess()) + return const_child_range(const_child_iterator(), const_child_iterator()); + return const_child_range(&Base, &Base + 1); + } }; /// Represents a C++ member access expression for which lookup @@ -3681,6 +3815,12 @@ public: return child_range(child_iterator(), child_iterator()); return child_range(&Base, &Base + 1); } + + const_child_range children() const { + if (isImplicitAccess()) + return const_child_range(const_child_iterator(), const_child_iterator()); + return const_child_range(&Base, &Base + 1); + } }; DeclAccessPair *OverloadExpr::getTrailingResults() { @@ -3750,6 +3890,10 @@ public: // Iterators child_range children() { return child_range(&Operand, &Operand + 1); } + + const_child_range children() const { + return const_child_range(&Operand, &Operand + 1); + } }; /// Represents a C++11 pack expansion that produces a sequence of @@ -3830,6 +3974,10 @@ public: child_range children() { return child_range(&Pattern, &Pattern + 1); } + + const_child_range children() const { + return const_child_range(&Pattern, &Pattern + 1); + } }; /// Represents an expression that computes the length of a parameter @@ -3951,6 +4099,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents a reference to a non-type template parameter @@ -3997,6 +4149,10 @@ public: // Iterators child_range children() { return child_range(&Replacement, &Replacement + 1); } + + const_child_range children() const { + return const_child_range(&Replacement, &Replacement + 1); + } }; /// Represents a reference to a non-type template parameter pack that @@ -4059,10 +4215,14 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; -/// Represents a reference to a function parameter pack that has been -/// substituted but not yet expanded. +/// Represents a reference to a function parameter pack or init-capture pack +/// that has been substituted but not yet expanded. /// /// When a pack expansion contains multiple parameter packs at different levels, /// this node is used to represent a function parameter pack at an outer level @@ -4077,13 +4237,13 @@ public: /// \endcode class FunctionParmPackExpr final : public Expr, - private llvm::TrailingObjects<FunctionParmPackExpr, ParmVarDecl *> { + private llvm::TrailingObjects<FunctionParmPackExpr, VarDecl *> { friend class ASTReader; friend class ASTStmtReader; friend TrailingObjects; /// The function parameter pack which was referenced. - ParmVarDecl *ParamPack; + VarDecl *ParamPack; /// The location of the function parameter pack reference. SourceLocation NameLoc; @@ -4091,35 +4251,35 @@ class FunctionParmPackExpr final /// The number of expansions of this pack. unsigned NumParameters; - FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, + FunctionParmPackExpr(QualType T, VarDecl *ParamPack, SourceLocation NameLoc, unsigned NumParams, - ParmVarDecl *const *Params); + VarDecl *const *Params); public: static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, - ParmVarDecl *ParamPack, + VarDecl *ParamPack, SourceLocation NameLoc, - ArrayRef<ParmVarDecl *> Params); + ArrayRef<VarDecl *> Params); static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context, unsigned NumParams); /// Get the parameter pack which this expression refers to. - ParmVarDecl *getParameterPack() const { return ParamPack; } + VarDecl *getParameterPack() const { return ParamPack; } /// Get the location of the parameter pack. SourceLocation getParameterPackLocation() const { return NameLoc; } /// Iterators over the parameters which the parameter pack expanded /// into. - using iterator = ParmVarDecl * const *; - iterator begin() const { return getTrailingObjects<ParmVarDecl *>(); } + using iterator = VarDecl * const *; + iterator begin() const { return getTrailingObjects<VarDecl *>(); } iterator end() const { return begin() + NumParameters; } /// Get the number of parameters in this parameter pack. unsigned getNumExpansions() const { return NumParameters; } /// Get an expansion of the parameter pack by index. - ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; } + VarDecl *getExpansion(unsigned I) const { return begin()[I]; } SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; } SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; } @@ -4131,6 +4291,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents a prvalue temporary that is written into memory so that @@ -4253,6 +4417,15 @@ public: auto ES = State.get<ExtraState *>(); return child_range(&ES->Temporary, &ES->Temporary + 1); } + + const_child_range children() const { + if (State.is<Stmt *>()) + return const_child_range(State.getAddrOfPtr1(), + State.getAddrOfPtr1() + 1); + + auto ES = State.get<ExtraState *>(); + return const_child_range(&ES->Temporary, &ES->Temporary + 1); + } }; /// Represents a folding of a pack over an operator. @@ -4270,18 +4443,21 @@ class CXXFoldExpr : public Expr { SourceLocation LParenLoc; SourceLocation EllipsisLoc; SourceLocation RParenLoc; + // When 0, the number of expansions is not known. Otherwise, this is one more + // than the number of expansions. + unsigned NumExpansions; Stmt *SubExprs[2]; BinaryOperatorKind Opcode; public: CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS, - SourceLocation RParenLoc) + SourceLocation RParenLoc, Optional<unsigned> NumExpansions) : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary, /*Dependent*/ true, true, true, /*ContainsUnexpandedParameterPack*/ false), LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc), - Opcode(Opcode) { + NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), Opcode(Opcode) { SubExprs[0] = LHS; SubExprs[1] = RHS; } @@ -4308,6 +4484,12 @@ public: SourceLocation getEllipsisLoc() const { return EllipsisLoc; } BinaryOperatorKind getOperator() const { return Opcode; } + Optional<unsigned> getNumExpansions() const { + if (NumExpansions) + return NumExpansions - 1; + return None; + } + SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; } SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } @@ -4318,6 +4500,10 @@ public: // Iterators child_range children() { return child_range(SubExprs, SubExprs + 2); } + + const_child_range children() const { + return const_child_range(SubExprs, SubExprs + 2); + } }; /// Represents an expression that might suspend coroutine execution; @@ -4409,6 +4595,10 @@ public: return child_range(SubExprs, SubExprs + SubExpr::Count); } + const_child_range children() const { + return const_child_range(SubExprs, SubExprs + SubExpr::Count); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == CoawaitExprClass || T->getStmtClass() == CoyieldExprClass; @@ -4493,6 +4683,10 @@ public: child_range children() { return child_range(SubExprs, SubExprs + 2); } + const_child_range children() const { + return const_child_range(SubExprs, SubExprs + 2); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == DependentCoawaitExprClass; } @@ -4522,6 +4716,35 @@ public: } }; +/// Represents a C++2a __builtin_bit_cast(T, v) expression. Used to implement +/// std::bit_cast. These can sometimes be evaluated as part of a constant +/// expression, but otherwise CodeGen to a simple memcpy in general. +class BuiltinBitCastExpr final + : public ExplicitCastExpr, + private llvm::TrailingObjects<BuiltinBitCastExpr, CXXBaseSpecifier *> { + friend class ASTStmtReader; + friend class CastExpr; + friend class TrailingObjects; + + SourceLocation KWLoc; + SourceLocation RParenLoc; + +public: + BuiltinBitCastExpr(QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr, + TypeSourceInfo *DstType, SourceLocation KWLoc, + SourceLocation RParenLoc) + : ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0, + DstType), + KWLoc(KWLoc), RParenLoc(RParenLoc) {} + + SourceLocation getBeginLoc() const LLVM_READONLY { return KWLoc; } + SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == BuiltinBitCastExprClass; + } +}; + } // namespace clang #endif // LLVM_CLANG_AST_EXPRCXX_H diff --git a/include/clang/AST/ExprObjC.h b/include/clang/AST/ExprObjC.h index c7b305f3304e..dbb2b2ff7099 100644 --- a/include/clang/AST/ExprObjC.h +++ b/include/clang/AST/ExprObjC.h @@ -1,9 +1,8 @@ //===- ExprObjC.h - Classes for representing ObjC expressions ---*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -73,6 +72,10 @@ public: // Iterators child_range children() { return child_range(&String, &String+1); } + const_child_range children() const { + return const_child_range(&String, &String + 1); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCStringLiteralClass; } @@ -105,6 +108,10 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCBoolLiteralExprClass; } @@ -139,6 +146,12 @@ public: return BoxingMethod; } + // Indicates whether this boxed expression can be emitted as a compile-time + // constant. + bool isExpressibleAsConstantInitializer() const { + return !BoxingMethod && SubExpr; + } + SourceLocation getAtLoc() const { return Range.getBegin(); } SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } @@ -151,6 +164,10 @@ public: // Iterators child_range children() { return child_range(&SubExpr, &SubExpr+1); } + const_child_range children() const { + return const_child_range(&SubExpr, &SubExpr + 1); + } + using const_arg_iterator = ConstExprIterator; const_arg_iterator arg_begin() const { @@ -229,6 +246,11 @@ public: reinterpret_cast<Stmt **>(getElements()) + NumElements); } + const_child_range children() const { + auto Children = const_cast<ObjCArrayLiteral *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCArrayLiteralClass; } @@ -256,12 +278,6 @@ struct ObjCDictionaryElement { } // namespace clang -namespace llvm { - -template <> struct isPodLike<clang::ObjCDictionaryElement> : std::true_type {}; - -} // namespace llvm - namespace clang { /// Internal struct for storing Key/value pair. @@ -375,6 +391,11 @@ public: NumElements * 2); } + const_child_range children() const { + auto Children = const_cast<ObjCDictionaryLiteral *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCDictionaryLiteralClass; } @@ -420,6 +441,10 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCEncodeExprClass; } @@ -458,6 +483,10 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCSelectorExprClass; } @@ -504,6 +533,10 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCProtocolExprClass; } @@ -567,6 +600,10 @@ public: // Iterators child_range children() { return child_range(&Base, &Base+1); } + const_child_range children() const { + return const_child_range(&Base, &Base + 1); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCIvarRefExprClass; } @@ -758,6 +795,11 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + auto Children = const_cast<ObjCPropertyRefExpr *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCPropertyRefExprClass; } @@ -867,6 +909,10 @@ public: return child_range(SubExprs, SubExprs+END_EXPR); } + const_child_range children() const { + return const_child_range(SubExprs, SubExprs + END_EXPR); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCSubscriptRefExprClass; } @@ -1187,6 +1233,13 @@ public: /// sent to. ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; } + /// \return the return type of the message being sent. + /// This is not always the type of the message expression itself because + /// of references (the expression would not have a reference type). + /// It is also not always the declared return type of the method because + /// of `instancetype` (in that case it's an expression type). + QualType getCallReturnType(ASTContext &Ctx) const; + /// Source range of the receiver. SourceRange getReceiverRange() const; @@ -1402,6 +1455,8 @@ public: // Iterators child_range children(); + const_child_range children() const; + using arg_iterator = ExprIterator; using const_arg_iterator = ConstExprIterator; @@ -1488,6 +1543,10 @@ public: // Iterators child_range children() { return child_range(&Base, &Base+1); } + const_child_range children() const { + return const_child_range(&Base, &Base + 1); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCIsaExprClass; } @@ -1549,6 +1608,10 @@ public: child_range children() { return child_range(&Operand, &Operand+1); } + const_child_range children() const { + return const_child_range(&Operand, &Operand + 1); + } + // Source locations are determined by the subexpression. SourceLocation getBeginLoc() const LLVM_READONLY { return Operand->getBeginLoc(); @@ -1661,6 +1724,10 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == ObjCAvailabilityCheckExprClass; } diff --git a/include/clang/AST/ExprOpenMP.h b/include/clang/AST/ExprOpenMP.h index d88eebf5e54f..5607d2d1dc58 100644 --- a/include/clang/AST/ExprOpenMP.h +++ b/include/clang/AST/ExprOpenMP.h @@ -1,9 +1,8 @@ //===--- ExprOpenMP.h - Classes for representing expressions ----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -123,6 +122,10 @@ public: child_range children() { return child_range(&SubExprs[BASE], &SubExprs[END_EXPR]); } + + const_child_range children() const { + return const_child_range(&SubExprs[BASE], &SubExprs[END_EXPR]); + } }; } // end namespace clang diff --git a/include/clang/AST/ExternalASTMerger.h b/include/clang/AST/ExternalASTMerger.h index 7b01fa8cbced..d89189da04f0 100644 --- a/include/clang/AST/ExternalASTMerger.h +++ b/include/clang/AST/ExternalASTMerger.h @@ -1,9 +1,8 @@ //===--- ExternalASTMerger.h - Merging External AST Interface ---*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/ExternalASTSource.h b/include/clang/AST/ExternalASTSource.h index 525d4c78b362..304633668bd1 100644 --- a/include/clang/AST/ExternalASTSource.h +++ b/include/clang/AST/ExternalASTSource.h @@ -1,9 +1,8 @@ //===- ExternalASTSource.h - Abstract External AST Interface ----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/FormatString.h b/include/clang/AST/FormatString.h index 4a89c797b648..643fb822f7f4 100644 --- a/include/clang/AST/FormatString.h +++ b/include/clang/AST/FormatString.h @@ -1,9 +1,8 @@ //= FormatString.h - Analysis of printf/fprintf format strings --*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -68,6 +67,7 @@ public: None, AsChar, // 'hh' AsShort, // 'h' + AsShortLong, // 'hl' (OpenCL float/int vector element) AsLong, // 'l' AsLongLong, // 'll' AsQuad, // 'q' (BSD, deprecated, for 64-bit integer types) @@ -437,7 +437,8 @@ public: bool usesPositionalArg() const { return UsesPositionalArg; } - bool hasValidLengthModifier(const TargetInfo &Target) const; + bool hasValidLengthModifier(const TargetInfo &Target, + const LangOptions &LO) const; bool hasStandardLengthModifier() const; diff --git a/include/clang/AST/GlobalDecl.h b/include/clang/AST/GlobalDecl.h index a3c0cab3799f..86fd0f6aa907 100644 --- a/include/clang/AST/GlobalDecl.h +++ b/include/clang/AST/GlobalDecl.h @@ -1,9 +1,8 @@ //===- GlobalDecl.h - Global declaration holder -----------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -28,6 +27,12 @@ namespace clang { +enum class DynamicInitKind : unsigned { + NoStub = 0, + Initializer, + AtExit, +}; + /// GlobalDecl - represents a global declaration. This can either be a /// CXXConstructorDecl and the constructor type (Base, Complete). /// a CXXDestructorDecl and the destructor type (Base, Complete) or @@ -56,6 +61,8 @@ public: GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); } GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {} GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {} + GlobalDecl(const VarDecl *D, DynamicInitKind StubKind) + : Value(D, unsigned(StubKind)) {} GlobalDecl getCanonicalDecl() const { GlobalDecl CanonGD; @@ -78,6 +85,13 @@ public: return static_cast<CXXDtorType>(Value.getInt()); } + DynamicInitKind getDynamicInitKind() const { + assert(isa<VarDecl>(getDecl()) && + cast<VarDecl>(getDecl())->hasGlobalStorage() && + "Decl is not a global variable!"); + return static_cast<DynamicInitKind>(Value.getInt()); + } + unsigned getMultiVersionIndex() const { assert(isa<FunctionDecl>(getDecl()) && !isa<CXXConstructorDecl>(getDecl()) && @@ -105,6 +119,20 @@ public: return Result; } + GlobalDecl getWithCtorType(CXXCtorType Type) { + assert(isa<CXXConstructorDecl>(getDecl())); + GlobalDecl Result(*this); + Result.Value.setInt(Type); + return Result; + } + + GlobalDecl getWithDtorType(CXXDtorType Type) { + assert(isa<CXXDestructorDecl>(getDecl())); + GlobalDecl Result(*this); + Result.Value.setInt(Type); + return Result; + } + GlobalDecl getWithMultiVersionIndex(unsigned Index) { assert(isa<FunctionDecl>(getDecl()) && !isa<CXXConstructorDecl>(getDecl()) && @@ -140,13 +168,6 @@ namespace llvm { } }; - // GlobalDecl isn't *technically* a POD type. However, its copy constructor, - // copy assignment operator, and destructor are all trivial. - template <> - struct isPodLike<clang::GlobalDecl> { - static const bool value = true; - }; - } // namespace llvm #endif // LLVM_CLANG_AST_GLOBALDECL_H diff --git a/include/clang/AST/JSONNodeDumper.h b/include/clang/AST/JSONNodeDumper.h new file mode 100644 index 000000000000..238e43aad78b --- /dev/null +++ b/include/clang/AST/JSONNodeDumper.h @@ -0,0 +1,425 @@ +//===--- JSONNodeDumper.h - Printing of AST nodes to JSON -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements AST dumping of components of individual AST nodes to +// a JSON. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_JSONNODEDUMPER_H +#define LLVM_CLANG_AST_JSONNODEDUMPER_H + +#include "clang/AST/ASTContext.h" +#include "clang/AST/ASTNodeTraverser.h" +#include "clang/AST/ASTDumperUtils.h" +#include "clang/AST/AttrVisitor.h" +#include "clang/AST/CommentCommandTraits.h" +#include "clang/AST/CommentVisitor.h" +#include "clang/AST/ExprCXX.h" +#include "llvm/Support/JSON.h" + +namespace clang { + +class NodeStreamer { + bool FirstChild = true; + bool TopLevel = true; + llvm::SmallVector<std::function<void(bool IsLastChild)>, 32> Pending; + +protected: + llvm::json::OStream JOS; + +public: + /// Add a child of the current node. Calls DoAddChild without arguments + template <typename Fn> void AddChild(Fn DoAddChild) { + return AddChild("", DoAddChild); + } + + /// Add a child of the current node with an optional label. + /// Calls DoAddChild without arguments. + template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) { + // If we're at the top level, there's nothing interesting to do; just + // run the dumper. + if (TopLevel) { + TopLevel = false; + JOS.objectBegin(); + + DoAddChild(); + + while (!Pending.empty()) { + Pending.back()(true); + Pending.pop_back(); + } + + JOS.objectEnd(); + TopLevel = true; + return; + } + + // We need to capture an owning-string in the lambda because the lambda + // is invoked in a deferred manner. + std::string LabelStr = !Label.empty() ? Label : "inner"; + bool WasFirstChild = FirstChild; + auto DumpWithIndent = [=](bool IsLastChild) { + if (WasFirstChild) { + JOS.attributeBegin(LabelStr); + JOS.arrayBegin(); + } + + FirstChild = true; + unsigned Depth = Pending.size(); + JOS.objectBegin(); + + DoAddChild(); + + // If any children are left, they're the last at their nesting level. + // Dump those ones out now. + while (Depth < Pending.size()) { + Pending.back()(true); + this->Pending.pop_back(); + } + + JOS.objectEnd(); + + if (IsLastChild) { + JOS.arrayEnd(); + JOS.attributeEnd(); + } + }; + + if (FirstChild) { + Pending.push_back(std::move(DumpWithIndent)); + } else { + Pending.back()(false); + Pending.back() = std::move(DumpWithIndent); + } + FirstChild = false; + } + + NodeStreamer(raw_ostream &OS) : JOS(OS, 2) {} +}; + +// Dumps AST nodes in JSON format. There is no implied stability for the +// content or format of the dump between major releases of Clang, other than it +// being valid JSON output. Further, there is no requirement that the +// information dumped is a complete representation of the AST, only that the +// information presented is correct. +class JSONNodeDumper + : public ConstAttrVisitor<JSONNodeDumper>, + public comments::ConstCommentVisitor<JSONNodeDumper, void, + const comments::FullComment *>, + public ConstTemplateArgumentVisitor<JSONNodeDumper>, + public ConstStmtVisitor<JSONNodeDumper>, + public TypeVisitor<JSONNodeDumper>, + public ConstDeclVisitor<JSONNodeDumper>, + public NodeStreamer { + friend class JSONDumper; + + const SourceManager &SM; + ASTContext& Ctx; + PrintingPolicy PrintPolicy; + const comments::CommandTraits *Traits; + StringRef LastLocFilename; + unsigned LastLocLine, LastLocPresumedLine; + + using InnerAttrVisitor = ConstAttrVisitor<JSONNodeDumper>; + using InnerCommentVisitor = + comments::ConstCommentVisitor<JSONNodeDumper, void, + const comments::FullComment *>; + using InnerTemplateArgVisitor = ConstTemplateArgumentVisitor<JSONNodeDumper>; + using InnerStmtVisitor = ConstStmtVisitor<JSONNodeDumper>; + using InnerTypeVisitor = TypeVisitor<JSONNodeDumper>; + using InnerDeclVisitor = ConstDeclVisitor<JSONNodeDumper>; + + void attributeOnlyIfTrue(StringRef Key, bool Value) { + if (Value) + JOS.attribute(Key, Value); + } + + // Writes the attributes of a SourceLocation object without. + void writeBareSourceLocation(SourceLocation Loc, bool IsSpelling); + + // Writes the attributes of a SourceLocation to JSON based on its presumed + // spelling location. If the given location represents a macro invocation, + // this outputs two sub-objects: one for the spelling and one for the + // expansion location. + void writeSourceLocation(SourceLocation Loc); + void writeSourceRange(SourceRange R); + std::string createPointerRepresentation(const void *Ptr); + llvm::json::Object createQualType(QualType QT, bool Desugar = true); + llvm::json::Object createBareDeclRef(const Decl *D); + void writeBareDeclRef(const Decl *D); + llvm::json::Object createCXXRecordDefinitionData(const CXXRecordDecl *RD); + llvm::json::Object createCXXBaseSpecifier(const CXXBaseSpecifier &BS); + std::string createAccessSpecifier(AccessSpecifier AS); + llvm::json::Array createCastPath(const CastExpr *C); + + void writePreviousDeclImpl(...) {} + + template <typename T> void writePreviousDeclImpl(const Mergeable<T> *D) { + const T *First = D->getFirstDecl(); + if (First != D) + JOS.attribute("firstRedecl", createPointerRepresentation(First)); + } + + template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) { + const T *Prev = D->getPreviousDecl(); + if (Prev) + JOS.attribute("previousDecl", createPointerRepresentation(Prev)); + } + void addPreviousDeclaration(const Decl *D); + + StringRef getCommentCommandName(unsigned CommandID) const; + +public: + JSONNodeDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx, + const PrintingPolicy &PrintPolicy, + const comments::CommandTraits *Traits) + : NodeStreamer(OS), SM(SrcMgr), Ctx(Ctx), PrintPolicy(PrintPolicy), + Traits(Traits), LastLocLine(0), LastLocPresumedLine(0) {} + + void Visit(const Attr *A); + void Visit(const Stmt *Node); + void Visit(const Type *T); + void Visit(QualType T); + void Visit(const Decl *D); + + void Visit(const comments::Comment *C, const comments::FullComment *FC); + void Visit(const TemplateArgument &TA, SourceRange R = {}, + const Decl *From = nullptr, StringRef Label = {}); + void Visit(const CXXCtorInitializer *Init); + void Visit(const OMPClause *C); + void Visit(const BlockDecl::Capture &C); + void Visit(const GenericSelectionExpr::ConstAssociation &A); + + void VisitTypedefType(const TypedefType *TT); + void VisitFunctionType(const FunctionType *T); + void VisitFunctionProtoType(const FunctionProtoType *T); + void VisitRValueReferenceType(const ReferenceType *RT); + void VisitArrayType(const ArrayType *AT); + void VisitConstantArrayType(const ConstantArrayType *CAT); + void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *VT); + void VisitVectorType(const VectorType *VT); + void VisitUnresolvedUsingType(const UnresolvedUsingType *UUT); + void VisitUnaryTransformType(const UnaryTransformType *UTT); + void VisitTagType(const TagType *TT); + void VisitTemplateTypeParmType(const TemplateTypeParmType *TTPT); + void VisitAutoType(const AutoType *AT); + void VisitTemplateSpecializationType(const TemplateSpecializationType *TST); + void VisitInjectedClassNameType(const InjectedClassNameType *ICNT); + void VisitObjCInterfaceType(const ObjCInterfaceType *OIT); + void VisitPackExpansionType(const PackExpansionType *PET); + void VisitElaboratedType(const ElaboratedType *ET); + void VisitMacroQualifiedType(const MacroQualifiedType *MQT); + void VisitMemberPointerType(const MemberPointerType *MPT); + + void VisitNamedDecl(const NamedDecl *ND); + void VisitTypedefDecl(const TypedefDecl *TD); + void VisitTypeAliasDecl(const TypeAliasDecl *TAD); + void VisitNamespaceDecl(const NamespaceDecl *ND); + void VisitUsingDirectiveDecl(const UsingDirectiveDecl *UDD); + void VisitNamespaceAliasDecl(const NamespaceAliasDecl *NAD); + void VisitUsingDecl(const UsingDecl *UD); + void VisitUsingShadowDecl(const UsingShadowDecl *USD); + void VisitVarDecl(const VarDecl *VD); + void VisitFieldDecl(const FieldDecl *FD); + void VisitFunctionDecl(const FunctionDecl *FD); + void VisitEnumDecl(const EnumDecl *ED); + void VisitEnumConstantDecl(const EnumConstantDecl *ECD); + void VisitRecordDecl(const RecordDecl *RD); + void VisitCXXRecordDecl(const CXXRecordDecl *RD); + void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D); + void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D); + void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D); + void VisitLinkageSpecDecl(const LinkageSpecDecl *LSD); + void VisitAccessSpecDecl(const AccessSpecDecl *ASD); + void VisitFriendDecl(const FriendDecl *FD); + + void VisitObjCIvarDecl(const ObjCIvarDecl *D); + void VisitObjCMethodDecl(const ObjCMethodDecl *D); + void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D); + void VisitObjCCategoryDecl(const ObjCCategoryDecl *D); + void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D); + void VisitObjCProtocolDecl(const ObjCProtocolDecl *D); + void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D); + void VisitObjCImplementationDecl(const ObjCImplementationDecl *D); + void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D); + void VisitObjCPropertyDecl(const ObjCPropertyDecl *D); + void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D); + void VisitBlockDecl(const BlockDecl *D); + + void VisitDeclRefExpr(const DeclRefExpr *DRE); + void VisitPredefinedExpr(const PredefinedExpr *PE); + void VisitUnaryOperator(const UnaryOperator *UO); + void VisitBinaryOperator(const BinaryOperator *BO); + void VisitCompoundAssignOperator(const CompoundAssignOperator *CAO); + void VisitMemberExpr(const MemberExpr *ME); + void VisitCXXNewExpr(const CXXNewExpr *NE); + void VisitCXXDeleteExpr(const CXXDeleteExpr *DE); + void VisitCXXThisExpr(const CXXThisExpr *TE); + void VisitCastExpr(const CastExpr *CE); + void VisitImplicitCastExpr(const ImplicitCastExpr *ICE); + void VisitCallExpr(const CallExpr *CE); + void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *TTE); + void VisitSizeOfPackExpr(const SizeOfPackExpr *SOPE); + void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *ULE); + void VisitAddrLabelExpr(const AddrLabelExpr *ALE); + void VisitCXXTypeidExpr(const CXXTypeidExpr *CTE); + void VisitConstantExpr(const ConstantExpr *CE); + void VisitInitListExpr(const InitListExpr *ILE); + void VisitGenericSelectionExpr(const GenericSelectionExpr *GSE); + void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *UCE); + void VisitCXXConstructExpr(const CXXConstructExpr *CE); + void VisitExprWithCleanups(const ExprWithCleanups *EWC); + void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE); + void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *MTE); + void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *ME); + + void VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE); + void VisitObjCMessageExpr(const ObjCMessageExpr *OME); + void VisitObjCBoxedExpr(const ObjCBoxedExpr *OBE); + void VisitObjCSelectorExpr(const ObjCSelectorExpr *OSE); + void VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE); + void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE); + void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *OSRE); + void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *OIRE); + void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *OBLE); + + void VisitIntegerLiteral(const IntegerLiteral *IL); + void VisitCharacterLiteral(const CharacterLiteral *CL); + void VisitFixedPointLiteral(const FixedPointLiteral *FPL); + void VisitFloatingLiteral(const FloatingLiteral *FL); + void VisitStringLiteral(const StringLiteral *SL); + void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *BLE); + + void VisitIfStmt(const IfStmt *IS); + void VisitSwitchStmt(const SwitchStmt *SS); + void VisitCaseStmt(const CaseStmt *CS); + void VisitLabelStmt(const LabelStmt *LS); + void VisitGotoStmt(const GotoStmt *GS); + void VisitWhileStmt(const WhileStmt *WS); + void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *OACS); + + void VisitNullTemplateArgument(const TemplateArgument &TA); + void VisitTypeTemplateArgument(const TemplateArgument &TA); + void VisitDeclarationTemplateArgument(const TemplateArgument &TA); + void VisitNullPtrTemplateArgument(const TemplateArgument &TA); + void VisitIntegralTemplateArgument(const TemplateArgument &TA); + void VisitTemplateTemplateArgument(const TemplateArgument &TA); + void VisitTemplateExpansionTemplateArgument(const TemplateArgument &TA); + void VisitExpressionTemplateArgument(const TemplateArgument &TA); + void VisitPackTemplateArgument(const TemplateArgument &TA); + + void visitTextComment(const comments::TextComment *C, + const comments::FullComment *); + void visitInlineCommandComment(const comments::InlineCommandComment *C, + const comments::FullComment *); + void visitHTMLStartTagComment(const comments::HTMLStartTagComment *C, + const comments::FullComment *); + void visitHTMLEndTagComment(const comments::HTMLEndTagComment *C, + const comments::FullComment *); + void visitBlockCommandComment(const comments::BlockCommandComment *C, + const comments::FullComment *); + void visitParamCommandComment(const comments::ParamCommandComment *C, + const comments::FullComment *FC); + void visitTParamCommandComment(const comments::TParamCommandComment *C, + const comments::FullComment *FC); + void visitVerbatimBlockComment(const comments::VerbatimBlockComment *C, + const comments::FullComment *); + void + visitVerbatimBlockLineComment(const comments::VerbatimBlockLineComment *C, + const comments::FullComment *); + void visitVerbatimLineComment(const comments::VerbatimLineComment *C, + const comments::FullComment *); +}; + +class JSONDumper : public ASTNodeTraverser<JSONDumper, JSONNodeDumper> { + JSONNodeDumper NodeDumper; + + template <typename SpecializationDecl> + void writeTemplateDeclSpecialization(const SpecializationDecl *SD, + bool DumpExplicitInst, + bool DumpRefOnly) { + bool DumpedAny = false; + for (const auto *RedeclWithBadType : SD->redecls()) { + // FIXME: The redecls() range sometimes has elements of a less-specific + // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives + // us TagDecls, and should give CXXRecordDecls). + const auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType); + if (!Redecl) { + // Found the injected-class-name for a class template. This will be + // dumped as part of its surrounding class so we don't need to dump it + // here. + assert(isa<CXXRecordDecl>(RedeclWithBadType) && + "expected an injected-class-name"); + continue; + } + + switch (Redecl->getTemplateSpecializationKind()) { + case TSK_ExplicitInstantiationDeclaration: + case TSK_ExplicitInstantiationDefinition: + if (!DumpExplicitInst) + break; + LLVM_FALLTHROUGH; + case TSK_Undeclared: + case TSK_ImplicitInstantiation: + if (DumpRefOnly) + NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(Redecl); }); + else + Visit(Redecl); + DumpedAny = true; + break; + case TSK_ExplicitSpecialization: + break; + } + } + + // Ensure we dump at least one decl for each specialization. + if (!DumpedAny) + NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(SD); }); + } + + template <typename TemplateDecl> + void writeTemplateDecl(const TemplateDecl *TD, bool DumpExplicitInst) { + // FIXME: it would be nice to dump template parameters and specializations + // to their own named arrays rather than shoving them into the "inner" + // array. However, template declarations are currently being handled at the + // wrong "level" of the traversal hierarchy and so it is difficult to + // achieve without losing information elsewhere. + + dumpTemplateParameters(TD->getTemplateParameters()); + + Visit(TD->getTemplatedDecl()); + + for (const auto *Child : TD->specializations()) + writeTemplateDeclSpecialization(Child, DumpExplicitInst, + !TD->isCanonicalDecl()); + } + +public: + JSONDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx, + const PrintingPolicy &PrintPolicy, + const comments::CommandTraits *Traits) + : NodeDumper(OS, SrcMgr, Ctx, PrintPolicy, Traits) {} + + JSONNodeDumper &doGetNodeDelegate() { return NodeDumper; } + + void VisitFunctionTemplateDecl(const FunctionTemplateDecl *FTD) { + writeTemplateDecl(FTD, true); + } + void VisitClassTemplateDecl(const ClassTemplateDecl *CTD) { + writeTemplateDecl(CTD, false); + } + void VisitVarTemplateDecl(const VarTemplateDecl *VTD) { + writeTemplateDecl(VTD, false); + } +}; + +} // namespace clang + +#endif // LLVM_CLANG_AST_JSONNODEDUMPER_H diff --git a/include/clang/AST/LambdaCapture.h b/include/clang/AST/LambdaCapture.h index f246bc423bfb..8e2806545dd6 100644 --- a/include/clang/AST/LambdaCapture.h +++ b/include/clang/AST/LambdaCapture.h @@ -1,9 +1,8 @@ //===--- LambdaCapture.h - Types for C++ Lambda Captures --------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// diff --git a/include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h b/include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h index 47dac4362c8e..e42f0449f6db 100644 --- a/include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h +++ b/include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h @@ -1,9 +1,8 @@ //===--- LexicallyOrderedRecursiveASTVisitor.h - ----------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/LocInfoType.h b/include/clang/AST/LocInfoType.h index 802d9134ebde..1073174bcf91 100644 --- a/include/clang/AST/LocInfoType.h +++ b/include/clang/AST/LocInfoType.h @@ -1,9 +1,8 @@ //===--- LocInfoType.h - Parsed Type with Location Information---*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/Mangle.h b/include/clang/AST/Mangle.h index 309ed5a1a5d2..b1fbe936136a 100644 --- a/include/clang/AST/Mangle.h +++ b/include/clang/AST/Mangle.h @@ -1,9 +1,8 @@ //===--- Mangle.h - Mangle C++ Names ----------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -244,6 +243,19 @@ public: static MicrosoftMangleContext *create(ASTContext &Context, DiagnosticsEngine &Diags); }; + +class ASTNameGenerator { +public: + explicit ASTNameGenerator(ASTContext &Ctx); + ~ASTNameGenerator(); + bool writeName(const Decl *D, raw_ostream &OS); + std::string getName(const Decl *D); + std::vector<std::string> getAllManglings(const Decl *D); + +private: + class Implementation; + std::unique_ptr<Implementation> Impl; +}; } #endif diff --git a/include/clang/AST/MangleNumberingContext.h b/include/clang/AST/MangleNumberingContext.h index ff2148e3516d..f1ca6a05dbaf 100644 --- a/include/clang/AST/MangleNumberingContext.h +++ b/include/clang/AST/MangleNumberingContext.h @@ -1,9 +1,8 @@ //=== MangleNumberingContext.h - Context for mangling numbers ---*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/NSAPI.h b/include/clang/AST/NSAPI.h index f9340c64f3eb..21f0c5458d81 100644 --- a/include/clang/AST/NSAPI.h +++ b/include/clang/AST/NSAPI.h @@ -1,9 +1,8 @@ //===--- NSAPI.h - NSFoundation APIs ----------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/clang/AST/NestedNameSpecifier.h b/include/clang/AST/NestedNameSpecifier.h index 8befe9ae4258..c6fae6f465ff 100644 --- a/include/clang/AST/NestedNameSpecifier.h +++ b/include/clang/AST/NestedNameSpecifier.h @@ -1,9 +1,8 @@ //===- NestedNameSpecifier.h - C++ nested name specifiers -------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/NonTrivialTypeVisitor.h b/include/clang/AST/NonTrivialTypeVisitor.h index bab373dbb298..aafcedb9d10b 100644 --- a/include/clang/AST/NonTrivialTypeVisitor.h +++ b/include/clang/AST/NonTrivialTypeVisitor.h @@ -1,9 +1,8 @@ //===-- NonTrivialTypeVisitor.h - Visitor for non-trivial Types *- C++ --*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/ODRHash.h b/include/clang/AST/ODRHash.h index feaa83844a1a..cd4a6f37f5db 100644 --- a/include/clang/AST/ODRHash.h +++ b/include/clang/AST/ODRHash.h @@ -1,9 +1,8 @@ //===-- ODRHash.h - Hashing to diagnose ODR failures ------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// diff --git a/include/clang/AST/OSLog.h b/include/clang/AST/OSLog.h index 2b21855e7a6e..c24e79ce6da0 100644 --- a/include/clang/AST/OSLog.h +++ b/include/clang/AST/OSLog.h @@ -1,9 +1,8 @@ //= OSLog.h - Analysis of calls to os_log builtins --*- C++ -*-===============// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/OpenMPClause.h b/include/clang/AST/OpenMPClause.h index bdcdf74b2630..eadcc62a3457 100644 --- a/include/clang/AST/OpenMPClause.h +++ b/include/clang/AST/OpenMPClause.h @@ -1,9 +1,8 @@ //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -91,6 +90,15 @@ public: return const_child_range(Children.begin(), Children.end()); } + /// Get the iterator range for the expressions used in the clauses. Used + /// expressions include only the children that must be evaluated at the + /// runtime before entering the construct. + child_range used_children(); + const_child_range used_children() const { + auto Children = const_cast<OMPClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + static bool classof(const OMPClause *) { return true; } }; @@ -157,6 +165,20 @@ public: static const OMPClauseWithPostUpdate *get(const OMPClause *C); }; +/// This structure contains most locations needed for by an OMPVarListClause. +struct OMPVarListLocTy { + /// Starting location of the clause (the clause keyword). + SourceLocation StartLoc; + /// Location of '('. + SourceLocation LParenLoc; + /// Ending location of the clause. + SourceLocation EndLoc; + OMPVarListLocTy() = default; + OMPVarListLocTy(SourceLocation StartLoc, SourceLocation LParenLoc, + SourceLocation EndLoc) + : StartLoc(StartLoc), LParenLoc(LParenLoc), EndLoc(EndLoc) {} +}; + /// This represents clauses with the list of variables like 'private', /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the /// '#pragma omp ...' directives. @@ -230,6 +252,166 @@ public: } }; +/// This represents 'allocator' clause in the '#pragma omp ...' +/// directive. +/// +/// \code +/// #pragma omp allocate(a) allocator(omp_default_mem_alloc) +/// \endcode +/// In this example directive '#pragma omp allocate' has simple 'allocator' +/// clause with the allocator 'omp_default_mem_alloc'. +class OMPAllocatorClause : public OMPClause { + friend class OMPClauseReader; + + /// Location of '('. + SourceLocation LParenLoc; + + /// Expression with the allocator. + Stmt *Allocator = nullptr; + + /// Set allocator. + void setAllocator(Expr *A) { Allocator = A; } + +public: + /// Build 'allocator' clause with the given allocator. + /// + /// \param A Allocator. + /// \param StartLoc Starting location of the clause. + /// \param LParenLoc Location of '('. + /// \param EndLoc Ending location of the clause. + OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, + SourceLocation EndLoc) + : OMPClause(OMPC_allocator, StartLoc, EndLoc), LParenLoc(LParenLoc), + Allocator(A) {} + + /// Build an empty clause. + OMPAllocatorClause() + : OMPClause(OMPC_allocator, SourceLocation(), SourceLocation()) {} + + /// Sets the location of '('. + void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + + /// Returns the location of '('. + SourceLocation getLParenLoc() const { return LParenLoc; } + + /// Returns allocator. + Expr *getAllocator() const { return cast_or_null<Expr>(Allocator); } + + child_range children() { return child_range(&Allocator, &Allocator + 1); } + + const_child_range children() const { + return const_child_range(&Allocator, &Allocator + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + static bool classof(const OMPClause *T) { + return T->getClauseKind() == OMPC_allocator; + } +}; + +/// This represents clause 'allocate' in the '#pragma omp ...' directives. +/// +/// \code +/// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a) +/// \endcode +/// In this example directive '#pragma omp parallel' has clause 'private' +/// and clause 'allocate' for the variable 'a'. +class OMPAllocateClause final + : public OMPVarListClause<OMPAllocateClause>, + private llvm::TrailingObjects<OMPAllocateClause, Expr *> { + friend class OMPClauseReader; + friend OMPVarListClause; + friend TrailingObjects; + + /// Allocator specified in the clause, or 'nullptr' if the default one is + /// used. + Expr *Allocator = nullptr; + /// Position of the ':' delimiter in the clause; + SourceLocation ColonLoc; + + /// Build clause with number of variables \a N. + /// + /// \param StartLoc Starting location of the clause. + /// \param LParenLoc Location of '('. + /// \param Allocator Allocator expression. + /// \param ColonLoc Location of ':' delimiter. + /// \param EndLoc Ending location of the clause. + /// \param N Number of the variables in the clause. + OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc, + Expr *Allocator, SourceLocation ColonLoc, + SourceLocation EndLoc, unsigned N) + : OMPVarListClause<OMPAllocateClause>(OMPC_allocate, StartLoc, LParenLoc, + EndLoc, N), + Allocator(Allocator), ColonLoc(ColonLoc) {} + + /// Build an empty clause. + /// + /// \param N Number of variables. + explicit OMPAllocateClause(unsigned N) + : OMPVarListClause<OMPAllocateClause>(OMPC_allocate, SourceLocation(), + SourceLocation(), SourceLocation(), + N) {} + + /// Sets location of ':' symbol in clause. + void setColonLoc(SourceLocation CL) { ColonLoc = CL; } + + void setAllocator(Expr *A) { Allocator = A; } + +public: + /// Creates clause with a list of variables \a VL. + /// + /// \param C AST context. + /// \param StartLoc Starting location of the clause. + /// \param LParenLoc Location of '('. + /// \param Allocator Allocator expression. + /// \param ColonLoc Location of ':' delimiter. + /// \param EndLoc Ending location of the clause. + /// \param VL List of references to the variables. + static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc, + SourceLocation LParenLoc, Expr *Allocator, + SourceLocation ColonLoc, + SourceLocation EndLoc, ArrayRef<Expr *> VL); + + /// Returns the allocator expression or nullptr, if no allocator is specified. + Expr *getAllocator() const { return Allocator; } + + /// Returns the location of the ':' delimiter. + SourceLocation getColonLoc() const { return ColonLoc; } + + /// Creates an empty clause with the place for \a N variables. + /// + /// \param C AST context. + /// \param N The number of variables. + static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N); + + child_range children() { + return child_range(reinterpret_cast<Stmt **>(varlist_begin()), + reinterpret_cast<Stmt **>(varlist_end())); + } + + const_child_range children() const { + auto Children = const_cast<OMPAllocateClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + static bool classof(const OMPClause *T) { + return T->getClauseKind() == OMPC_allocate; + } +}; + /// This represents 'if' clause in the '#pragma omp ...' directive. /// /// \code @@ -315,6 +497,16 @@ public: child_range children() { return child_range(&Condition, &Condition + 1); } + const_child_range children() const { + return const_child_range(&Condition, &Condition + 1); + } + + child_range used_children(); + const_child_range used_children() const { + auto Children = const_cast<OMPIfClause *>(this)->used_children(); + return const_child_range(Children.begin(), Children.end()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_if; } @@ -366,6 +558,17 @@ public: child_range children() { return child_range(&Condition, &Condition + 1); } + const_child_range children() const { + return const_child_range(&Condition, &Condition + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_final; } @@ -427,6 +630,17 @@ public: child_range children() { return child_range(&NumThreads, &NumThreads + 1); } + const_child_range children() const { + return const_child_range(&NumThreads, &NumThreads + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_num_threads; } @@ -482,6 +696,17 @@ public: child_range children() { return child_range(&Safelen, &Safelen + 1); } + const_child_range children() const { + return const_child_range(&Safelen, &Safelen + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_safelen; } @@ -536,6 +761,17 @@ public: child_range children() { return child_range(&Simdlen, &Simdlen + 1); } + const_child_range children() const { + return const_child_range(&Simdlen, &Simdlen + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_simdlen; } @@ -591,6 +827,17 @@ public: child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); } + const_child_range children() const { + return const_child_range(&NumForLoops, &NumForLoops + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_collapse; } @@ -659,6 +906,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_default; } @@ -729,6 +987,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_proc_bind; } @@ -760,6 +1029,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_unified_address; } @@ -791,6 +1071,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_unified_shared_memory; } @@ -822,6 +1113,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_reverse_offload; } @@ -854,6 +1156,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_dynamic_allocators; } @@ -933,6 +1246,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_atomic_default_mem_order; } @@ -1114,6 +1438,18 @@ public: reinterpret_cast<Stmt **>(&ChunkSize) + 1); } + const_child_range children() const { + auto Children = const_cast<OMPScheduleClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_schedule; } @@ -1199,6 +1535,17 @@ public: child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); } + const_child_range children() const { + return const_child_range(&NumForLoops, &NumForLoops + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_ordered; } @@ -1227,6 +1574,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_nowait; } @@ -1255,6 +1613,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_untied; } @@ -1284,6 +1653,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_mergeable; } @@ -1311,6 +1691,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_read; } @@ -1339,6 +1730,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_write; } @@ -1368,6 +1770,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_update; } @@ -1397,6 +1810,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_capture; } @@ -1426,6 +1850,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_seq_cst; } @@ -1519,6 +1954,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPPrivateClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_private; } @@ -1646,6 +2093,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPFirstprivateClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_firstprivate; } @@ -1845,6 +2304,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPLastprivateClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_lastprivate; } @@ -1905,6 +2376,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPSharedClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_shared; } @@ -2127,6 +2610,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPReductionClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_reduction; } @@ -2347,6 +2842,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPTaskReductionClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_task_reduction; } @@ -2590,6 +3097,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPInReductionClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_in_reduction; } @@ -2829,6 +3348,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPLinearClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_linear; } @@ -2916,6 +3447,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPAlignedClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_aligned; } @@ -3080,6 +3623,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPCopyinClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_copyin; } @@ -3231,6 +3786,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPCopyprivateClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_copyprivate; } @@ -3296,6 +3863,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPFlushClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_flush; } @@ -3415,6 +3994,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPDependClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_depend; } @@ -3478,6 +4069,17 @@ public: child_range children() { return child_range(&Device, &Device + 1); } + const_child_range children() const { + return const_child_range(&Device, &Device + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_device; } @@ -3506,6 +4108,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_threads; } @@ -3533,6 +4146,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_simd; } @@ -3596,6 +4220,24 @@ protected: getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations); }; +/// This structure contains all sizes needed for by an +/// OMPMappableExprListClause. +struct OMPMappableExprListSizeTy { + /// Number of expressions listed. + unsigned NumVars; + /// Number of unique base declarations. + unsigned NumUniqueDeclarations; + /// Number of component lists. + unsigned NumComponentLists; + /// Total number of expression components. + unsigned NumComponents; + OMPMappableExprListSizeTy() = default; + OMPMappableExprListSizeTy(unsigned NumVars, unsigned NumUniqueDeclarations, + unsigned NumComponentLists, unsigned NumComponents) + : NumVars(NumVars), NumUniqueDeclarations(NumUniqueDeclarations), + NumComponentLists(NumComponentLists), NumComponents(NumComponents) {} +}; + /// This represents clauses with a list of expressions that are mappable. /// Examples of these clauses are 'map' in /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from @@ -3614,28 +4256,44 @@ class OMPMappableExprListClause : public OMPVarListClause<T>, /// Total number of components in this clause. unsigned NumComponents; + /// C++ nested name specifier for the associated user-defined mapper. + NestedNameSpecifierLoc MapperQualifierLoc; + + /// The associated user-defined mapper identifier information. + DeclarationNameInfo MapperIdInfo; + protected: /// Build a clause for \a NumUniqueDeclarations declarations, \a /// NumComponentLists total component lists, and \a NumComponents total /// components. /// /// \param K Kind of the clause. - /// \param StartLoc Starting location of the clause (the clause keyword). - /// \param LParenLoc Location of '('. - /// \param EndLoc Ending location of the clause. - /// \param NumVars Number of expressions listed in the clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause - one - /// list for each expression in the clause. - /// \param NumComponents Total number of expression components in the clause. - OMPMappableExprListClause(OpenMPClauseKind K, SourceLocation StartLoc, - SourceLocation LParenLoc, SourceLocation EndLoc, - unsigned NumVars, unsigned NumUniqueDeclarations, - unsigned NumComponentLists, unsigned NumComponents) - : OMPVarListClause<T>(K, StartLoc, LParenLoc, EndLoc, NumVars), - NumUniqueDeclarations(NumUniqueDeclarations), - NumComponentLists(NumComponentLists), NumComponents(NumComponents) {} + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + /// \param MapperQualifierLocPtr C++ nested name specifier for the associated + /// user-defined mapper. + /// \param MapperIdInfoPtr The identifier of associated user-defined mapper. + OMPMappableExprListClause( + OpenMPClauseKind K, const OMPVarListLocTy &Locs, + const OMPMappableExprListSizeTy &Sizes, + NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr, + DeclarationNameInfo *MapperIdInfoPtr = nullptr) + : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc, + Sizes.NumVars), + NumUniqueDeclarations(Sizes.NumUniqueDeclarations), + NumComponentLists(Sizes.NumComponentLists), + NumComponents(Sizes.NumComponents) { + if (MapperQualifierLocPtr) + MapperQualifierLoc = *MapperQualifierLocPtr; + if (MapperIdInfoPtr) + MapperIdInfo = *MapperIdInfoPtr; + } /// Get the unique declarations that are in the trailing objects of the /// class. @@ -3816,6 +4474,42 @@ protected: } } + /// Set the nested name specifier of associated user-defined mapper. + void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL) { + MapperQualifierLoc = NNSL; + } + + /// Set the name of associated user-defined mapper. + void setMapperIdInfo(DeclarationNameInfo MapperId) { + MapperIdInfo = MapperId; + } + + /// Get the user-defined mapper references that are in the trailing objects of + /// the class. + MutableArrayRef<Expr *> getUDMapperRefs() { + return llvm::makeMutableArrayRef<Expr *>( + static_cast<T *>(this)->template getTrailingObjects<Expr *>() + + OMPVarListClause<T>::varlist_size(), + OMPVarListClause<T>::varlist_size()); + } + + /// Get the user-defined mappers references that are in the trailing objects + /// of the class. + ArrayRef<Expr *> getUDMapperRefs() const { + return llvm::makeArrayRef<Expr *>( + static_cast<T *>(this)->template getTrailingObjects<Expr *>() + + OMPVarListClause<T>::varlist_size(), + OMPVarListClause<T>::varlist_size()); + } + + /// Set the user-defined mappers that are in the trailing objects of the + /// class. + void setUDMapperRefs(ArrayRef<Expr *> DMDs) { + assert(DMDs.size() == OMPVarListClause<T>::varlist_size() && + "Unexpected number of user-defined mappers."); + std::copy(DMDs.begin(), DMDs.end(), getUDMapperRefs().begin()); + } + public: /// Return the number of unique base declarations in this clause. unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; } @@ -3827,6 +4521,14 @@ public: /// clause. unsigned getTotalComponentsNum() const { return NumComponents; } + /// Gets the nested name specifier for associated user-defined mapper. + NestedNameSpecifierLoc getMapperQualifierLoc() const { + return MapperQualifierLoc; + } + + /// Gets the name info for associated user-defined mapper. + const DeclarationNameInfo &getMapperIdInfo() const { return MapperIdInfo; } + /// Iterator that browse the components by lists. It also allows /// browsing components of a single declaration. class const_component_lists_iterator @@ -4030,6 +4732,27 @@ public: auto A = getComponentsRef(); return const_all_components_range(A.begin(), A.end()); } + + using mapperlist_iterator = MutableArrayRef<Expr *>::iterator; + using mapperlist_const_iterator = ArrayRef<const Expr *>::iterator; + using mapperlist_range = llvm::iterator_range<mapperlist_iterator>; + using mapperlist_const_range = + llvm::iterator_range<mapperlist_const_iterator>; + + mapperlist_iterator mapperlist_begin() { return getUDMapperRefs().begin(); } + mapperlist_iterator mapperlist_end() { return getUDMapperRefs().end(); } + mapperlist_const_iterator mapperlist_begin() const { + return getUDMapperRefs().begin(); + } + mapperlist_const_iterator mapperlist_end() const { + return getUDMapperRefs().end(); + } + mapperlist_range mapperlists() { + return mapperlist_range(mapperlist_begin(), mapperlist_end()); + } + mapperlist_const_range mapperlists() const { + return mapperlist_const_range(mapperlist_begin(), mapperlist_end()); + } }; /// This represents clause 'map' in the '#pragma omp ...' @@ -4052,7 +4775,9 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>, /// Define the sizes of each trailing object array except the last one. This /// is required for TrailingObjects to work properly. size_t numTrailingObjects(OverloadToken<Expr *>) const { - return varlist_size(); + // There are varlist_size() of expressions, and varlist_size() of + // user-defined mappers. + return 2 * varlist_size(); } size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { return getUniqueDeclarationsNum(); @@ -4069,9 +4794,9 @@ public: private: /// Map-type-modifiers for the 'map' clause. OpenMPMapModifierKind MapTypeModifiers[NumberOfModifiers] = { - OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown - }; - + OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown, + OMPC_MAP_MODIFIER_unknown}; + /// Location of map-type-modifiers for the 'map' clause. SourceLocation MapTypeModifiersLoc[NumberOfModifiers]; @@ -4093,50 +4818,49 @@ private: /// /// \param MapModifiers Map-type-modifiers. /// \param MapModifiersLoc Locations of map-type-modifiers. + /// \param MapperQualifierLoc C++ nested name specifier for the associated + /// user-defined mapper. + /// \param MapperIdInfo The identifier of associated user-defined mapper. /// \param MapType Map type. /// \param MapTypeIsImplicit Map type is inferred implicitly. /// \param MapLoc Location of the map type. - /// \param StartLoc Starting location of the clause. - /// \param EndLoc Ending location of the clause. - /// \param NumVars Number of expressions listed in this clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause. - /// \param NumComponents Total number of expression components in the clause. + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. explicit OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers, ArrayRef<SourceLocation> MapModifiersLoc, + NestedNameSpecifierLoc MapperQualifierLoc, + DeclarationNameInfo MapperIdInfo, OpenMPMapClauseKind MapType, bool MapTypeIsImplicit, - SourceLocation MapLoc, SourceLocation StartLoc, - SourceLocation LParenLoc, SourceLocation EndLoc, - unsigned NumVars, unsigned NumUniqueDeclarations, - unsigned NumComponentLists, unsigned NumComponents) - : OMPMappableExprListClause(OMPC_map, StartLoc, LParenLoc, EndLoc, - NumVars, NumUniqueDeclarations, - NumComponentLists, NumComponents), - MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), - MapLoc(MapLoc) { - assert(llvm::array_lengthof(MapTypeModifiers) == MapModifiers.size() - && "Unexpected number of map type modifiers."); - llvm::copy(MapModifiers, std::begin(MapTypeModifiers)); - - assert(llvm::array_lengthof(MapTypeModifiersLoc) == - MapModifiersLoc.size() && - "Unexpected number of map type modifier locations."); - llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc)); + SourceLocation MapLoc, const OMPVarListLocTy &Locs, + const OMPMappableExprListSizeTy &Sizes) + : OMPMappableExprListClause(OMPC_map, Locs, Sizes, &MapperQualifierLoc, + &MapperIdInfo), + MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) { + assert(llvm::array_lengthof(MapTypeModifiers) == MapModifiers.size() && + "Unexpected number of map type modifiers."); + llvm::copy(MapModifiers, std::begin(MapTypeModifiers)); + + assert(llvm::array_lengthof(MapTypeModifiersLoc) == + MapModifiersLoc.size() && + "Unexpected number of map type modifier locations."); + llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc)); } /// Build an empty clause. /// - /// \param NumVars Number of expressions listed in this clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause. - /// \param NumComponents Total number of expression components in the clause. - explicit OMPMapClause(unsigned NumVars, unsigned NumUniqueDeclarations, - unsigned NumComponentLists, unsigned NumComponents) - : OMPMappableExprListClause( - OMPC_map, SourceLocation(), SourceLocation(), SourceLocation(), - NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {} + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + explicit OMPMapClause(const OMPMappableExprListSizeTy &Sizes) + : OMPMappableExprListClause(OMPC_map, OMPVarListLocTy(), Sizes) {} /// Set map-type-modifier for the clause. /// @@ -4175,41 +4899,44 @@ public: /// Creates clause with a list of variables \a VL. /// /// \param C AST context. - /// \param StartLoc Starting location of the clause. - /// \param EndLoc Ending location of the clause. + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. /// \param Vars The original expression used in the clause. /// \param Declarations Declarations used in the clause. /// \param ComponentLists Component lists used in the clause. + /// \param UDMapperRefs References to user-defined mappers associated with + /// expressions used in the clause. /// \param MapModifiers Map-type-modifiers. /// \param MapModifiersLoc Location of map-type-modifiers. + /// \param UDMQualifierLoc C++ nested name specifier for the associated + /// user-defined mapper. + /// \param MapperId The identifier of associated user-defined mapper. /// \param Type Map type. /// \param TypeIsImplicit Map type is inferred implicitly. /// \param TypeLoc Location of the map type. - static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc, - SourceLocation LParenLoc, SourceLocation EndLoc, - ArrayRef<Expr *> Vars, - ArrayRef<ValueDecl *> Declarations, - MappableExprComponentListsRef ComponentLists, - ArrayRef<OpenMPMapModifierKind> MapModifiers, - ArrayRef<SourceLocation> MapModifiersLoc, - OpenMPMapClauseKind Type, bool TypeIsImplicit, - SourceLocation TypeLoc); + static OMPMapClause * + Create(const ASTContext &C, const OMPVarListLocTy &Locs, + ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, + MappableExprComponentListsRef ComponentLists, + ArrayRef<Expr *> UDMapperRefs, + ArrayRef<OpenMPMapModifierKind> MapModifiers, + ArrayRef<SourceLocation> MapModifiersLoc, + NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId, + OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc); /// Creates an empty clause with the place for \a NumVars original /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists /// lists, and \a NumComponents expression components. /// /// \param C AST context. - /// \param NumVars Number of expressions listed in the clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of unique base declarations in this - /// clause. - /// \param NumComponents Total number of expression components in the clause. - static OMPMapClause *CreateEmpty(const ASTContext &C, unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, - unsigned NumComponents); + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + static OMPMapClause *CreateEmpty(const ASTContext &C, + const OMPMappableExprListSizeTy &Sizes); /// Fetches mapping kind for the clause. OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; } @@ -4233,7 +4960,7 @@ public: /// Fetches the map-type-modifier location at 'Cnt' index of array of /// modifiers' locations. /// - /// \param Cnt index for map-type-modifier location. + /// \param Cnt index for map-type-modifier location. SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY { assert(Cnt < NumberOfModifiers && "Requested modifier location exceeds total number of modifiers."); @@ -4244,7 +4971,7 @@ public: ArrayRef<OpenMPMapModifierKind> getMapTypeModifiers() const LLVM_READONLY { return llvm::makeArrayRef(MapTypeModifiers); } - + /// Fetches ArrayRef of location of map-type-modifiers. ArrayRef<SourceLocation> getMapTypeModifiersLoc() const LLVM_READONLY { return llvm::makeArrayRef(MapTypeModifiersLoc); @@ -4262,6 +4989,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPMapClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_map; } @@ -4326,6 +5065,17 @@ public: child_range children() { return child_range(&NumTeams, &NumTeams + 1); } + const_child_range children() const { + return const_child_range(&NumTeams, &NumTeams + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_num_teams; } @@ -4391,6 +5141,17 @@ public: child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); } + const_child_range children() const { + return const_child_range(&ThreadLimit, &ThreadLimit + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_thread_limit; } @@ -4448,6 +5209,17 @@ public: child_range children() { return child_range(&Priority, &Priority + 1); } + const_child_range children() const { + return const_child_range(&Priority, &Priority + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_priority; } @@ -4499,6 +5271,17 @@ public: child_range children() { return child_range(&Grainsize, &Grainsize + 1); } + const_child_range children() const { + return const_child_range(&Grainsize, &Grainsize + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_grainsize; } @@ -4527,6 +5310,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_nogroup; } @@ -4578,6 +5372,17 @@ public: child_range children() { return child_range(&NumTasks, &NumTasks + 1); } + const_child_range children() const { + return const_child_range(&NumTasks, &NumTasks + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_num_tasks; } @@ -4628,6 +5433,17 @@ public: child_range children() { return child_range(&Hint, &Hint + 1); } + const_child_range children() const { + return const_child_range(&Hint, &Hint + 1); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_hint; } @@ -4735,6 +5551,18 @@ public: reinterpret_cast<Stmt **>(&ChunkSize) + 1); } + const_child_range children() const { + auto Children = const_cast<OMPDistScheduleClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_dist_schedule; } @@ -4836,6 +5664,17 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_defaultmap; } @@ -4860,38 +5699,40 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>, /// Build clause with number of variables \a NumVars. /// - /// \param StartLoc Starting location of the clause. - /// \param EndLoc Ending location of the clause. - /// \param NumVars Number of expressions listed in this clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause. - /// \param NumComponents Total number of expression components in the clause. - explicit OMPToClause(SourceLocation StartLoc, SourceLocation LParenLoc, - SourceLocation EndLoc, unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, unsigned NumComponents) - : OMPMappableExprListClause(OMPC_to, StartLoc, LParenLoc, EndLoc, NumVars, - NumUniqueDeclarations, NumComponentLists, - NumComponents) {} + /// \param MapperQualifierLoc C++ nested name specifier for the associated + /// user-defined mapper. + /// \param MapperIdInfo The identifier of associated user-defined mapper. + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + explicit OMPToClause(NestedNameSpecifierLoc MapperQualifierLoc, + DeclarationNameInfo MapperIdInfo, + const OMPVarListLocTy &Locs, + const OMPMappableExprListSizeTy &Sizes) + : OMPMappableExprListClause(OMPC_to, Locs, Sizes, &MapperQualifierLoc, + &MapperIdInfo) {} /// Build an empty clause. /// - /// \param NumVars Number of expressions listed in this clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause. - /// \param NumComponents Total number of expression components in the clause. - explicit OMPToClause(unsigned NumVars, unsigned NumUniqueDeclarations, - unsigned NumComponentLists, unsigned NumComponents) - : OMPMappableExprListClause( - OMPC_to, SourceLocation(), SourceLocation(), SourceLocation(), - NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {} + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + explicit OMPToClause(const OMPMappableExprListSizeTy &Sizes) + : OMPMappableExprListClause(OMPC_to, OMPVarListLocTy(), Sizes) {} /// Define the sizes of each trailing object array except the last one. This /// is required for TrailingObjects to work properly. size_t numTrailingObjects(OverloadToken<Expr *>) const { - return varlist_size(); + // There are varlist_size() of expressions, and varlist_size() of + // user-defined mappers. + return 2 * varlist_size(); } size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { return getUniqueDeclarationsNum(); @@ -4904,36 +5745,53 @@ public: /// Creates clause with a list of variables \a Vars. /// /// \param C AST context. - /// \param StartLoc Starting location of the clause. - /// \param EndLoc Ending location of the clause. + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. /// \param Vars The original expression used in the clause. /// \param Declarations Declarations used in the clause. /// \param ComponentLists Component lists used in the clause. - static OMPToClause *Create(const ASTContext &C, SourceLocation StartLoc, - SourceLocation LParenLoc, SourceLocation EndLoc, + /// \param UDMapperRefs References to user-defined mappers associated with + /// expressions used in the clause. + /// \param UDMQualifierLoc C++ nested name specifier for the associated + /// user-defined mapper. + /// \param MapperId The identifier of associated user-defined mapper. + static OMPToClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, - MappableExprComponentListsRef ComponentLists); + MappableExprComponentListsRef ComponentLists, + ArrayRef<Expr *> UDMapperRefs, + NestedNameSpecifierLoc UDMQualifierLoc, + DeclarationNameInfo MapperId); /// Creates an empty clause with the place for \a NumVars variables. /// /// \param C AST context. - /// \param NumVars Number of expressions listed in the clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of unique base declarations in this - /// clause. - /// \param NumComponents Total number of expression components in the clause. - static OMPToClause *CreateEmpty(const ASTContext &C, unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, - unsigned NumComponents); + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + static OMPToClause *CreateEmpty(const ASTContext &C, + const OMPMappableExprListSizeTy &Sizes); child_range children() { return child_range(reinterpret_cast<Stmt **>(varlist_begin()), reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPToClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_to; } @@ -4959,38 +5817,40 @@ class OMPFromClause final /// Build clause with number of variables \a NumVars. /// - /// \param StartLoc Starting location of the clause. - /// \param EndLoc Ending location of the clause. - /// \param NumVars Number of expressions listed in this clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause. - /// \param NumComponents Total number of expression components in the clause. - explicit OMPFromClause(SourceLocation StartLoc, SourceLocation LParenLoc, - SourceLocation EndLoc, unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, unsigned NumComponents) - : OMPMappableExprListClause(OMPC_from, StartLoc, LParenLoc, EndLoc, - NumVars, NumUniqueDeclarations, - NumComponentLists, NumComponents) {} + /// \param MapperQualifierLoc C++ nested name specifier for the associated + /// user-defined mapper. + /// \param MapperIdInfo The identifier of associated user-defined mapper. + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + explicit OMPFromClause(NestedNameSpecifierLoc MapperQualifierLoc, + DeclarationNameInfo MapperIdInfo, + const OMPVarListLocTy &Locs, + const OMPMappableExprListSizeTy &Sizes) + : OMPMappableExprListClause(OMPC_from, Locs, Sizes, &MapperQualifierLoc, + &MapperIdInfo) {} /// Build an empty clause. /// - /// \param NumVars Number of expressions listed in this clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause. - /// \param NumComponents Total number of expression components in the clause. - explicit OMPFromClause(unsigned NumVars, unsigned NumUniqueDeclarations, - unsigned NumComponentLists, unsigned NumComponents) - : OMPMappableExprListClause( - OMPC_from, SourceLocation(), SourceLocation(), SourceLocation(), - NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {} + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + explicit OMPFromClause(const OMPMappableExprListSizeTy &Sizes) + : OMPMappableExprListClause(OMPC_from, OMPVarListLocTy(), Sizes) {} /// Define the sizes of each trailing object array except the last one. This /// is required for TrailingObjects to work properly. size_t numTrailingObjects(OverloadToken<Expr *>) const { - return varlist_size(); + // There are varlist_size() of expressions, and varlist_size() of + // user-defined mappers. + return 2 * varlist_size(); } size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { return getUniqueDeclarationsNum(); @@ -5003,36 +5863,53 @@ public: /// Creates clause with a list of variables \a Vars. /// /// \param C AST context. - /// \param StartLoc Starting location of the clause. - /// \param EndLoc Ending location of the clause. + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. /// \param Vars The original expression used in the clause. /// \param Declarations Declarations used in the clause. /// \param ComponentLists Component lists used in the clause. - static OMPFromClause *Create(const ASTContext &C, SourceLocation StartLoc, - SourceLocation LParenLoc, SourceLocation EndLoc, + /// \param UDMapperRefs References to user-defined mappers associated with + /// expressions used in the clause. + /// \param UDMQualifierLoc C++ nested name specifier for the associated + /// user-defined mapper. + /// \param MapperId The identifier of associated user-defined mapper. + static OMPFromClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, - MappableExprComponentListsRef ComponentLists); + MappableExprComponentListsRef ComponentLists, + ArrayRef<Expr *> UDMapperRefs, + NestedNameSpecifierLoc UDMQualifierLoc, + DeclarationNameInfo MapperId); /// Creates an empty clause with the place for \a NumVars variables. /// /// \param C AST context. - /// \param NumVars Number of expressions listed in the clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of unique base declarations in this - /// clause. - /// \param NumComponents Total number of expression components in the clause. - static OMPFromClause *CreateEmpty(const ASTContext &C, unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, - unsigned NumComponents); + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + static OMPFromClause *CreateEmpty(const ASTContext &C, + const OMPMappableExprListSizeTy &Sizes); child_range children() { return child_range(reinterpret_cast<Stmt **>(varlist_begin()), reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPFromClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_from; } @@ -5058,38 +5935,28 @@ class OMPUseDevicePtrClause final /// Build clause with number of variables \a NumVars. /// - /// \param StartLoc Starting location of the clause. - /// \param EndLoc Ending location of the clause. - /// \param NumVars Number of expressions listed in this clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause. - /// \param NumComponents Total number of expression components in the clause. - explicit OMPUseDevicePtrClause(SourceLocation StartLoc, - SourceLocation LParenLoc, - SourceLocation EndLoc, unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, - unsigned NumComponents) - : OMPMappableExprListClause(OMPC_use_device_ptr, StartLoc, LParenLoc, - EndLoc, NumVars, NumUniqueDeclarations, - NumComponentLists, NumComponents) {} + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + explicit OMPUseDevicePtrClause(const OMPVarListLocTy &Locs, + const OMPMappableExprListSizeTy &Sizes) + : OMPMappableExprListClause(OMPC_use_device_ptr, Locs, Sizes) {} /// Build an empty clause. /// - /// \param NumVars Number of expressions listed in this clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause. - /// \param NumComponents Total number of expression components in the clause. - explicit OMPUseDevicePtrClause(unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, - unsigned NumComponents) - : OMPMappableExprListClause(OMPC_use_device_ptr, SourceLocation(), - SourceLocation(), SourceLocation(), NumVars, - NumUniqueDeclarations, NumComponentLists, - NumComponents) {} + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + explicit OMPUseDevicePtrClause(const OMPMappableExprListSizeTy &Sizes) + : OMPMappableExprListClause(OMPC_use_device_ptr, OMPVarListLocTy(), + Sizes) {} /// Define the sizes of each trailing object array except the last one. This /// is required for TrailingObjects to work properly. @@ -5135,34 +6002,30 @@ public: /// Creates clause with a list of variables \a Vars. /// /// \param C AST context. - /// \param StartLoc Starting location of the clause. - /// \param EndLoc Ending location of the clause. + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. /// \param Vars The original expression used in the clause. /// \param PrivateVars Expressions referring to private copies. /// \param Inits Expressions referring to private copy initializers. /// \param Declarations Declarations used in the clause. /// \param ComponentLists Component lists used in the clause. static OMPUseDevicePtrClause * - Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, - SourceLocation EndLoc, ArrayRef<Expr *> Vars, - ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits, - ArrayRef<ValueDecl *> Declarations, + Create(const ASTContext &C, const OMPVarListLocTy &Locs, + ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars, + ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations, MappableExprComponentListsRef ComponentLists); /// Creates an empty clause with the place for \a NumVars variables. /// /// \param C AST context. - /// \param NumVars Number of expressions listed in the clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of unique base declarations in this - /// clause. - /// \param NumComponents Total number of expression components in the clause. - static OMPUseDevicePtrClause *CreateEmpty(const ASTContext &C, - unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, - unsigned NumComponents); + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + static OMPUseDevicePtrClause * + CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes); using private_copies_iterator = MutableArrayRef<Expr *>::iterator; using private_copies_const_iterator = ArrayRef<const Expr *>::iterator; @@ -5198,6 +6061,18 @@ public: reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPUseDevicePtrClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_use_device_ptr; } @@ -5223,38 +6098,28 @@ class OMPIsDevicePtrClause final /// Build clause with number of variables \a NumVars. /// - /// \param StartLoc Starting location of the clause. - /// \param EndLoc Ending location of the clause. - /// \param NumVars Number of expressions listed in this clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause. - /// \param NumComponents Total number of expression components in the clause. - explicit OMPIsDevicePtrClause(SourceLocation StartLoc, - SourceLocation LParenLoc, SourceLocation EndLoc, - unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, - unsigned NumComponents) - : OMPMappableExprListClause(OMPC_is_device_ptr, StartLoc, LParenLoc, - EndLoc, NumVars, NumUniqueDeclarations, - NumComponentLists, NumComponents) {} + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + explicit OMPIsDevicePtrClause(const OMPVarListLocTy &Locs, + const OMPMappableExprListSizeTy &Sizes) + : OMPMappableExprListClause(OMPC_is_device_ptr, Locs, Sizes) {} /// Build an empty clause. /// - /// \param NumVars Number of expressions listed in this clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of component lists in this clause. - /// \param NumComponents Total number of expression components in the clause. - explicit OMPIsDevicePtrClause(unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, - unsigned NumComponents) - : OMPMappableExprListClause(OMPC_is_device_ptr, SourceLocation(), - SourceLocation(), SourceLocation(), NumVars, - NumUniqueDeclarations, NumComponentLists, - NumComponents) {} + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + explicit OMPIsDevicePtrClause(const OMPMappableExprListSizeTy &Sizes) + : OMPMappableExprListClause(OMPC_is_device_ptr, OMPVarListLocTy(), + Sizes) {} /// Define the sizes of each trailing object array except the last one. This /// is required for TrailingObjects to work properly. @@ -5272,37 +6137,45 @@ public: /// Creates clause with a list of variables \a Vars. /// /// \param C AST context. - /// \param StartLoc Starting location of the clause. - /// \param EndLoc Ending location of the clause. + /// \param Locs Locations needed to build a mappable clause. It includes 1) + /// StartLoc: starting location of the clause (the clause keyword); 2) + /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. /// \param Vars The original expression used in the clause. /// \param Declarations Declarations used in the clause. /// \param ComponentLists Component lists used in the clause. static OMPIsDevicePtrClause * - Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, - SourceLocation EndLoc, ArrayRef<Expr *> Vars, - ArrayRef<ValueDecl *> Declarations, + Create(const ASTContext &C, const OMPVarListLocTy &Locs, + ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, MappableExprComponentListsRef ComponentLists); /// Creates an empty clause with the place for \a NumVars variables. /// /// \param C AST context. - /// \param NumVars Number of expressions listed in the clause. - /// \param NumUniqueDeclarations Number of unique base declarations in this - /// clause. - /// \param NumComponentLists Number of unique base declarations in this - /// clause. - /// \param NumComponents Total number of expression components in the clause. - static OMPIsDevicePtrClause *CreateEmpty(const ASTContext &C, - unsigned NumVars, - unsigned NumUniqueDeclarations, - unsigned NumComponentLists, - unsigned NumComponents); + /// \param Sizes All required sizes to build a mappable clause. It includes 1) + /// NumVars: number of expressions listed in this clause; 2) + /// NumUniqueDeclarations: number of unique base declarations in this clause; + /// 3) NumComponentLists: number of component lists in this clause; and 4) + /// NumComponents: total number of expression components in the clause. + static OMPIsDevicePtrClause * + CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes); child_range children() { return child_range(reinterpret_cast<Stmt **>(varlist_begin()), reinterpret_cast<Stmt **>(varlist_end())); } + const_child_range children() const { + auto Children = const_cast<OMPIsDevicePtrClause *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + + child_range used_children() { + return child_range(child_iterator(), child_iterator()); + } + const_child_range used_children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const OMPClause *T) { return T->getClauseKind() == OMPC_is_device_ptr; } diff --git a/include/clang/AST/OperationKinds.def b/include/clang/AST/OperationKinds.def index cd19091e31d6..9af92c1ae7ff 100644 --- a/include/clang/AST/OperationKinds.def +++ b/include/clang/AST/OperationKinds.def @@ -1,9 +1,8 @@ //===--- OperationKinds.def - Operations Database ---------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -67,6 +66,10 @@ CAST_OPERATION(BitCast) /// bool b; reinterpret_cast<char&>(b) = 'a'; CAST_OPERATION(LValueBitCast) +/// CK_LValueToRValueBitCast - A conversion that causes us to reinterpret an +/// lvalue as an rvalue of a different type. Created by __builtin_bit_cast. +CAST_OPERATION(LValueToRValueBitCast) + /// CK_LValueToRValue - A conversion which causes the extraction of /// an r-value from the operand gl-value. The result of an r-value /// conversion is always unqualified. @@ -201,6 +204,14 @@ CAST_OPERATION(IntegralToFloating) /// (_Accum) 0.5r CAST_OPERATION(FixedPointCast) +/// CK_FixedPointToIntegral - Fixed point to integral. +/// (int) 2.0k +CAST_OPERATION(FixedPointToIntegral) + +/// CK_IntegralToFixedPoint - Integral to a fixed point. +/// (_Accum) 2 +CAST_OPERATION(IntegralToFixedPoint) + /// CK_FixedPointToBoolean - Fixed point to boolean. /// (bool) 0.5r CAST_OPERATION(FixedPointToBoolean) diff --git a/include/clang/AST/OperationKinds.h b/include/clang/AST/OperationKinds.h index ac512d721e34..679e0fdd4056 100644 --- a/include/clang/AST/OperationKinds.h +++ b/include/clang/AST/OperationKinds.h @@ -1,9 +1,8 @@ //===- OperationKinds.h - Operation enums -----------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/ParentMap.h b/include/clang/AST/ParentMap.h index c1c76ceaaf69..1e65d7efd272 100644 --- a/include/clang/AST/ParentMap.h +++ b/include/clang/AST/ParentMap.h @@ -1,9 +1,8 @@ //===--- ParentMap.h - Mappings from Stmts to their Parents -----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/PrettyDeclStackTrace.h b/include/clang/AST/PrettyDeclStackTrace.h index 8eb519eae26d..899bbcb3be45 100644 --- a/include/clang/AST/PrettyDeclStackTrace.h +++ b/include/clang/AST/PrettyDeclStackTrace.h @@ -1,9 +1,8 @@ //===- PrettyDeclStackTrace.h - Stack trace for decl processing -*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/PrettyPrinter.h b/include/clang/AST/PrettyPrinter.h index 3c877f5ea19c..0cd62ba373dc 100644 --- a/include/clang/AST/PrettyPrinter.h +++ b/include/clang/AST/PrettyPrinter.h @@ -1,9 +1,8 @@ //===--- PrettyPrinter.h - Classes for aiding with AST printing -*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/QualTypeNames.h b/include/clang/AST/QualTypeNames.h index 422ed9e4c8fc..8313e0441be5 100644 --- a/include/clang/AST/QualTypeNames.h +++ b/include/clang/AST/QualTypeNames.h @@ -1,7 +1,8 @@ //===--- QualTypeNames.h - Generate Complete QualType Names ----*- C++ -*-===// // -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // // ===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/RawCommentList.h b/include/clang/AST/RawCommentList.h index d17c9df67e41..5dc8694e77e9 100644 --- a/include/clang/AST/RawCommentList.h +++ b/include/clang/AST/RawCommentList.h @@ -1,9 +1,8 @@ //===--- RawCommentList.h - Classes for processing raw comments -*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/clang/AST/RecordLayout.h b/include/clang/AST/RecordLayout.h index a546c200ffe0..b259791af509 100644 --- a/include/clang/AST/RecordLayout.h +++ b/include/clang/AST/RecordLayout.h @@ -1,9 +1,8 @@ //===- RecordLayout.h - Layout information for a struct/union ---*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index 44aba6355758..698fba2f4ed1 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -1,9 +1,8 @@ //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -1066,6 +1065,9 @@ DEF_TRAVERSE_TYPE(AttributedType, DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); }) +DEF_TRAVERSE_TYPE(MacroQualifiedType, + { TRY_TO(TraverseType(T->getUnderlyingType())); }) + DEF_TRAVERSE_TYPE(ElaboratedType, { if (T->getQualifier()) { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); @@ -1309,6 +1311,9 @@ DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {}) DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); }) +DEF_TRAVERSE_TYPELOC(MacroQualifiedType, + { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); }) + DEF_TRAVERSE_TYPELOC(AttributedType, { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); }) @@ -1459,9 +1464,9 @@ DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, { TRY_TO(TraverseDecl(D->getSpecialization())); if (D->hasExplicitTemplateArgs()) { - const TemplateArgumentListInfo &args = D->templateArgs(); - TRY_TO(TraverseTemplateArgumentLocsHelper(args.getArgumentArray(), - args.size())); + TRY_TO(TraverseTemplateArgumentLocsHelper( + D->getTemplateArgsAsWritten()->getTemplateArgs(), + D->getTemplateArgsAsWritten()->NumTemplateArgs)); } }) @@ -1590,7 +1595,7 @@ DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, { TRY_TO(TraverseStmt(I)); } }) - + DEF_TRAVERSE_DECL(OMPRequiresDecl, { for (auto *C : D->clauselists()) { TRY_TO(TraverseOMPClause(C)); @@ -1605,8 +1610,22 @@ DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, { return true; }) +DEF_TRAVERSE_DECL(OMPDeclareMapperDecl, { + for (auto *C : D->clauselists()) + TRY_TO(TraverseOMPClause(C)); + TRY_TO(TraverseType(D->getType())); + return true; +}) + DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); }) +DEF_TRAVERSE_DECL(OMPAllocateDecl, { + for (auto *I : D->varlists()) + TRY_TO(TraverseStmt(I)); + for (auto *C : D->clauselists()) + TRY_TO(TraverseOMPClause(C)); +}) + // A helper method for TemplateDecl's children. template <typename Derived> bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper( @@ -1781,6 +1800,11 @@ DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, { TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); }) +DEF_TRAVERSE_DECL(ConceptDecl, { + TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); + TRY_TO(TraverseStmt(D->getConstraintExpr())); +}) + DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, { // A dependent using declaration which was marked with 'typename'. // template<class T> class A : public B<T> { using typename B<T>::foo; }; @@ -2263,6 +2287,10 @@ DEF_TRAVERSE_STMT(CXXStaticCastExpr, { TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); }) +DEF_TRAVERSE_STMT(BuiltinBitCastExpr, { + TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); +}) + template <typename Derived> bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr( InitListExpr *S, DataRecursionQueue *Queue) { @@ -2301,10 +2329,10 @@ bool RecursiveASTVisitor<Derived>::TraverseInitListExpr( // generic associations). DEF_TRAVERSE_STMT(GenericSelectionExpr, { TRY_TO(TraverseStmt(S->getControllingExpr())); - for (unsigned i = 0; i != S->getNumAssocs(); ++i) { - if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i)) - TRY_TO(TraverseTypeLoc(TS->getTypeLoc())); - TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAssocExpr(i)); + for (const GenericSelectionExpr::Association &Assoc : S->associations()) { + if (TypeSourceInfo *TSI = Assoc.getTypeSourceInfo()) + TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); + TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Assoc.getAssociationExpr()); } ShouldVisitChildren = false; }) @@ -2410,6 +2438,10 @@ DEF_TRAVERSE_STMT(LambdaExpr, { TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc(); FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>(); + for (Decl *D : S->getExplicitTemplateParameters()) { + // Visit explicit template parameters. + TRY_TO(TraverseDecl(D)); + } if (S->hasExplicitParameters()) { // Visit parameters. for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) @@ -2527,6 +2559,8 @@ DEF_TRAVERSE_STMT(PredefinedExpr, {}) DEF_TRAVERSE_STMT(ShuffleVectorExpr, {}) DEF_TRAVERSE_STMT(ConvertVectorExpr, {}) DEF_TRAVERSE_STMT(StmtExpr, {}) +DEF_TRAVERSE_STMT(SourceLocExpr, {}) + DEF_TRAVERSE_STMT(UnresolvedLookupExpr, { TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); if (S->hasExplicitTemplateArgs()) { @@ -2814,6 +2848,20 @@ bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate( } template <typename Derived> +bool RecursiveASTVisitor<Derived>::VisitOMPAllocatorClause( + OMPAllocatorClause *C) { + TRY_TO(TraverseStmt(C->getAllocator())); + return true; +} + +template <typename Derived> +bool RecursiveASTVisitor<Derived>::VisitOMPAllocateClause(OMPAllocateClause *C) { + TRY_TO(TraverseStmt(C->getAllocator())); + TRY_TO(VisitOMPClauseList(C)); + return true; +} + +template <typename Derived> bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) { TRY_TO(VisitOMPClauseWithPreInit(C)); TRY_TO(TraverseStmt(C->getCondition())); diff --git a/include/clang/AST/Redeclarable.h b/include/clang/AST/Redeclarable.h index c2bd6e6fd136..0975773dd2cb 100644 --- a/include/clang/AST/Redeclarable.h +++ b/include/clang/AST/Redeclarable.h @@ -1,9 +1,8 @@ //===- Redeclarable.h - Base for Decls that can be redeclared --*- C++ -*-====// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -362,6 +361,13 @@ public: decl_type &operator*() { return *Ptr; } const decl_type &operator*() const { return *Ptr; } + friend bool operator==(CanonicalDeclPtr LHS, CanonicalDeclPtr RHS) { + return LHS.Ptr == RHS.Ptr; + } + friend bool operator!=(CanonicalDeclPtr LHS, CanonicalDeclPtr RHS) { + return LHS.Ptr != RHS.Ptr; + } + private: friend struct llvm::DenseMapInfo<CanonicalDeclPtr<decl_type>>; diff --git a/include/clang/AST/SelectorLocationsKind.h b/include/clang/AST/SelectorLocationsKind.h index 6ca2dba47558..6e9923de6742 100644 --- a/include/clang/AST/SelectorLocationsKind.h +++ b/include/clang/AST/SelectorLocationsKind.h @@ -1,9 +1,8 @@ //===--- SelectorLocationsKind.h - Kind of selector locations ---*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index ff5baa21adff..403b88ac3a3c 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -1,9 +1,8 @@ //===- Stmt.h - Classes for representing statements -------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -47,6 +46,7 @@ class Attr; class CapturedDecl; class Decl; class Expr; +class AddrLabelExpr; class LabelDecl; class ODRHash; class PrinterHelper; @@ -92,12 +92,20 @@ protected: //===--- Statement bitfields classes ---===// class StmtBitfields { + friend class ASTStmtReader; + friend class ASTStmtWriter; friend class Stmt; /// The statement class. unsigned sClass : 8; + + /// This bit is set only for the Stmts that are the structured-block of + /// OpenMP executable directives. Directives that have a structured block + /// are called "non-standalone" directives. + /// I.e. those returned by OMPExecutableDirective::getStructuredBlock(). + unsigned IsOMPStructuredBlock : 1; }; - enum { NumStmtBits = 8 }; + enum { NumStmtBits = 9 }; class NullStmtBitfields { friend class ASTStmtReader; @@ -314,6 +322,33 @@ protected: }; enum { NumExprBits = NumStmtBits + 9 }; + class ConstantExprBitfields { + friend class ASTStmtReader; + friend class ASTStmtWriter; + friend class ConstantExpr; + + unsigned : NumExprBits; + + /// The kind of result that is trail-allocated. + unsigned ResultKind : 2; + + /// Kind of Result as defined by APValue::Kind + unsigned APValueKind : 4; + + /// When ResultKind == RSK_Int64. whether the trail-allocated integer is + /// signed. + unsigned IsUnsigned : 1; + + /// When ResultKind == RSK_Int64. the BitWidth of the trail-allocated + /// integer. 7 bits because it is the minimal number of bit to represent a + /// value from 0 to 64 (the size of the trail-allocated number). + unsigned BitWidth : 7; + + /// When ResultKind == RSK_APValue. Wether the ASTContext will cleanup the + /// destructor on the trail-allocated APValue. + unsigned HasCleanup : 1; + }; + class PredefinedExprBitfields { friend class ASTStmtReader; friend class PredefinedExpr; @@ -343,19 +378,12 @@ protected: unsigned HasFoundDecl : 1; unsigned HadMultipleCandidates : 1; unsigned RefersToEnclosingVariableOrCapture : 1; + unsigned NonOdrUseReason : 2; /// The location of the declaration name itself. SourceLocation Loc; }; - enum APFloatSemantics { - IEEEhalf, - IEEEsingle, - IEEEdouble, - x87DoubleExtended, - IEEEquad, - PPCDoubleDouble - }; class FloatingLiteralBitfields { friend class FloatingLiteral; @@ -445,6 +473,7 @@ protected: enum { NumCallExprBits = 32 }; class MemberExprBitfields { + friend class ASTStmtReader; friend class MemberExpr; unsigned : NumExprBits; @@ -469,6 +498,11 @@ protected: /// was resolved from an overloaded set having size greater than 1. unsigned HadMultipleCandidates : 1; + /// Value of type NonOdrUseReason indicating why this MemberExpr does + /// not constitute an odr-use of the named declaration. Meaningful only + /// when naming a static member. + unsigned NonOdrUseReason : 2; + /// This is the location of the -> or . in the expression. SourceLocation OperatorLoc; }; @@ -521,6 +555,16 @@ protected: unsigned NumExprs; }; + class GenericSelectionExprBitfields { + friend class ASTStmtReader; + friend class GenericSelectionExpr; + + unsigned : NumExprBits; + + /// The location of the "_Generic". + SourceLocation GenericLoc; + }; + class PseudoObjectExprBitfields { friend class ASTStmtReader; // deserialization friend class PseudoObjectExpr; @@ -533,6 +577,17 @@ protected: unsigned ResultIndex : 32 - 8 - NumExprBits; }; + class SourceLocExprBitfields { + friend class ASTStmtReader; + friend class SourceLocExpr; + + unsigned : NumExprBits; + + /// The kind of source location builtin represented by the SourceLocExpr. + /// Ex. __builtin_LINE, __builtin_FUNCTION, ect. + unsigned Kind : 2; + }; + //===--- C++ Expression bitfields classes ---===// class CXXOperatorCallExprBitfields { @@ -902,6 +957,7 @@ protected: // Expressions ExprBitfields ExprBits; + ConstantExprBitfields ConstantExprBits; PredefinedExprBitfields PredefinedExprBits; DeclRefExprBitfields DeclRefExprBits; FloatingLiteralBitfields FloatingLiteralBits; @@ -916,7 +972,9 @@ protected: BinaryOperatorBitfields BinaryOperatorBits; InitListExprBitfields InitListExprBits; ParenListExprBitfields ParenListExprBits; + GenericSelectionExprBitfields GenericSelectionExprBits; PseudoObjectExprBitfields PseudoObjectExprBits; + SourceLocExprBitfields SourceLocExprBits; // C++ Expressions CXXOperatorCallExprBitfields CXXOperatorCallExprBits; @@ -976,38 +1034,31 @@ public: struct EmptyShell {}; protected: - /// Iterator for iterating over Stmt * arrays that contain only Expr * + /// Iterator for iterating over Stmt * arrays that contain only T *. /// /// This is needed because AST nodes use Stmt* arrays to store /// references to children (to be compatible with StmtIterator). - struct ExprIterator - : llvm::iterator_adaptor_base<ExprIterator, Stmt **, - std::random_access_iterator_tag, Expr *> { - ExprIterator() : iterator_adaptor_base(nullptr) {} - ExprIterator(Stmt **I) : iterator_adaptor_base(I) {} - - reference operator*() const { - assert((*I)->getStmtClass() >= firstExprConstant && - (*I)->getStmtClass() <= lastExprConstant); - return *reinterpret_cast<Expr **>(I); - } - }; + template<typename T, typename TPtr = T *, typename StmtPtr = Stmt *> + struct CastIterator + : llvm::iterator_adaptor_base<CastIterator<T, TPtr, StmtPtr>, StmtPtr *, + std::random_access_iterator_tag, TPtr> { + using Base = typename CastIterator::iterator_adaptor_base; - /// Const iterator for iterating over Stmt * arrays that contain only Expr * - struct ConstExprIterator - : llvm::iterator_adaptor_base<ConstExprIterator, const Stmt *const *, - std::random_access_iterator_tag, - const Expr *const> { - ConstExprIterator() : iterator_adaptor_base(nullptr) {} - ConstExprIterator(const Stmt *const *I) : iterator_adaptor_base(I) {} + CastIterator() : Base(nullptr) {} + CastIterator(StmtPtr *I) : Base(I) {} - reference operator*() const { - assert((*I)->getStmtClass() >= firstExprConstant && - (*I)->getStmtClass() <= lastExprConstant); - return *reinterpret_cast<const Expr *const *>(I); + typename Base::value_type operator*() const { + return cast_or_null<T>(*this->I); } }; + /// Const iterator for iterating over Stmt * arrays that contain only T *. + template <typename T> + using ConstCastIterator = CastIterator<T, const T *const, const Stmt *const>; + + using ExprIterator = CastIterator<Expr>; + using ConstExprIterator = ConstCastIterator<Expr>; + private: /// Whether statistic collection is enabled. static bool StatisticsEnabled; @@ -1017,12 +1068,19 @@ protected: explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {} public: + Stmt() = delete; + Stmt(const Stmt &) = delete; + Stmt(Stmt &&) = delete; + Stmt &operator=(const Stmt &) = delete; + Stmt &operator=(Stmt &&) = delete; + Stmt(StmtClass SC) { static_assert(sizeof(*this) <= 8, "changing bitfields changed sizeof(Stmt)"); static_assert(sizeof(*this) % alignof(void *) == 0, "Insufficient alignment!"); StmtBits.sClass = SC; + StmtBits.IsOMPStructuredBlock = false; if (StatisticsEnabled) Stmt::addStmtClass(SC); } @@ -1032,6 +1090,11 @@ public: const char *getStmtClassName() const; + bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; } + void setIsOMPStructuredBlock(bool IsOMPStructuredBlock) { + StmtBits.IsOMPStructuredBlock = IsOMPStructuredBlock; + } + /// SourceLocation tokens are not useful in isolation - they are low level /// value objects created/interpreted by SourceManager. We assume AST /// clients will have a pointer to the respective SourceManager. @@ -1065,17 +1128,14 @@ public: StringRef NewlineSymbol = "\n", const ASTContext *Context = nullptr) const; + /// Pretty-prints in JSON format. + void printJson(raw_ostream &Out, PrinterHelper *Helper, + const PrintingPolicy &Policy, bool AddQuotes) const; + /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only /// works on systems with GraphViz (Mac OS X) or dot+gv installed. void viewAST() const; - /// Skip past any implicit AST nodes which might surround this - /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes. - Stmt *IgnoreImplicit(); - const Stmt *IgnoreImplicit() const { - return const_cast<Stmt *>(this)->IgnoreImplicit(); - } - /// Skip no-op (attributed, compound) container stmts and skip captured /// stmt at the top, if \a IgnoreCaptured is true. Stmt *IgnoreContainers(bool IgnoreCaptured = false); @@ -1178,6 +1238,11 @@ public: child_iterator(DG.end(), DG.end())); } + const_child_range children() const { + auto Children = const_cast<DeclStmt *>(this)->children(); + return const_child_range(Children); + } + using decl_iterator = DeclGroupRef::iterator; using const_decl_iterator = DeclGroupRef::const_iterator; using decl_range = llvm::iterator_range<decl_iterator>; @@ -1235,6 +1300,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// CompoundStmt - This represents a group of statements like { stmt stmt }. @@ -1280,11 +1349,6 @@ public: return !body_empty() ? body_begin()[size() - 1] : nullptr; } - void setLastStmt(Stmt *S) { - assert(!body_empty() && "setLastStmt"); - body_begin()[size() - 1] = S; - } - using const_body_iterator = Stmt *const *; using body_const_range = llvm::iterator_range<const_body_iterator>; @@ -1327,6 +1391,26 @@ public: return const_reverse_body_iterator(body_begin()); } + // Get the Stmt that StmtExpr would consider to be the result of this + // compound statement. This is used by StmtExpr to properly emulate the GCC + // compound expression extension, which ignores trailing NullStmts when + // getting the result of the expression. + // i.e. ({ 5;;; }) + // ^^ ignored + // If we don't find something that isn't a NullStmt, just return the last + // Stmt. + Stmt *getStmtExprResult() { + for (auto *B : llvm::reverse(body())) { + if (!isa<NullStmt>(B)) + return B; + } + return body_back(); + } + + const Stmt *getStmtExprResult() const { + return const_cast<CompoundStmt *>(this)->getStmtExprResult(); + } + SourceLocation getBeginLoc() const { return CompoundStmtBits.LBraceLoc; } SourceLocation getEndLoc() const { return RBraceLoc; } @@ -1539,6 +1623,12 @@ public: getTrailingObjects<Stmt *>() + numTrailingObjects(OverloadToken<Stmt *>())); } + + const_child_range children() const { + return const_child_range(getTrailingObjects<Stmt *>(), + getTrailingObjects<Stmt *>() + + numTrailingObjects(OverloadToken<Stmt *>())); + } }; class DefaultStmt : public SwitchCase { @@ -1570,6 +1660,10 @@ public: // Iterators child_range children() { return child_range(&SubStmt, &SubStmt + 1); } + + const_child_range children() const { + return const_child_range(&SubStmt, &SubStmt + 1); + } }; SourceLocation SwitchCase::getEndLoc() const { @@ -1588,21 +1682,44 @@ Stmt *SwitchCase::getSubStmt() { llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!"); } +/// Represents a statement that could possibly have a value and type. This +/// covers expression-statements, as well as labels and attributed statements. +/// +/// Value statements have a special meaning when they are the last non-null +/// statement in a GNU statement expression, where they determine the value +/// of the statement expression. +class ValueStmt : public Stmt { +protected: + using Stmt::Stmt; + +public: + const Expr *getExprStmt() const; + Expr *getExprStmt() { + const ValueStmt *ConstThis = this; + return const_cast<Expr*>(ConstThis->getExprStmt()); + } + + static bool classof(const Stmt *T) { + return T->getStmtClass() >= firstValueStmtConstant && + T->getStmtClass() <= lastValueStmtConstant; + } +}; + /// LabelStmt - Represents a label, which has a substatement. For example: /// foo: return; -class LabelStmt : public Stmt { +class LabelStmt : public ValueStmt { LabelDecl *TheDecl; Stmt *SubStmt; public: /// Build a label statement. LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt) - : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) { + : ValueStmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) { setIdentLoc(IL); } /// Build an empty label statement. - explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) {} + explicit LabelStmt(EmptyShell Empty) : ValueStmt(LabelStmtClass, Empty) {} SourceLocation getIdentLoc() const { return LabelStmtBits.IdentLoc; } void setIdentLoc(SourceLocation L) { LabelStmtBits.IdentLoc = L; } @@ -1621,6 +1738,10 @@ public: child_range children() { return child_range(&SubStmt, &SubStmt + 1); } + const_child_range children() const { + return const_child_range(&SubStmt, &SubStmt + 1); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == LabelStmtClass; } @@ -1631,7 +1752,7 @@ public: /// Represents an attribute applied to a statement. For example: /// [[omp::for(...)]] for (...) { ... } class AttributedStmt final - : public Stmt, + : public ValueStmt, private llvm::TrailingObjects<AttributedStmt, const Attr *> { friend class ASTStmtReader; friend TrailingObjects; @@ -1640,14 +1761,14 @@ class AttributedStmt final AttributedStmt(SourceLocation Loc, ArrayRef<const Attr *> Attrs, Stmt *SubStmt) - : Stmt(AttributedStmtClass), SubStmt(SubStmt) { + : ValueStmt(AttributedStmtClass), SubStmt(SubStmt) { AttributedStmtBits.NumAttrs = Attrs.size(); AttributedStmtBits.AttrLoc = Loc; std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr()); } explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) - : Stmt(AttributedStmtClass, Empty) { + : ValueStmt(AttributedStmtClass, Empty) { AttributedStmtBits.NumAttrs = NumAttrs; AttributedStmtBits.AttrLoc = SourceLocation{}; std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr); @@ -1678,6 +1799,10 @@ public: child_range children() { return child_range(&SubStmt, &SubStmt + 1); } + const_child_range children() const { + return const_child_range(&SubStmt, &SubStmt + 1); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == AttributedStmtClass; } @@ -1877,6 +2002,12 @@ public: numTrailingObjects(OverloadToken<Stmt *>())); } + const_child_range children() const { + return const_child_range(getTrailingObjects<Stmt *>(), + getTrailingObjects<Stmt *>() + + numTrailingObjects(OverloadToken<Stmt *>())); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == IfStmtClass; } @@ -2054,6 +2185,12 @@ public: numTrailingObjects(OverloadToken<Stmt *>())); } + const_child_range children() const { + return const_child_range(getTrailingObjects<Stmt *>(), + getTrailingObjects<Stmt *>() + + numTrailingObjects(OverloadToken<Stmt *>())); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == SwitchStmtClass; } @@ -2179,6 +2316,12 @@ public: getTrailingObjects<Stmt *>() + numTrailingObjects(OverloadToken<Stmt *>())); } + + const_child_range children() const { + return const_child_range(getTrailingObjects<Stmt *>(), + getTrailingObjects<Stmt *>() + + numTrailingObjects(OverloadToken<Stmt *>())); + } }; /// DoStmt - This represents a 'do/while' stmt. @@ -2229,6 +2372,10 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); } + + const_child_range children() const { + return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); + } }; /// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of @@ -2298,6 +2445,10 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); } + + const_child_range children() const { + return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); + } }; /// GotoStmt - This represents a direct goto. @@ -2333,6 +2484,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// IndirectGotoStmt - This represents an indirect goto. @@ -2378,6 +2533,10 @@ public: // Iterators child_range children() { return child_range(&Target, &Target + 1); } + + const_child_range children() const { + return const_child_range(&Target, &Target + 1); + } }; /// ContinueStmt - This represents a continue. @@ -2404,6 +2563,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// BreakStmt - This represents a break. @@ -2430,6 +2593,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// ReturnStmt - This represents a return, optionally of an expression: @@ -2514,6 +2681,12 @@ public: return child_range(&RetExpr, &RetExpr + 1); return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + if (RetExpr) + return const_child_range(&RetExpr, &RetExpr + 1); + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt. @@ -2669,6 +2842,10 @@ public: child_range children() { return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); } + + const_child_range children() const { + return const_child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); + } }; /// This represents a GCC inline-assembly statement extension. @@ -2682,13 +2859,15 @@ class GCCAsmStmt : public AsmStmt { StringLiteral **Constraints = nullptr; StringLiteral **Clobbers = nullptr; IdentifierInfo **Names = nullptr; + unsigned NumLabels = 0; public: GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile, unsigned numoutputs, unsigned numinputs, IdentifierInfo **names, StringLiteral **constraints, Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, - StringLiteral **clobbers, SourceLocation rparenloc); + StringLiteral **clobbers, unsigned numlabels, + SourceLocation rparenloc); /// Build an empty inline-assembly statement. explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {} @@ -2813,6 +2992,51 @@ public: return const_cast<GCCAsmStmt*>(this)->getInputExpr(i); } + //===--- Labels ---===// + + bool isAsmGoto() const { + return NumLabels > 0; + } + + unsigned getNumLabels() const { + return NumLabels; + } + + IdentifierInfo *getLabelIdentifier(unsigned i) const { + return Names[i + NumInputs]; + } + + AddrLabelExpr *getLabelExpr(unsigned i) const; + StringRef getLabelName(unsigned i) const; + using labels_iterator = CastIterator<AddrLabelExpr>; + using const_labels_iterator = ConstCastIterator<AddrLabelExpr>; + using labels_range = llvm::iterator_range<labels_iterator>; + using labels_const_range = llvm::iterator_range<const_labels_iterator>; + + labels_iterator begin_labels() { + return &Exprs[0] + NumInputs; + } + + labels_iterator end_labels() { + return &Exprs[0] + NumInputs + NumLabels; + } + + labels_range labels() { + return labels_range(begin_labels(), end_labels()); + } + + const_labels_iterator begin_labels() const { + return &Exprs[0] + NumInputs; + } + + const_labels_iterator end_labels() const { + return &Exprs[0] + NumInputs + NumLabels; + } + + labels_const_range labels() const { + return labels_const_range(begin_labels(), end_labels()); + } + private: void setOutputsAndInputsAndClobbers(const ASTContext &C, IdentifierInfo **Names, @@ -2820,6 +3044,7 @@ private: Stmt **Exprs, unsigned NumOutputs, unsigned NumInputs, + unsigned NumLabels, StringLiteral **Clobbers, unsigned NumClobbers); @@ -2945,6 +3170,10 @@ public: child_range children() { return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]); } + + const_child_range children() const { + return const_child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]); + } }; class SEHExceptStmt : public Stmt { @@ -2982,6 +3211,10 @@ public: return child_range(Children, Children+2); } + const_child_range children() const { + return const_child_range(Children, Children + 2); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == SEHExceptStmtClass; } @@ -3013,6 +3246,10 @@ public: return child_range(&Block,&Block+1); } + const_child_range children() const { + return const_child_range(&Block, &Block + 1); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == SEHFinallyStmtClass; } @@ -3061,6 +3298,10 @@ public: return child_range(Children, Children+2); } + const_child_range children() const { + return const_child_range(Children, Children + 2); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == SEHTryStmtClass; } @@ -3091,6 +3332,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// This captures a statement into a function. For example, the following @@ -3311,6 +3556,8 @@ public: } child_range children(); + + const_child_range children() const; }; } // namespace clang diff --git a/include/clang/AST/StmtCXX.h b/include/clang/AST/StmtCXX.h index d3a3cf783c66..4d1f3e8ef255 100644 --- a/include/clang/AST/StmtCXX.h +++ b/include/clang/AST/StmtCXX.h @@ -1,9 +1,8 @@ //===--- StmtCXX.h - Classes for representing C++ statements ----*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -57,6 +56,10 @@ public: child_range children() { return child_range(&HandlerBlock, &HandlerBlock+1); } + const_child_range children() const { + return const_child_range(&HandlerBlock, &HandlerBlock + 1); + } + friend class ASTStmtReader; }; @@ -115,6 +118,10 @@ public: child_range children() { return child_range(getStmts(), getStmts() + getNumHandlers() + 1); } + + const_child_range children() const { + return const_child_range(getStmts(), getStmts() + getNumHandlers() + 1); + } }; /// CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for @@ -209,6 +216,10 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[END]); } + + const_child_range children() const { + return const_child_range(&SubExprs[0], &SubExprs[END]); + } }; /// Representation of a Microsoft __if_exists or __if_not_exists @@ -291,6 +302,10 @@ public: return child_range(&SubStmt, &SubStmt+1); } + const_child_range children() const { + return const_child_range(&SubStmt, &SubStmt + 1); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == MSDependentExistsStmtClass; } @@ -416,6 +431,12 @@ public: getStoredStmts() + SubStmt::FirstParamMove + NumParams); } + const_child_range children() const { + return const_child_range(getStoredStmts(), getStoredStmts() + + SubStmt::FirstParamMove + + NumParams); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == CoroutineBodyStmtClass; } @@ -480,6 +501,13 @@ public: return child_range(SubStmts, SubStmts + SubStmt::Count); } + const_child_range children() const { + if (!getOperand()) + return const_child_range(SubStmts + SubStmt::PromiseCall, + SubStmts + SubStmt::Count); + return const_child_range(SubStmts, SubStmts + SubStmt::Count); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == CoreturnStmtClass; } diff --git a/include/clang/AST/StmtDataCollectors.td b/include/clang/AST/StmtDataCollectors.td index 90ca08027330..a46d2714eb4b 100644 --- a/include/clang/AST/StmtDataCollectors.td +++ b/include/clang/AST/StmtDataCollectors.td @@ -189,8 +189,8 @@ class CXXFoldExpr { } class GenericSelectionExpr { code Code = [{ - for (unsigned i = 0; i < S->getNumAssocs(); ++i) { - addData(S->getAssocType(i)); + for (const GenericSelectionExpr::ConstAssociation &Assoc : S->associations()) { + addData(Assoc.getType()); } }]; } diff --git a/include/clang/AST/StmtGraphTraits.h b/include/clang/AST/StmtGraphTraits.h index 02c77b242c7c..ee1e8cfa1912 100644 --- a/include/clang/AST/StmtGraphTraits.h +++ b/include/clang/AST/StmtGraphTraits.h @@ -1,9 +1,8 @@ //===- StmtGraphTraits.h - Graph Traits for the class Stmt ------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/StmtIterator.h b/include/clang/AST/StmtIterator.h index 806edaa38821..911205347aad 100644 --- a/include/clang/AST/StmtIterator.h +++ b/include/clang/AST/StmtIterator.h @@ -1,9 +1,8 @@ //===- StmtIterator.h - Iterators for Statements ----------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/StmtObjC.h b/include/clang/AST/StmtObjC.h index f0c0a9aeb6ac..948ef2421cb9 100644 --- a/include/clang/AST/StmtObjC.h +++ b/include/clang/AST/StmtObjC.h @@ -1,9 +1,8 @@ //===--- StmtObjC.h - Classes for representing ObjC statements --*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -68,6 +67,10 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[END_EXPR]); } + + const_child_range children() const { + return const_child_range(&SubExprs[0], &SubExprs[END_EXPR]); + } }; /// Represents Objective-C's \@catch statement. @@ -114,6 +117,10 @@ public: } child_range children() { return child_range(&Body, &Body + 1); } + + const_child_range children() const { + return const_child_range(&Body, &Body + 1); + } }; /// Represents Objective-C's \@finally statement @@ -148,6 +155,10 @@ public: child_range children() { return child_range(&AtFinallyStmt, &AtFinallyStmt+1); } + + const_child_range children() const { + return const_child_range(&AtFinallyStmt, &AtFinallyStmt + 1); + } }; /// Represents Objective-C's \@try ... \@catch ... \@finally statement. @@ -249,6 +260,10 @@ public: return child_range(getStmts(), getStmts() + 1 + NumCatchStmts + HasFinally); } + + const_child_range children() const { + return const_child_range(const_cast<ObjCAtTryStmt *>(this)->children()); + } }; /// Represents Objective-C's \@synchronized statement. @@ -307,6 +322,10 @@ public: child_range children() { return child_range(&SubStmts[0], &SubStmts[0]+END_EXPR); } + + const_child_range children() const { + return const_child_range(&SubStmts[0], &SubStmts[0] + END_EXPR); + } }; /// Represents Objective-C's \@throw statement. @@ -339,6 +358,10 @@ public: } child_range children() { return child_range(&Throw, &Throw+1); } + + const_child_range children() const { + return const_child_range(&Throw, &Throw + 1); + } }; /// Represents Objective-C's \@autoreleasepool Statement @@ -370,6 +393,10 @@ public: } child_range children() { return child_range(&SubStmt, &SubStmt + 1); } + + const_child_range children() const { + return const_child_range(&SubStmt, &SubStmt + 1); + } }; } // end namespace clang diff --git a/include/clang/AST/StmtOpenMP.h b/include/clang/AST/StmtOpenMP.h index d1eedd62b372..e37f5b1e0004 100644 --- a/include/clang/AST/StmtOpenMP.h +++ b/include/clang/AST/StmtOpenMP.h @@ -1,9 +1,8 @@ //===- StmtOpenMP.h - Classes for OpenMP directives ------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// \file @@ -88,6 +87,63 @@ protected: } public: + /// Iterates over expressions/statements used in the construct. + class used_clauses_child_iterator + : public llvm::iterator_adaptor_base< + used_clauses_child_iterator, ArrayRef<OMPClause *>::iterator, + std::forward_iterator_tag, Stmt *, ptrdiff_t, Stmt *, Stmt *> { + ArrayRef<OMPClause *>::iterator End; + OMPClause::child_iterator ChildI, ChildEnd; + + void MoveToNext() { + if (ChildI != ChildEnd) + return; + while (this->I != End) { + ++this->I; + if (this->I != End) { + ChildI = (*this->I)->used_children().begin(); + ChildEnd = (*this->I)->used_children().end(); + if (ChildI != ChildEnd) + return; + } + } + } + + public: + explicit used_clauses_child_iterator(ArrayRef<OMPClause *> Clauses) + : used_clauses_child_iterator::iterator_adaptor_base(Clauses.begin()), + End(Clauses.end()) { + if (this->I != End) { + ChildI = (*this->I)->used_children().begin(); + ChildEnd = (*this->I)->used_children().end(); + MoveToNext(); + } + } + Stmt *operator*() const { return *ChildI; } + Stmt *operator->() const { return **this; } + + used_clauses_child_iterator &operator++() { + ++ChildI; + if (ChildI != ChildEnd) + return *this; + if (this->I != End) { + ++this->I; + if (this->I != End) { + ChildI = (*this->I)->used_children().begin(); + ChildEnd = (*this->I)->used_children().end(); + } + } + MoveToNext(); + return *this; + } + }; + + static llvm::iterator_range<used_clauses_child_iterator> + used_clauses_children(ArrayRef<OMPClause *> Clauses) { + return {used_clauses_child_iterator(Clauses), + used_clauses_child_iterator(llvm::makeArrayRef(Clauses.end(), 0))}; + } + /// Iterates over a filtered subrange of clauses applied to a /// directive. /// @@ -257,11 +313,35 @@ public: return child_range(ChildStorage, ChildStorage + 1); } + const_child_range children() const { + if (!hasAssociatedStmt()) + return const_child_range(const_child_iterator(), const_child_iterator()); + Stmt **ChildStorage = reinterpret_cast<Stmt **>( + const_cast<OMPExecutableDirective *>(this)->getClauses().end()); + return const_child_range(ChildStorage, ChildStorage + 1); + } + ArrayRef<OMPClause *> clauses() { return getClauses(); } ArrayRef<OMPClause *> clauses() const { return const_cast<OMPExecutableDirective *>(this)->getClauses(); } + + /// Returns whether or not this is a Standalone directive. + /// + /// Stand-alone directives are executable directives + /// that have no associated user code. + bool isStandaloneDirective() const; + + /// Returns the AST node representing OpenMP structured-block of this + /// OpenMP executable directive, + /// Prerequisite: Executable Directive must not be Standalone directive. + const Stmt *getStructuredBlock() const; + + Stmt *getStructuredBlock() { + return const_cast<Stmt *>( + const_cast<const OMPExecutableDirective *>(this)->getStructuredBlock()); + } }; /// This represents '#pragma omp parallel' directive. diff --git a/include/clang/AST/StmtVisitor.h b/include/clang/AST/StmtVisitor.h index ea40e0497307..d3be93d228cc 100644 --- a/include/clang/AST/StmtVisitor.h +++ b/include/clang/AST/StmtVisitor.h @@ -1,9 +1,8 @@ //===- StmtVisitor.h - Visitor for Stmt subclasses --------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/TemplateArgumentVisitor.h b/include/clang/AST/TemplateArgumentVisitor.h index e1cc392a1705..190aa97adf45 100644 --- a/include/clang/AST/TemplateArgumentVisitor.h +++ b/include/clang/AST/TemplateArgumentVisitor.h @@ -1,9 +1,8 @@ //===- TemplateArgumentVisitor.h - Visitor for TArg subclasses --*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/TemplateBase.h b/include/clang/AST/TemplateBase.h index e3a773b4e490..058a5bc0a067 100644 --- a/include/clang/AST/TemplateBase.h +++ b/include/clang/AST/TemplateBase.h @@ -1,9 +1,8 @@ //===- TemplateBase.h - Core classes for C++ templates ----------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/TemplateName.h b/include/clang/AST/TemplateName.h index 48272597d4d1..4cc6f5e6ce82 100644 --- a/include/clang/AST/TemplateName.h +++ b/include/clang/AST/TemplateName.h @@ -1,9 +1,8 @@ //===- TemplateName.h - C++ Template Name Representation --------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -32,6 +31,8 @@ class NamedDecl; class NestedNameSpecifier; enum OverloadedOperatorKind : int; class OverloadedTemplateStorage; +class AssumedTemplateStorage; +class PartialDiagnostic; struct PrintingPolicy; class QualifiedTemplateName; class SubstTemplateTemplateParmPackStorage; @@ -46,6 +47,7 @@ class UncommonTemplateNameStorage { protected: enum Kind { Overloaded, + Assumed, // defined in DeclarationName.h SubstTemplateTemplateParm, SubstTemplateTemplateParmPack }; @@ -78,6 +80,12 @@ public: : nullptr; } + AssumedTemplateStorage *getAsAssumedTemplateName() { + return Bits.Kind == Assumed + ? reinterpret_cast<AssumedTemplateStorage *>(this) + : nullptr; + } + SubstTemplateTemplateParmStorage *getAsSubstTemplateTemplateParm() { return Bits.Kind == SubstTemplateTemplateParm ? reinterpret_cast<SubstTemplateTemplateParmStorage *>(this) @@ -194,6 +202,10 @@ public: /// A set of overloaded template declarations. OverloadedTemplate, + /// An unqualified-id that has been assumed to name a function template + /// that will be found by ADL. + AssumedTemplate, + /// A qualified template name, where the qualification is kept /// to describe the source code as written. QualifiedTemplate, @@ -215,6 +227,7 @@ public: TemplateName() = default; explicit TemplateName(TemplateDecl *Template); explicit TemplateName(OverloadedTemplateStorage *Storage); + explicit TemplateName(AssumedTemplateStorage *Storage); explicit TemplateName(SubstTemplateTemplateParmStorage *Storage); explicit TemplateName(SubstTemplateTemplateParmPackStorage *Storage); explicit TemplateName(QualifiedTemplateName *Qual); @@ -236,7 +249,7 @@ public: TemplateDecl *getAsTemplateDecl() const; /// Retrieve the underlying, overloaded function template - // declarations that this template name refers to, if known. + /// declarations that this template name refers to, if known. /// /// \returns The set of overloaded function templates that this template /// name refers to, if known. If the template name does not refer to a @@ -244,6 +257,10 @@ public: /// refers to a single template, returns NULL. OverloadedTemplateStorage *getAsOverloadedTemplate() const; + /// Retrieve information on a name that has been assumed to be a + /// template-name in order to permit a call via ADL. + AssumedTemplateStorage *getAsAssumedTemplateName() const; + /// Retrieve the substituted template template parameter, if /// known. /// @@ -320,6 +337,8 @@ public: /// into a diagnostic with <<. const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, TemplateName N); +const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, + TemplateName N); /// A structure for storing the information associated with a /// substituted template template parameter. diff --git a/include/clang/AST/TextNodeDumper.h b/include/clang/AST/TextNodeDumper.h index 794066376300..4c2d0710963b 100644 --- a/include/clang/AST/TextNodeDumper.h +++ b/include/clang/AST/TextNodeDumper.h @@ -1,9 +1,8 @@ //===--- TextNodeDumper.h - Printing of AST nodes -------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -19,6 +18,7 @@ #include "clang/AST/AttrVisitor.h" #include "clang/AST/CommentCommandTraits.h" #include "clang/AST/CommentVisitor.h" +#include "clang/AST/DeclVisitor.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/StmtVisitor.h" #include "clang/AST/TemplateArgumentVisitor.h" @@ -129,7 +129,8 @@ class TextNodeDumper public ConstAttrVisitor<TextNodeDumper>, public ConstTemplateArgumentVisitor<TextNodeDumper>, public ConstStmtVisitor<TextNodeDumper>, - public TypeVisitor<TextNodeDumper> { + public TypeVisitor<TextNodeDumper>, + public ConstDeclVisitor<TextNodeDumper> { raw_ostream &OS; const bool ShowColors; @@ -145,6 +146,8 @@ class TextNodeDumper const comments::CommandTraits *Traits; + const ASTContext *Context; + const char *getCommandName(unsigned CommandID); public: @@ -173,6 +176,8 @@ public: void Visit(const BlockDecl::Capture &C); + void Visit(const GenericSelectionExpr::ConstAssociation &A); + void dumpPointer(const void *Ptr); void dumpLocation(SourceLocation Loc); void dumpSourceRange(SourceRange R); @@ -225,6 +230,7 @@ public: void VisitLabelStmt(const LabelStmt *Node); void VisitGotoStmt(const GotoStmt *Node); void VisitCaseStmt(const CaseStmt *Node); + void VisitConstantExpr(const ConstantExpr *Node); void VisitCallExpr(const CallExpr *Node); void VisitCastExpr(const CastExpr *Node); void VisitImplicitCastExpr(const ImplicitCastExpr *Node); @@ -236,6 +242,7 @@ public: void VisitFloatingLiteral(const FloatingLiteral *Node); void VisitStringLiteral(const StringLiteral *Str); void VisitInitListExpr(const InitListExpr *ILE); + void VisitGenericSelectionExpr(const GenericSelectionExpr *E); void VisitUnaryOperator(const UnaryOperator *Node); void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node); void VisitMemberExpr(const MemberExpr *Node); @@ -289,8 +296,58 @@ public: void VisitObjCInterfaceType(const ObjCInterfaceType *T); void VisitPackExpansionType(const PackExpansionType *T); -private: - void dumpCXXTemporary(const CXXTemporary *Temporary); + void VisitLabelDecl(const LabelDecl *D); + void VisitTypedefDecl(const TypedefDecl *D); + void VisitEnumDecl(const EnumDecl *D); + void VisitRecordDecl(const RecordDecl *D); + void VisitEnumConstantDecl(const EnumConstantDecl *D); + void VisitIndirectFieldDecl(const IndirectFieldDecl *D); + void VisitFunctionDecl(const FunctionDecl *D); + void VisitFieldDecl(const FieldDecl *D); + void VisitVarDecl(const VarDecl *D); + void VisitBindingDecl(const BindingDecl *D); + void VisitCapturedDecl(const CapturedDecl *D); + void VisitImportDecl(const ImportDecl *D); + void VisitPragmaCommentDecl(const PragmaCommentDecl *D); + void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D); + void VisitOMPExecutableDirective(const OMPExecutableDirective *D); + void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D); + void VisitOMPRequiresDecl(const OMPRequiresDecl *D); + void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D); + void VisitNamespaceDecl(const NamespaceDecl *D); + void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D); + void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D); + void VisitTypeAliasDecl(const TypeAliasDecl *D); + void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D); + void VisitCXXRecordDecl(const CXXRecordDecl *D); + void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D); + void VisitClassTemplateDecl(const ClassTemplateDecl *D); + void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D); + void VisitVarTemplateDecl(const VarTemplateDecl *D); + void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D); + void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D); + void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D); + void VisitUsingDecl(const UsingDecl *D); + void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D); + void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D); + void VisitUsingShadowDecl(const UsingShadowDecl *D); + void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D); + void VisitLinkageSpecDecl(const LinkageSpecDecl *D); + void VisitAccessSpecDecl(const AccessSpecDecl *D); + void VisitFriendDecl(const FriendDecl *D); + void VisitObjCIvarDecl(const ObjCIvarDecl *D); + void VisitObjCMethodDecl(const ObjCMethodDecl *D); + void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D); + void VisitObjCCategoryDecl(const ObjCCategoryDecl *D); + void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D); + void VisitObjCProtocolDecl(const ObjCProtocolDecl *D); + void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D); + void VisitObjCImplementationDecl(const ObjCImplementationDecl *D); + void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D); + void VisitObjCPropertyDecl(const ObjCPropertyDecl *D); + void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D); + void VisitBlockDecl(const BlockDecl *D); + void VisitConceptDecl(const ConceptDecl *D); }; } // namespace clang diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index d4c97b1b5efc..584655fe789e 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -1,9 +1,8 @@ //===- Type.h - C Language Family Type Representation -----------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -95,9 +94,6 @@ namespace llvm { enum { NumLowBitsAvailable = clang::TypeAlignmentInBits }; }; - template <> - struct isPodLike<clang::QualType> { static const bool value = true; }; - } // namespace llvm namespace clang { @@ -321,6 +317,11 @@ public: qs.removeObjCLifetime(); return qs; } + Qualifiers withoutAddressSpace() const { + Qualifiers qs = *this; + qs.removeAddressSpace(); + return qs; + } bool hasObjCLifetime() const { return Mask & LifetimeMask; } ObjCLifetime getObjCLifetime() const { @@ -459,21 +460,25 @@ public: Mask |= qs.Mask; } - /// Returns true if this address space is a superset of the other one. + /// Returns true if address space A is equal to or a superset of B. /// OpenCL v2.0 defines conversion rules (OpenCLC v2.0 s6.5.5) and notion of /// overlapping address spaces. /// CL1.1 or CL1.2: /// every address space is a superset of itself. /// CL2.0 adds: /// __generic is a superset of any address space except for __constant. + static bool isAddressSpaceSupersetOf(LangAS A, LangAS B) { + // Address spaces must match exactly. + return A == B || + // Otherwise in OpenCLC v2.0 s6.5.5: every address space except + // for __constant can be used as __generic. + (A == LangAS::opencl_generic && B != LangAS::opencl_constant); + } + + /// Returns true if the address space in these qualifiers is equal to or + /// a superset of the address space in the argument qualifiers. bool isAddressSpaceSupersetOf(Qualifiers other) const { - return - // Address spaces must match exactly. - getAddressSpace() == other.getAddressSpace() || - // Otherwise in OpenCLC v2.0 s6.5.5: every address space except - // for __constant can be used as __generic. - (getAddressSpace() == LangAS::opencl_generic && - other.getAddressSpace() != LangAS::opencl_constant); + return isAddressSpaceSupersetOf(getAddressSpace(), other.getAddressSpace()); } /// Determines if these qualifiers compatibly include another set. @@ -1153,6 +1158,22 @@ public: return isDestructedTypeImpl(*this); } + /// Check if this is or contains a C union that is non-trivial to + /// default-initialize, which is a union that has a member that is non-trivial + /// to default-initialize. If this returns true, + /// isNonTrivialToPrimitiveDefaultInitialize returns PDIK_Struct. + bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const; + + /// Check if this is or contains a C union that is non-trivial to destruct, + /// which is a union that has a member that is non-trivial to destruct. If + /// this returns true, isDestructedType returns DK_nontrivial_c_struct. + bool hasNonTrivialToPrimitiveDestructCUnion() const; + + /// Check if this is or contains a C union that is non-trivial to copy, which + /// is a union that has a member that is non-trivial to copy. If this returns + /// true, isNonTrivialToPrimitiveCopy returns PCK_Struct. + bool hasNonTrivialToPrimitiveCopyCUnion() const; + /// Determine whether expressions of the given type are forbidden /// from being lvalues in C. /// @@ -1225,6 +1246,11 @@ private: const ASTContext &C); static QualType IgnoreParens(QualType T); static DestructionKind isDestructedTypeImpl(QualType type); + + /// Check if \param RD is or contains a non-trivial C union. + static bool hasNonTrivialToPrimitiveDefaultInitializeCUnion(const RecordDecl *RD); + static bool hasNonTrivialToPrimitiveDestructCUnion(const RecordDecl *RD); + static bool hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD); }; } // namespace clang @@ -1404,7 +1430,7 @@ enum class AutoTypeKeyword { /// /// Types, once created, are immutable. /// -class Type : public ExtQualsTypeCommonBase { +class alignas(8) Type : public ExtQualsTypeCommonBase { public: enum TypeClass { #define TYPE(Class, Base) Class, @@ -1806,7 +1832,9 @@ public: friend class ASTWriter; Type(const Type &) = delete; + Type(Type &&) = delete; Type &operator=(const Type &) = delete; + Type &operator=(Type &&) = delete; TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); } @@ -1953,6 +1981,7 @@ public: bool isLValueReferenceType() const; bool isRValueReferenceType() const; bool isFunctionPointerType() const; + bool isFunctionReferenceType() const; bool isMemberPointerType() const; bool isMemberFunctionPointerType() const; bool isMemberDataPointerType() const; @@ -1986,7 +2015,7 @@ public: bool isObjCQualifiedClassType() const; // Class<foo> bool isObjCObjectOrInterfaceType() const; bool isObjCIdType() const; // id - + bool isDecltypeType() const; /// Was this type written with the special inert-in-ARC __unsafe_unretained /// qualifier? /// @@ -2269,6 +2298,9 @@ public: /// ISO/IEC JTC1 SC22 WG14 N1169. bool isFixedPointType() const; + /// Return true if this is a fixed point or integer type. + bool isFixedPointOrIntegerType() const; + /// Return true if this is a saturated fixed point type according to /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned. bool isSaturatedFixedPointType() const; @@ -3843,6 +3875,7 @@ private: case EST_MSAny: case EST_BasicNoexcept: case EST_Unparsed: + case EST_NoThrow: return {0, 0, 0}; case EST_Dynamic: @@ -3902,7 +3935,7 @@ public: EPI.Variadic = isVariadic(); EPI.HasTrailingReturn = hasTrailingReturn(); EPI.ExceptionSpec.Type = getExceptionSpecType(); - EPI.TypeQuals = getTypeQuals(); + EPI.TypeQuals = getMethodQuals(); EPI.RefQualifier = getRefQualifier(); if (EPI.ExceptionSpec.Type == EST_Dynamic) { EPI.ExceptionSpec.Exceptions = exceptions(); @@ -4012,7 +4045,7 @@ public: /// Whether this function prototype has a trailing return type. bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; } - Qualifiers getTypeQuals() const { + Qualifiers getMethodQuals() const { if (hasExtQualifiers()) return *getTrailingObjects<Qualifiers>(); else @@ -4172,6 +4205,41 @@ public: static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } }; +/// Sugar type that represents a type that was qualified by a qualifier written +/// as a macro invocation. +class MacroQualifiedType : public Type { + friend class ASTContext; // ASTContext creates these. + + QualType UnderlyingTy; + const IdentifierInfo *MacroII; + + MacroQualifiedType(QualType UnderlyingTy, QualType CanonTy, + const IdentifierInfo *MacroII) + : Type(MacroQualified, CanonTy, UnderlyingTy->isDependentType(), + UnderlyingTy->isInstantiationDependentType(), + UnderlyingTy->isVariablyModifiedType(), + UnderlyingTy->containsUnexpandedParameterPack()), + UnderlyingTy(UnderlyingTy), MacroII(MacroII) { + assert(isa<AttributedType>(UnderlyingTy) && + "Expected a macro qualified type to only wrap attributed types."); + } + +public: + const IdentifierInfo *getMacroIdentifier() const { return MacroII; } + QualType getUnderlyingType() const { return UnderlyingTy; } + + /// Return this attributed type's modified type with no qualifiers attached to + /// it. + QualType getModifiedType() const; + + bool isSugared() const { return true; } + QualType desugar() const; + + static bool classof(const Type *T) { + return T->getTypeClass() == MacroQualified; + } +}; + /// Represents a `typeof` (or __typeof__) expression (a GCC extension). class TypeOfExprType : public Type { Expr *TOExpr; @@ -4750,9 +4818,9 @@ class AutoType : public DeducedType, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword, - bool IsDeducedAsDependent) + bool IsDeducedAsDependent, bool IsDeducedAsPack) : DeducedType(Auto, DeducedAsType, IsDeducedAsDependent, - IsDeducedAsDependent, /*ContainsPack=*/false) { + IsDeducedAsDependent, IsDeducedAsPack) { AutoTypeBits.Keyword = (unsigned)Keyword; } @@ -4766,14 +4834,16 @@ public: } void Profile(llvm::FoldingSetNodeID &ID) { - Profile(ID, getDeducedType(), getKeyword(), isDependentType()); + Profile(ID, getDeducedType(), getKeyword(), isDependentType(), + containsUnexpandedParameterPack()); } static void Profile(llvm::FoldingSetNodeID &ID, QualType Deduced, - AutoTypeKeyword Keyword, bool IsDependent) { + AutoTypeKeyword Keyword, bool IsDependent, bool IsPack) { ID.AddPointer(Deduced.getAsOpaquePtr()); ID.AddInteger((unsigned)Keyword); ID.AddBoolean(IsDependent); + ID.AddBoolean(IsPack); } static bool classof(const Type *T) { @@ -6194,6 +6264,24 @@ inline Qualifiers::GC QualType::getObjCGCAttr() const { return getQualifiers().getObjCGCAttr(); } +inline bool QualType::hasNonTrivialToPrimitiveDefaultInitializeCUnion() const { + if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl()) + return hasNonTrivialToPrimitiveDefaultInitializeCUnion(RD); + return false; +} + +inline bool QualType::hasNonTrivialToPrimitiveDestructCUnion() const { + if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl()) + return hasNonTrivialToPrimitiveDestructCUnion(RD); + return false; +} + +inline bool QualType::hasNonTrivialToPrimitiveCopyCUnion() const { + if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl()) + return hasNonTrivialToPrimitiveCopyCUnion(RD); + return false; +} + inline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { if (const auto *PT = t.getAs<PointerType>()) { if (const auto *FT = PT->getPointeeType()->getAs<FunctionType>()) @@ -6324,6 +6412,13 @@ inline bool Type::isFunctionPointerType() const { return false; } +inline bool Type::isFunctionReferenceType() const { + if (const auto *T = getAs<ReferenceType>()) + return T->getPointeeType()->isFunctionType(); + else + return false; +} + inline bool Type::isMemberPointerType() const { return isa<MemberPointerType>(CanonicalType); } @@ -6441,6 +6536,10 @@ inline bool Type::isObjCBuiltinType() const { return isObjCIdType() || isObjCClassType() || isObjCSelType(); } +inline bool Type::isDecltypeType() const { + return isa<DecltypeType>(this); +} + #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ inline bool Type::is##Id##Type() const { \ return isSpecificBuiltinType(BuiltinType::Id); \ @@ -6596,6 +6695,10 @@ inline bool Type::isFixedPointType() const { return false; } +inline bool Type::isFixedPointOrIntegerType() const { + return isFixedPointType() || isIntegerType(); +} + inline bool Type::isSaturatedFixedPointType() const { if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { return BT->getKind() >= BuiltinType::SatShortAccum && @@ -6785,6 +6888,8 @@ template <typename T> const T *Type::getAsAdjusted() const { Ty = P->desugar().getTypePtr(); else if (const auto *A = dyn_cast<AdjustedType>(Ty)) Ty = A->desugar().getTypePtr(); + else if (const auto *M = dyn_cast<MacroQualifiedType>(Ty)) + Ty = M->desugar().getTypePtr(); else break; } @@ -6841,6 +6946,8 @@ QualType DecayedType::getPointeeType() const { // Get the decimal string representation of a fixed point type, represented // as a scaled integer. +// TODO: At some point, we should change the arguments to instead just accept an +// APFixedPoint instead of APSInt and scale. void FixedPointValueToString(SmallVectorImpl<char> &Str, llvm::APSInt Val, unsigned Scale); diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h index 1e89e9386719..40d17f991f1f 100644 --- a/include/clang/AST/TypeLoc.h +++ b/include/clang/AST/TypeLoc.h @@ -1,9 +1,8 @@ //===- TypeLoc.h - Type Source Info Wrapper ---------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -174,6 +173,9 @@ public: TypeLoc IgnoreParens() const; + /// Strips MacroDefinitionTypeLocs from a type location. + TypeLoc IgnoreMacroDefinitions() const; + /// Find a type with the location of an explicit type qualifier. /// /// The result, if non-null, will be one of: @@ -1081,6 +1083,39 @@ public: } }; +struct MacroQualifiedLocInfo { + SourceLocation ExpansionLoc; +}; + +class MacroQualifiedTypeLoc + : public ConcreteTypeLoc<UnqualTypeLoc, MacroQualifiedTypeLoc, + MacroQualifiedType, MacroQualifiedLocInfo> { +public: + void initializeLocal(ASTContext &Context, SourceLocation Loc) { + setExpansionLoc(Loc); + } + + TypeLoc getInnerLoc() const { return getInnerTypeLoc(); } + + const IdentifierInfo *getMacroIdentifier() const { + return getTypePtr()->getMacroIdentifier(); + } + + SourceLocation getExpansionLoc() const { + return this->getLocalData()->ExpansionLoc; + } + + void setExpansionLoc(SourceLocation Loc) { + this->getLocalData()->ExpansionLoc = Loc; + } + + QualType getInnerType() const { return getTypePtr()->getUnderlyingType(); } + + SourceRange getLocalSourceRange() const { + return getInnerLoc().getLocalSourceRange(); + } +}; + struct ParenLocInfo { SourceLocation LParenLoc; SourceLocation RParenLoc; @@ -2290,6 +2325,8 @@ inline T TypeLoc::getAsAdjusted() const { Cur = ETL.getNamedTypeLoc(); else if (auto ATL = Cur.getAs<AdjustedTypeLoc>()) Cur = ATL.getOriginalLoc(); + else if (auto MQL = Cur.getAs<MacroQualifiedTypeLoc>()) + Cur = MQL.getInnerLoc(); else break; } diff --git a/include/clang/AST/TypeLocNodes.def b/include/clang/AST/TypeLocNodes.def index 4590e489e3f7..c0dfe150d6cc 100644 --- a/include/clang/AST/TypeLocNodes.def +++ b/include/clang/AST/TypeLocNodes.def @@ -1,9 +1,8 @@ //===-- TypeLocNodes.def - Metadata about TypeLoc wrappers ------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/TypeLocVisitor.h b/include/clang/AST/TypeLocVisitor.h index db5775aa146e..ec780884e96c 100644 --- a/include/clang/AST/TypeLocVisitor.h +++ b/include/clang/AST/TypeLocVisitor.h @@ -1,9 +1,8 @@ //===--- TypeLocVisitor.h - Visitor for TypeLoc subclasses ------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/TypeNodes.def b/include/clang/AST/TypeNodes.def index 8638f94bda14..58a5f880cbe6 100644 --- a/include/clang/AST/TypeNodes.def +++ b/include/clang/AST/TypeNodes.def @@ -1,9 +1,8 @@ //===-- TypeNodes.def - Metadata about Type AST nodes -----------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -83,6 +82,7 @@ TYPE(FunctionNoProto, FunctionType) DEPENDENT_TYPE(UnresolvedUsing, Type) NON_CANONICAL_TYPE(Paren, Type) NON_CANONICAL_TYPE(Typedef, Type) +NON_CANONICAL_TYPE(MacroQualified, Type) NON_CANONICAL_TYPE(Adjusted, Type) NON_CANONICAL_TYPE(Decayed, AdjustedType) NON_CANONICAL_UNLESS_DEPENDENT_TYPE(TypeOfExpr, Type) diff --git a/include/clang/AST/TypeOrdering.h b/include/clang/AST/TypeOrdering.h index 7ea78071f5cf..6630105136f5 100644 --- a/include/clang/AST/TypeOrdering.h +++ b/include/clang/AST/TypeOrdering.h @@ -1,9 +1,8 @@ //===-------------- TypeOrdering.h - Total ordering for types ---*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// diff --git a/include/clang/AST/TypeVisitor.h b/include/clang/AST/TypeVisitor.h index 75fa0ec15ce2..8930ec853949 100644 --- a/include/clang/AST/TypeVisitor.h +++ b/include/clang/AST/TypeVisitor.h @@ -1,9 +1,8 @@ //===--- TypeVisitor.h - Visitor for Type subclasses ------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/UnresolvedSet.h b/include/clang/AST/UnresolvedSet.h index b62e9f138bb6..cfc0b87eec7e 100644 --- a/include/clang/AST/UnresolvedSet.h +++ b/include/clang/AST/UnresolvedSet.h @@ -1,9 +1,8 @@ //===- UnresolvedSet.h - Unresolved sets of declarations --------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/VTTBuilder.h b/include/clang/AST/VTTBuilder.h index 3a8a6a9c15f0..4acbc1f9e96b 100644 --- a/include/clang/AST/VTTBuilder.h +++ b/include/clang/AST/VTTBuilder.h @@ -1,9 +1,8 @@ //===- VTTBuilder.h - C++ VTT layout builder --------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // diff --git a/include/clang/AST/VTableBuilder.h b/include/clang/AST/VTableBuilder.h index 4a779db01ff8..43c84292c091 100644 --- a/include/clang/AST/VTableBuilder.h +++ b/include/clang/AST/VTableBuilder.h @@ -1,9 +1,8 @@ //===--- VTableBuilder.h - C++ vtable layout builder --------------*- C++ -*-=// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // |