#include "TypeLocBuilder.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTMutationListener.h"
#include "clang/AST/ASTStructuralEquivalence.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/LocInfoType.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeLocVisitor.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/DelayedDiagnostic.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/ParsedAttr.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaCUDA.h"
#include "clang/Sema/SemaHLSL.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/SemaObjC.h"
#include "clang/Sema/SemaOpenMP.h"
#include "clang/Sema/Template.h"
#include "clang/Sema/TemplateInstCallback.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include <bitset>
#include <optional>
usingnamespaceclang;
enum TypeDiagSelector { … };
static bool isOmittedBlockReturnType(const Declarator &D) { … }
static void diagnoseBadTypeAttribute(Sema &S, const ParsedAttr &attr,
QualType type) { … }
#define OBJC_POINTER_TYPE_ATTRS_CASELIST …
#define CALLING_CONV_ATTRS_CASELIST …
#define FUNCTION_TYPE_ATTRS_CASELIST …
#define MS_TYPE_ATTRS_CASELIST …
#define NULLABILITY_TYPE_ATTRS_CASELIST …
namespace {
class TypeProcessingState { … };
}
static void moveAttrFromListToList(ParsedAttr &attr,
ParsedAttributesView &fromList,
ParsedAttributesView &toList) { … }
enum TypeAttrLocation { … };
static void
processTypeAttrs(TypeProcessingState &state, QualType &type,
TypeAttrLocation TAL, const ParsedAttributesView &attrs,
CUDAFunctionTarget CFT = CUDAFunctionTarget::HostDevice);
static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
QualType &type, CUDAFunctionTarget CFT);
static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &state,
ParsedAttr &attr, QualType &type);
static bool handleObjCGCTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
QualType &type);
static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
ParsedAttr &attr, QualType &type);
static bool handleObjCPointerTypeAttr(TypeProcessingState &state,
ParsedAttr &attr, QualType &type) { … }
static DeclaratorChunk *maybeMovePastReturnType(Declarator &declarator,
unsigned i,
bool onlyBlockPointers) { … }
static void distributeObjCPointerTypeAttr(TypeProcessingState &state,
ParsedAttr &attr, QualType type) { … }
static void distributeObjCPointerTypeAttrFromDeclarator(
TypeProcessingState &state, ParsedAttr &attr, QualType &declSpecType) { … }
static void distributeFunctionTypeAttr(TypeProcessingState &state,
ParsedAttr &attr, QualType type) { … }
static bool distributeFunctionTypeAttrToInnermost(
TypeProcessingState &state, ParsedAttr &attr,
ParsedAttributesView &attrList, QualType &declSpecType,
CUDAFunctionTarget CFT) { … }
static void distributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state,
ParsedAttr &attr,
QualType &declSpecType,
CUDAFunctionTarget CFT) { … }
static void distributeFunctionTypeAttrFromDeclarator(TypeProcessingState &state,
ParsedAttr &attr,
QualType &declSpecType,
CUDAFunctionTarget CFT) { … }
static void distributeTypeAttrsFromDeclarator(TypeProcessingState &state,
QualType &declSpecType,
CUDAFunctionTarget CFT) { … }
static void maybeSynthesizeBlockSignature(TypeProcessingState &state,
QualType declSpecType) { … }
static void diagnoseAndRemoveTypeQualifiers(Sema &S, const DeclSpec &DS,
unsigned &TypeQuals,
QualType TypeSoFar,
unsigned RemoveTQs,
unsigned DiagID) { … }
static bool checkOmittedBlockReturnType(Sema &S, Declarator &declarator,
QualType Result) { … }
static OpenCLAccessAttr::Spelling
getImageAccess(const ParsedAttributesView &Attrs) { … }
static UnaryTransformType::UTTKind
TSTToUnaryTransformType(DeclSpec::TST SwitchTST) { … }
static QualType ConvertDeclSpecToType(TypeProcessingState &state) { … }
static std::string getPrintableNameForEntity(DeclarationName Entity) { … }
static bool isDependentOrGNUAutoType(QualType T) { … }
QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc,
Qualifiers Qs, const DeclSpec *DS) { … }
QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc,
unsigned CVRAU, const DeclSpec *DS) { … }
QualType Sema::BuildParenType(QualType T) { … }
static QualType inferARCLifetimeForPointee(Sema &S, QualType type,
SourceLocation loc,
bool isReference) { … }
static std::string getFunctionQualifiersAsString(const FunctionProtoType *FnTy){ … }
namespace {
enum QualifiedFunctionKind { … };
}
static bool checkQualifiedFunction(Sema &S, QualType T, SourceLocation Loc,
QualifiedFunctionKind QFK) { … }
bool Sema::CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc) { … }
static QualType deduceOpenCLPointeeAddrSpace(Sema &S, QualType PointeeType) { … }
QualType Sema::BuildPointerType(QualType T,
SourceLocation Loc, DeclarationName Entity) { … }
QualType Sema::BuildReferenceType(QualType T, bool SpelledAsLValue,
SourceLocation Loc,
DeclarationName Entity) { … }
QualType Sema::BuildReadPipeType(QualType T, SourceLocation Loc) { … }
QualType Sema::BuildWritePipeType(QualType T, SourceLocation Loc) { … }
QualType Sema::BuildBitIntType(bool IsUnsigned, Expr *BitWidth,
SourceLocation Loc) { … }
static ExprResult checkArraySize(Sema &S, Expr *&ArraySize,
llvm::APSInt &SizeVal, unsigned VLADiag,
bool VLAIsError) { … }
bool Sema::checkArrayElementAlignment(QualType EltTy, SourceLocation Loc) { … }
QualType Sema::BuildArrayType(QualType T, ArraySizeModifier ASM,
Expr *ArraySize, unsigned Quals,
SourceRange Brackets, DeclarationName Entity) { … }
QualType Sema::BuildVectorType(QualType CurType, Expr *SizeExpr,
SourceLocation AttrLoc) { … }
QualType Sema::BuildExtVectorType(QualType T, Expr *ArraySize,
SourceLocation AttrLoc) { … }
QualType Sema::BuildMatrixType(QualType ElementTy, Expr *NumRows, Expr *NumCols,
SourceLocation AttrLoc) { … }
bool Sema::CheckFunctionReturnType(QualType T, SourceLocation Loc) { … }
static void checkExtParameterInfos(Sema &S, ArrayRef<QualType> paramTypes,
const FunctionProtoType::ExtProtoInfo &EPI,
llvm::function_ref<SourceLocation(unsigned)> getParamLoc) { … }
QualType Sema::BuildFunctionType(QualType T,
MutableArrayRef<QualType> ParamTypes,
SourceLocation Loc, DeclarationName Entity,
const FunctionProtoType::ExtProtoInfo &EPI) { … }
QualType Sema::BuildMemberPointerType(QualType T, QualType Class,
SourceLocation Loc,
DeclarationName Entity) { … }
QualType Sema::BuildBlockPointerType(QualType T,
SourceLocation Loc,
DeclarationName Entity) { … }
QualType Sema::GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo) { … }
static void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state,
Qualifiers::ObjCLifetime ownership,
unsigned chunkIndex);
static void inferARCWriteback(TypeProcessingState &state,
QualType &declSpecType) { … }
void Sema::diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals,
SourceLocation FallbackLoc,
SourceLocation ConstQualLoc,
SourceLocation VolatileQualLoc,
SourceLocation RestrictQualLoc,
SourceLocation AtomicQualLoc,
SourceLocation UnalignedQualLoc) { … }
static void diagnoseRedundantReturnTypeQualifiers(Sema &S, QualType RetTy,
Declarator &D,
unsigned FunctionChunkIndex) { … }
static std::pair<QualType, TypeSourceInfo *>
InventTemplateParameter(TypeProcessingState &state, QualType T,
TypeSourceInfo *TrailingTSI, AutoType *Auto,
InventedTemplateParameterInfo &Info) { … }
static TypeSourceInfo *
GetTypeSourceInfoForDeclarator(TypeProcessingState &State,
QualType T, TypeSourceInfo *ReturnTypeInfo);
static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
TypeSourceInfo *&ReturnTypeInfo) { … }
static void warnAboutAmbiguousFunction(Sema &S, Declarator &D,
DeclaratorChunk &DeclType, QualType RT) { … }
static void warnAboutRedundantParens(Sema &S, Declarator &D, QualType T) { … }
static CallingConv getCCForDeclaratorChunk(
Sema &S, Declarator &D, const ParsedAttributesView &AttrList,
const DeclaratorChunk::FunctionTypeInfo &FTI, unsigned ChunkIndex) { … }
namespace {
enum class SimplePointerKind { … };
}
IdentifierInfo *Sema::getNullabilityKeyword(NullabilityKind nullability) { … }
static bool hasNullabilityAttr(const ParsedAttributesView &attrs) { … }
namespace {
enum class PointerDeclaratorKind { … };
enum class PointerWrappingDeclaratorKind { … };
}
static PointerDeclaratorKind
classifyPointerDeclarator(Sema &S, QualType type, Declarator &declarator,
PointerWrappingDeclaratorKind &wrappingKind) { … }
static FileID getNullabilityCompletenessCheckFileID(Sema &S,
SourceLocation loc) { … }
template <typename DiagBuilderT>
static void fixItNullability(Sema &S, DiagBuilderT &Diag,
SourceLocation PointerLoc,
NullabilityKind Nullability) { … }
static void emitNullabilityConsistencyWarning(Sema &S,
SimplePointerKind PointerKind,
SourceLocation PointerLoc,
SourceLocation PointerEndLoc) { … }
static void
checkNullabilityConsistency(Sema &S, SimplePointerKind pointerKind,
SourceLocation pointerLoc,
SourceLocation pointerEndLoc = SourceLocation()) { … }
static void recordNullabilitySeen(Sema &S, SourceLocation loc) { … }
static bool hasOuterPointerLikeChunk(const Declarator &D, unsigned endIndex) { … }
static bool IsNoDerefableChunk(const DeclaratorChunk &Chunk) { … }
template<typename AttrT>
static AttrT *createSimpleAttr(ASTContext &Ctx, ParsedAttr &AL) { … }
static Attr *createNullabilityAttr(ASTContext &Ctx, ParsedAttr &Attr,
NullabilityKind NK) { … }
static bool DiagnoseMultipleAddrSpaceAttributes(Sema &S, LangAS ASOld,
LangAS ASNew,
SourceLocation AttrLoc) { … }
static bool shouldHaveNullability(QualType T) { … }
static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
QualType declSpecType,
TypeSourceInfo *TInfo) { … }
TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D) { … }
static void transferARCOwnershipToDeclSpec(Sema &S,
QualType &declSpecTy,
Qualifiers::ObjCLifetime ownership) { … }
static void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state,
Qualifiers::ObjCLifetime ownership,
unsigned chunkIndex) { … }
static void transferARCOwnership(TypeProcessingState &state,
QualType &declSpecTy,
Qualifiers::ObjCLifetime ownership) { … }
TypeSourceInfo *Sema::GetTypeForDeclaratorCast(Declarator &D, QualType FromTy) { … }
static void fillAttributedTypeLoc(AttributedTypeLoc TL,
TypeProcessingState &State) { … }
static void fillHLSLAttributedResourceTypeLoc(HLSLAttributedResourceTypeLoc TL,
TypeProcessingState &State) { … }
static void fillMatrixTypeLoc(MatrixTypeLoc MTL,
const ParsedAttributesView &Attrs) { … }
namespace {
class TypeSpecLocFiller : public TypeLocVisitor<TypeSpecLocFiller> { … };
class DeclaratorLocFiller : public TypeLocVisitor<DeclaratorLocFiller> { … };
}
static void fillAtomicQualLoc(AtomicTypeLoc ATL, const DeclaratorChunk &Chunk) { … }
static void
fillDependentAddressSpaceTypeLoc(DependentAddressSpaceTypeLoc DASTL,
const ParsedAttributesView &Attrs) { … }
static TypeSourceInfo *
GetTypeSourceInfoForDeclarator(TypeProcessingState &State,
QualType T, TypeSourceInfo *ReturnTypeInfo) { … }
ParsedType Sema::CreateParsedType(QualType T, TypeSourceInfo *TInfo) { … }
void LocInfoType::getAsStringInternal(std::string &Str,
const PrintingPolicy &Policy) const { … }
TypeResult Sema::ActOnTypeName(Declarator &D) { … }
static bool BuildAddressSpaceIndex(Sema &S, LangAS &ASIdx,
const Expr *AddrSpace,
SourceLocation AttrLoc) { … }
QualType Sema::BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace,
SourceLocation AttrLoc) { … }
QualType Sema::BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
SourceLocation AttrLoc) { … }
static void HandleBTFTypeTagAttribute(QualType &Type, const ParsedAttr &Attr,
TypeProcessingState &State) { … }
static void HandleAddressSpaceTypeAttribute(QualType &Type,
const ParsedAttr &Attr,
TypeProcessingState &State) { … }
static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
ParsedAttr &attr, QualType &type) { … }
static bool handleObjCGCTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
QualType &type) { … }
namespace {
struct FunctionTypeUnwrapper { … };
}
static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &State,
ParsedAttr &PAttr, QualType &Type) { … }
static bool HandleWebAssemblyFuncrefAttr(TypeProcessingState &State,
QualType &QT, ParsedAttr &PAttr) { … }
static QualType rebuildAttributedTypeWithoutNullability(ASTContext &Ctx,
QualType Type) { … }
static NullabilityKind mapNullabilityAttrKind(ParsedAttr::Kind kind) { … }
static bool CheckNullabilityTypeSpecifier(
Sema &S, TypeProcessingState *State, ParsedAttr *PAttr, QualType &QT,
NullabilityKind Nullability, SourceLocation NullabilityLoc,
bool IsContextSensitive, bool AllowOnArrayType, bool OverrideExisting) { … }
static bool CheckNullabilityTypeSpecifier(TypeProcessingState &State,
QualType &Type, ParsedAttr &Attr,
bool AllowOnArrayType) { … }
bool Sema::CheckImplicitNullabilityTypeSpecifier(QualType &Type,
NullabilityKind Nullability,
SourceLocation DiagLoc,
bool AllowArrayTypes,
bool OverrideExisting) { … }
static bool checkObjCKindOfType(TypeProcessingState &state, QualType &type,
ParsedAttr &attr) { … }
static bool distributeNullabilityTypeAttr(TypeProcessingState &state,
QualType type, ParsedAttr &attr) { … }
static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr) { … }
std::optional<FunctionEffectMode>
Sema::ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName) { … }
static bool
handleNonBlockingNonAllocatingTypeAttr(TypeProcessingState &TPState,
ParsedAttr &PAttr, QualType &QT,
FunctionTypeUnwrapper &Unwrapped) { … }
static bool checkMutualExclusion(TypeProcessingState &state,
const FunctionProtoType::ExtProtoInfo &EPI,
ParsedAttr &Attr,
AttributeCommonInfo::Kind OtherKind) { … }
static bool handleArmStateAttribute(Sema &S,
FunctionProtoType::ExtProtoInfo &EPI,
ParsedAttr &Attr,
FunctionType::ArmStateValue State) { … }
static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
QualType &type, CUDAFunctionTarget CFT) { … }
bool Sema::hasExplicitCallingConv(QualType T) { … }
void Sema::adjustMemberFunctionCC(QualType &T, bool HasThisPointer,
bool IsCtorOrDtor, SourceLocation Loc) { … }
static void HandleVectorSizeAttr(QualType &CurType, const ParsedAttr &Attr,
Sema &S) { … }
static void HandleExtVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
Sema &S) { … }
static bool isPermittedNeonBaseType(QualType &Ty, VectorKind VecKind, Sema &S) { … }
static bool verifyValidIntegerConstantExpr(Sema &S, const ParsedAttr &Attr,
llvm::APSInt &Result) { … }
static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
Sema &S, VectorKind VecKind) { … }
static void HandleArmSveVectorBitsTypeAttr(QualType &CurType, ParsedAttr &Attr,
Sema &S) { … }
static void HandleArmMveStrictPolymorphismAttr(TypeProcessingState &State,
QualType &CurType,
ParsedAttr &Attr) { … }
static void HandleRISCVRVVVectorBitsTypeAttr(QualType &CurType,
ParsedAttr &Attr, Sema &S) { … }
static void HandleOpenCLAccessAttr(QualType &CurType, const ParsedAttr &Attr,
Sema &S) { … }
static void HandleMatrixTypeAttr(QualType &CurType, const ParsedAttr &Attr,
Sema &S) { … }
static void HandleAnnotateTypeAttr(TypeProcessingState &State,
QualType &CurType, const ParsedAttr &PA) { … }
static void HandleLifetimeBoundAttr(TypeProcessingState &State,
QualType &CurType,
ParsedAttr &Attr) { … }
static void HandleHLSLParamModifierAttr(TypeProcessingState &State,
QualType &CurType,
const ParsedAttr &Attr, Sema &S) { … }
static void processTypeAttrs(TypeProcessingState &state, QualType &type,
TypeAttrLocation TAL,
const ParsedAttributesView &attrs,
CUDAFunctionTarget CFT) { … }
void Sema::completeExprArrayBound(Expr *E) { … }
QualType Sema::getCompletedType(Expr *E) { … }
bool Sema::RequireCompleteExprType(Expr *E, CompleteTypeKind Kind,
TypeDiagnoser &Diagnoser) { … }
bool Sema::RequireCompleteExprType(Expr *E, unsigned DiagID) { … }
bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
CompleteTypeKind Kind,
TypeDiagnoser &Diagnoser) { … }
bool Sema::hasStructuralCompatLayout(Decl *D, Decl *Suggested) { … }
bool Sema::hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested,
AcceptableKind Kind, bool OnlyNeedComplete) { … }
bool Sema::hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested,
bool OnlyNeedComplete) { … }
bool Sema::hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested,
bool OnlyNeedComplete) { … }
static void assignInheritanceModel(Sema &S, CXXRecordDecl *RD) { … }
bool Sema::RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
CompleteTypeKind Kind,
TypeDiagnoser *Diagnoser) { … }
bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
CompleteTypeKind Kind, unsigned DiagID) { … }
static unsigned getLiteralDiagFromTagKind(TagTypeKind Tag) { … }
bool Sema::RequireLiteralType(SourceLocation Loc, QualType T,
TypeDiagnoser &Diagnoser) { … }
bool Sema::RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID) { … }
QualType Sema::getElaboratedType(ElaboratedTypeKeyword Keyword,
const CXXScopeSpec &SS, QualType T,
TagDecl *OwnedTagDecl) { … }
QualType Sema::BuildTypeofExprType(Expr *E, TypeOfKind Kind) { … }
static void
BuildTypeCoupledDecls(Expr *E,
llvm::SmallVectorImpl<TypeCoupledDeclRefInfo> &Decls) { … }
QualType Sema::BuildCountAttributedArrayOrPointerType(QualType WrappedTy,
Expr *CountExpr,
bool CountInBytes,
bool OrNull) { … }
QualType Sema::getDecltypeForExpr(Expr *E) { … }
QualType Sema::BuildDecltypeType(Expr *E, bool AsUnevaluated) { … }
QualType Sema::ActOnPackIndexingType(QualType Pattern, Expr *IndexExpr,
SourceLocation Loc,
SourceLocation EllipsisLoc) { … }
QualType Sema::BuildPackIndexingType(QualType Pattern, Expr *IndexExpr,
SourceLocation Loc,
SourceLocation EllipsisLoc,
bool FullySubstituted,
ArrayRef<QualType> Expansions) { … }
static QualType GetEnumUnderlyingType(Sema &S, QualType BaseType,
SourceLocation Loc) { … }
QualType Sema::BuiltinEnumUnderlyingType(QualType BaseType,
SourceLocation Loc) { … }
QualType Sema::BuiltinAddPointer(QualType BaseType, SourceLocation Loc) { … }
QualType Sema::BuiltinRemovePointer(QualType BaseType, SourceLocation Loc) { … }
QualType Sema::BuiltinDecay(QualType BaseType, SourceLocation Loc) { … }
QualType Sema::BuiltinAddReference(QualType BaseType, UTTKind UKind,
SourceLocation Loc) { … }
QualType Sema::BuiltinRemoveExtent(QualType BaseType, UTTKind UKind,
SourceLocation Loc) { … }
QualType Sema::BuiltinRemoveReference(QualType BaseType, UTTKind UKind,
SourceLocation Loc) { … }
QualType Sema::BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind,
SourceLocation Loc) { … }
static QualType ChangeIntegralSignedness(Sema &S, QualType BaseType,
bool IsMakeSigned,
SourceLocation Loc) { … }
QualType Sema::BuiltinChangeSignedness(QualType BaseType, UTTKind UKind,
SourceLocation Loc) { … }
QualType Sema::BuildUnaryTransformType(QualType BaseType, UTTKind UKind,
SourceLocation Loc) { … }
QualType Sema::BuildAtomicType(QualType T, SourceLocation Loc) { … }