45#include "llvm/ADT/ArrayRef.h"
46#include "llvm/ADT/STLForwardCompat.h"
47#include "llvm/ADT/StringExtras.h"
48#include "llvm/IR/DerivedTypes.h"
49#include "llvm/Support/ErrorHandling.h"
83 bool useExpansionLoc =
true;
84 switch (
attr.getKind()) {
85 case ParsedAttr::AT_ObjCGC:
88 case ParsedAttr::AT_ObjCOwnership:
94 useExpansionLoc =
false;
99 StringRef name =
attr.getAttrName()->getName();
103 attr.isArgIdent(0) ?
attr.getArgAsIdent(0)->getIdentifierInfo() :
nullptr;
104 if (useExpansionLoc && loc.
isMacroID() && II) {
105 if (II->
isStr(
"strong")) {
107 }
else if (II->
isStr(
"weak")) {
112 S.
Diag(loc,
attr.isRegularKeywordAttribute()
113 ? diag::err_type_attribute_wrong_type
114 : diag::warn_type_attribute_wrong_type)
115 << name << WhichType <<
type;
120#define OBJC_POINTER_TYPE_ATTRS_CASELIST \
121 case ParsedAttr::AT_ObjCGC: \
122 case ParsedAttr::AT_ObjCOwnership
125#define CALLING_CONV_ATTRS_CASELIST \
126 case ParsedAttr::AT_CDecl: \
127 case ParsedAttr::AT_FastCall: \
128 case ParsedAttr::AT_StdCall: \
129 case ParsedAttr::AT_ThisCall: \
130 case ParsedAttr::AT_RegCall: \
131 case ParsedAttr::AT_Pascal: \
132 case ParsedAttr::AT_SwiftCall: \
133 case ParsedAttr::AT_SwiftAsyncCall: \
134 case ParsedAttr::AT_VectorCall: \
135 case ParsedAttr::AT_AArch64VectorPcs: \
136 case ParsedAttr::AT_AArch64SVEPcs: \
137 case ParsedAttr::AT_DeviceKernel: \
138 case ParsedAttr::AT_MSABI: \
139 case ParsedAttr::AT_SysVABI: \
140 case ParsedAttr::AT_Pcs: \
141 case ParsedAttr::AT_IntelOclBicc: \
142 case ParsedAttr::AT_PreserveMost: \
143 case ParsedAttr::AT_PreserveAll: \
144 case ParsedAttr::AT_M68kRTD: \
145 case ParsedAttr::AT_PreserveNone: \
146 case ParsedAttr::AT_RISCVVectorCC: \
147 case ParsedAttr::AT_RISCVVLSCC
150#define FUNCTION_TYPE_ATTRS_CASELIST \
151 case ParsedAttr::AT_NSReturnsRetained: \
152 case ParsedAttr::AT_NoReturn: \
153 case ParsedAttr::AT_NonBlocking: \
154 case ParsedAttr::AT_NonAllocating: \
155 case ParsedAttr::AT_Blocking: \
156 case ParsedAttr::AT_Allocating: \
157 case ParsedAttr::AT_Regparm: \
158 case ParsedAttr::AT_CFIUncheckedCallee: \
159 case ParsedAttr::AT_CFISalt: \
160 case ParsedAttr::AT_CmseNSCall: \
161 case ParsedAttr::AT_ArmStreaming: \
162 case ParsedAttr::AT_ArmStreamingCompatible: \
163 case ParsedAttr::AT_ArmPreserves: \
164 case ParsedAttr::AT_ArmIn: \
165 case ParsedAttr::AT_ArmOut: \
166 case ParsedAttr::AT_ArmInOut: \
167 case ParsedAttr::AT_ArmAgnostic: \
168 case ParsedAttr::AT_AnyX86NoCallerSavedRegisters: \
169 case ParsedAttr::AT_AnyX86NoCfCheck: \
170 CALLING_CONV_ATTRS_CASELIST
173#define MS_TYPE_ATTRS_CASELIST \
174 case ParsedAttr::AT_Ptr32: \
175 case ParsedAttr::AT_Ptr64: \
176 case ParsedAttr::AT_SPtr: \
177 case ParsedAttr::AT_UPtr
180#define NULLABILITY_TYPE_ATTRS_CASELIST \
181 case ParsedAttr::AT_TypeNonNull: \
182 case ParsedAttr::AT_TypeNullable: \
183 case ParsedAttr::AT_TypeNullableResult: \
184 case ParsedAttr::AT_TypeNullUnspecified
189 class TypeProcessingState {
213 using TypeAttrPair = std::pair<const AttributedType*, const Attr*>;
215 bool AttrsForTypesSorted =
true;
219 llvm::DenseMap<const MacroQualifiedType *, SourceLocation> LocsForMacros;
227 bool ParsedHLSLParamMod;
231 :
sema(
sema), declarator(declarator),
233 ParsedHLSLParamMod(
false) {}
235 Sema &getSema()
const {
243 bool isProcessingDeclSpec()
const {
247 unsigned getCurrentChunkIndex()
const {
251 void setCurrentChunkIndex(
unsigned idx) {
257 if (isProcessingDeclSpec())
258 return getMutableDeclSpec().getAttributes();
263 void saveDeclSpecAttrs() {
265 if (!savedAttrs.empty())
268 DeclSpec &spec = getMutableDeclSpec();
269 llvm::append_range(savedAttrs,
276 ignoredTypeAttrs.push_back(&
attr);
282 for (
auto *
Attr : ignoredTypeAttrs)
291 sema.Context.getAttributedType(A, ModifiedType, EquivType);
293 AttrsForTypesSorted =
false;
298 QualType getBTFTagAttributedType(
const BTFTypeTagAttr *BTFAttr,
300 return sema.Context.getBTFTagAttributedType(BTFAttr, WrappedType);
307 QualType T =
sema.ReplaceAutoType(TypeWithAuto, Replacement);
308 if (
auto *AttrTy = TypeWithAuto->
getAs<AttributedType>()) {
311 for (TypeAttrPair &A : AttrsForTypes) {
312 if (A.first == AttrTy)
315 AttrsForTypesSorted =
false;
321 const Attr *takeAttrForAttributedType(
const AttributedType *AT) {
322 if (!AttrsForTypesSorted) {
323 llvm::stable_sort(AttrsForTypes, llvm::less_first());
324 AttrsForTypesSorted =
true;
329 for (
auto It = llvm::partition_point(
331 [=](
const TypeAttrPair &A) {
return A.first < AT; });
332 It != AttrsForTypes.end() && It->first == AT; ++It) {
334 const Attr *Result = It->second;
335 It->second =
nullptr;
340 llvm_unreachable(
"no Attr* for AttributedType*");
345 auto FoundLoc = LocsForMacros.find(MQT);
346 assert(FoundLoc != LocsForMacros.end() &&
347 "Unable to find macro expansion location for MacroQualifedType");
348 return FoundLoc->second;
353 LocsForMacros[MQT] = Loc;
356 void setParsedNoDeref(
bool parsed) { parsedNoDeref = parsed; }
358 bool didParseNoDeref()
const {
return parsedNoDeref; }
360 void setParsedHLSLParamMod(
bool Parsed) { ParsedHLSLParamMod = Parsed; }
362 bool didParseHLSLParamMod()
const {
return ParsedHLSLParamMod; }
364 ~TypeProcessingState() {
365 if (savedAttrs.empty())
368 getMutableDeclSpec().getAttributes().clearListOnly();
370 getMutableDeclSpec().getAttributes().addAtEnd(AL);
374 DeclSpec &getMutableDeclSpec()
const {
416 if (
attr.getKind() == ParsedAttr::AT_ObjCGC)
418 assert(
attr.getKind() == ParsedAttr::AT_ObjCOwnership);
433 bool onlyBlockPointers) {
439 for (; i != 0; --i) {
441 switch (fnChunk.
Kind) {
457 for (--i; i != 0; --i) {
459 switch (ptrChunk.
Kind) {
469 if (onlyBlockPointers)
478 llvm_unreachable(
"bad declarator chunk kind");
484 llvm_unreachable(
"bad declarator chunk kind");
501 Declarator &declarator = state.getDeclarator();
504 for (
unsigned i = state.getCurrentChunkIndex(); i != 0; --i) {
506 switch (chunk.
Kind) {
512 if (state.isProcessingDeclSpec() &&
513 attr.getKind() == ParsedAttr::AT_ObjCOwnership)
516 if (!destChunk) destChunk = &chunk;
529 if (state.isProcessingDeclSpec() &&
530 attr.getKind() == ParsedAttr::AT_ObjCOwnership) {
557 Declarator &declarator = state.getDeclarator();
561 unsigned innermost = -1U;
562 bool considerDeclSpec =
true;
565 switch (chunk.
Kind) {
579 considerDeclSpec =
false;
587 if (considerDeclSpec) {
592 state.saveDeclSpecAttrs();
601 if (innermost != -1U) {
609 state.addIgnoredTypeAttr(
attr);
618 Declarator &declarator = state.getDeclarator();
622 for (
unsigned i = state.getCurrentChunkIndex(); i != 0; --i) {
624 switch (chunk.
Kind) {
651 Declarator &declarator = state.getDeclarator();
671 state.saveDeclSpecAttrs();
675 state,
attr, state.getCurrentAttributes(), declSpecType, CFT))
680 state.addIgnoredTypeAttr(
attr);
691 Declarator &declarator = state.getDeclarator();
701 state.addIgnoredTypeAttr(
attr);
726 if (
attr.isStandardAttributeSyntax() ||
attr.isRegularKeywordAttribute())
729 switch (
attr.getKind()) {
746 case ParsedAttr::AT_ObjCKindOf:
759 Declarator &declarator = state.getDeclarator();
805 {}, loc, loc, declarator));
820 typedef std::pair<DeclSpec::TQ, SourceLocation> QualLoc;
825 if (!(RemoveTQs & Qual.first))
829 if (TypeQuals & Qual.first)
830 S.
Diag(Qual.second, DiagID)
835 TypeQuals &= ~Qual.first;
849 if (AL.isInvalid() || !AL.isTypeAttr())
852 diag::warn_block_literal_attributes_on_omitted_return_type)
854 ToBeRemoved.push_back(&AL);
864 diag::warn_block_literal_qualifiers_on_omitted_return_type);
870static OpenCLAccessAttr::Spelling
873 if (AL.getKind() == ParsedAttr::AT_OpenCLAccess)
874 return static_cast<OpenCLAccessAttr::Spelling
>(AL.getSemanticSpelling());
875 return OpenCLAccessAttr::Keyword_read_only;
878static UnaryTransformType::UTTKind
881#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
883 return UnaryTransformType::Enum;
884#include "clang/Basic/TransformTypeTraits.def"
886 llvm_unreachable(
"attempted to parse a non-unary transform builtin");
900 Sema &S = state.getSema();
901 Declarator &declarator = state.getDeclarator();
912 Result = Context.VoidTy;
916 Result = Context.CharTy;
918 Result = Context.SignedCharTy;
921 "Unknown TSS value");
922 Result = Context.UnsignedCharTy;
927 Result = Context.WCharTy;
931 Context.getPrintingPolicy());
932 Result = Context.getSignedWCharType();
935 "Unknown TSS value");
938 Context.getPrintingPolicy());
939 Result = Context.getUnsignedWCharType();
944 "Unknown TSS value");
945 Result = Context.Char8Ty;
949 "Unknown TSS value");
950 Result = Context.Char16Ty;
954 "Unknown TSS value");
955 Result = Context.Char32Ty;
965 Result = Context.getAutoDeductType();
969 Context.DependentTy)) {
970 Result = Context.DependentTy;
982 S.
Diag(DeclLoc, diag::warn_missing_type_specifier)
991 S.
Diag(DeclLoc, diag::err_missing_type_specifier)
1000 S.
Diag(DeclLoc, diag::err_missing_actual_pipe_type)
1005 "implicit int is disabled?");
1006 S.
Diag(DeclLoc, diag::ext_missing_type_specifier)
1017 Result = Context.IntTy;
1020 Result = Context.ShortTy;
1023 Result = Context.LongTy;
1026 Result = Context.LongLongTy;
1033 diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
1042 Result = Context.UnsignedIntTy;
1045 Result = Context.UnsignedShortTy;
1048 Result = Context.UnsignedLongTy;
1051 Result = Context.UnsignedLongLongTy;
1058 diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
1073 if (Result.isNull()) {
1074 Result = Context.IntTy;
1082 Result = Context.ShortAccumTy;
1085 Result = Context.AccumTy;
1088 Result = Context.LongAccumTy;
1091 llvm_unreachable(
"Unable to specify long long as _Accum width");
1095 Result = Context.getCorrespondingUnsignedType(Result);
1098 Result = Context.getCorrespondingSaturatedType(Result);
1105 Result = Context.ShortFractTy;
1108 Result = Context.FractTy;
1111 Result = Context.LongFractTy;
1114 llvm_unreachable(
"Unable to specify long long as _Fract width");
1118 Result = Context.getCorrespondingUnsignedType(Result);
1121 Result = Context.getCorrespondingSaturatedType(Result);
1131 Result = Context.UnsignedInt128Ty;
1133 Result = Context.Int128Ty;
1143 Result = Context.Float16Ty;
1151 Result = Context.BFloat16Ty;
1156 Result = Context.LongDoubleTy;
1158 Result = Context.DoubleTy;
1163 << (S.
getLangOpts().getOpenCLCompatibleVersion() == 300
1164 ?
"cl_khr_fp64 and __opencl_c_fp64"
1175 Result = Context.Float128Ty;
1182 Result = Context.Ibm128Ty;
1185 Result = Context.BoolTy;
1191 Result = Context.IntTy;
1202 Result = Context.IntTy;
1213 "No qualifiers on tag names!");
1226 "Can't handle qualifiers on typedef names yet!");
1228 if (Result.isNull()) {
1239 assert(!Result.isNull() &&
"Didn't get a type for typeof?");
1240 if (!Result->isDependentType())
1241 if (
const TagType *TT = Result->getAs<TagType>())
1244 Result = Context.getTypeOfType(
1252 assert(E &&
"Didn't get an expression for typeof?");
1258 if (Result.isNull()) {
1259 Result = Context.IntTy;
1266 assert(E &&
"Didn't get an expression for decltype?");
1269 if (Result.isNull()) {
1270 Result = Context.IntTy;
1277 assert(E &&
"Didn't get an expression for pack indexing");
1281 if (Result.isNull()) {
1283 Result = Context.IntTy;
1288#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case DeclSpec::TST_##Trait:
1289#include "clang/Basic/TransformTypeTraits.def"
1291 assert(!Result.isNull() &&
"Didn't get a type for the transformation?");
1295 if (Result.isNull()) {
1296 Result = Context.IntTy;
1311 TypeConstraintConcept =
1317 TemplateId->NumArgs);
1319 for (
const auto &ArgLoc : TemplateArgsInfo.
arguments())
1320 TemplateArgs.push_back(ArgLoc.getArgument());
1327 TypeConstraintConcept, TemplateArgs);
1336 Result = Context.UnknownAnyTy;
1341 assert(!Result.isNull() &&
"Didn't get a type for _Atomic?");
1343 if (Result.isNull()) {
1344 Result = Context.IntTy;
1349#define GENERIC_IMAGE_TYPE(ImgType, Id) \
1350 case DeclSpec::TST_##ImgType##_t: \
1351 switch (getImageAccess(DS.getAttributes())) { \
1352 case OpenCLAccessAttr::Keyword_write_only: \
1353 Result = Context.Id##WOTy; \
1355 case OpenCLAccessAttr::Keyword_read_write: \
1356 Result = Context.Id##RWTy; \
1358 case OpenCLAccessAttr::Keyword_read_only: \
1359 Result = Context.Id##ROTy; \
1361 case OpenCLAccessAttr::SpellingNotCalculated: \
1362 llvm_unreachable("Spelling not yet calculated"); \
1365#include "clang/Basic/OpenCLImageTypes.def"
1367#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1368 case DeclSpec::TST_##Name: \
1369 Result = Context.SingletonId; \
1371#include "clang/Basic/HLSLIntangibleTypes.def"
1374 Result = Context.IntTy;
1382 if (Result->containsErrors())
1387 bool IsOpenCLC30Compatible =
1396 if ((Result->isImageType() || Result->isSamplerT()) &&
1397 (IsOpenCLC30Compatible &&
1400 << 0 << Result <<
"__opencl_c_images";
1402 }
else if (Result->isOCLImage3dWOType() &&
1407 << (IsOpenCLC30Compatible
1408 ?
"cl_khr_3d_image_writes and __opencl_c_3d_image_writes"
1409 :
"cl_khr_3d_image_writes");
1421 Context.getPrintingPolicy());
1427 Result = Context.getComplexType(Result);
1429 unsigned typeSize =
static_cast<unsigned>(Context.getTypeSize(Result));
1430 assert(typeSize > 0 &&
"type size for vector must be greater than 0 bits");
1436 Result = Context.getVectorType(Result, 128/typeSize, VecKind);
1461 if (AL.slidesFromDeclToDeclSpecLegacyBehavior()) {
1472 if (AL.isStandardAttributeSyntax() && AL.isClangScope() &&
1473 !(AL.getKind() == ParsedAttr::AT_MatrixType &&
1475 S.
Diag(AL.getLoc(), diag::warn_type_attribute_deprecated_on_decl)
1503 if (Result->isFunctionType()) {
1504 unsigned DiagId = diag::warn_typecheck_function_qualifiers_ignored;
1506 DiagId = diag::ext_typecheck_function_qualifiers_unspecified;
1522 if (TypeQuals && Result->isReferenceType()) {
1524 S, DS, TypeQuals, Result,
1526 diag::warn_typecheck_reference_qualifiers);
1533 && TypeQuals & Result.getCVRQualifiers()) {
1560 assert(!Result.isNull() &&
"This function should not return a null type");
1572 if (
T->isDependentType())
1575 const auto *AT = dyn_cast<AutoType>(
T);
1576 return AT && AT->isGNUAutoType();
1585 if (
T->isReferenceType()) {
1593 unsigned DiagID = 0;
1607 DiagID = diag::err_typecheck_invalid_restrict_invalid_pointee;
1613 DiagID = diag::err_typecheck_invalid_restrict_not_pointer;
1619 Diag(Loc, DiagID) << EltTy;
1622 if (
T->isArrayType())
1624 ? diag::warn_c23_compat_restrict_on_array_of_pointers
1625 : diag::ext_restrict_on_array_of_pointers_c23);
1629 return Context.getQualifiedType(
T, Qs);
1633 unsigned CVRAU,
const DeclSpec *DS) {
1638 if (
T->isReferenceType())
1667 Split.Quals.addCVRQualifiers(CVR);
1685 if (!
type->isObjCLifetimeType() ||
1695 if (
type.isConstQualified()) {
1701 }
else if (
type->isObjCARCImplicitlyUnretainedType()) {
1719 diag::err_arc_indirect_no_ownership,
type, isReference));
1721 S.
Diag(loc, diag::err_arc_indirect_no_ownership) <<
type << isReference;
1725 assert(implicitLifetime &&
"didn't infer any lifetime!");
1766enum QualifiedFunctionKind { QFK_BlockPointer, QFK_Pointer, QFK_Reference };
1772 QualifiedFunctionKind QFK) {
1779 S.
Diag(Loc, diag::err_compound_qualified_function_type)
1780 << QFK << isa<FunctionType>(
T.IgnoreParens()) <<
T
1791 Diag(Loc, diag::err_qualified_function_typeid)
1808 if (
T->isReferenceType()) {
1810 Diag(Loc, diag::err_illegal_decl_pointer_to_reference)
1818 Diag(Loc, diag::err_opencl_function_pointer) << 0;
1823 Diag(Loc, diag::err_hlsl_pointers_unsupported) << 0;
1830 if (
T->isObjCObjectType())
1831 return Context.getObjCObjectPointerType(
T);
1843 if (
T.isWebAssemblyReferenceType()) {
1844 Diag(Loc, diag::err_wasm_reference_pr) << 0;
1849 if (
T->getUnqualifiedDesugaredType()->isWebAssemblyTableType()) {
1850 Diag(Loc, diag::err_wasm_table_pr) << 0;
1863 "Unresolved overloaded function type");
1890 if (
T->isVoidType()) {
1891 Diag(Loc, diag::err_reference_to_void);
1896 Diag(Loc, diag::err_hlsl_pointers_unsupported) << 1;
1906 Diag(Loc, diag::err_opencl_function_pointer) << 1;
1919 T.isWebAssemblyReferenceType()) {
1920 Diag(Loc, diag::err_wasm_reference_pr) << 1;
1923 if (
T->isWebAssemblyTableType()) {
1924 Diag(Loc, diag::err_wasm_table_pr) << 1;
1930 return Context.getLValueReferenceType(
T, SpelledAsLValue);
1931 return Context.getRValueReferenceType(
T);
1939 return Context.getWritePipeType(
T);
1945 return Context.getDependentBitIntType(IsUnsigned, BitWidth);
1947 llvm::APSInt Bits(32);
1954 size_t NumBits = Bits.getZExtValue();
1955 if (!IsUnsigned && NumBits < 2) {
1956 Diag(Loc, diag::err_bit_int_bad_size) << 0;
1960 if (IsUnsigned && NumBits < 1) {
1961 Diag(Loc, diag::err_bit_int_bad_size) << 1;
1967 Diag(Loc, diag::err_bit_int_max_size)
1972 return Context.getBitIntType(IsUnsigned, NumBits);
1981 llvm::APSInt &SizeVal,
unsigned VLADiag,
2006 VLADiagnoser(
unsigned VLADiag,
bool VLAIsError)
2007 : VLADiag(VLADiag), VLAIsError(VLAIsError) {}
2011 return S.
Diag(Loc, diag::err_array_size_non_int) <<
T;
2016 IsVLA = !VLAIsError;
2017 return S.
Diag(Loc, VLADiag);
2022 return S.
Diag(Loc, diag::ext_vla_folded_to_constant);
2024 } Diagnoser(VLADiag, VLAIsError);
2028 if (Diagnoser.IsVLA)
2034 EltTy =
Context.getBaseElementType(EltTy);
2042 if (Size.isMultipleOf(Alignment))
2045 Diag(Loc, diag::err_array_element_alignment)
2046 << EltTy << Size.getQuantity() << Alignment.
getQuantity();
2051 Expr *ArraySize,
unsigned Quals,
2067 if (
T->isReferenceType()) {
2068 Diag(Loc, diag::err_illegal_decl_array_of_references)
2073 if (
T->isVoidType() ||
T->isIncompleteArrayType()) {
2074 Diag(Loc, diag::err_array_incomplete_or_sizeless_type) << 0 <<
T;
2079 diag::err_array_of_abstract_type))
2084 if (
Context.getTargetInfo().getCXXABI().isMicrosoft())
2086 if (!MPTy->getQualifier().isDependent())
2092 if (!
T.isWebAssemblyReferenceType() &&
2094 diag::err_array_incomplete_or_sizeless_type))
2099 if (
Context.getTargetInfo().getTriple().isWasm() &&
T->isArrayType()) {
2100 const auto *ATy = dyn_cast<ArrayType>(
T);
2101 if (ATy && ATy->getElementType().isWebAssemblyReferenceType()) {
2102 Diag(Loc, diag::err_wasm_reftype_multidimensional_array);
2107 if (
T->isSizelessType() && !
T.isWebAssemblyReferenceType()) {
2108 Diag(Loc, diag::err_array_incomplete_or_sizeless_type) << 1 <<
T;
2112 if (
T->isFunctionType()) {
2113 Diag(Loc, diag::err_illegal_decl_array_of_functions)
2118 if (
const auto *RD =
T->getAsRecordDecl()) {
2121 if (RD->hasFlexibleArrayMember())
2122 Diag(Loc, diag::ext_flexible_array_in_array) <<
T;
2123 }
else if (
T->isObjCObjectType()) {
2124 Diag(Loc, diag::err_objc_array_of_interfaces) <<
T;
2135 ArraySize =
Result.get();
2139 if (ArraySize && !ArraySize->
isPRValue()) {
2144 ArraySize =
Result.get();
2167 if (
const auto *CondExpr = dyn_cast_if_present<ConditionalOperator>(
2169 std::optional<llvm::APSInt> LHS =
2170 CondExpr->getLHS()->getIntegerConstantExpr(
Context);
2171 std::optional<llvm::APSInt> RHS =
2172 CondExpr->getRHS()->getIntegerConstantExpr(
Context);
2173 return LHS && RHS && LHS->isNegative() != RHS->isNegative();
2183 VLADiag = diag::err_opencl_vla;
2186 VLADiag = diag::warn_vla_used;
2189 VLADiag = diag::err_vla_in_sfinae;
2192 VLADiag = diag::err_openmp_vla_in_task_untied;
2197 ? diag::ext_vla_cxx_in_gnu_mode_static_assert
2198 : diag::ext_vla_cxx_static_assert;
2200 VLADiag =
getLangOpts().GNUMode ? diag::ext_vla_cxx_in_gnu_mode
2201 : diag::ext_vla_cxx;
2204 VLADiag = diag::ext_vla;
2208 llvm::APSInt ConstVal(
Context.getTypeSize(
Context.getSizeType()));
2215 T =
Context.getVariableArrayType(
T,
nullptr, ASM, Quals);
2217 T =
Context.getIncompleteArrayType(
T, ASM, Quals);
2220 T =
Context.getDependentSizedArrayType(
T, ArraySize, ASM, Quals);
2231 T =
Context.getVariableArrayType(
T, ArraySize, ASM, Quals);
2232 }
else if (!
T->isDependentType() && !
T->isIncompleteType() &&
2233 !
T->isConstantSizeType()) {
2240 T =
Context.getVariableArrayType(
T, ArraySize, ASM, Quals);
2245 if (ConstVal.isSigned() && ConstVal.isNegative()) {
2252 diag::err_typecheck_negative_array_size)
2256 if (ConstVal == 0 && !
T.isWebAssemblyReferenceType()) {
2261 : diag::ext_typecheck_zero_array_size)
2266 unsigned ActiveSizeBits =
2267 (!
T->isDependentType() && !
T->isVariablyModifiedType() &&
2268 !
T->isIncompleteType() && !
T->isUndeducedType())
2270 : ConstVal.getActiveBits();
2273 <<
toString(ConstVal, 10, ConstVal.isSigned(),
2280 T =
Context.getConstantArrayType(
T, ConstVal, ArraySize, ASM, Quals);
2284 if (
T->isVariableArrayType()) {
2285 if (!
Context.getTargetInfo().isVLASupported()) {
2289 IsCUDADevice ? diag::err_cuda_vla : diag::err_vla_unsupported)
2290 << (IsCUDADevice ? llvm::to_underlying(
CUDA().CurrentTarget()) : 0);
2294 FSI->setHasVLA(Loc);
2302 : diag::ext_c99_array_usage)
2313 Diag(Loc, diag::err_opencl_invalid_type_array) << ArrType;
2323 bool ForMatrixType =
false) {
2326 if (!llvm::isPowerOf2_32(NumBits))
2327 return S.
Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
2341 Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << CurType;
2350 return Context.getDependentVectorType(CurType, SizeExpr, AttrLoc,
2353 std::optional<llvm::APSInt> VecSize =
2356 Diag(AttrLoc, diag::err_attribute_argument_type)
2363 return Context.getDependentVectorType(CurType, SizeExpr, AttrLoc,
2367 if (!VecSize->isIntN(61)) {
2369 Diag(AttrLoc, diag::err_attribute_size_too_large)
2373 uint64_t VectorSizeBits = VecSize->getZExtValue() * 8;
2374 unsigned TypeSize =
static_cast<unsigned>(
Context.getTypeSize(CurType));
2376 if (VectorSizeBits == 0) {
2377 Diag(AttrLoc, diag::err_attribute_zero_size)
2382 if (!TypeSize || VectorSizeBits % TypeSize) {
2383 Diag(AttrLoc, diag::err_attribute_invalid_size)
2388 if (VectorSizeBits / TypeSize > std::numeric_limits<uint32_t>::max()) {
2389 Diag(AttrLoc, diag::err_attribute_size_too_large)
2394 return Context.getVectorType(CurType, VectorSizeBits / TypeSize,
2410 if ((!
T->isDependentType() && !
T->isIntegerType() &&
2411 !
T->isRealFloatingType()) ||
2412 (IsNoBoolVecLang &&
T->isBooleanType())) {
2413 Diag(AttrLoc, diag::err_attribute_invalid_vector_type) <<
T;
2422 std::optional<llvm::APSInt> vecSize =
2425 Diag(AttrLoc, diag::err_attribute_argument_type)
2431 if (!vecSize->isIntN(32)) {
2432 Diag(AttrLoc, diag::err_attribute_size_too_large)
2438 unsigned vectorSize =
static_cast<unsigned>(vecSize->getZExtValue());
2440 if (vectorSize == 0) {
2441 Diag(AttrLoc, diag::err_attribute_zero_size)
2446 return Context.getExtVectorType(
T, vectorSize);
2449 return Context.getDependentSizedExtVectorType(
T, ArraySize, AttrLoc);
2454 assert(
Context.getLangOpts().MatrixTypes &&
2455 "Should never build a matrix type when it is disabled");
2460 Diag(AttrLoc, diag::err_attribute_invalid_matrix_type) << ElementTy;
2471 return Context.getDependentSizedMatrixType(ElementTy, NumRows, NumCols,
2474 std::optional<llvm::APSInt> ValueRows =
2476 std::optional<llvm::APSInt> ValueColumns =
2483 if (!ValueRows && !ValueColumns) {
2484 Diag(AttrLoc, diag::err_attribute_argument_type)
2492 Diag(AttrLoc, diag::err_attribute_argument_type)
2498 if (!ValueColumns) {
2499 Diag(AttrLoc, diag::err_attribute_argument_type)
2505 unsigned MatrixRows =
static_cast<unsigned>(ValueRows->getZExtValue());
2506 unsigned MatrixColumns =
static_cast<unsigned>(ValueColumns->getZExtValue());
2507 if (MatrixRows == 0 && MatrixColumns == 0) {
2508 Diag(AttrLoc, diag::err_attribute_zero_size)
2509 <<
"matrix" << RowRange << ColRange;
2512 if (MatrixRows == 0) {
2513 Diag(AttrLoc, diag::err_attribute_zero_size) <<
"matrix" << RowRange;
2516 if (MatrixColumns == 0) {
2517 Diag(AttrLoc, diag::err_attribute_zero_size) <<
"matrix" << ColRange;
2521 Diag(AttrLoc, diag::err_attribute_size_too_large)
2522 << RowRange <<
"matrix row";
2526 Diag(AttrLoc, diag::err_attribute_size_too_large)
2527 << ColRange <<
"matrix column";
2530 return Context.getConstantMatrixType(ElementTy, MatrixRows, MatrixColumns);
2534 if ((
T->isArrayType() && !
getLangOpts().allowArrayReturnTypes()) ||
2535 T->isFunctionType()) {
2536 Diag(Loc, diag::err_func_returning_array_function)
2537 <<
T->isFunctionType() <<
T;
2542 if (
T->isHalfType() && !
getLangOpts().NativeHalfArgsAndReturns &&
2543 !
Context.getTargetInfo().allowHalfArgsAndReturns()) {
2544 Diag(Loc, diag::err_parameters_retval_cannot_have_fp16_type) << 1 <<
2551 if (
T->isObjCObjectType()) {
2552 Diag(Loc, diag::err_object_cannot_be_passed_returned_by_value)
2558 if (
T.getPointerAuth()) {
2559 Diag(Loc, diag::err_ptrauth_qualifier_invalid) <<
T << 0;
2563 if (
T.hasNonTrivialToPrimitiveDestructCUnion() ||
2564 T.hasNonTrivialToPrimitiveCopyCUnion())
2571 Diag(Loc, diag::warn_deprecated_volatile_return) <<
T;
2586 bool emittedError =
false;
2588 enum class RequiredCC { OnlySwift, SwiftOrSwiftAsync };
2589 auto checkCompatible = [&](
unsigned paramIndex, RequiredCC required) {
2591 (required == RequiredCC::OnlySwift)
2594 if (isCompatible || emittedError)
2596 S.
Diag(getParamLoc(paramIndex), diag::err_swift_param_attr_not_swiftcall)
2598 << (required == RequiredCC::OnlySwift);
2599 emittedError =
true;
2601 for (
size_t paramIndex = 0, numParams = paramTypes.size();
2602 paramIndex != numParams; ++paramIndex) {
2613 checkCompatible(paramIndex, RequiredCC::SwiftOrSwiftAsync);
2614 if (paramIndex != 0 &&
2617 S.
Diag(getParamLoc(paramIndex),
2618 diag::err_swift_indirect_result_not_first);
2623 checkCompatible(paramIndex, RequiredCC::SwiftOrSwiftAsync);
2632 checkCompatible(paramIndex, RequiredCC::OnlySwift);
2633 if (paramIndex == 0 ||
2636 S.
Diag(getParamLoc(paramIndex),
2637 diag::err_swift_error_result_not_after_swift_context);
2641 llvm_unreachable(
"bad ABI kind");
2653 for (
unsigned Idx = 0, Cnt = ParamTypes.size(); Idx < Cnt; ++Idx) {
2655 QualType ParamType =
Context.getAdjustedParameterType(ParamTypes[Idx]);
2657 Diag(Loc, diag::err_param_with_void_type);
2660 !
Context.getTargetInfo().allowHalfArgsAndReturns()) {
2662 Diag(Loc, diag::err_parameters_retval_cannot_have_fp16_type) << 0 <<
2666 Diag(Loc, diag::err_wasm_table_as_function_parameter);
2670 Diag(Loc, diag::err_ptrauth_qualifier_invalid) <<
T << 1;
2677 Diag(Loc, diag::warn_deprecated_volatile_param) << ParamType;
2679 ParamTypes[Idx] = ParamType;
2684 [=](
unsigned i) {
return Loc; });
2695 return Context.getFunctionType(
T, ParamTypes, EPI);
2710 D <<
"member pointer";
2718 Diag(Loc, diag::err_distant_exception_spec);
2724 if (
T->isReferenceType()) {
2725 Diag(Loc, diag::err_illegal_decl_mempointer_to_reference)
2730 if (
T->isVoidType()) {
2731 Diag(Loc, diag::err_illegal_decl_mempointer_to_void)
2739 Diag(Loc, diag::err_opencl_function_pointer) << 0;
2744 Diag(Loc, diag::err_hlsl_pointers_unsupported) << 0;
2753 if (
T->isFunctionType())
2762 if (!
T->isFunctionType()) {
2763 Diag(Loc, diag::err_nonfunction_block_type);
2773 return Context.getBlockPointerType(
T);
2779 if (TInfo) *TInfo =
nullptr;
2784 if (
const LocInfoType *LIT = dyn_cast<LocInfoType>(QT)) {
2785 QT = LIT->getType();
2786 DI = LIT->getTypeSourceInfo();
2789 if (TInfo) *TInfo = DI;
2795 unsigned chunkIndex);
2802 Sema &S = state.getSema();
2803 Declarator &declarator = state.getDeclarator();
2809 unsigned outermostPointerIndex = 0;
2811 unsigned numPointers = 0;
2813 unsigned chunkIndex = i;
2815 switch (chunk.
Kind) {
2825 outermostPointerIndex = chunkIndex;
2833 if (numPointers != 1)
return;
2835 outermostPointerIndex = chunkIndex;
2853 if (numPointers == 1) {
2871 }
else if (numPointers == 2) {
2884 if (AL.getKind() == ParsedAttr::AT_ObjCOwnership)
2888 outermostPointerIndex);
2910 }
const QualKinds[5] = {
2924 for (
auto &E : QualKinds) {
2925 if (Quals & E.Mask) {
2926 if (!QualStr.empty()) QualStr +=
' ';
2943 << QualStr <<
NumQuals << FixIts[0] << FixIts[1] << FixIts[2] << FixIts[3];
2949 unsigned FunctionChunkIndex) {
2959 for (
unsigned OuterChunkIndex = FunctionChunkIndex + 1,
2961 OuterChunkIndex != End; ++OuterChunkIndex) {
2963 switch (OuterChunk.
Kind) {
2970 diag::warn_qual_return_type,
2996 llvm_unreachable(
"unknown declarator chunk kind");
3017static std::pair<QualType, TypeSourceInfo *>
3021 Sema &S = state.getSema();
3025 const unsigned AutoParameterPosition = Info.
TemplateParams.size();
3039 TemplateParameterDepth, AutoParameterPosition,
3042 IsParameterPack,
Auto->isConstrained());
3047 if (
Auto->isConstrained()) {
3054 for (
unsigned Idx = 0; Idx < AutoLoc.
getNumArgs(); ++Idx) {
3112 QualType NewT = state.ReplaceAutoType(
T, Replacement);
3116 return {NewT, NewTSI};
3125 Sema &SemaRef = state.getSema();
3128 ReturnTypeInfo =
nullptr;
3131 TagDecl *OwnedTagDecl =
nullptr;
3181 DeducedType *Deduced =
T->getContainedDeducedType();
3182 bool DeducedIsTrailingReturnType =
false;
3185 Deduced =
T.isNull() ?
nullptr :
T->getContainedDeducedType();
3186 DeducedIsTrailingReturnType =
true;
3191 AutoType *
Auto = dyn_cast<AutoType>(Deduced);
3196 bool IsCXXAutoType =
3198 bool IsDeducedReturnType =
false;
3239 assert(Info &&
"No LambdaScopeInfo on the stack!");
3245 if (!DeducedIsTrailingReturnType)
3258 llvm_unreachable(
"unhandled tag kind");
3260 Error = Cxx ? 1 : 2;
3263 Error = Cxx ? 3 : 4;
3308 if (!SemaRef.
getLangOpts().CPlusPlus14 || !IsCXXAutoType)
3310 IsDeducedReturnType =
true;
3313 if (!SemaRef.
getLangOpts().CPlusPlus14 || !IsCXXAutoType)
3315 IsDeducedReturnType =
true;
3320 if (SemaRef.
getLangOpts().CPlusPlus23 && IsCXXAutoType &&
3321 !
Auto->isDecltypeAuto())
3354 (!SemaRef.
getLangOpts().CPlusPlus11 || !IsCXXAutoType))
3364 switch (
Auto->getKeyword()) {
3371 "unknown auto type");
3375 auto *DTST = dyn_cast<DeducedTemplateSpecializationType>(Deduced);
3378 SemaRef.
Diag(AutoRange.
getBegin(), diag::err_auto_not_allowed)
3380 <<
QualType(Deduced, 0) << AutoRange;
3391 unsigned DiagId = 0;
3393 DiagId = diag::warn_cxx11_compat_generic_lambda;
3394 else if (IsDeducedReturnType)
3395 DiagId = diag::warn_cxx11_compat_deduced_return_type;
3397 DiagId = diag::warn_cxx98_compat_auto_type_specifier;
3400 SemaRef.
Diag(AutoRange.
getBegin(), DiagId) << AutoRange;
3408 unsigned DiagID = 0;
3414 llvm_unreachable(
"parser should not have allowed this");
3430 DiagID = diag::err_type_defined_in_alias_template;
3442 DiagID = diag::err_type_defined_in_type_specifier;
3452 DiagID = diag::err_type_defined_in_param_type;
3458 DiagID = diag::err_type_defined_in_condition;
3469 assert(!
T.isNull() &&
"This function should not return a null type");
3478 assert(FTI.
isAmbiguous &&
"no direct-initializer / function ambiguity");
3508 FTI.
NumParams ? diag::warn_parens_disambiguated_as_function_declaration
3509 : diag::warn_empty_parens_are_function_decl)
3520 if (Comma.getFileID() != Name.
getFileID() ||
3528 Result.suppressDiagnostics();
3541 S.
Diag(B, diag::note_additional_parens_for_variable_declaration)
3556 S.
Diag(DeclType.
Loc, diag::note_empty_parens_default_ctor)
3564 S.
Diag(DeclType.
Loc, diag::note_empty_parens_zero_initialize)
3575 "do not have redundant top-level parentheses");
3584 bool CouldBeTemporaryObject =
3588 (
T->isRecordType() ||
T->isDependentType()) &&
3591 bool StartsWithDeclaratorId =
true;
3599 StartsWithDeclaratorId =
false;
3604 CouldBeTemporaryObject =
false;
3612 CouldBeTemporaryObject =
false;
3613 StartsWithDeclaratorId =
false;
3623 CouldBeTemporaryObject =
false;
3630 CouldBeTemporaryObject =
false;
3631 StartsWithDeclaratorId =
false;
3641 if (CouldBeTemporaryObject) {
3645 CouldBeTemporaryObject =
false;
3646 Result.suppressDiagnostics();
3651 if (!CouldBeTemporaryObject) {
3675 S.
Diag(
Paren.Loc, diag::warn_redundant_parens_around_declarator)
3681 S.
Diag(
Paren.Loc, diag::warn_parens_disambiguated_as_variable_declaration)
3683 auto *RD =
T->getAsCXXRecordDecl();
3684 if (!RD || !RD->hasDefinition() || RD->hasNonTrivialDestructor())
3685 S.
Diag(
Paren.Loc, diag::note_raii_guard_add_name)
3690 S.
Diag(D.
getBeginLoc(), diag::note_function_style_cast_add_parentheses)
3693 S.
Diag(
Paren.Loc, diag::note_remove_parens_for_variable_declaration)
3709 switch (AL.getKind()) {
3728 bool IsCXXInstanceMethod =
false;
3734 unsigned I = ChunkIndex;
3735 bool FoundNonParen =
false;
3736 while (I && !FoundNonParen) {
3739 FoundNonParen =
true;
3742 if (FoundNonParen) {
3745 IsCXXInstanceMethod =
3750 IsCXXInstanceMethod =
3758 IsCXXInstanceMethod =
3766 IsCXXInstanceMethod);
3774 if (Triple.isSPIRV() && Triple.getVendor() != llvm::Triple::AMD) {
3776 if (AL.getKind() == ParsedAttr::AT_CUDAGlobal) {
3785 if (AL.getKind() == ParsedAttr::AT_DeviceKernel) {
3797 enum class SimplePointerKind {
3806 switch (nullability) {
3808 if (!Ident__Nonnull)
3809 Ident__Nonnull =
PP.getIdentifierInfo(
"_Nonnull");
3810 return Ident__Nonnull;
3813 if (!Ident__Nullable)
3814 Ident__Nullable =
PP.getIdentifierInfo(
"_Nullable");
3815 return Ident__Nullable;
3818 if (!Ident__Nullable_result)
3819 Ident__Nullable_result =
PP.getIdentifierInfo(
"_Nullable_result");
3820 return Ident__Nullable_result;
3823 if (!Ident__Null_unspecified)
3824 Ident__Null_unspecified =
PP.getIdentifierInfo(
"_Null_unspecified");
3825 return Ident__Null_unspecified;
3827 llvm_unreachable(
"Unknown nullability kind.");
3834 if (AL.getKind() == ParsedAttr::AT_TypeNonNull ||
3835 AL.getKind() == ParsedAttr::AT_TypeNullable ||
3836 AL.getKind() == ParsedAttr::AT_TypeNullableResult ||
3837 AL.getKind() == ParsedAttr::AT_TypeNullUnspecified)
3846 enum class PointerDeclaratorKind {
3854 MaybePointerToCFRef,
3858 NSErrorPointerPointer,
3864 enum class PointerWrappingDeclaratorKind {
3878static PointerDeclaratorKind
3880 PointerWrappingDeclaratorKind &wrappingKind) {
3881 unsigned numNormalPointers = 0;
3884 if (
type->isDependentType())
3885 return PointerDeclaratorKind::NonPointer;
3890 switch (chunk.
Kind) {
3892 if (numNormalPointers == 0)
3893 wrappingKind = PointerWrappingDeclaratorKind::Array;
3902 return numNormalPointers > 0 ? PointerDeclaratorKind::MultiLevelPointer
3903 : PointerDeclaratorKind::SingleLevelPointer;
3909 if (numNormalPointers == 0)
3910 wrappingKind = PointerWrappingDeclaratorKind::Reference;
3914 ++numNormalPointers;
3915 if (numNormalPointers > 2)
3916 return PointerDeclaratorKind::MultiLevelPointer;
3922 unsigned numTypeSpecifierPointers = 0;
3926 ++numNormalPointers;
3928 if (numNormalPointers > 2)
3929 return PointerDeclaratorKind::MultiLevelPointer;
3931 type = ptrType->getPointeeType();
3932 ++numTypeSpecifierPointers;
3938 return numNormalPointers > 0 ? PointerDeclaratorKind::MultiLevelPointer
3939 : PointerDeclaratorKind::SingleLevelPointer;
3944 return numNormalPointers > 0 ? PointerDeclaratorKind::MultiLevelPointer
3945 : PointerDeclaratorKind::SingleLevelPointer;
3950 ++numNormalPointers;
3951 ++numTypeSpecifierPointers;
3954 if (
auto objcClassDecl = objcObjectPtr->getInterfaceDecl()) {
3956 numNormalPointers == 2 && numTypeSpecifierPointers < 2) {
3957 return PointerDeclaratorKind::NSErrorPointerPointer;
3966 if (objcClass->getInterface()->getIdentifier() ==
3968 if (numNormalPointers == 2 && numTypeSpecifierPointers < 2)
3969 return PointerDeclaratorKind::NSErrorPointerPointer;
3976 if (numNormalPointers == 0)
3977 return PointerDeclaratorKind::NonPointer;
3981 if (numNormalPointers == 2 && numTypeSpecifierPointers < 2 &&
3983 return PointerDeclaratorKind::CFErrorRefPointer;
3991 switch (numNormalPointers) {
3993 return PointerDeclaratorKind::NonPointer;
3996 return PointerDeclaratorKind::SingleLevelPointer;
3999 return PointerDeclaratorKind::MaybePointerToCFRef;
4002 return PointerDeclaratorKind::MultiLevelPointer;
4011 if (ctx->isFunctionOrMethod())
4014 if (ctx->isFileContext())
4025 bool invalid =
false;
4027 if (invalid || !sloc.
isFile())
4045template <
typename DiagBuilderT>
4054 if (!FixItLoc.
isValid() || FixItLoc == PointerLoc)
4063 InsertionTextBuf +=
" ";
4064 StringRef InsertionText = InsertionTextBuf.str();
4067 InsertionText = InsertionText.drop_back();
4068 }
else if (NextChar[-1] ==
'[') {
4069 if (NextChar[0] ==
']')
4070 InsertionText = InsertionText.drop_back().drop_front();
4072 InsertionText = InsertionText.drop_front();
4075 InsertionText = InsertionText.drop_back().drop_front();
4082 SimplePointerKind PointerKind,
4087 if (PointerKind == SimplePointerKind::Array) {
4088 S.
Diag(PointerLoc, diag::warn_nullability_missing_array);
4090 S.
Diag(PointerLoc, diag::warn_nullability_missing)
4091 <<
static_cast<unsigned>(PointerKind);
4094 auto FixItLoc = PointerEndLoc.
isValid() ? PointerEndLoc : PointerLoc;
4095 if (FixItLoc.isMacroID())
4099 auto Diag = S.
Diag(FixItLoc, diag::note_nullability_fix_it);
4130 if (pointerKind == SimplePointerKind::Array)
4131 diagKind = diag::warn_nullability_missing_array;
4133 diagKind = diag::warn_nullability_missing;
4139 fileNullability.
PointerKind =
static_cast<unsigned>(pointerKind);
4171 auto kind =
static_cast<SimplePointerKind
>(fileNullability.
PointerKind);
4186 unsigned i = endIndex;
4214template<
typename AttrT>
4217 return ::new (Ctx) AttrT(Ctx, AL);
4235 llvm_unreachable(
"unknown NullabilityKind");
4246 if (ASOld != ASNew) {
4247 S.
Diag(AttrLoc, diag::err_attribute_address_multiple_qualifiers);
4252 diag::warn_attribute_address_multiple_identical_qualifiers);
4261 return T->canHaveNullability(
false) &&
4267 T->getCanonicalTypeInternal());
4277 Sema &S = state.getSema();
4287 bool IsTypedefName =
4293 bool IsQualifiedFunction =
T->isFunctionProtoType() &&
4301 if (
auto *DT =
T->getAs<DeducedType>()) {
4302 const AutoType *AT =
T->getAs<AutoType>();
4304 if ((AT && AT->isDecltypeAuto()) || IsClassTemplateDeduction) {
4306 unsigned Index = E - I - 1;
4308 unsigned DiagId = IsClassTemplateDeduction
4309 ? diag::err_deduced_class_template_compound_type
4310 : diag::err_decltype_auto_compound_type;
4311 unsigned DiagKind = 0;
4312 switch (DeclChunk.
Kind) {
4316 if (IsClassTemplateDeduction) {
4324 DiagId = diag::err_decltype_auto_function_declarator_not_declaration;
4342 S.
Diag(DeclChunk.
Loc, DiagId) << DiagKind;
4350 std::optional<NullabilityKind> inferNullability;
4351 bool inferNullabilityCS =
false;
4352 bool inferNullabilityInnerOnly =
false;
4353 bool inferNullabilityInnerOnlyComplete =
false;
4356 bool inAssumeNonNullRegion =
false;
4358 if (assumeNonNullLoc.
isValid()) {
4359 inAssumeNonNullRegion =
true;
4373 } complainAboutMissingNullability = CAMN_No;
4374 unsigned NumPointersRemaining = 0;
4375 auto complainAboutInferringWithinChunk = PointerWrappingDeclaratorKind::None;
4377 if (IsTypedefName) {
4381 complainAboutMissingNullability = CAMN_InnerPointers;
4385 ++NumPointersRemaining;
4390 switch (chunk.
Kind) {
4398 ++NumPointersRemaining;
4406 ++NumPointersRemaining;
4411 bool isFunctionOrMethod =
false;
4412 switch (
auto context = state.getDeclarator().getContext()) {
4418 isFunctionOrMethod =
true;
4422 if (state.getDeclarator().isObjCIvar() && !isFunctionOrMethod) {
4423 complainAboutMissingNullability = CAMN_No;
4428 if (state.getDeclarator().isObjCWeakProperty()) {
4431 complainAboutMissingNullability = CAMN_No;
4432 if (inAssumeNonNullRegion) {
4442 complainAboutMissingNullability = CAMN_Yes;
4445 auto wrappingKind = PointerWrappingDeclaratorKind::None;
4447 case PointerDeclaratorKind::NonPointer:
4448 case PointerDeclaratorKind::MultiLevelPointer:
4452 case PointerDeclaratorKind::SingleLevelPointer:
4454 if (inAssumeNonNullRegion) {
4455 complainAboutInferringWithinChunk = wrappingKind;
4462 case PointerDeclaratorKind::CFErrorRefPointer:
4463 case PointerDeclaratorKind::NSErrorPointerPointer:
4466 if (isFunctionOrMethod && inAssumeNonNullRegion)
4470 case PointerDeclaratorKind::MaybePointerToCFRef:
4471 if (isFunctionOrMethod) {
4475 auto hasCFReturnsAttr =
4477 return AttrList.hasAttribute(ParsedAttr::AT_CFReturnsRetained) ||
4478 AttrList.hasAttribute(ParsedAttr::AT_CFReturnsNotRetained);
4483 hasCFReturnsAttr(InnermostChunk->getAttrs()) ||
4486 inferNullabilityInnerOnly =
true;
4496 complainAboutMissingNullability = CAMN_Yes;
4524 auto isVaList = [&S](
QualType T) ->
bool {
4530 if (typedefTy->getDecl() == vaListTypedef)
4532 if (
auto *name = typedefTy->getDecl()->getIdentifier())
4533 if (name->isStr(
"va_list"))
4535 typedefTy = typedefTy->desugar()->getAs<
TypedefType>();
4536 }
while (typedefTy);
4542 auto inferPointerNullability =
4547 if (NumPointersRemaining > 0)
4548 --NumPointersRemaining;
4555 if (inferNullability && !inferNullabilityInnerOnlyComplete) {
4558 ? ParsedAttr::Form::ContextSensitiveKeyword()
4559 : ParsedAttr::Form::Keyword(
false ,
4565 attrs.addAtEnd(nullabilityAttr);
4567 if (inferNullabilityCS) {
4568 state.getDeclarator().getMutableDeclSpec().getObjCQualifiers()
4572 if (pointerLoc.isValid() &&
4573 complainAboutInferringWithinChunk !=
4574 PointerWrappingDeclaratorKind::None) {
4576 S.
Diag(pointerLoc, diag::warn_nullability_inferred_on_nested_type);
4581 if (inferNullabilityInnerOnly)
4582 inferNullabilityInnerOnlyComplete =
true;
4583 return nullabilityAttr;
4588 switch (complainAboutMissingNullability) {
4592 case CAMN_InnerPointers:
4593 if (NumPointersRemaining == 0)
4609 if (NumPointersRemaining > 0)
4610 --NumPointersRemaining;
4612 SimplePointerKind pointerKind = SimplePointerKind::Pointer;
4613 if (
T->isBlockPointerType())
4614 pointerKind = SimplePointerKind::BlockPointer;
4615 else if (
T->isMemberPointerType())
4616 pointerKind = SimplePointerKind::MemberPointer;
4618 if (
auto *
attr = inferPointerNullability(
4623 T = state.getAttributedType(
4629 if (complainAboutMissingNullability == CAMN_Yes &&
T->isArrayType() &&
4637 bool ExpectNoDerefChunk =
4638 state.getCurrentAttributes().hasAttribute(ParsedAttr::AT_NoDeref);
4648 bool AreDeclaratorChunksValid =
true;
4650 unsigned chunkIndex = e - i - 1;
4651 state.setCurrentChunkIndex(chunkIndex);
4654 switch (DeclType.
Kind) {
4662 if (!LangOpts.Blocks)
4663 S.
Diag(DeclType.
Loc, diag::err_blocks_disable) << LangOpts.OpenCL;
4666 inferPointerNullability(SimplePointerKind::BlockPointer, DeclType.
Loc,
4668 state.getDeclarator().getAttributePool());
4674 if (LangOpts.OpenCL)
4689 inferPointerNullability(SimplePointerKind::Pointer, DeclType.
Loc,
4691 state.getDeclarator().getAttributePool());
4694 T = Context.getObjCObjectPointerType(
T);
4703 if (LangOpts.OpenCL) {
4704 if (
T->isImageType() ||
T->isSamplerT() ||
T->isPipeType() ||
4705 T->isBlockPointerType()) {
4744 if (chunkIndex != 0 && !ArraySize &&
4763 S.
Diag(DeclType.
Loc, diag::err_array_star_outside_prototype);
4774 S.
Diag(DeclType.
Loc, diag::err_array_static_outside_prototype)
4776 :
"type qualifier");
4787 S.
Diag(DeclType.
Loc, diag::err_array_static_not_outermost)
4789 :
"type qualifier");
4799 if (complainAboutMissingNullability == CAMN_Yes &&
4815 IsQualifiedFunction =
4824 return SS.isInvalid() ||
4846 ? dyn_cast_if_present<ParmVarDecl>(FTI.
Params[0].
Param)
4850 if (
First &&
First->isExplicitObjectParameter() &&
4864 diag::err_explicit_object_parameter_nonmember)
4866 <<
First->getSourceRange();
4869 diag::err_explicit_object_parameter_invalid)
4870 <<
First->getSourceRange();
4875 AreDeclaratorChunksValid =
false;
4885 ? diag::err_auto_missing_trailing_return
4886 : diag::err_deduced_return_type);
4889 AreDeclaratorChunksValid =
false;
4892 diag::warn_cxx11_compat_deduced_return_type);
4901 AreDeclaratorChunksValid =
false;
4904 if (
T != Context.DependentTy) {
4906 diag::err_deduction_guide_with_complex_decl)
4910 AreDeclaratorChunksValid =
false;
4927 S.
Diag(Loc, diag::err_trailing_return_without_auto) <<
T << SR;
4930 AreDeclaratorChunksValid =
false;
4937 }
else if (AutoType *
Auto =
T->getContainedAutoType()) {
4946 if (InventedParamInfo) {
4948 state,
T, TInfo,
Auto, *InventedParamInfo);
4961 T->isFunctionType()) &&
4964 unsigned diagID = diag::err_func_returning_array_function;
4967 if (chunkIndex == 0 &&
4969 diagID = diag::err_block_returning_array_function;
4970 S.
Diag(DeclType.
Loc, diagID) <<
T->isFunctionType() <<
T;
4973 AreDeclaratorChunksValid =
false;
4978 if (
T->isHalfType()) {
4986 }
else if (!S.
getLangOpts().NativeHalfArgsAndReturns &&
4989 diag::err_parameters_retval_cannot_have_fp16_type) << 1;
4995 if (
T.getPointerAuth()) {
4996 S.
Diag(DeclType.
Loc, diag::err_ptrauth_qualifier_invalid) <<
T << 0;
4999 if (LangOpts.OpenCL) {
5002 if (
T->isBlockPointerType() ||
T->isImageType() ||
T->isSamplerT() ||
5013 "__cl_clang_variadic_functions", S.
getLangOpts()) &&
5025 if (
T->isObjCObjectType()) {
5034 S.
Diag(DiagLoc, diag::err_object_cannot_be_passed_returned_by_value)
5038 T = Context.getObjCObjectPointerType(
T);
5046 AreDeclaratorChunksValid =
false;
5054 if ((
T.getCVRQualifiers() ||
T->isAtomicType()) &&
5056 (
T->isDependentType() ||
T->isRecordType()))) {
5063 S.
Diag(DeclType.
Loc, diag::err_func_returning_qualified_void) <<
T;
5070 if (
T.isVolatileQualified() && S.
getLangOpts().CPlusPlus20)
5071 S.
Diag(DeclType.
Loc, diag::warn_deprecated_volatile_return) <<
T;
5076 if (
T.getQualifiers().hasObjCLifetime()) {
5081 if (AL.getKind() == ParsedAttr::AT_ObjCOwnership) {
5082 AttrLoc = AL.getLoc();
5089 if (AL.getKind() == ParsedAttr::AT_ObjCOwnership) {
5090 AttrLoc = AL.getLoc();
5104 S.
Diag(AttrLoc, diag::warn_arc_lifetime_result_type)
5105 <<
T.getQualifiers().getObjCLifetime();
5113 S.
Diag(Tag->getLocation(), diag::err_type_defined_in_result_type)
5114 << Context.getCanonicalTagType(Tag);
5121 diag::err_exception_spec_in_typedef)
5139 T = Context.getFunctionNoProtoType(
T, EI);
5147 diag::warn_c17_compat_ellipsis_only_parameter);
5149 ParsedAttr::AT_Overloadable) &&
5151 ParsedAttr::AT_Overloadable) &&
5153 ParsedAttr::AT_Overloadable))
5161 diag::err_ident_list_in_fn_declaration);
5165 ? Context.getFunctionNoProtoType(
T, EI)
5167 AreDeclaratorChunksValid =
false;
5190 bool HasAnyInterestingExtParameterInfos =
false;
5192 for (
unsigned i = 0, e = FTI.
NumParams; i != e; ++i) {
5194 QualType ParamTy = Param->getType();
5195 assert(!ParamTy.
isNull() &&
"Couldn't parse type?");
5206 ParamTy = Context.IntTy;
5207 Param->setType(ParamTy);
5211 ParamTy = Context.IntTy;
5212 Param->setType(ParamTy);
5216 S.
Diag(DeclType.
Loc, diag::err_void_param_qualified);
5218 for (
const auto *A : Param->attrs()) {
5219 S.
Diag(A->getLoc(), diag::warn_attribute_on_void_param)
5220 << A << A->getRange();
5225 if (Param->isExplicitObjectParameter()) {
5226 S.
Diag(Param->getLocation(),
5227 diag::err_void_explicit_object_param);
5240 S.
Diag(Param->getLocation(), diag::err_opencl_invalid_param)
5243 Param->setInvalidDecl();
5245 }
else if (!S.
getLangOpts().NativeHalfArgsAndReturns &&
5247 S.
Diag(Param->getLocation(),
5248 diag::err_parameters_retval_cannot_have_fp16_type) << 0;
5252 if (Context.isPromotableIntegerType(ParamTy)) {
5253 ParamTy = Context.getPromotedIntegerType(ParamTy);
5254 Param->setKNRPromoted(
true);
5256 if (BTy->getKind() == BuiltinType::Float) {
5257 ParamTy = Context.DoubleTy;
5258 Param->setKNRPromoted(
true);
5263 S.
Diag(Param->getLocation(), diag::err_opencl_invalid_param)
5268 if (LangOpts.ObjCAutoRefCount && Param->hasAttr<NSConsumedAttr>()) {
5269 ExtParameterInfos[i] = ExtParameterInfos[i].withIsConsumed(
true);
5270 HasAnyInterestingExtParameterInfos =
true;
5274 ExtParameterInfos[i] =
5275 ExtParameterInfos[i].withABI(
attr->getABI());
5276 HasAnyInterestingExtParameterInfos =
true;
5279 if (Param->hasAttr<PassObjectSizeAttr>()) {
5280 ExtParameterInfos[i] = ExtParameterInfos[i].withHasPassObjectSize();
5281 HasAnyInterestingExtParameterInfos =
true;
5284 if (Param->hasAttr<NoEscapeAttr>()) {
5285 ExtParameterInfos[i] = ExtParameterInfos[i].withIsNoEscape(
true);
5286 HasAnyInterestingExtParameterInfos =
true;
5289 ParamTys.push_back(ParamTy);
5292 if (HasAnyInterestingExtParameterInfos) {
5301 Expr *NoexceptExpr =
nullptr;
5307 DynamicExceptions.reserve(N);
5308 DynamicExceptionRanges.reserve(N);
5309 for (
unsigned I = 0; I != N; ++I) {
5320 DynamicExceptionRanges,
5327 auto IsClassMember = [&]() {
5328 return (!state.getDeclarator().getCXXScopeSpec().isEmpty() &&
5329 state.getDeclarator()
5333 state.getDeclarator().getContext() ==
5335 state.getDeclarator().getContext() ==
5339 if (state.getSema().getLangOpts().OpenCLCPlusPlus && IsClassMember()) {
5359 T = Context.getFunctionType(
T, ParamTys, EPI);
5368 inferPointerNullability(SimplePointerKind::MemberPointer, DeclType.
Loc,
5370 state.getDeclarator().getAttributePool());
5375 AreDeclaratorChunksValid =
false;
5384 AreDeclaratorChunksValid =
false;
5402 AreDeclaratorChunksValid =
false;
5411 S.
Diag(DeclType.
Loc, diag::warn_noderef_on_non_pointer_or_array);
5413 ExpectNoDerefChunk = state.didParseNoDeref();
5417 if (ExpectNoDerefChunk)
5418 S.
Diag(state.getDeclarator().getBeginLoc(),
5419 diag::warn_noderef_on_non_pointer_or_array);
5432 bool IsBlock =
false;
5434 switch (DeclType.Kind) {
5446 S.
Diag(DeclType.Loc, diag::warn_strict_prototypes)
5458 assert(!
T.isNull() &&
"T must not be null after this point");
5460 if (LangOpts.CPlusPlus &&
T->isFunctionType()) {
5462 assert(FnTy &&
"Why oh why is there not a FunctionProtoType here?");
5475 ExplicitObjectMember,
5479 Kind = DeductionGuide;
5496 auto *P = dyn_cast_or_null<ParmVarDecl>(Chunk.
Fun.
Params->
Param);
5497 if (P && P->isExplicitObjectParameter())
5498 Kind = ExplicitObjectMember;
5524 if (IsQualifiedFunction &&
5549 if (!RemovalLocs.empty()) {
5550 llvm::sort(RemovalLocs,
5552 RemovalRange =
SourceRange(RemovalLocs.front(), RemovalLocs.back());
5553 Loc = RemovalLocs.front();
5557 S.
Diag(Loc, diag::err_invalid_qualified_function_type)
5581 if (!AL.slidesFromDeclToDeclSpecLegacyBehavior()) {
5589 state.diagnoseIgnoredTypeAttrs(
T);
5600 if (
T.isVolatileQualified() && S.
getLangOpts().CPlusPlus20 &&
5625 if (!
T->containsUnexpandedParameterPack() &&
5626 (!LangOpts.CPlusPlus20 || !
T->getContainedAutoType())) {
5628 diag::err_function_parameter_pack_without_parameter_packs)
5632 T = Context.getPackExpansionType(
T, std::nullopt,
5645 if (
T->containsUnexpandedParameterPack())
5646 T = Context.getPackExpansionType(
T, std::nullopt);
5649 LangOpts.CPlusPlus11
5650 ? diag::warn_cxx98_compat_variadic_templates
5651 : diag::ext_variadic_templates);
5681 diag::err_ellipsis_in_declarator_not_parameter);
5687 assert(!
T.isNull() &&
"T must not be null at the end of this function");
5688 if (!AreDeclaratorChunksValid)
5689 return Context.getTrivialTypeSourceInfo(
T);
5691 if (state.didParseHLSLParamMod() && !
T->isConstantArrayType())
5700 TypeProcessingState state(*
this, D);
5723 unsigned chunkIndex) {
5724 Sema &S = state.getSema();
5732 const char *attrStr =
nullptr;
5733 switch (ownership) {
5751 &Args, 1, ParsedAttr::Form::GNU());
5760 Sema &S = state.getSema();
5764 bool hasIndirection =
false;
5767 switch (chunk.
Kind) {
5776 hasIndirection =
true;
5809 TypeProcessingState state(*
this, D);
5824 TypeProcessingState &State) {
5829 TypeProcessingState &State) {
5831 State.getSema().HLSL().TakeLocForHLSLAttribute(TL.
getTypePtr());
5839 if (AL.getKind() == ParsedAttr::AT_MatrixType) {
5848 llvm_unreachable(
"no matrix_type attribute found at the expected location!");
5853 switch (Chunk.
Kind) {
5858 llvm_unreachable(
"cannot be _Atomic qualified");
5876 class TypeSpecLocFiller :
public TypeLocVisitor<TypeSpecLocFiller> {
5878 ASTContext &Context;
5879 TypeProcessingState &State;
5883 TypeSpecLocFiller(Sema &S, ASTContext &Context, TypeProcessingState &State,
5885 : SemaRef(S), Context(Context), State(State), DS(DS) {}
5887 void VisitAttributedTypeLoc(AttributedTypeLoc TL) {
5891 void VisitBTFTagAttributedTypeLoc(BTFTagAttributedTypeLoc TL) {
5894 void VisitHLSLAttributedResourceTypeLoc(HLSLAttributedResourceTypeLoc TL) {
5898 void VisitHLSLInlineSpirvTypeLoc(HLSLInlineSpirvTypeLoc TL) {}
5899 void VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) {
5902 State.getExpansionLocForMacroQualifiedType(TL.
getTypePtr()));
5904 void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
5909 void VisitPointerTypeLoc(PointerTypeLoc TL) { Visit(TL.
getNextTypeLoc()); }
5910 void VisitTypedefTypeLoc(TypedefTypeLoc TL) {
5912 TypeSourceInfo *TInfo =
nullptr;
5925 void VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
5927 TypeSourceInfo *TInfo =
nullptr;
5940 void VisitUsingTypeLoc(UsingTypeLoc TL) {
5942 TypeSourceInfo *TInfo =
nullptr;
5955 void VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
5962 void VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
5963 TypeSourceInfo *RepTInfo =
nullptr;
5967 void VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
5968 TypeSourceInfo *RepTInfo =
nullptr;
5972 void VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
5973 TypeSourceInfo *TInfo =
nullptr;
5984 TL.
copy(OldTL.
castAs<TemplateSpecializationTypeLoc>());
5986 OldTL.
castAs<TemplateSpecializationTypeLoc>().getRAngleLoc());
5988 void VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
5994 void VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
6000 TypeSourceInfo *TInfo =
nullptr;
6004 void VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
6009 void VisitPackIndexingTypeLoc(PackIndexingTypeLoc TL) {
6013 void VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
6018 TypeSourceInfo *TInfo =
nullptr;
6022 void VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
6035 void VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
6037 TypeSourceInfo *TInfo =
nullptr;
6042 void VisitAutoTypeLoc(AutoTypeLoc TL) {
6056 NestedNameSpecifierLoc NNS =
6059 : NestedNameSpecifierLoc());
6060 TemplateArgumentListInfo TemplateArgsInfo(TemplateId->
LAngleLoc,
6062 if (TemplateId->
NumArgs > 0) {
6067 DeclarationNameInfo DNI = DeclarationNameInfo(
6068 TL.
getTypePtr()->getTypeConstraintConcept()->getDeclName(),
6071 NamedDecl *FoundDecl;
6076 FoundDecl = cast_if_present<NamedDecl>(TN.getAsTemplateDecl());
6084 void VisitDeducedTemplateSpecializationTypeLoc(
6085 DeducedTemplateSpecializationTypeLoc TL) {
6087 TypeSourceInfo *TInfo =
nullptr;
6093 void VisitTagTypeLoc(TagTypeLoc TL) {
6095 TypeSourceInfo *TInfo =
nullptr;
6103 ElaboratedTypeKeyword::None
6105 : SourceLocation());
6109 void VisitAtomicTypeLoc(AtomicTypeLoc TL) {
6116 TypeSourceInfo *TInfo =
nullptr;
6128 void VisitPipeTypeLoc(PipeTypeLoc TL) {
6131 TypeSourceInfo *TInfo =
nullptr;
6136 void VisitExtIntTypeLoc(BitIntTypeLoc TL) {
6140 void VisitDependentExtIntTypeLoc(DependentBitIntTypeLoc TL) {
6144 void VisitTypeLoc(TypeLoc TL) {
6150 class DeclaratorLocFiller :
public TypeLocVisitor<DeclaratorLocFiller> {
6151 ASTContext &Context;
6152 TypeProcessingState &State;
6153 const DeclaratorChunk &Chunk;
6156 DeclaratorLocFiller(ASTContext &Context, TypeProcessingState &State,
6157 const DeclaratorChunk &Chunk)
6158 : Context(Context), State(State), Chunk(Chunk) {}
6160 void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
6161 llvm_unreachable(
"qualified type locs not expected here!");
6163 void VisitDecayedTypeLoc(DecayedTypeLoc TL) {
6164 llvm_unreachable(
"decayed type locs not expected here!");
6166 void VisitArrayParameterTypeLoc(ArrayParameterTypeLoc TL) {
6167 llvm_unreachable(
"array parameter type locs not expected here!");
6170 void VisitAttributedTypeLoc(AttributedTypeLoc TL) {
6173 void VisitCountAttributedTypeLoc(CountAttributedTypeLoc TL) {
6176 void VisitBTFTagAttributedTypeLoc(BTFTagAttributedTypeLoc TL) {
6179 void VisitAdjustedTypeLoc(AdjustedTypeLoc TL) {
6182 void VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
6186 void VisitPointerTypeLoc(PointerTypeLoc TL) {
6190 void VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
6194 void VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
6199 void VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
6205 void VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
6210 void VisitArrayTypeLoc(ArrayTypeLoc TL) {
6216 void VisitFunctionTypeLoc(FunctionTypeLoc TL) {
6221 const DeclaratorChunk::FunctionTypeInfo &FTI = Chunk.
Fun;
6224 for (
unsigned i = 0, e = TL.
getNumParams(), tpi = 0; i != e; ++i) {
6230 void VisitParenTypeLoc(ParenTypeLoc TL) {
6235 void VisitPipeTypeLoc(PipeTypeLoc TL) {
6239 void VisitBitIntTypeLoc(BitIntTypeLoc TL) {
6242 void VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) {
6245 void VisitVectorTypeLoc(VectorTypeLoc TL) { TL.
setNameLoc(Chunk.
Loc); }
6246 void VisitDependentVectorTypeLoc(DependentVectorTypeLoc TL) {
6249 void VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
6252 void VisitAtomicTypeLoc(AtomicTypeLoc TL) {
6256 VisitDependentSizedExtVectorTypeLoc(DependentSizedExtVectorTypeLoc TL) {
6259 void VisitMatrixTypeLoc(MatrixTypeLoc TL) {
6263 void VisitTypeLoc(TypeLoc TL) {
6264 llvm_unreachable(
"unsupported TypeLoc kind in declarator!");
6273 if (AL.getKind() == ParsedAttr::AT_AddressSpace) {
6282 "no address_space attribute found at the expected location!");
6296 Sema &S = State.getSema();
6322 bool HasDesugaredTypeLoc =
true;
6323 while (HasDesugaredTypeLoc) {
6325 case TypeLoc::MacroQualified: {
6328 State.getExpansionLocForMacroQualifiedType(TL.
getTypePtr()));
6333 case TypeLoc::Attributed: {
6340 case TypeLoc::Adjusted:
6341 case TypeLoc::BTFTagAttributed: {
6346 case TypeLoc::DependentAddressSpace: {
6354 HasDesugaredTypeLoc =
false;
6365 if (ReturnTypeInfo) {
6385 "LocInfoType's TypeClass conflicts with an existing Type class");
6391 llvm_unreachable(
"LocInfoType leaked into the type system; an opaque TypeTy*"
6392 " was used directly instead of getting the QualType through"
6393 " GetTypeFromParser");
6400 "Type name should have no identifier!");
6437 const Expr *AddrSpace,
6440 std::optional<llvm::APSInt> OptAddrSpace =
6442 if (!OptAddrSpace) {
6443 S.
Diag(AttrLoc, diag::err_attribute_argument_type)
6448 llvm::APSInt &addrSpace = *OptAddrSpace;
6451 if (addrSpace.isSigned()) {
6452 if (addrSpace.isNegative()) {
6453 S.
Diag(AttrLoc, diag::err_attribute_address_space_negative)
6457 addrSpace.setIsSigned(
false);
6460 llvm::APSInt
max(addrSpace.getBitWidth());
6464 if (addrSpace >
max) {
6465 S.
Diag(AttrLoc, diag::err_attribute_address_space_too_high)
6487 return Context.getAddrSpaceQualType(
T, ASIdx);
6496 Diag(AttrLoc, diag::err_attribute_address_multiple_qualifiers);
6500 return Context.getDependentAddressSpaceType(
T, AddrSpace, AttrLoc);
6512 TypeProcessingState &State) {
6513 Sema &S = State.getSema();
6519 if (!
Attr.diagnoseLangOpts(S)) {
6525 if (
Attr.getNumArgs() != 1) {
6526 S.
Diag(
Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
6533 auto *StrLiteral = dyn_cast<StringLiteral>(
Attr.getArgAsExpr(0));
6542 StringRef BTFTypeTag = StrLiteral->getString();
6543 Type = State.getBTFTagAttributedType(
6544 ::new (Ctx) BTFTypeTagAttr(Ctx,
Attr, BTFTypeTag),
Type);
6552 TypeProcessingState &State) {
6553 Sema &S = State.getSema();
6558 S.
Diag(
Attr.
getLoc(), diag::err_attribute_address_function_type);
6564 if (
Attr.
getKind() == ParsedAttr::AT_AddressSpace) {
6567 if (
Attr.getNumArgs() != 1) {
6574 Expr *ASArgExpr =
Attr.getArgAsExpr(0);
6583 ::new (Ctx) AddressSpaceAttr(Ctx,
Attr,
static_cast<unsigned>(ASIdx));
6595 if (EquivType.
isNull()) {
6599 T = State.getAttributedType(ASAttr,
Type, EquivType);
6601 T = State.getAttributedType(ASAttr,
Type,
Type);
6612 :
Attr.asOpenCLLangAS();
6614 ASIdx =
Attr.asHLSLLangAS();
6617 llvm_unreachable(
"Invalid address space");
6635 bool NonObjCPointer =
false;
6637 if (!
type->isDependentType() && !
type->isUndeducedType()) {
6645 NonObjCPointer =
true;
6646 }
else if (!
type->isObjCRetainableType()) {
6652 if (state.isProcessingDeclSpec()) {
6660 Sema &S = state.getSema();
6666 if (!
attr.isArgIdent(0)) {
6667 S.
Diag(AttrLoc, diag::err_attribute_argument_type) <<
attr
6675 if (II->
isStr(
"none"))
6677 else if (II->
isStr(
"strong"))
6679 else if (II->
isStr(
"weak"))
6681 else if (II->
isStr(
"autoreleasing"))
6684 S.
Diag(AttrLoc, diag::warn_attribute_type_not_supported) <<
attr << II;
6701 =
type.getQualifiers().getObjCLifetime()) {
6704 S.
Diag(AttrLoc, diag::err_attr_objc_ownership_redundant)
6711 if (previousLifetime != lifetime) {
6714 const Type *prevTy =
nullptr;
6715 while (!prevTy || prevTy != underlyingType.
Ty) {
6716 prevTy = underlyingType.
Ty;
6725 if (NonObjCPointer) {
6726 StringRef name =
attr.getAttrName()->getName();
6735 S.
Diag(AttrLoc, diag::warn_type_attribute_wrong_type) << name
6752 type = state.getAttributedType(
6759 if (!NonObjCPointer)
6776 diagnostic,
type, 0));
6778 S.
Diag(loc, diagnostic);
6787 unsigned diagnostic =
6788 (S.
getLangOpts().ObjCWeakRuntime ? diag::err_arc_weak_disabled
6789 : diag::err_arc_weak_no_runtime);
6792 diagnoseOrDelay(S, AttrLoc, diagnostic,
type);
6804 if (Class->isArcWeakrefUnavailable()) {
6805 S.
Diag(AttrLoc, diag::err_arc_unsupported_weak_class);
6806 S.
Diag(ObjT->getInterfaceDecl()->getLocation(),
6807 diag::note_class_declared);
6822 Sema &S = state.getSema();
6825 if (!
type->isPointerType() &&
6826 !
type->isObjCObjectPointerType() &&
6827 !
type->isBlockPointerType())
6831 S.
Diag(
attr.getLoc(), diag::err_attribute_multiple_objc_gc);
6837 if (!
attr.isArgIdent(0)) {
6838 S.
Diag(
attr.getLoc(), diag::err_attribute_argument_type)
6844 if (
attr.getNumArgs() > 1) {
6845 S.
Diag(
attr.getLoc(), diag::err_attribute_wrong_number_arguments) <<
attr
6852 if (II->
isStr(
"weak"))
6854 else if (II->
isStr(
"strong"))
6857 S.
Diag(
attr.getLoc(), diag::warn_attribute_type_not_supported)
6867 if (
attr.getLoc().isValid())
6868 type = state.getAttributedType(
6885 struct FunctionTypeUnwrapper {
6899 const FunctionType *
Fn;
6900 SmallVector<
unsigned char , 8> Stack;
6902 FunctionTypeUnwrapper(Sema &S, QualType
T) : Original(
T) {
6904 const Type *Ty =
T.getTypePtr();
6914 Stack.push_back(Array);
6920 Stack.push_back(BlockPointer);
6923 Stack.push_back(MemberPointer);
6929 Stack.push_back(Attributed);
6932 Stack.push_back(MacroQualified);
6940 T = QualType(DTy, 0);
6941 Stack.push_back(Desugar);
6946 bool isFunctionType()
const {
return (Fn !=
nullptr); }
6947 const FunctionType *get()
const {
return Fn; }
6949 QualType wrap(Sema &S,
const FunctionType *
New) {
6951 if (
New == get())
return Original;
6954 return wrap(S.
Context, Original, 0);
6958 QualType wrap(ASTContext &
C, QualType Old,
unsigned I) {
6959 if (I == Stack.size())
6964 SplitQualType SplitOld = Old.
split();
6968 return wrap(
C, SplitOld.
Ty, I);
6969 return C.getQualifiedType(wrap(
C, SplitOld.
Ty, I), SplitOld.
Quals);
6972 QualType wrap(ASTContext &
C,
const Type *Old,
unsigned I) {
6973 if (I == Stack.size())
return QualType(Fn, 0);
6975 switch (
static_cast<WrapKind
>(Stack[I++])) {
6986 return C.getParenType(
New);
6989 case MacroQualified:
6993 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Old)) {
6994 QualType
New = wrap(
C, CAT->getElementType(), I);
6995 return C.getConstantArrayType(
New, CAT->getSize(), CAT->getSizeExpr(),
6996 CAT->getSizeModifier(),
6997 CAT->getIndexTypeCVRQualifiers());
7000 if (
const auto *VAT = dyn_cast<VariableArrayType>(Old)) {
7001 QualType
New = wrap(
C, VAT->getElementType(), I);
7002 return C.getVariableArrayType(
New, VAT->getSizeExpr(),
7003 VAT->getSizeModifier(),
7004 VAT->getIndexTypeCVRQualifiers());
7008 QualType
New = wrap(
C, IAT->getElementType(), I);
7009 return C.getIncompleteArrayType(
New, IAT->getSizeModifier(),
7010 IAT->getIndexTypeCVRQualifiers());
7015 return C.getPointerType(
New);
7018 case BlockPointer: {
7020 return C.getBlockPointerType(
New);
7023 case MemberPointer: {
7036 return C.getRValueReferenceType(
New);
7040 llvm_unreachable(
"unknown wrapping kind");
7047 Sema &S = State.getSema();
7051 default: llvm_unreachable(
"Unknown attribute kind");
7052 case ParsedAttr::AT_Ptr32:
7055 case ParsedAttr::AT_Ptr64:
7058 case ParsedAttr::AT_SPtr:
7061 case ParsedAttr::AT_UPtr:
7066 std::bitset<attr::LastAttr> Attrs;
7069 if (
const TypedefType *TT = dyn_cast<TypedefType>(Desugared)) {
7070 Desugared = TT->desugar();
7073 const AttributedType *AT = dyn_cast<AttributedType>(Desugared);
7076 Attrs[AT->getAttrKind()] =
true;
7077 Desugared = AT->getModifiedType();
7083 if (Attrs[NewAttrKind]) {
7084 S.
Diag(PAttr.
getLoc(), diag::warn_duplicate_attribute_exact) << PAttr;
7087 Attrs[NewAttrKind] =
true;
7091 if (Attrs[attr::Ptr32] && Attrs[attr::Ptr64]) {
7092 S.
Diag(PAttr.
getLoc(), diag::err_attributes_are_not_compatible)
7094 <<
"'__ptr64'" << 0;
7096 }
else if (Attrs[attr::SPtr] && Attrs[attr::UPtr]) {
7097 S.
Diag(PAttr.
getLoc(), diag::err_attributes_are_not_compatible)
7109 S.
Diag(PAttr.
getLoc(), diag::err_attribute_no_member_pointers) << PAttr;
7111 S.
Diag(PAttr.
getLoc(), diag::err_attribute_pointers_only) << PAttr << 0;
7119 if (PtrWidth == 32) {
7120 if (Attrs[attr::Ptr64])
7122 else if (Attrs[attr::UPtr])
7124 }
else if (PtrWidth == 64 && Attrs[attr::Ptr32]) {
7141 assert(PAttr.
getKind() == ParsedAttr::AT_WebAssemblyFuncref);
7143 Sema &S = State.getSema();
7146 std::bitset<attr::LastAttr> Attrs;
7148 const auto *AT = dyn_cast<AttributedType>(QT);
7150 Attrs[AT->getAttrKind()] =
true;
7151 AT = dyn_cast<AttributedType>(AT->getModifiedType());
7156 if (Attrs[NewAttrKind]) {
7157 S.
Diag(PAttr.
getLoc(), diag::warn_duplicate_attribute_exact) << PAttr;
7175 Sema &S = State.getSema();
7176 auto &D = State.getDeclarator();
7182 if (State.isProcessingDeclSpec()) {
7183 if (!(D.isPrototypeContext() ||
7187 if (
auto *chunk = D.getInnermostNonParenChunk()) {
7210 auto chunkIdx = State.getCurrentChunkIndex();
7211 if (chunkIdx >= 1 &&
7214 D.getTypeObject(chunkIdx - 1).getAttrs());
7219 auto *A = ::new (S.
Context) SwiftAttrAttr(S.
Context, PAttr, Str);
7220 QT = State.getAttributedType(A, QT, QT);
7227 auto Attributed = dyn_cast<AttributedType>(
Type.getTypePtr());
7232 if (Attributed->getImmediateNullability())
7233 return Attributed->getModifiedType();
7237 Ctx, Attributed->getModifiedType());
7238 assert(Modified.
getTypePtr() != Attributed->getModifiedType().getTypePtr());
7240 Attributed->getEquivalentType(),
7241 Attributed->getAttr());
7247 case ParsedAttr::AT_TypeNonNull:
7250 case ParsedAttr::AT_TypeNullable:
7253 case ParsedAttr::AT_TypeNullableResult:
7256 case ParsedAttr::AT_TypeNullUnspecified:
7260 llvm_unreachable(
"not a nullability attribute kind");
7267 bool IsContextSensitive,
bool AllowOnArrayType,
bool OverrideExisting) {
7268 bool Implicit = (State ==
nullptr);
7274 while (
auto *Attributed = dyn_cast<AttributedType>(Desugared.
getTypePtr())) {
7276 if (
auto ExistingNullability = Attributed->getImmediateNullability()) {
7278 if (Nullability == *ExistingNullability) {
7282 S.
Diag(NullabilityLoc, diag::warn_nullability_duplicate)
7289 if (!OverrideExisting) {
7291 S.
Diag(NullabilityLoc, diag::err_nullability_conflicting)
7301 Desugared = Attributed->getModifiedType();
7309 if (Nullability != *ExistingNullability && !
Implicit) {
7310 S.
Diag(NullabilityLoc, diag::err_nullability_conflicting)
7318 if (
auto typedefNullability =
7319 AttributedType::stripOuterNullability(underlyingType)) {
7320 if (*typedefNullability == *ExistingNullability) {
7333 !(AllowOnArrayType && Desugared->
isArrayType())) {
7335 S.
Diag(NullabilityLoc, diag::err_nullability_nonpointer)
7343 if (IsContextSensitive) {
7345 const Type *pointeeType =
nullptr;
7354 S.
Diag(NullabilityLoc, diag::err_nullability_cs_multilevel)
7356 S.
Diag(NullabilityLoc, diag::note_nullability_type_specifier)
7368 QT = State->getAttributedType(A, QT, QT);
7377 bool AllowOnArrayType) {
7383 Nullability, NullabilityLoc,
7384 IsContextSensitive, AllowOnArrayType,
7391 bool AllowArrayTypes,
7392 bool OverrideExisting) {
7394 *
this,
nullptr,
nullptr,
Type, Nullability, DiagLoc,
7395 false, AllowArrayTypes, OverrideExisting);
7402 Sema &S = state.getSema();
7406 type = state.getAttributedType(
7419 S.
Diag(
attr.getLoc(), diag::err_objc_kindof_nonobject)
7428 objType->getBaseType(), objType->getTypeArgsAsWritten(),
7429 objType->getProtocols(),
7430 objType->isObjCUnqualifiedId() ?
false :
true);
7435 if (
auto nullability =
type->getNullability()) {
7438 assert(
attr.getAttributeSpellingListIndex() == 0 &&
7439 "multiple spellings for __kindof?");
7442 equivType = state.getAttributedType(A, equivType, equivType);
7447 type = state.getAttributedType(
7460 Declarator &declarator = state.getDeclarator();
7463 auto moveToChunk = [&](
DeclaratorChunk &chunk,
bool inFunction) ->
bool {
7476 PK_MemberFunctionPointer,
7481 : inFunction? PK_MemberFunctionPointer : PK_MemberPointer;
7483 auto diag = state.getSema().Diag(
attr.getLoc(),
7484 diag::warn_nullability_declspec)
7486 attr.isContextSensitiveKeywordAttribute())
7488 <<
static_cast<unsigned>(pointerKind);
7494 state.getSema().getPreprocessor().getLocForEndOfToken(
7496 " " +
attr.getAttrName()->getName().str() +
" ");
7506 for (
unsigned i = state.getCurrentChunkIndex(); i != 0; --i) {
7508 switch (chunk.
Kind) {
7512 return moveToChunk(chunk,
false);
7524 return moveToChunk(*dest,
true);
7540 assert(!
Attr.isInvalid());
7543 llvm_unreachable(
"not a calling convention attribute");
7544 case ParsedAttr::AT_CDecl:
7546 case ParsedAttr::AT_FastCall:
7548 case ParsedAttr::AT_StdCall:
7550 case ParsedAttr::AT_ThisCall:
7552 case ParsedAttr::AT_RegCall:
7554 case ParsedAttr::AT_Pascal:
7556 case ParsedAttr::AT_SwiftCall:
7558 case ParsedAttr::AT_SwiftAsyncCall:
7560 case ParsedAttr::AT_VectorCall:
7562 case ParsedAttr::AT_AArch64VectorPcs:
7564 case ParsedAttr::AT_AArch64SVEPcs:
7566 case ParsedAttr::AT_ArmStreaming:
7568 case ParsedAttr::AT_DeviceKernel:
7570 case ParsedAttr::AT_Pcs: {
7575 if (
Attr.isArgExpr(0))
7578 Str =
Attr.getArgAsIdent(0)->getIdentifierInfo()->getName();
7579 PcsAttr::PCSType
Type;
7580 if (!PcsAttr::ConvertStrToPCSType(Str,
Type))
7581 llvm_unreachable(
"already validated the attribute");
7582 return ::new (Ctx) PcsAttr(Ctx,
Attr,
Type);
7584 case ParsedAttr::AT_IntelOclBicc:
7586 case ParsedAttr::AT_MSABI:
7588 case ParsedAttr::AT_SysVABI:
7590 case ParsedAttr::AT_PreserveMost:
7592 case ParsedAttr::AT_PreserveAll:
7594 case ParsedAttr::AT_M68kRTD:
7596 case ParsedAttr::AT_PreserveNone:
7598 case ParsedAttr::AT_RISCVVectorCC:
7600 case ParsedAttr::AT_RISCVVLSCC: {
7603 unsigned ABIVLen = 128;
7604 if (
Attr.getNumArgs()) {
7605 std::optional<llvm::APSInt> MaybeABIVLen =
7606 Attr.getArgAsExpr(0)->getIntegerConstantExpr(Ctx);
7608 llvm_unreachable(
"Invalid RISC-V ABI VLEN");
7609 ABIVLen = MaybeABIVLen->getZExtValue();
7612 return ::new (Ctx) RISCVVLSCCAttr(Ctx,
Attr, ABIVLen);
7615 llvm_unreachable(
"unexpected attribute kind!");
7618std::optional<FunctionEffectMode>
7623 std::optional<llvm::APSInt> ConditionValue =
7625 if (!ConditionValue) {
7631 return std::nullopt;
7640 FunctionTypeUnwrapper &Unwrapped) {
7642 if (!Unwrapped.isFunctionType())
7645 Sema &S = TPState.getSema();
7649 if (FPT ==
nullptr) {
7650 S.
Diag(PAttr.
getLoc(), diag::err_func_with_effects_no_prototype)
7657 bool IsNonBlocking = PAttr.
getKind() == ParsedAttr::AT_NonBlocking ||
7658 PAttr.
getKind() == ParsedAttr::AT_Blocking;
7661 Expr *CondExpr =
nullptr;
7663 if (PAttr.
getKind() == ParsedAttr::AT_NonBlocking ||
7664 PAttr.
getKind() == ParsedAttr::AT_NonAllocating) {
7673 std::optional<FunctionEffectMode> MaybeMode =
7679 NewMode = *MaybeMode;
7714 assert(
Success &&
"effect conflicts should have been diagnosed above");
7718 FPT->getParamTypes(), EPI);
7727 auto OtherAttr = llvm::find_if(
7728 state.getCurrentAttributes(),
7729 [OtherKind](
const ParsedAttr &A) { return A.getKind() == OtherKind; });
7730 if (OtherAttr == state.getCurrentAttributes().end() || OtherAttr->isInvalid())
7733 Sema &S = state.getSema();
7735 << *OtherAttr <<
Attr
7736 << (OtherAttr->isRegularKeywordAttribute() ||
7738 S.
Diag(OtherAttr->getLoc(), diag::note_conflicting_attribute);
7746 if (!
Attr.getNumArgs()) {
7752 for (
unsigned I = 0; I <
Attr.getNumArgs(); ++I) {
7753 StringRef StateName;
7758 if (StateName !=
"sme_za_state") {
7759 S.
Diag(LiteralLoc, diag::err_unknown_arm_state) << StateName;
7766 S.
Diag(
Attr.
getLoc(), diag::err_conflicting_attributes_arm_agnostic);
7781 if (!
Attr.getNumArgs()) {
7787 for (
unsigned I = 0; I <
Attr.getNumArgs(); ++I) {
7788 StringRef StateName;
7795 if (StateName ==
"za") {
7798 }
else if (StateName ==
"zt0") {
7802 S.
Diag(LiteralLoc, diag::err_unknown_arm_state) << StateName;
7808 S.
Diag(LiteralLoc, diag::err_conflicting_attributes_arm_agnostic);
7817 S.
Diag(LiteralLoc, diag::err_conflicting_attributes_arm_state)
7833 Sema &S = state.getSema();
7835 FunctionTypeUnwrapper unwrapped(S,
type);
7837 if (
attr.getKind() == ParsedAttr::AT_NoReturn) {
7842 if (!unwrapped.isFunctionType())
7851 if (
attr.getKind() == ParsedAttr::AT_CFIUncheckedCallee) {
7853 if (!unwrapped.isFunctionType())
7856 if (!unwrapped.get()->isFunctionProtoType()) {
7857 S.
Diag(
attr.getLoc(), diag::warn_attribute_wrong_decl_type)
7858 <<
attr <<
attr.isRegularKeywordAttribute()
7866 FPT->getReturnType(), FPT->getParamTypes(),
7867 FPT->getExtProtoInfo().withCFIUncheckedCallee(
true));
7872 if (
attr.getKind() == ParsedAttr::AT_CmseNSCall) {
7874 if (!unwrapped.isFunctionType())
7879 S.
Diag(
attr.getLoc(), diag::warn_attribute_ignored) <<
attr;
7886 unwrapped.get()->getExtInfo().withCmseNSCall(
true);
7893 if (
attr.getKind() == ParsedAttr::AT_NSReturnsRetained) {
7894 if (
attr.getNumArgs())
return true;
7897 if (!unwrapped.isFunctionType())
7902 attr.getLoc(), unwrapped.get()->getReturnType()))
7907 if (state.getSema().getLangOpts().ObjCAutoRefCount) {
7909 = unwrapped.get()->getExtInfo().withProducesResult(
true);
7912 type = state.getAttributedType(
7918 if (
attr.getKind() == ParsedAttr::AT_AnyX86NoCallerSavedRegisters) {
7923 if (!unwrapped.isFunctionType())
7927 unwrapped.get()->getExtInfo().withNoCallerSavedRegs(
true);
7932 if (
attr.getKind() == ParsedAttr::AT_AnyX86NoCfCheck) {
7934 S.
Diag(
attr.getLoc(), diag::warn_nocf_check_attribute_ignored);
7944 if (!unwrapped.isFunctionType())
7948 unwrapped.get()->getExtInfo().withNoCfCheck(
true);
7953 if (
attr.getKind() == ParsedAttr::AT_Regparm) {
7959 if (!unwrapped.isFunctionType())
7966 S.
Diag(
attr.getLoc(), diag::err_attributes_are_not_compatible)
7968 <<
attr.isRegularKeywordAttribute();
7974 unwrapped.get()->getExtInfo().withRegParm(value);
7979 if (
attr.getKind() == ParsedAttr::AT_CFISalt) {
7980 if (
attr.getNumArgs() != 1)
7988 if (!unwrapped.isFunctionType())
7993 S.
Diag(
attr.getLoc(), diag::err_attribute_wrong_decl_type)
7994 <<
attr <<
attr.isRegularKeywordAttribute()
8004 FnTy->getParamTypes(), EPI);
8009 if (
attr.getKind() == ParsedAttr::AT_ArmStreaming ||
8010 attr.getKind() == ParsedAttr::AT_ArmStreamingCompatible ||
8011 attr.getKind() == ParsedAttr::AT_ArmPreserves ||
8012 attr.getKind() == ParsedAttr::AT_ArmIn ||
8013 attr.getKind() == ParsedAttr::AT_ArmOut ||
8014 attr.getKind() == ParsedAttr::AT_ArmInOut ||
8015 attr.getKind() == ParsedAttr::AT_ArmAgnostic) {
8019 if (
attr.getKind() == ParsedAttr::AT_ArmStreaming ||
8020 attr.getKind() == ParsedAttr::AT_ArmStreamingCompatible)
8024 if (!unwrapped.isFunctionType())
8031 S.
Diag(
attr.getLoc(), diag::warn_attribute_wrong_decl_type)
8032 <<
attr <<
attr.isRegularKeywordAttribute()
8039 switch (
attr.getKind()) {
8040 case ParsedAttr::AT_ArmStreaming:
8042 ParsedAttr::AT_ArmStreamingCompatible))
8046 case ParsedAttr::AT_ArmStreamingCompatible:
8051 case ParsedAttr::AT_ArmPreserves:
8055 case ParsedAttr::AT_ArmIn:
8059 case ParsedAttr::AT_ArmOut:
8063 case ParsedAttr::AT_ArmInOut:
8067 case ParsedAttr::AT_ArmAgnostic:
8072 llvm_unreachable(
"Unsupported attribute");
8076 FnTy->getParamTypes(), EPI);
8081 if (
attr.getKind() == ParsedAttr::AT_NoThrow) {
8083 if (!unwrapped.isFunctionType())
8096 if (Proto->hasExceptionSpec()) {
8097 switch (Proto->getExceptionSpecType()) {
8099 llvm_unreachable(
"This doesn't have an exception spec!");
8117 S.
Diag(
attr.getLoc(), diag::warn_nothrow_attribute_ignored);
8123 type = unwrapped.wrap(
8132 if (
attr.getKind() == ParsedAttr::AT_NonBlocking ||
8133 attr.getKind() == ParsedAttr::AT_NonAllocating ||
8134 attr.getKind() == ParsedAttr::AT_Blocking ||
8135 attr.getKind() == ParsedAttr::AT_Allocating) {
8140 if (!unwrapped.isFunctionType())
return false;
8155 S.
Diag(
attr.getLoc(), diag::err_attributes_are_not_compatible)
8158 <<
attr.isRegularKeywordAttribute();
8177 return S.
Diag(
attr.getLoc(), diag::warn_cconv_unsupported)
8182 return S.
Diag(
attr.getLoc(), diag::err_cconv_varargs)
8189 S.
Diag(
attr.getLoc(), diag::err_attributes_are_not_compatible)
8191 <<
attr.isRegularKeywordAttribute();
8203 auto EI = unwrapped.get()->getExtInfo().withCallingConv(CC);
8212 const AttributedType *AT;
8216 while ((AT =
T->getAs<AttributedType>()) &&
8218 if (AT->isCallingConv())
8220 T = AT->getModifiedType();
8227 FunctionTypeUnwrapper Unwrapped(*
this,
T);
8233 Context.getDefaultCallingConvention(IsVariadic, HasThisPointer);
8240 if (
Context.getTargetInfo().getCXXABI().isMicrosoft() && IsCtorOrDtor) {
8244 Diag(Loc, diag::warn_cconv_unsupported)
8253 Context.getDefaultCallingConvention(IsVariadic, !HasThisPointer);
8255 if (CurCC != DefaultCC)
8263 QualType Wrapped = Unwrapped.wrap(*
this, FT);
8264 T =
Context.getAdjustedType(
T, Wrapped);
8277 if (
Attr.getNumArgs() != 1) {
8284 Expr *SizeExpr =
Attr.getArgAsExpr(0);
8297 if (
Attr.getNumArgs() != 1) {
8303 Expr *SizeExpr =
Attr.getArgAsExpr(0);
8318 bool IsPolyUnsigned = Triple.getArch() == llvm::Triple::aarch64 ||
8319 Triple.getArch() == llvm::Triple::aarch64_32 ||
8320 Triple.getArch() == llvm::Triple::aarch64_be;
8322 if (IsPolyUnsigned) {
8324 return BTy->
getKind() == BuiltinType::UChar ||
8325 BTy->
getKind() == BuiltinType::UShort ||
8326 BTy->
getKind() == BuiltinType::ULong ||
8327 BTy->
getKind() == BuiltinType::ULongLong;
8330 return BTy->
getKind() == BuiltinType::SChar ||
8331 BTy->
getKind() == BuiltinType::Short ||
8332 BTy->
getKind() == BuiltinType::LongLong;
8338 if ((Triple.isArch64Bit() || Triple.getArch() == llvm::Triple::aarch64_32) &&
8339 BTy->
getKind() == BuiltinType::Double)
8342 return BTy->
getKind() == BuiltinType::SChar ||
8343 BTy->
getKind() == BuiltinType::UChar ||
8344 BTy->
getKind() == BuiltinType::Short ||
8345 BTy->
getKind() == BuiltinType::UShort ||
8346 BTy->
getKind() == BuiltinType::Int ||
8347 BTy->
getKind() == BuiltinType::UInt ||
8348 BTy->
getKind() == BuiltinType::Long ||
8349 BTy->
getKind() == BuiltinType::ULong ||
8350 BTy->
getKind() == BuiltinType::LongLong ||
8351 BTy->
getKind() == BuiltinType::ULongLong ||
8352 BTy->
getKind() == BuiltinType::Float ||
8353 BTy->
getKind() == BuiltinType::Half ||
8354 BTy->
getKind() == BuiltinType::BFloat16 ||
8355 BTy->
getKind() == BuiltinType::MFloat8;
8359 llvm::APSInt &Result) {
8360 const auto *AttrExpr =
Attr.getArgAsExpr(0);
8361 if (!AttrExpr->isTypeDependent()) {
8362 if (std::optional<llvm::APSInt> Res =
8363 AttrExpr->getIntegerConstantExpr(S.
Context)) {
8405 if (
Attr.getNumArgs() != 1) {
8406 S.
Diag(
Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
8412 llvm::APSInt numEltsInt(32);
8418 S.
Diag(
Attr.
getLoc(), diag::err_attribute_invalid_vector_type) << CurType;
8425 unsigned numElts =
static_cast<unsigned>(numEltsInt.getZExtValue());
8426 unsigned vecSize = typeSize * numElts;
8427 if (vecSize != 64 && vecSize != 128) {
8428 S.
Diag(
Attr.
getLoc(), diag::err_attribute_bad_neon_vector_size) << CurType;
8440 assert((
Attr.getNumArgs() > 0 &&
Attr.getNumArgs() <= 3) &&
8441 "__ptrauth qualifier takes between 1 and 3 arguments");
8442 Expr *KeyArg =
Attr.getArgAsExpr(0);
8443 Expr *IsAddressDiscriminatedArg =
8444 Attr.getNumArgs() >= 2 ?
Attr.getArgAsExpr(1) :
nullptr;
8445 Expr *ExtraDiscriminatorArg =
8446 Attr.getNumArgs() >= 3 ?
Attr.getArgAsExpr(2) :
nullptr;
8455 bool IsInvalid =
false;
8456 unsigned IsAddressDiscriminated, ExtraDiscriminator;
8459 IsAddressDiscriminated);
8468 if (!
T->isSignableType(Ctx) && !
T->isDependentType()) {
8469 S.
Diag(
Attr.
getLoc(), diag::err_ptrauth_qualifier_invalid_target) <<
T;
8474 if (
T.getPointerAuth()) {
8486 assert((!IsAddressDiscriminatedArg || IsAddressDiscriminated <= 1) &&
8487 "address discriminator arg should be either 0 or 1");
8489 Key, IsAddressDiscriminated, ExtraDiscriminator,
8511 S.
Diag(
Attr.
getLoc(), diag::err_attribute_arm_feature_sve_bits_unsupported)
8518 if (
Attr.getNumArgs() != 1) {
8519 S.
Diag(
Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
8526 llvm::APSInt SveVectorSizeInBits(32);
8530 unsigned VecSize =
static_cast<unsigned>(SveVectorSizeInBits.getZExtValue());
8553 if (BT->getKind() == BuiltinType::SveBool) {
8558 VecSize /= TypeSize;
8565 const VectorType *VT = dyn_cast<VectorType>(CurType);
8568 diag::err_attribute_arm_mve_polymorphism);
8575 State.getSema().Context,
Attr),
8587 <<
Attr <<
"'zve32x'";
8594 if (!VScale || !VScale->first || VScale->first != VScale->second) {
8595 S.
Diag(
Attr.
getLoc(), diag::err_attribute_riscv_rvv_bits_unsupported)
8602 if (
Attr.getNumArgs() != 1) {
8603 S.
Diag(
Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
8610 llvm::APSInt RVVVectorSizeInBits(32);
8622 unsigned VecSize =
static_cast<unsigned>(RVVVectorSizeInBits.getZExtValue());
8626 unsigned MinElts = Info.
EC.getKnownMinValue();
8629 unsigned ExpectedSize = VScale->first * MinElts;
8651 ExpectedSize *= EltSize;
8652 NumElts = VecSize / EltSize;
8656 if (VecSize != ExpectedSize) {
8658 << VecSize << ExpectedSize;
8671 S.
Diag(
Attr.
getLoc(), diag::err_opencl_invalid_access_qualifier);
8677 QualType BaseTy = TypedefTy->desugar();
8679 std::string PrevAccessQual;
8681 if (TypedefTy->getDecl()->hasAttr<OpenCLAccessAttr>()) {
8682 OpenCLAccessAttr *
Attr =
8683 TypedefTy->getDecl()->getAttr<OpenCLAccessAttr>();
8686 PrevAccessQual =
"read_only";
8690 switch (ImgType->getKind()) {
8691 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
8692 case BuiltinType::Id: \
8693 PrevAccessQual = #Access; \
8695 #include "clang/Basic/OpenCLImageTypes.def"
8697 llvm_unreachable(
"Unable to find corresponding image type.");
8700 llvm_unreachable(
"unexpected type");
8703 if (PrevAccessQual == AttrName.ltrim(
"_")) {
8709 S.
Diag(
Attr.
getLoc(), diag::err_opencl_multiple_access_qualifiers);
8712 S.
Diag(TypedefTy->getDecl()->getBeginLoc(),
8713 diag::note_opencl_typedef_access_qualifier) << PrevAccessQual;
8715 if (
Attr.getSemanticSpelling() == OpenCLAccessAttr::Keyword_write_only) {
8730 if (
Attr.getNumArgs() != 2) {
8731 S.
Diag(
Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
8736 Expr *RowsExpr =
Attr.getArgAsExpr(0);
8737 Expr *ColsExpr =
Attr.getArgAsExpr(1);
8745 Sema &S = State.getSema();
8748 S.
Diag(PA.
getLoc(), diag::err_attribute_too_few_arguments) << PA << 1;
8760 for (
unsigned Idx = 1; Idx < PA.
getNumArgs(); Idx++) {
8766 auto *AnnotateTypeAttr =
8767 AnnotateTypeAttr::Create(S.
Context, Str, Args.data(), Args.size(), PA);
8768 CurType = State.getAttributedType(AnnotateTypeAttr, CurType, CurType);
8774 if (State.getDeclarator().isDeclarationOfFunction()) {
8775 CurType = State.getAttributedType(
8780 State.getSema().Diag(
Attr.
getLoc(), diag::err_attribute_wrong_decl_type)
8787 if (State.getDeclarator().isDeclarationOfFunction()) {
8788 auto *
Attr = State.getSema().ParseLifetimeCaptureByAttr(PA,
"this");
8790 CurType = State.getAttributedType(
Attr, CurType, CurType);
8802 if (
Attr.getSemanticSpelling() == HLSLParamModifierAttr::Keyword_inout ||
8803 Attr.getSemanticSpelling() == HLSLParamModifierAttr::Keyword_out) {
8804 State.setParsedHLSLParamMod(
true);
8813 if (
Attr.
getKind() != ParsedAttr::AT_DeviceKernel)
8815 return DeviceKernelAttr::isAMDGPUSpelling(
Attr);
8823 state.setParsedNoDeref(
false);
8839 if (
attr.isInvalid())
8842 if (
attr.isStandardAttributeSyntax() ||
attr.isRegularKeywordAttribute()) {
8847 if (
attr.isGNUScope()) {
8848 assert(
attr.isStandardAttributeSyntax());
8849 bool IsTypeAttr =
attr.isTypeAttr();
8851 state.getSema().Diag(
attr.getLoc(),
8853 ? diag::warn_gcc_ignores_type_attr
8854 : diag::warn_cxx11_gnu_attribute_on_type)
8860 !
attr.isTypeAttr()) {
8873 switch (
attr.getKind()) {
8876 if ((
attr.isStandardAttributeSyntax() ||
8877 attr.isRegularKeywordAttribute()) &&
8879 state.getSema().Diag(
attr.getLoc(), diag::err_attribute_not_type_attr)
8880 <<
attr <<
attr.isRegularKeywordAttribute();
8881 attr.setUsedAsTypeAttr();
8886 if (
attr.isStandardAttributeSyntax()) {
8887 state.getSema().DiagnoseUnknownAttribute(
attr);
8897 case ParsedAttr::AT_BTFTypeTag:
8899 attr.setUsedAsTypeAttr();
8902 case ParsedAttr::AT_MayAlias:
8905 attr.setUsedAsTypeAttr();
8907 case ParsedAttr::AT_OpenCLPrivateAddressSpace:
8908 case ParsedAttr::AT_OpenCLGlobalAddressSpace:
8909 case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace:
8910 case ParsedAttr::AT_OpenCLGlobalHostAddressSpace:
8911 case ParsedAttr::AT_OpenCLLocalAddressSpace:
8912 case ParsedAttr::AT_OpenCLConstantAddressSpace:
8913 case ParsedAttr::AT_OpenCLGenericAddressSpace:
8914 case ParsedAttr::AT_HLSLGroupSharedAddressSpace:
8915 case ParsedAttr::AT_AddressSpace:
8917 attr.setUsedAsTypeAttr();
8922 attr.setUsedAsTypeAttr();
8924 case ParsedAttr::AT_VectorSize:
8926 attr.setUsedAsTypeAttr();
8928 case ParsedAttr::AT_ExtVectorType:
8930 attr.setUsedAsTypeAttr();
8932 case ParsedAttr::AT_NeonVectorType:
8934 attr.setUsedAsTypeAttr();
8936 case ParsedAttr::AT_NeonPolyVectorType:
8939 attr.setUsedAsTypeAttr();
8941 case ParsedAttr::AT_ArmSveVectorBits:
8943 attr.setUsedAsTypeAttr();
8945 case ParsedAttr::AT_ArmMveStrictPolymorphism: {
8947 attr.setUsedAsTypeAttr();
8950 case ParsedAttr::AT_RISCVRVVVectorBits:
8952 attr.setUsedAsTypeAttr();
8954 case ParsedAttr::AT_OpenCLAccess:
8956 attr.setUsedAsTypeAttr();
8958 case ParsedAttr::AT_PointerAuth:
8961 attr.setUsedAsTypeAttr();
8963 case ParsedAttr::AT_LifetimeBound:
8967 case ParsedAttr::AT_LifetimeCaptureBy:
8972 case ParsedAttr::AT_NoDeref: {
8977 if (
attr.isStandardAttributeSyntax()) {
8978 state.getSema().Diag(
attr.getLoc(), diag::warn_attribute_ignored)
8985 attr.setUsedAsTypeAttr();
8986 state.setParsedNoDeref(
true);
8990 case ParsedAttr::AT_MatrixType:
8992 attr.setUsedAsTypeAttr();
8995 case ParsedAttr::AT_WebAssemblyFuncref: {
8997 attr.setUsedAsTypeAttr();
9001 case ParsedAttr::AT_HLSLParamModifier: {
9003 attr.setUsedAsTypeAttr();
9007 case ParsedAttr::AT_SwiftAttr: {
9014 attr.setUsedAsTypeAttr();
9022 if (
type->canHaveNullability() ||
type->isDependentType() ||
9023 type->isArrayType() ||
9027 endIndex = state.getCurrentChunkIndex();
9029 endIndex = state.getDeclarator().getNumTypeObjects();
9030 bool allowOnArrayType =
9031 state.getDeclarator().isPrototypeContext() &&
9034 allowOnArrayType)) {
9038 attr.setUsedAsTypeAttr();
9042 case ParsedAttr::AT_ObjCKindOf:
9050 state.getSema().Diag(
attr.getLoc(),
9051 diag::err_objc_kindof_wrong_position)
9054 state.getDeclarator().getDeclSpec().getBeginLoc(),
9064 case ParsedAttr::AT_NoThrow:
9067 if (!state.getSema().getLangOpts().CPlusPlus)
9074 attr.setUsedAsTypeAttr();
9078 if (
attr.isStandardAttributeSyntax() ||
9079 attr.isRegularKeywordAttribute()) {
9096 case ParsedAttr::AT_AcquireHandle: {
9097 if (!
type->isFunctionType())
9100 if (
attr.getNumArgs() != 1) {
9101 state.getSema().Diag(
attr.getLoc(),
9102 diag::err_attribute_wrong_number_arguments)
9108 StringRef HandleType;
9109 if (!state.getSema().checkStringLiteralArgumentAttr(
attr, 0, HandleType))
9111 type = state.getAttributedType(
9112 AcquireHandleAttr::Create(state.getSema().Context, HandleType,
attr),
9114 attr.setUsedAsTypeAttr();
9117 case ParsedAttr::AT_AnnotateType: {
9119 attr.setUsedAsTypeAttr();
9122 case ParsedAttr::AT_HLSLResourceClass:
9123 case ParsedAttr::AT_HLSLROV:
9124 case ParsedAttr::AT_HLSLRawBuffer:
9125 case ParsedAttr::AT_HLSLContainedType: {
9130 state.getSema().HLSL().handleResourceTypeAttr(
type,
attr))
9131 attr.setUsedAsTypeAttr();
9139 !
type.getQualifiers().hasObjCLifetime() &&
9140 !
type.getQualifiers().hasObjCGCAttr() &&
9141 attr.getKind() != ParsedAttr::AT_ObjCGC &&
9142 attr.getKind() != ParsedAttr::AT_ObjCOwnership) {
9144 type = state.getSema().Context.getMacroQualifiedType(
type, MacroII);
9145 state.setExpansionLocForMacroQualifiedType(
9147 attr.getMacroExpansionLoc());
9154 if (
VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl())) {
9156 auto *Def = Var->getDefinition();
9162 Def = Var->getDefinition();
9169 if (Var->getPointOfInstantiation().isInvalid() && Def) {
9170 assert(Var->getTemplateSpecializationKind() ==
9172 "explicit instantiation with no point of instantiation");
9173 Var->setTemplateSpecializationKind(
9174 Var->getTemplateSpecializationKind(), PointOfInstantiation);
9194 if (
const auto CastE = dyn_cast<ExplicitCastExpr>(E)) {
9195 QualType DestType = CastE->getTypeAsWritten();
9196 if (
const auto *IAT =
Context.getAsIncompleteArrayType(DestType)) {
9201 IAT->getElementType(),
9238 if (RequireCompleteTypeImpl(Loc,
T, Kind, &Diagnoser))
9240 if (
auto *TD =
T->getAsTagDecl(); TD && !TD->isCompleteDefinitionRequired()) {
9241 TD->setCompleteDefinitionRequired();
9242 Consumer.HandleTagDeclRequiredDefinition(TD);
9274 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(D)) {
9275 if (
auto *Pattern = RD->getTemplateInstantiationPattern())
9277 D = RD->getDefinition();
9278 }
else if (
auto *ED = dyn_cast<EnumDecl>(D)) {
9279 if (
auto *Pattern = ED->getTemplateInstantiationPattern())
9281 if (OnlyNeedComplete && (ED->isFixed() ||
getLangOpts().MSVCCompat)) {
9287 *Suggested =
nullptr;
9288 for (
auto *Redecl : ED->redecls()) {
9291 if (Redecl->isThisDeclarationADefinition() ||
9292 (Redecl->isCanonicalDecl() && !*Suggested))
9293 *Suggested = Redecl;
9298 D = ED->getDefinition();
9299 }
else if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
9300 if (
auto *Pattern = FD->getTemplateInstantiationPattern())
9302 D = FD->getDefinition();
9303 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
9304 if (
auto *Pattern = VD->getTemplateInstantiationPattern())
9306 D = VD->getDefinition();
9309 assert(D &&
"missing definition for pattern of instantiated definition");
9313 auto DefinitionIsAcceptable = [&] {
9333 if (DefinitionIsAcceptable())
9338 if (
auto *Source =
Context.getExternalSource()) {
9339 Source->CompleteRedeclChain(D);
9340 return DefinitionIsAcceptable();
9356 bool OnlyNeedComplete) {
9373 bool OnlyNeedComplete) {
9381 if (!RD->
hasAttr<MSInheritanceAttr>()) {
9383 bool BestCase =
false;
9403 RD->
addAttr(MSInheritanceAttr::CreateImplicit(
9404 S.
getASTContext(), BestCase, Loc, MSInheritanceAttr::Spelling(IM)));
9410 CompleteTypeKind Kind,
9411 TypeDiagnoser *Diagnoser) {
9420 if (
const auto *MPTy = dyn_cast<MemberPointerType>(
T.getCanonicalType())) {
9421 if (CXXRecordDecl *RD = MPTy->getMostRecentCXXRecordDecl();
9422 RD && !RD->isDependentType()) {
9424 if (
getLangOpts().CompleteMemberPointers && !RD->isBeingDefined() &&
9430 if (
Context.getTargetInfo().getCXXABI().isMicrosoft()) {
9437 NamedDecl *Def =
nullptr;
9449 NamedDecl *Suggested =
nullptr;
9455 if (Diagnoser && Suggested)
9458 return !TreatAsComplete;
9462 TempInst.Template = Def;
9463 TempInst.Entity = Def;
9464 TempInst.PointOfInstantiation = Loc;
9472 TagDecl *
Tag = dyn_cast_or_null<TagDecl>(Def);
9473 ObjCInterfaceDecl *IFace = dyn_cast_or_null<ObjCInterfaceDecl>(Def);
9485 if (
auto *Source =
Context.getExternalSource()) {
9486 if (Tag &&
Tag->hasExternalLexicalStorage())
9487 Source->CompleteType(Tag);
9489 Source->CompleteType(IFace);
9493 return RequireCompleteTypeImpl(Loc,
T, Kind, Diagnoser);
9500 if (
auto *RD = dyn_cast_or_null<CXXRecordDecl>(Tag)) {
9501 bool Instantiated =
false;
9502 bool Diagnosed =
false;
9503 if (RD->isDependentContext()) {
9507 }
else if (
auto *ClassTemplateSpec =
9508 dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
9509 if (ClassTemplateSpec->getSpecializationKind() ==
TSK_Undeclared) {
9513 Diagnoser, ClassTemplateSpec->hasStrictPackMatch());
9515 Instantiated =
true;
9518 CXXRecordDecl *Pattern = RD->getInstantiatedFromMemberClass();
9519 if (!RD->isBeingDefined() && Pattern) {
9520 MemberSpecializationInfo *MSI = RD->getMemberSpecializationInfo();
9521 assert(MSI &&
"Missing member specialization information?");
9531 Instantiated =
true;
9539 if (Diagnoser && Diagnosed)
9545 return RequireCompleteTypeImpl(Loc,
T, Kind, Diagnoser);
9555 Diagnoser->diagnose(*
this, Loc,
T);
9559 if (Tag && !
Tag->isInvalidDecl() && !
Tag->getLocation().isInvalid())
9560 Diag(
Tag->getLocation(),
Tag->isBeingDefined()
9561 ? diag::note_type_being_defined
9562 : diag::note_forward_declaration)
9563 <<
Context.getCanonicalTagType(Tag);
9596 default: llvm_unreachable(
"Invalid tag kind for literal type diagnostic!");
9602 assert(!
T->isDependentType() &&
"type should not be dependent");
9611 if (
T->isVariableArrayType())
9627 Diag(RD->getLocation(), diag::note_non_literal_lambda);
9635 if (RD->getNumVBases()) {
9636 Diag(RD->getLocation(), diag::note_non_literal_virtual_base)
9638 for (
const auto &I : RD->vbases())
9639 Diag(I.getBeginLoc(), diag::note_constexpr_virtual_base_here)
9640 << I.getSourceRange();
9641 }
else if (!RD->isAggregate() && !RD->hasConstexprNonCopyMoveConstructor() &&
9642 !RD->hasTrivialDefaultConstructor()) {
9643 Diag(RD->getLocation(), diag::note_non_literal_no_constexpr_ctors) << RD;
9644 }
else if (RD->hasNonLiteralTypeFieldsOrBases()) {
9645 for (
const auto &I : RD->bases()) {
9646 if (!I.getType()->isLiteralType(
Context)) {
9647 Diag(I.getBeginLoc(), diag::note_non_literal_base_class)
9648 << RD << I.getType() << I.getSourceRange();
9652 for (
const auto *I : RD->fields()) {
9653 if (!I->getType()->isLiteralType(
Context) ||
9654 I->getType().isVolatileQualified()) {
9655 Diag(I->getLocation(), diag::note_non_literal_field)
9656 << RD << I << I->getType()
9657 << I->getType().isVolatileQualified();
9662 : !RD->hasTrivialDestructor()) {
9667 assert(Dtor &&
"class has literal fields and bases but no dtor?");
9676 ? diag::note_non_literal_user_provided_dtor
9677 : diag::note_non_literal_nontrivial_dtor)
9703 if (
const TagType *TT =
T->getAs<TagType>())
9706 return Context.getTypeOfExprType(E, Kind);
9727 return Context.getCountAttributedType(WrappedTy, CountExpr, CountInBytes,
9737 if (
auto *ImplCastExpr = dyn_cast<ImplicitCastExpr>(E))
9738 IDExpr = ImplCastExpr->getSubExpr();
9740 if (
auto *PackExpr = dyn_cast<PackIndexingExpr>(E)) {
9742 IDExpr = PackExpr->getPackIdExpression();
9744 IDExpr = PackExpr->getSelectedExpr();
9760 if (
const auto *SNTTPE = dyn_cast<SubstNonTypeTemplateParmExpr>(IDExpr))
9761 return SNTTPE->getParameterType(
Context);
9769 if (
const auto *DRE = dyn_cast<DeclRefExpr>(IDExpr)) {
9774 if (
const auto *ME = dyn_cast<MemberExpr>(IDExpr)) {
9775 if (
const auto *VD = ME->getMemberDecl())
9777 return VD->getType();
9778 }
else if (
const auto *IR = dyn_cast<ObjCIvarRefExpr>(IDExpr)) {
9779 return IR->getDecl()->getType();
9780 }
else if (
const auto *PR = dyn_cast<ObjCPropertyRefExpr>(IDExpr)) {
9781 if (PR->isExplicitProperty())
9782 return PR->getExplicitProperty()->getType();
9783 }
else if (
const auto *PE = dyn_cast<PredefinedExpr>(IDExpr)) {
9784 return PE->getType();
9795 if (
auto *DRE = dyn_cast<DeclRefExpr>(IDExpr->
IgnoreParens())) {
9796 if (
auto *Var = dyn_cast<VarDecl>(DRE->getDecl())) {
9799 return Context.getLValueReferenceType(
T);
9804 return Context.getReferenceQualifiedType(E);
9816 Diag(E->
getExprLoc(), diag::warn_side_effects_unevaluated_context);
9829 Diag(Loc, diag::err_expected_name_of_pack) << Pattern;
9835 : diag::ext_pack_indexing);
9842 bool FullySubstituted,
9853 IndexExpr = Res.
get();
9854 int64_t
V =
Value.getExtValue();
9855 if (FullySubstituted && (
V < 0 || V >= int64_t(Expansions.size()))) {
9857 <<
V << Pattern << Expansions.size();
9860 Index =
static_cast<unsigned>(
V);
9863 return Context.getPackIndexingType(Pattern, IndexExpr, FullySubstituted,
9869 assert(BaseType->isEnumeralType());
9870 EnumDecl *ED = BaseType->castAs<EnumType>()->getOriginalDecl();
9875 if (Underlying.
isNull()) {
9881 assert(!Underlying.
isNull());
9889 if (!BaseType->isEnumeralType()) {
9890 Diag(Loc, diag::err_only_enums_have_underlying_types);
9897 if (BaseType->isIncompleteType(&FwdDecl)) {
9898 Diag(Loc, diag::err_underlying_type_of_incomplete_enum) << BaseType;
9899 Diag(FwdDecl->
getLocation(), diag::note_forward_declaration) << FwdDecl;
9907 QualType Pointer = BaseType.isReferenceable() || BaseType->isVoidType()
9916 if (!BaseType->isAnyPointerType())
9925 return Context.getDecayedType(Underlying);
9934 Split.Quals.removeCVRQualifiers();
9935 return Context.getQualifiedType(Split);
9942 BaseType.isReferenceable()
9944 UKind == UnaryTransformType::AddLvalueReference,
9952 if (UKind == UnaryTransformType::RemoveAllExtents)
9953 return Context.getBaseElementType(BaseType);
9955 if (
const auto *AT =
Context.getAsArrayType(BaseType))
9956 return AT->getElementType();
9964 QualType T = BaseType.getNonReferenceType();
9965 if (UKind == UTTKind::RemoveCVRef &&
9966 (
T.isConstQualified() ||
T.isVolatileQualified())) {
9971 T =
Context.getQualifiedType(Unqual, Quals);
9978 if ((BaseType->isReferenceType() && UKind != UTTKind::RemoveRestrict) ||
9979 BaseType->isFunctionType())
9985 if (UKind == UTTKind::RemoveConst || UKind == UTTKind::RemoveCV)
9987 if (UKind == UTTKind::RemoveVolatile || UKind == UTTKind::RemoveCV)
9989 if (UKind == UTTKind::RemoveRestrict)
9992 return Context.getQualifiedType(Unqual, Quals);
9998 if (BaseType->isEnumeralType()) {
10000 if (
auto *
BitInt = dyn_cast<BitIntType>(Underlying)) {
10001 unsigned int Bits =
BitInt->getNumBits();
10005 S.
Diag(Loc, diag::err_make_signed_integral_only)
10006 << IsMakeSigned <<
true << BaseType << 1 << Underlying;
10010 S.
Diag(Loc, diag::err_make_signed_integral_only)
10011 << IsMakeSigned <<
false << BaseType << 1
10018 std::array<CanQualType *, 6> AllSignedIntegers = {
10022 AllSignedIntegers.data(), AllSignedIntegers.size() - Int128Unsupported);
10023 std::array<CanQualType *, 6> AllUnsignedIntegers = {
10028 AllUnsignedIntegers.size() -
10029 Int128Unsupported);
10031 IsMakeSigned ? &AvailableSignedIntegers : &AvailableUnsignedIntegers;
10035 llvm::find_if(*Consider, [&S, BaseSize](
const CanQual<Type> *
T) {
10039 assert(Result != Consider->end());
10040 return QualType((*Result)->getTypePtr(), 0);
10045 bool IsMakeSigned = UKind == UnaryTransformType::MakeSigned;
10046 if ((!BaseType->isIntegerType() && !BaseType->isEnumeralType()) ||
10047 BaseType->isBooleanType() ||
10048 (BaseType->isBitIntType() &&
10050 Diag(Loc, diag::err_make_signed_integral_only)
10051 << IsMakeSigned << BaseType->isBitIntType() << BaseType << 0;
10055 bool IsNonIntIntegral =
10056 BaseType->
isChar16Type() || BaseType->isChar32Type() ||
10057 BaseType->isWideCharType() || BaseType->isEnumeralType();
10062 : IsMakeSigned ?
Context.getCorrespondingSignedType(BaseType)
10063 :
Context.getCorrespondingUnsignedType(BaseType);
10064 if (Underlying.
isNull())
10071 if (BaseType->isDependentType())
10072 return Context.getUnaryTransformType(BaseType, BaseType, UKind);
10075 case UnaryTransformType::EnumUnderlyingType: {
10079 case UnaryTransformType::AddPointer: {
10083 case UnaryTransformType::RemovePointer: {
10087 case UnaryTransformType::Decay: {
10091 case UnaryTransformType::AddLvalueReference:
10092 case UnaryTransformType::AddRvalueReference: {
10096 case UnaryTransformType::RemoveAllExtents:
10097 case UnaryTransformType::RemoveExtent: {
10101 case UnaryTransformType::RemoveCVRef:
10102 case UnaryTransformType::RemoveReference: {
10106 case UnaryTransformType::RemoveConst:
10107 case UnaryTransformType::RemoveCV:
10108 case UnaryTransformType::RemoveRestrict:
10109 case UnaryTransformType::RemoveVolatile: {
10113 case UnaryTransformType::MakeSigned:
10114 case UnaryTransformType::MakeUnsigned: {
10132 int DisallowedKind = -1;
10133 if (
T->isArrayType())
10134 DisallowedKind = 1;
10135 else if (
T->isFunctionType())
10136 DisallowedKind = 2;
10137 else if (
T->isReferenceType())
10138 DisallowedKind = 3;
10139 else if (
T->isAtomicType())
10140 DisallowedKind = 4;
10141 else if (
T.hasQualifiers())
10142 DisallowedKind = 5;
10143 else if (
T->isSizelessType())
10144 DisallowedKind = 6;
10147 DisallowedKind = 7;
10148 else if (
T->isBitIntType())
10149 DisallowedKind = 8;
10152 DisallowedKind = 9;
10154 if (DisallowedKind != -1) {
10155 Diag(Loc, diag::err_atomic_specifier_bad_type) << DisallowedKind <<
T;
Defines the clang::ASTContext interface.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
Defines the clang::LangOptions interface.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Defines the clang::Preprocessor interface.
static QualType getUnderlyingType(const SubRegion *R)
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
This file declares semantic analysis for CUDA constructs.
This file declares semantic analysis for HLSL constructs.
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenMP constructs and clauses.
static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr, Sema &S, VectorKind VecKind)
HandleNeonVectorTypeAttr - The "neon_vector_type" and "neon_polyvector_type" attributes are used to c...
static QualType deduceOpenCLPointeeAddrSpace(Sema &S, QualType PointeeType)
static bool isPermittedNeonBaseType(QualType &Ty, VectorKind VecKind, Sema &S)
static void distributeObjCPointerTypeAttr(TypeProcessingState &state, ParsedAttr &attr, QualType type)
Given that an objc_gc attribute was written somewhere on a declaration other than on the declarator i...
static void maybeSynthesizeBlockSignature(TypeProcessingState &state, QualType declSpecType)
Add a synthetic '()' to a block-literal declarator if it is required, given the return type.
#define MS_TYPE_ATTRS_CASELIST
#define CALLING_CONV_ATTRS_CASELIST
static void emitNullabilityConsistencyWarning(Sema &S, SimplePointerKind PointerKind, SourceLocation PointerLoc, SourceLocation PointerEndLoc)
static void fixItNullability(Sema &S, DiagBuilderT &Diag, SourceLocation PointerLoc, NullabilityKind Nullability)
Creates a fix-it to insert a C-style nullability keyword at pointerLoc, taking into account whitespac...
static ExprResult checkArraySize(Sema &S, Expr *&ArraySize, llvm::APSInt &SizeVal, unsigned VLADiag, bool VLAIsError)
Check whether the specified array bound can be evaluated using the relevant language rules.
static Attr * createNullabilityAttr(ASTContext &Ctx, ParsedAttr &Attr, NullabilityKind NK)
static void HandleVectorSizeAttr(QualType &CurType, const ParsedAttr &Attr, Sema &S)
HandleVectorSizeAttribute - this attribute is only applicable to integral and float scalars,...
static void inferARCWriteback(TypeProcessingState &state, QualType &declSpecType)
Given that this is the declaration of a parameter under ARC, attempt to infer attributes and such for...
static TypeSourceInfo * GetTypeSourceInfoForDeclarator(TypeProcessingState &State, QualType T, TypeSourceInfo *ReturnTypeInfo)
Create and instantiate a TypeSourceInfo with type source information.
static bool BuildAddressSpaceIndex(Sema &S, LangAS &ASIdx, const Expr *AddrSpace, SourceLocation AttrLoc)
Build an AddressSpace index from a constant expression and diagnose any errors related to invalid add...
static void HandleBTFTypeTagAttribute(QualType &Type, const ParsedAttr &Attr, TypeProcessingState &State)
static void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state, Qualifiers::ObjCLifetime ownership, unsigned chunkIndex)
static bool handleObjCGCTypeAttr(TypeProcessingState &state, ParsedAttr &attr, QualType &type)
handleObjCGCTypeAttr - Process the attribute((objc_gc)) type attribute on the specified type.
static void fillAtomicQualLoc(AtomicTypeLoc ATL, const DeclaratorChunk &Chunk)
static void HandleExtVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr, Sema &S)
Process the OpenCL-like ext_vector_type attribute when it occurs on a type.
static void HandleHLSLParamModifierAttr(TypeProcessingState &State, QualType &CurType, const ParsedAttr &Attr, Sema &S)
static void HandleLifetimeBoundAttr(TypeProcessingState &State, QualType &CurType, ParsedAttr &Attr)
static bool handleArmStateAttribute(Sema &S, FunctionProtoType::ExtProtoInfo &EPI, ParsedAttr &Attr, FunctionType::ArmStateValue State)
static bool handleArmAgnosticAttribute(Sema &S, FunctionProtoType::ExtProtoInfo &EPI, ParsedAttr &Attr)
static void distributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state, ParsedAttr &attr, QualType &declSpecType, CUDAFunctionTarget CFT)
A function type attribute was written in the decl spec.
static bool handleObjCPointerTypeAttr(TypeProcessingState &state, ParsedAttr &attr, QualType &type)
static QualType inferARCLifetimeForPointee(Sema &S, QualType type, SourceLocation loc, bool isReference)
Given that we're building a pointer or reference to the given.
static bool handleNonBlockingNonAllocatingTypeAttr(TypeProcessingState &TPState, ParsedAttr &PAttr, QualType &QT, FunctionTypeUnwrapper &Unwrapped)
static QualType ChangeIntegralSignedness(Sema &S, QualType BaseType, bool IsMakeSigned, SourceLocation Loc)
static bool CheckNullabilityTypeSpecifier(Sema &S, TypeProcessingState *State, ParsedAttr *PAttr, QualType &QT, NullabilityKind Nullability, SourceLocation NullabilityLoc, bool IsContextSensitive, bool AllowOnArrayType, bool OverrideExisting)
#define OBJC_POINTER_TYPE_ATTRS_CASELIST
static void diagnoseBadTypeAttribute(Sema &S, const ParsedAttr &attr, QualType type)
diagnoseBadTypeAttribute - Diagnoses a type attribute which doesn't apply to the given type.
static PointerDeclaratorKind classifyPointerDeclarator(Sema &S, QualType type, Declarator &declarator, PointerWrappingDeclaratorKind &wrappingKind)
Classify the given declarator, whose type-specified is type, based on what kind of pointer it refers ...
static bool verifyValidIntegerConstantExpr(Sema &S, const ParsedAttr &Attr, llvm::APSInt &Result)
static void HandleSwiftAttr(TypeProcessingState &State, TypeAttrLocation TAL, QualType &QT, ParsedAttr &PAttr)
static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &state, ParsedAttr &attr, QualType &type)
static bool shouldHaveNullability(QualType T)
static void HandleArmMveStrictPolymorphismAttr(TypeProcessingState &State, QualType &CurType, ParsedAttr &Attr)
static void warnAboutAmbiguousFunction(Sema &S, Declarator &D, DeclaratorChunk &DeclType, QualType RT)
Produce an appropriate diagnostic for an ambiguity between a function declarator and a C++ direct-ini...
static void distributeObjCPointerTypeAttrFromDeclarator(TypeProcessingState &state, ParsedAttr &attr, QualType &declSpecType)
Distribute an objc_gc type attribute that was written on the declarator.
static bool isMultiSubjectAttrAllowedOnType(const ParsedAttr &Attr)
static FileID getNullabilityCompletenessCheckFileID(Sema &S, SourceLocation loc)
static void HandleArmSveVectorBitsTypeAttr(QualType &CurType, ParsedAttr &Attr, Sema &S)
HandleArmSveVectorBitsTypeAttr - The "arm_sve_vector_bits" attribute is used to create fixed-length v...
#define FUNCTION_TYPE_ATTRS_CASELIST
static void HandleLifetimeCaptureByAttr(TypeProcessingState &State, QualType &CurType, ParsedAttr &PA)
static bool distributeNullabilityTypeAttr(TypeProcessingState &state, QualType type, ParsedAttr &attr)
Distribute a nullability type attribute that cannot be applied to the type specifier to a pointer,...
static void distributeTypeAttrsFromDeclarator(TypeProcessingState &state, QualType &declSpecType, CUDAFunctionTarget CFT)
Given that there are attributes written on the declarator or declaration itself, try to distribute an...
static void fillHLSLAttributedResourceTypeLoc(HLSLAttributedResourceTypeLoc TL, TypeProcessingState &State)
static bool isDependentOrGNUAutoType(QualType T)
static void distributeFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr, QualType type)
A function type attribute was written somewhere in a declaration other than on the declarator itself ...
static void HandleMatrixTypeAttr(QualType &CurType, const ParsedAttr &Attr, Sema &S)
HandleMatrixTypeAttr - "matrix_type" attribute, like ext_vector_type.
static bool HandleWebAssemblyFuncrefAttr(TypeProcessingState &State, QualType &QT, ParsedAttr &PAttr)
static bool hasOuterPointerLikeChunk(const Declarator &D, unsigned endIndex)
Returns true if any of the declarator chunks before endIndex include a level of indirection: array,...
static void HandleOpenCLAccessAttr(QualType &CurType, const ParsedAttr &Attr, Sema &S)
Handle OpenCL Access Qualifier Attribute.
static NullabilityKind mapNullabilityAttrKind(ParsedAttr::Kind kind)
Map a nullability attribute kind to a nullability kind.
static bool distributeFunctionTypeAttrToInnermost(TypeProcessingState &state, ParsedAttr &attr, ParsedAttributesView &attrList, QualType &declSpecType, CUDAFunctionTarget CFT)
Try to distribute a function type attribute to the innermost function chunk or type.
#define NULLABILITY_TYPE_ATTRS_CASELIST
static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state, TypeSourceInfo *&ReturnTypeInfo)
static void checkNullabilityConsistency(Sema &S, SimplePointerKind pointerKind, SourceLocation pointerLoc, SourceLocation pointerEndLoc=SourceLocation())
Complains about missing nullability if the file containing pointerLoc has other uses of nullability (...
static void transferARCOwnership(TypeProcessingState &state, QualType &declSpecTy, Qualifiers::ObjCLifetime ownership)
Used for transferring ownership in casts resulting in l-values.
static std::string getPrintableNameForEntity(DeclarationName Entity)
static std::string getFunctionQualifiersAsString(const FunctionProtoType *FnTy)
static QualType rebuildAttributedTypeWithoutNullability(ASTContext &Ctx, QualType Type)
Rebuild an attributed type without the nullability attribute on it.
static DeclaratorChunk * maybeMovePastReturnType(Declarator &declarator, unsigned i, bool onlyBlockPointers)
Given the index of a declarator chunk, check whether that chunk directly specifies the return type of...
static OpenCLAccessAttr::Spelling getImageAccess(const ParsedAttributesView &Attrs)
static void fillMatrixTypeLoc(MatrixTypeLoc MTL, const ParsedAttributesView &Attrs)
static UnaryTransformType::UTTKind TSTToUnaryTransformType(DeclSpec::TST SwitchTST)
static void HandleRISCVRVVVectorBitsTypeAttr(QualType &CurType, ParsedAttr &Attr, Sema &S)
HandleRISCVRVVVectorBitsTypeAttr - The "riscv_rvv_vector_bits" attribute is used to create fixed-leng...
static void HandleAddressSpaceTypeAttribute(QualType &Type, const ParsedAttr &Attr, TypeProcessingState &State)
HandleAddressSpaceTypeAttribute - Process an address_space attribute on the specified type.
static bool checkQualifiedFunction(Sema &S, QualType T, SourceLocation Loc, QualifiedFunctionKind QFK)
Check whether the type T is a qualified function type, and if it is, diagnose that it cannot be conta...
static bool checkOmittedBlockReturnType(Sema &S, Declarator &declarator, QualType Result)
Return true if this is omitted block return type.
static void HandlePtrAuthQualifier(ASTContext &Ctx, QualType &T, const ParsedAttr &Attr, Sema &S)
Handle the __ptrauth qualifier.
static bool DiagnoseMultipleAddrSpaceAttributes(Sema &S, LangAS ASOld, LangAS ASNew, SourceLocation AttrLoc)
static void warnAboutRedundantParens(Sema &S, Declarator &D, QualType T)
Produce an appropriate diagnostic for a declarator with top-level parentheses.
static QualType ConvertDeclSpecToType(TypeProcessingState &state)
Convert the specified declspec to the appropriate type object.
static std::pair< QualType, TypeSourceInfo * > InventTemplateParameter(TypeProcessingState &state, QualType T, TypeSourceInfo *TrailingTSI, AutoType *Auto, InventedTemplateParameterInfo &Info)
static void distributeFunctionTypeAttrFromDeclarator(TypeProcessingState &state, ParsedAttr &attr, QualType &declSpecType, CUDAFunctionTarget CFT)
A function type attribute was written on the declarator or declaration.
static void diagnoseAndRemoveTypeQualifiers(Sema &S, const DeclSpec &DS, unsigned &TypeQuals, QualType TypeSoFar, unsigned RemoveTQs, unsigned DiagID)
static CallingConv getCCForDeclaratorChunk(Sema &S, Declarator &D, const ParsedAttributesView &AttrList, const DeclaratorChunk::FunctionTypeInfo &FTI, unsigned ChunkIndex)
Helper for figuring out the default CC for a function declarator type.
static unsigned getLiteralDiagFromTagKind(TagTypeKind Tag)
Get diagnostic select index for tag kind for literal type diagnostic message.
static void recordNullabilitySeen(Sema &S, SourceLocation loc)
Marks that a nullability feature has been used in the file containing loc.
static bool CheckBitIntElementType(Sema &S, SourceLocation AttrLoc, const BitIntType *BIT, bool ForMatrixType=false)
static void checkExtParameterInfos(Sema &S, ArrayRef< QualType > paramTypes, const FunctionProtoType::ExtProtoInfo &EPI, llvm::function_ref< SourceLocation(unsigned)> getParamLoc)
Check the extended parameter information.
static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr, QualType &type, CUDAFunctionTarget CFT)
Process an individual function attribute.
static void transferARCOwnershipToDeclSpec(Sema &S, QualType &declSpecTy, Qualifiers::ObjCLifetime ownership)
static void BuildTypeCoupledDecls(Expr *E, llvm::SmallVectorImpl< TypeCoupledDeclRefInfo > &Decls)
static void assignInheritanceModel(Sema &S, CXXRecordDecl *RD)
Locks in the inheritance model for the given class and all of its bases.
static bool checkObjCKindOfType(TypeProcessingState &state, QualType &type, ParsedAttr &attr)
Check the application of the Objective-C '__kindof' qualifier to the given type.
static bool hasNullabilityAttr(const ParsedAttributesView &attrs)
Check whether there is a nullability attribute of any kind in the given attribute list.
static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state, ParsedAttr &attr, QualType &type)
handleObjCOwnershipTypeAttr - Process an objc_ownership attribute on the specified type.
static void moveAttrFromListToList(ParsedAttr &attr, ParsedAttributesView &fromList, ParsedAttributesView &toList)
static void HandleAnnotateTypeAttr(TypeProcessingState &State, QualType &CurType, const ParsedAttr &PA)
static void fillAttributedTypeLoc(AttributedTypeLoc TL, TypeProcessingState &State)
static void fillDependentAddressSpaceTypeLoc(DependentAddressSpaceTypeLoc DASTL, const ParsedAttributesView &Attrs)
TypeAttrLocation
The location of a type attribute.
@ TAL_DeclChunk
The attribute is part of a DeclaratorChunk.
@ TAL_DeclSpec
The attribute is in the decl-specifier-seq.
@ TAL_DeclName
The attribute is immediately after the declaration's name.
static bool isOmittedBlockReturnType(const Declarator &D)
isOmittedBlockReturnType - Return true if this declarator is missing a return type because this is a ...
static TypeSourceInfo * GetFullTypeForDeclarator(TypeProcessingState &state, QualType declSpecType, TypeSourceInfo *TInfo)
static QualType GetEnumUnderlyingType(Sema &S, QualType BaseType, SourceLocation Loc)
static bool IsNoDerefableChunk(const DeclaratorChunk &Chunk)
static AttrT * createSimpleAttr(ASTContext &Ctx, ParsedAttr &AL)
static void diagnoseRedundantReturnTypeQualifiers(Sema &S, QualType RetTy, Declarator &D, unsigned FunctionChunkIndex)
static void processTypeAttrs(TypeProcessingState &state, QualType &type, TypeAttrLocation TAL, const ParsedAttributesView &attrs, CUDAFunctionTarget CFT=CUDAFunctionTarget::HostDevice)
static bool checkMutualExclusion(TypeProcessingState &state, const FunctionProtoType::ExtProtoInfo &EPI, ParsedAttr &Attr, AttributeCommonInfo::Kind OtherKind)
static Attr * getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr)
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
static QualType getPointeeType(const MemRegion *R)
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__DEVICE__ int max(int __a, int __b)
virtual void AssignInheritanceModel(CXXRecordDecl *RD)
Callback invoked when an MSInheritanceAttr has been attached to a CXXRecordDecl.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
BuiltinVectorTypeInfo getBuiltinVectorTypeInfo(const BuiltinType *VecTy) const
Returns the element type, element count and number of vectors (in case of tuple) for a builtin vector...
TranslationUnitDecl * getTranslationUnitDecl() const
const FunctionType * adjustFunctionType(const FunctionType *Fn, FunctionType::ExtInfo EInfo)
Change the ExtInfo on a function type.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current context.
QualType getFunctionTypeWithExceptionSpec(QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI) const
Get a function type and produce the equivalent function type with the specified exception specificati...
CanQualType UnsignedLongTy
QualType removeAddrSpaceQualType(QualType T) const
Remove any existing address space on the type and returns the type with qualifiers intact (or that's ...
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
LangAS getDefaultOpenCLPointeeAddrSpace()
Returns default address space based on OpenCL version and enabled features.
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CanQualType UnsignedInt128Ty
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, TemplateDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
TypedefDecl * getBuiltinVaListDecl() const
Retrieve the C type declaration corresponding to the predefined __builtin_va_list type.
CanQualType UnsignedCharTy
CanQualType UnsignedIntTy
TypeSourceInfo * CreateTypeSourceInfo(QualType T, unsigned Size=0) const
Allocate an uninitialized TypeSourceInfo.
CanQualType UnsignedLongLongTy
CanQualType UnsignedShortTy
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
bool hasDirectOwnershipQualifier(QualType Ty) const
Return true if the type has been explicitly qualified with ObjC ownership.
DiagnosticsEngine & getDiagnostics() const
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
const TargetInfo & getTargetInfo() const
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
CanQualType getCanonicalTagType(const TagDecl *TD) const
QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const
Return the uniqued reference to the type for an Objective-C gc-qualified type.
QualType getPointerAuthType(QualType Ty, PointerAuthQualifier PointerAuth)
Return a type with the given __ptrauth qualifier.
uint64_t getCharWidth() const
Return the size of the character type, in bits.
QualType getBitIntType(bool Unsigned, unsigned NumBits) const
Return a bit-precise integer type with the specified signedness and bit count.
void setLBracketLoc(SourceLocation Loc)
void setRBracketLoc(SourceLocation Loc)
void setSizeExpr(Expr *Size)
TypeLoc getValueLoc() const
void setKWLoc(SourceLocation Loc)
void setParensRange(SourceRange Range)
Attr - This represents one attribute.
attr::Kind getKind() const
const char * getSpelling() const
SourceRange getRange() const
bool isContextSensitiveKeywordAttribute() const
bool isRegularKeywordAttribute() const
SourceLocation getLoc() const
const IdentifierInfo * getAttrName() const
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Type source information for an attributed type.
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
void setAttr(const Attr *A)
bool hasExplicitTemplateArgs() const
const NestedNameSpecifierLoc getNestedNameSpecifierLoc() const
SourceLocation getRAngleLoc() const
SourceLocation getLAngleLoc() const
void setConceptReference(ConceptReference *CR)
NamedDecl * getFoundDecl() const
TemplateArgumentLoc getArgLoc(unsigned i) const
unsigned getNumArgs() const
TemplateDecl * getNamedConcept() const
DeclarationNameInfo getConceptNameInfo() const
void setRParenLoc(SourceLocation Loc)
TypeLoc getWrappedLoc() const
Comparison function object.
A fixed int type of a specified bitwidth.
unsigned getNumBits() const
void setCaretLoc(SourceLocation Loc)
TypeSpecifierWidth getWrittenWidthSpec() const
bool needsExtraLocalData() const
void setBuiltinLoc(SourceLocation Loc)
WrittenBuiltinSpecs & getWrittenBuiltinSpecs()
TypeSpecifierSign getWrittenSignSpec() const
void expandBuiltinRange(SourceRange Range)
This class is used for builtin types like 'int'.
Represents a C++ destructor within a class.
Represents a C++ struct/union/class.
CXXRecordDecl * getMostRecentDecl()
bool hasUserProvidedDefaultConstructor() const
Whether this class has a user-provided default constructor per C++11.
bool hasDefinition() const
MSInheritanceModel calculateInheritanceModel() const
Calculate what the inheritance model would be for this class.
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Represents a C++ nested-name-specifier or a global scope specifier.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
Represents a canonical, potentially-qualified type.
SourceLocation getBegin() const
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
const TypeClass * getTypePtr() const
TypeLoc getNextTypeLoc() const
static unsigned getNumAddressingBits(const ASTContext &Context, QualType ElementType, const llvm::APInt &NumElements)
Determine the number of bits required to address a member of.
static unsigned getMaxSizeBits(const ASTContext &Context)
Determine the maximum number of active bits that an array's size can require, which limits the maximu...
static constexpr bool isDimensionValid(size_t NumElements)
Returns true if NumElements is a valid matrix dimension.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
bool isFunctionOrMethod() const
A reference to a declared variable, function, enum, etc.
Captures information about "declaration specifiers".
const WrittenBuiltinSpecs & getWrittenBuiltinSpecs() const
bool isTypeSpecPipe() const
static const TST TST_typeof_unqualType
SourceLocation getTypeSpecSignLoc() const
bool hasAutoTypeSpec() const
static const TST TST_typename
SourceLocation getEndLoc() const LLVM_READONLY
bool hasTypeSpecifier() const
Return true if any type-specifier has been found.
static const TST TST_char8
static const TST TST_BFloat16
Expr * getPackIndexingExpr() const
TST getTypeSpecType() const
SCS getStorageClassSpec() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool isTypeSpecSat() const
SourceRange getSourceRange() const LLVM_READONLY
static const TST TST_auto_type
static const TST TST_interface
static const TST TST_double
static const TST TST_typeofExpr
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
TemplateIdAnnotation * getRepAsTemplateId() const
static const TST TST_union
static const TST TST_typename_pack_indexing
static const TST TST_char
static const TST TST_bool
static const TST TST_char16
static const TST TST_unknown_anytype
TSC getTypeSpecComplex() const
ParsedType getRepAsType() const
static const TST TST_accum
static const TST TST_half
ParsedAttributes & getAttributes()
SourceLocation getEllipsisLoc() const
bool isTypeAltiVecPixel() const
void ClearTypeQualifiers()
Clear out all of the type qualifiers.
SourceLocation getConstSpecLoc() const
static const TST TST_ibm128
Expr * getRepAsExpr() const
static const TST TST_enum
AttributePool & getAttributePool() const
static const TST TST_float128
static const TST TST_decltype
SourceRange getTypeSpecWidthRange() const
SourceLocation getTypeSpecTypeNameLoc() const
SourceLocation getTypeSpecWidthLoc() const
SourceLocation getRestrictSpecLoc() const
static const TST TST_typeof_unqualExpr
static const TST TST_class
bool hasTagDefinition() const
static const TST TST_decimal64
unsigned getParsedSpecifiers() const
Return a bitmask of which flavors of specifiers this DeclSpec includes.
bool isTypeAltiVecBool() const
bool isConstrainedAuto() const
static const TST TST_wchar
SourceLocation getTypeSpecComplexLoc() const
static const TST TST_void
bool isTypeAltiVecVector() const
static const TST TST_bitint
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
static const TST TST_float
static const TST TST_atomic
static const TST TST_fract
Decl * getRepAsDecl() const
static const TST TST_float16
static bool isTransformTypeTrait(TST T)
static const TST TST_unspecified
SourceLocation getAtomicSpecLoc() const
TypeSpecifierSign getTypeSpecSign() const
CXXScopeSpec & getTypeSpecScope()
SourceLocation getTypeSpecTypeLoc() const
static const TST TST_decltype_auto
static const TST TST_error
void forEachQualifier(llvm::function_ref< void(TQ, StringRef, SourceLocation)> Handle)
This method calls the passed in handler on each qual being set.
static const TST TST_decimal32
TypeSpecifierWidth getTypeSpecWidth() const
static const TST TST_char32
static const TST TST_decimal128
bool isTypeSpecOwned() const
SourceLocation getTypeSpecSatLoc() const
SourceRange getTypeofParensRange() const
SourceLocation getUnalignedSpecLoc() const
static const TST TST_int128
SourceLocation getVolatileSpecLoc() const
FriendSpecified isFriendSpecified() const
static const TST TST_typeofType
static const TST TST_auto
ConstexprSpecKind getConstexprSpecifier() const
static const TST TST_struct
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
bool isInvalidDecl() const
SourceLocation getLocation() const
void setImplicit(bool I=true)
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
std::string getAsString() const
Retrieve the human-readable string for this name.
NameKind getNameKind() const
Determine what kind of name this is.
Information about one declarator, including the parsed type information and the identifier.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
const DeclaratorChunk * getInnermostNonParenChunk() const
Return the innermost (closest to the declarator) chunk of this declarator that is not a parens chunk,...
void AddInnermostTypeInfo(const DeclaratorChunk &TI)
Add a new innermost chunk to this declarator.
bool isFunctionDeclarationContext() const
Return true if this declaration appears in a context where a function declarator would be a function ...
FunctionDefinitionKind getFunctionDefinitionKind() const
const ParsedAttributes & getAttributes() const
SourceLocation getIdentifierLoc() const
bool hasTrailingReturnType() const
Determine whether a trailing return type was written (at any level) within this declarator.
SourceLocation getEndLoc() const LLVM_READONLY
bool isExpressionContext() const
Determine whether this declaration appears in a context where an expression could appear.
type_object_range type_objects() const
Returns the range of type objects, from the identifier outwards.
void setInvalidType(bool Val=true)
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
const ParsedAttributesView & getDeclarationAttributes() const
SourceLocation getEllipsisLoc() const
DeclaratorContext getContext() const
SourceLocation getBeginLoc() const LLVM_READONLY
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
bool isFirstDeclarator() const
SourceLocation getCommaLoc() const
AttributePool & getAttributePool() const
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
ParsedType getTrailingReturnType() const
Get the trailing return type appearing (at any level) within this declarator.
bool isInvalidType() const
bool isExplicitObjectMemberFunction()
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
bool isFirstDeclarationOfMember()
Returns true if this declares a real member and not a friend.
bool isPrototypeContext() const
bool isStaticMember()
Returns true if this declares a static member.
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
void setEllipsisLoc(SourceLocation EL)
const IdentifierInfo * getIdentifier() const
void setRParenLoc(SourceLocation Loc)
void setDecltypeLoc(SourceLocation Loc)
void setAttrNameLoc(SourceLocation loc)
void setAttrOperandParensRange(SourceRange range)
void setAttrExprOperand(Expr *e)
Represents an extended address space qualifier where the input address space value is dependent.
void copy(DependentNameTypeLoc Loc)
void setNameLoc(SourceLocation Loc)
void setNameLoc(SourceLocation Loc)
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
bool getSuppressSystemWarnings() const
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
void set(SourceLocation ElaboratedKeywordLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation NameLoc)
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
EnumDecl * getDefinition() const
This represents one expression.
bool isValueDependent() const
Determines whether the value of this expression depends on.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
A SourceLocation and its associated SourceManager.
unsigned getSpellingLineNumber(bool *Invalid=nullptr) const
bool isUserProvided() const
True if this method is user-declared and was not deleted or defaulted on its first declaration.
A mutable set of FunctionEffects and possibly conditions attached to them.
bool insert(const FunctionEffectWithCondition &NewEC, Conflicts &Errs)
SmallVector< Conflict > Conflicts
Represents an abstract function effect, using just an enumeration describing its kind.
Kind
Identifies the particular effect.
An immutable set of FunctionEffects and possibly conditions attached to them.
Represents a prototype with parameter type info, e.g.
Qualifiers getMethodQuals() const
bool isVariadic() const
Whether this function prototype is variadic.
ExtProtoInfo getExtProtoInfo() const
ArrayRef< QualType > getParamTypes() const
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
unsigned getNumParams() const
void setLocalRangeBegin(SourceLocation L)
void setLParenLoc(SourceLocation Loc)
void setParam(unsigned i, ParmVarDecl *VD)
void setRParenLoc(SourceLocation Loc)
void setLocalRangeEnd(SourceLocation L)
void setExceptionSpecRange(SourceRange R)
A class which abstracts out some details necessary for making a call.
ExtInfo withCallingConv(CallingConv cc) const
CallingConv getCC() const
bool getProducesResult() const
ParameterABI getABI() const
Return the ABI treatment of this parameter.
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
static StringRef getNameForCallConv(CallingConv CC)
AArch64SMETypeAttributes
The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number of function type attributes that...
@ SME_PStateSMEnabledMask
@ SME_PStateSMCompatibleMask
@ SME_AgnosticZAStateMask
static ArmStateValue getArmZT0State(unsigned AttrBits)
static ArmStateValue getArmZAState(unsigned AttrBits)
CallingConv getCallConv() const
QualType getReturnType() const
bool getHasRegParm() const
Type source information for HLSL attributed resource type.
TypeLoc getWrappedLoc() const
void setContainedTypeSourceInfo(TypeSourceInfo *TSI) const
void setSourceRange(const SourceRange &R)
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
A simple pair of identifier info and location.
void setIdentifierInfo(IdentifierInfo *Ident)
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ElaboratedTypeKeyword getKeyword() const
void setAmpLoc(SourceLocation Loc)
An lvalue reference type, per C++11 [dcl.ref].
@ PPTMK_FullGeneralityMultipleInheritance
@ PPTMK_FullGeneralityVirtualInheritance
@ PPTMK_FullGeneralitySingleInheritance
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool requiresStrictPrototypes() const
Returns true if functions without prototypes or functions with an identifier list (aka K&R C function...
bool isImplicitIntAllowed() const
Returns true if implicit int is supported at all.
bool allowArrayReturnTypes() const
bool isTargetDevice() const
True when compiling for an offloading target device.
bool isImplicitIntRequired() const
Returns true if implicit int is part of the language requirements.
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
Holds a QualType and a TypeSourceInfo* that came out of a declarator parsing.
void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const
Represents the results of name lookup.
TypeLoc getInnerLoc() const
void setExpansionLoc(SourceLocation Loc)
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
void setAttrRowOperand(Expr *e)
void setAttrColumnOperand(Expr *e)
void setAttrOperandParensRange(SourceRange range)
void setAttrNameLoc(SourceLocation loc)
static bool isValidElementType(QualType T)
Valid elements types are the following:
void setStarLoc(SourceLocation Loc)
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
A pointer to member type per C++ 8.3.3 - Pointers to members.
NestedNameSpecifier getQualifier() const
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
QualType getPointeeType() const
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
This represents a decl that may have a name.
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
NamespaceAndPrefix getAsNamespaceAndPrefix() const
const Type * getAsType() const
@ Global
The global specifier '::'. There is no stored value.
@ Type
A type, stored as a Type*.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
Represents an ObjC class declaration.
void setNameLoc(SourceLocation Loc)
void setNameEndLoc(SourceLocation Loc)
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Wraps an ObjCPointerType with source location information.
void setStarLoc(SourceLocation Loc)
Represents a pointer to an Objective C object.
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
static OpaquePtr make(QualType P)
OpenCL supported extensions and optional core features.
bool isAvailableOption(llvm::StringRef Ext, const LangOptions &LO) const
bool isSupported(llvm::StringRef Ext, const LangOptions &LO) const
void setEllipsisLoc(SourceLocation Loc)
A parameter attribute which changes the argument-passing ABI rule for the parameter.
void setRParenLoc(SourceLocation Loc)
void setLParenLoc(SourceLocation Loc)
Represents a parameter to a function.
ParsedAttr - Represents a syntactic attribute.
void setInvalid(bool b=true) const
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
bool isArgIdent(unsigned Arg) const
Expr * getArgAsExpr(unsigned Arg) const
AttributeCommonInfo::Kind getKind() const
void setUsedAsTypeAttr(bool Used=true)
bool checkAtMostNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at most as many args as Num.
bool hasMSPropertyAttr() const
void addAtEnd(ParsedAttr *newAttr)
bool hasAttribute(ParsedAttr::Kind K) const
void remove(ParsedAttr *ToBeRemoved)
void takeOneFrom(ParsedAttributes &Other, ParsedAttr *PA)
TypeLoc getValueLoc() const
void setKWLoc(SourceLocation Loc)
Pointer-authentication qualifiers.
static PointerAuthQualifier Create(unsigned Key, bool IsAddressDiscriminated, unsigned ExtraDiscriminator, PointerAuthenticationMode AuthenticationMode, bool IsIsaPointer, bool AuthenticatesNullValues)
@ MaxKey
The maximum supported pointer-authentication key.
void setStarLoc(SourceLocation Loc)
PointerType - C99 6.7.5.1 - Pointer Declarators.
SourceLocation getPragmaAssumeNonNullLoc() const
The location of the currently-active #pragma clang assume_nonnull begin.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
PointerAuthQualifier getPointerAuth() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
unsigned getLocalCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers local to this particular QualType instan...
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
SplitQualType getSplitUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool hasAddressSpace() const
Check if this type has any address space qualifier.
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
UnqualTypeLoc getUnqualifiedLoc() const
The collection of all-type qualifiers we support.
void removeCVRQualifiers(unsigned mask)
void addAddressSpace(LangAS space)
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
void removeObjCLifetime()
void addCVRUQualifiers(unsigned mask)
static Qualifiers fromCVRMask(unsigned CVR)
void setUnaligned(bool flag)
std::string getAsString() const
@ MaxAddressSpace
The maximum supported address space number.
void addObjCLifetime(ObjCLifetime type)
void setAmpAmpLoc(SourceLocation Loc)
QualType getPointeeType() const
bool isSpelledAsLValue() const
bool isFunctionDeclarationScope() const
isFunctionDeclarationScope - Return true if this scope is a function prototype scope.
A generic diagnostic builder for errors which may or may not be deferred.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
CUDAFunctionTarget IdentifyTarget(const FunctionDecl *D, bool IgnoreImplicitHDAttr=false)
Determines whether the given function is a CUDA device/host/kernel/etc.
QualType ProcessResourceTypeAttributes(QualType Wrapped)
QualType getInoutParameterType(QualType Ty)
bool isCFError(RecordDecl *D)
IdentifierInfo * getNSErrorIdent()
Retrieve the identifier "NSError".
bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type)
bool shouldDelayDiagnostics()
Determines whether diagnostics should be delayed.
void add(const sema::DelayedDiagnostic &diag)
Adds a delayed diagnostic.
Abstract base class used for diagnosing integer constant expression violations.
Sema - This implements semantic analysis and AST building for C.
bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a reachable definition.
QualType BuildParenType(QualType T)
Build a paren type including T.
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, MutableArrayRef< Expr * > Args)
ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs (unless they are value dependent ...
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
Scope * getCurScope() const
Retrieve the parser's current scope.
bool hasStructuralCompatLayout(Decl *D, Decl *Suggested)
Determine if D and Suggested have a structurally compatible layout as described in C11 6....
bool checkArrayElementAlignment(QualType EltTy, SourceLocation Loc)
bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, const Ts &...Args)
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
UnaryTransformType::UTTKind UTTKind
QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, SourceLocation AttrLoc)
BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an expression is uninstantiated.
bool checkPointerAuthDiscriminatorArg(Expr *Arg, PointerAuthDiscArgKind Kind, unsigned &IntVal)
QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc)
std::optional< FunctionEffectMode > ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName)
Try to parse the conditional expression attached to an effect attribute (e.g.
@ AcceptSizeless
Relax the normal rules for complete types so that they include sizeless built-in types.
class clang::Sema::DelayedDiagnostics DelayedDiagnostics
QualType BuildExtVectorType(QualType T, Expr *ArraySize, SourceLocation AttrLoc)
Build an ext-vector type.
const AttributedType * getCallingConvAttributedType(QualType T) const
Get the outermost AttributedType node that sets a calling convention.
bool hasMergedDefinitionInCurrentModule(const NamedDecl *Def)
bool InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain, bool PrimaryStrictPackMatch)
QualType BuildFunctionType(QualType T, MutableArrayRef< QualType > ParamTypes, SourceLocation Loc, DeclarationName Entity, const FunctionProtoType::ExtProtoInfo &EPI)
Build a function type.
bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMemberKind CSM, TrivialABIHandling TAH=TrivialABIHandling::IgnoreTrivialABI, bool Diagnose=false)
Determine whether a defaulted or deleted special member function is trivial, as specified in C++11 [c...
void checkSpecializationReachability(SourceLocation Loc, NamedDecl *Spec)
ASTContext & getASTContext() const
void translateTemplateArguments(const ASTTemplateArgsPtr &In, TemplateArgumentListInfo &Out)
Translates template arguments as provided by the parser into template arguments used by semantic anal...
void checkExceptionSpecification(bool IsTopLevel, ExceptionSpecificationType EST, ArrayRef< ParsedType > DynamicExceptions, ArrayRef< SourceRange > DynamicExceptionRanges, Expr *NoexceptExpr, SmallVectorImpl< QualType > &Exceptions, FunctionProtoType::ExceptionSpecInfo &ESI)
Check the given exception-specification and update the exception specification information with the r...
void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, VarDecl *Var, bool Recursive=false, bool DefinitionRequired=false, bool AtEndOfTU=false)
Instantiate the definition of the given variable from its template.
bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC, const FunctionDecl *FD=nullptr, CUDAFunctionTarget CFT=CUDAFunctionTarget::InvalidTarget)
Check validaty of calling convention attribute attr.
bool RequireLiteralType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a literal type.
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
std::string getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const
Get a string to suggest for zero-initialization of a type.
bool CheckAttrNoArgs(const ParsedAttr &CurrAttr)
ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, llvm::APSInt &Value, CCEKind CCE)
QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc)
Build a bit-precise integer type.
LangAS getDefaultCXXMethodAddrSpace() const
Returns default addr space for method qualifiers.
QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind, SourceLocation Loc)
QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, const DeclSpec *DS=nullptr)
bool CheckFunctionReturnType(QualType T, SourceLocation Loc)
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
@ UPPC_TypeConstraint
A type constraint.
const LangOptions & getLangOpts() const
bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type of the given expression is complete.
void NoteTemplateLocation(const NamedDecl &Decl, std::optional< SourceRange > ParamRange={})
QualType BuiltinEnumUnderlyingType(QualType BaseType, SourceLocation Loc)
bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)
If the given type contains an unexpanded parameter pack, diagnose the error.
bool RequireNonAbstractType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
void CheckExtraCXXDefaultArguments(Declarator &D)
CheckExtraCXXDefaultArguments - Check for any extra default arguments in the declarator,...
const LangOptions & LangOpts
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
IdentifierInfo * InventAbbreviatedTemplateParameterTypeName(const IdentifierInfo *ParamName, unsigned Index)
Invent a new identifier for parameters of abbreviated templates.
bool checkConstantPointerAuthKey(Expr *keyExpr, unsigned &key)
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
SmallVector< InventedTemplateParameterInfo, 4 > InventedParameterInfos
Stack containing information needed when in C++2a an 'auto' is encountered in a function declaration ...
std::vector< std::unique_ptr< TemplateInstantiationCallback > > TemplateInstCallbacks
The template instantiation callbacks to trace or track instantiations (objects can be chained).
void completeExprArrayBound(Expr *E)
bool hasExplicitCallingConv(QualType T)
bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value)
Checks a regparm attribute, returning true if it is ill-formed and otherwise setting numParams to the...
FileNullabilityMap NullabilityMap
A mapping that describes the nullability we've seen in each header file.
sema::FunctionScopeInfo * getCurFunction() const
QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc, DeclarationName Entity)
Build a reference type.
std::optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
bool findMacroSpelling(SourceLocation &loc, StringRef name)
Looks through the macro-expansion chain for the given location, looking for a macro expansion with th...
QualType BuildMemberPointerType(QualType T, const CXXScopeSpec &SS, CXXRecordDecl *Cls, SourceLocation Loc, DeclarationName Entity)
Build a member pointer type T Class::*.
ExprResult DefaultLvalueConversion(Expr *E)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(const NamedDecl *D, const DeclContext *DC=nullptr, bool Final=false, std::optional< ArrayRef< TemplateArgument > > Innermost=std::nullopt, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr, bool ForConstraintInstantiation=false, bool SkipForSpecialization=false, bool ForDefaultArgumentSubstitution=false)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
QualType BuiltinDecay(QualType BaseType, SourceLocation Loc)
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
Retrieve the keyword associated.
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5.
TemplateNameKindForDiagnostics getTemplateNameKindForDiagnostics(TemplateName Name)
bool isAcceptable(const NamedDecl *D, AcceptableKind Kind)
Determine whether a declaration is acceptable (visible/reachable).
QualType getDecltypeForExpr(Expr *E)
getDecltypeForExpr - Given an expr, will return the decltype for that expression, according to the ru...
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a visible definition.
bool inTemplateInstantiation() const
Determine whether we are currently performing template instantiation.
SourceManager & getSourceManager() const
QualType BuiltinAddReference(QualType BaseType, UTTKind UKind, SourceLocation Loc)
bool hasVisibleMergedDefinition(const NamedDecl *Def)
QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted=false, ArrayRef< QualType > Expansions={})
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
QualType BuildAtomicType(QualType T, SourceLocation Loc)
void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, MissingImportKind MIK, bool Recover=true)
Diagnose that the specified declaration needs to be visible but isn't, and suggest a module import th...
bool AttachTypeConstraint(NestedNameSpecifierLoc NS, DeclarationNameInfo NameInfo, TemplateDecl *NamedConcept, NamedDecl *FoundDecl, const TemplateArgumentListInfo *TemplateArgs, TemplateTypeParmDecl *ConstrainedParameter, SourceLocation EllipsisLoc)
Attach a type-constraint to a template parameter.
bool diagnoseConflictingFunctionEffect(const FunctionEffectsRef &FX, const FunctionEffectWithCondition &EC, SourceLocation NewAttrLoc)
Warn and return true if adding a function effect to a set would create a conflict.
TypeSourceInfo * ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, QualType Replacement)
TypeResult ActOnTypeName(Declarator &D)
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr, bool SkipTrailingRequiresClause=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics.
bool isCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind=CompleteTypeKind::Default)
bool InstantiateClass(SourceLocation PointOfInstantiation, CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK, bool Complain=true)
Instantiate the definition of a class from a given pattern.
void checkUnusedDeclAttributes(Declarator &D)
checkUnusedDeclAttributes - Given a declarator which is not being used to build a declaration,...
QualType BuildPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a pointer type.
bool CheckAttrTarget(const ParsedAttr &CurrAttr)
QualType BuiltinAddPointer(QualType BaseType, SourceLocation Loc)
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, VerifyICEDiagnoser &Diagnoser, AllowFoldKind CanFold=AllowFoldKind::No)
VerifyIntegerConstantExpression - Verifies that an expression is an ICE, and reports the appropriate ...
IntrusiveRefCntPtr< ExternalSemaSource > ExternalSource
Source of additional semantic information.
bool CheckImplicitNullabilityTypeSpecifier(QualType &Type, NullabilityKind Nullability, SourceLocation DiagLoc, bool AllowArrayTypes, bool OverrideExisting)
Check whether a nullability type specifier can be added to the given type through some means not writ...
void CheckConstrainedAuto(const AutoType *AutoT, SourceLocation Loc)
bool CheckDistantExceptionSpec(QualType T)
CheckDistantExceptionSpec - Check if the given type is a pointer or pointer to member to a function w...
QualType BuildDecltypeType(Expr *E, bool AsUnevaluated=true)
If AsUnevaluated is false, E is treated as though it were an evaluated context, such as when building...
QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, SourceLocation Loc)
TypeSourceInfo * GetTypeForDeclarator(Declarator &D)
GetTypeForDeclarator - Convert the type for the specified declarator to Type instances.
TypeSourceInfo * GetTypeForDeclaratorCast(Declarator &D, QualType FromTy)
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
QualType getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc)
Given a variable, determine the type that a reference to that variable will have in the given scope.
QualType BuiltinRemoveExtent(QualType BaseType, UTTKind UKind, SourceLocation Loc)
QualType getCompletedType(Expr *E)
Get the type of expression E, triggering instantiation to complete the type if necessary – that is,...
QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind, SourceLocation Loc)
bool isDependentScopeSpecifier(const CXXScopeSpec &SS)
SourceManager & SourceMgr
DiagnosticsEngine & Diags
OpenCLOptions & getOpenCLOptions()
QualType BuiltinRemovePointer(QualType BaseType, SourceLocation Loc)
QualType BuildArrayType(QualType T, ArraySizeModifier ASM, Expr *ArraySize, unsigned Quals, SourceRange Brackets, DeclarationName Entity)
Build an array type.
bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc)
QualType BuildReadPipeType(QualType T, SourceLocation Loc)
Build a Read-only Pipe type.
void diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, SourceLocation FallbackLoc, SourceLocation ConstQualLoc=SourceLocation(), SourceLocation VolatileQualLoc=SourceLocation(), SourceLocation RestrictQualLoc=SourceLocation(), SourceLocation AtomicQualLoc=SourceLocation(), SourceLocation UnalignedQualLoc=SourceLocation())
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
llvm::BumpPtrAllocator BumpAlloc
QualType BuildWritePipeType(QualType T, SourceLocation Loc)
Build a Write-only Pipe type.
QualType ActOnPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc)
QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind)
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, SourceLocation AttrLoc)
SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, const FunctionDecl *FD=nullptr)
bool hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested, AcceptableKind Kind, bool OnlyNeedComplete=false)
QualType BuiltinChangeSignedness(QualType BaseType, UTTKind UKind, SourceLocation Loc)
void adjustMemberFunctionCC(QualType &T, bool HasThisPointer, bool IsCtorOrDtor, SourceLocation Loc)
Adjust the calling convention of a method to be the ABI default if it wasn't specified explicitly.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, NonTrivialCUnionContext UseContext, unsigned NonTrivialKind)
Emit diagnostics if a non-trivial C union type or a struct that contains a non-trivial C union is use...
bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI, const Expr *E, StringRef &Str, SourceLocation *ArgLocation=nullptr)
Check if the argument E is a ASCII string literal.
QualType BuildBlockPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a block pointer type.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer.
CharSourceRange getImmediateExpansionRange(SourceLocation Loc) const
Return the start/end of the expansion information for an expansion location.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Information about a FileID, basically just the logical file that it represents and include stack info...
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
SourceLocation getIncludeLoc() const
This is a discriminated union of FileInfo and ExpansionInfo.
const FileInfo & getFile() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
Represents the declaration of a struct/union/class/enum.
void setEmbeddedInDeclarator(bool isInDeclarator)
True if this tag declaration is "embedded" (i.e., defined or declared for the very first time) in the...
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool isThisDeclarationADemotedDefinition() const
Whether this declaration was a definition in some module but was forced to be a declaration.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
void setNameLoc(SourceLocation Loc)
void setElaboratedKeywordLoc(SourceLocation Loc)
Exposes information about the current target.
virtual bool hasBitIntType() const
Determine whether the _BitInt type is supported on this target.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
virtual size_t getMaxBitIntWidth() const
virtual std::optional< std::pair< unsigned, unsigned > > getVScaleRange(const LangOptions &LangOpts, ArmStreamingKind Mode, llvm::StringMap< bool > *FeatureMap=nullptr) const
Returns target-specific min and max values VScale_Range.
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
virtual bool allowHalfArgsAndReturns() const
Whether half args and returns are supported.
virtual bool hasInt128Type() const
Determine whether the __int128 type is supported on this target.
virtual bool hasFloat16Type() const
Determine whether the _Float16 type is supported on this target.
virtual bool hasIbm128Type() const
Determine whether the __ibm128 type is supported on this target.
virtual bool hasFloat128Type() const
Determine whether the __float128 type is supported on this target.
virtual bool hasBFloat16Type() const
Determine whether the _BFloat16 type is supported on this target.
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
void addArgument(const TemplateArgumentLoc &Loc)
ArrayRef< TemplateArgumentLoc > arguments() const
Location wrapper for a TemplateArgument.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
SourceLocation getRAngleLoc() const
void copy(TemplateSpecializationTypeLoc Loc)
Declaration of a template type parameter.
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack, bool HasTypeConstraint=false, UnsignedOrNone NumExpanded=std::nullopt)
[BoundsSafety] Represents information of declarations referenced by the arguments of the counted_by a...
const Type * getTypeForDecl() const
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void pushFullCopy(TypeLoc L)
Pushes a copy of the given TypeLoc onto this builder.
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Base wrapper for a particular "section" of type source info.
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
TypeLoc getNextTypeLoc() const
Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the TypeLoc is a PointerLoc and next Typ...
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
void initializeFullCopy(TypeLoc Other)
Initializes this by copying its information from another TypeLoc of the same type.
unsigned getFullDataSize() const
Returns the size of the type source info data block.
AutoTypeLoc getContainedAutoTypeLoc() const
Get the typeloc of an AutoType whose type will be deduced for a variable with an initializer of this ...
void * getOpaqueData() const
Get the pointer where source information is stored.
void copy(TypeLoc other)
Copies the other type loc into this one.
void initialize(ASTContext &Context, SourceLocation Loc) const
Initializes this to state that every location in this type is the given location.
SourceLocation getEndLoc() const
Get the end source location.
SourceLocation getBeginLoc() const
Get the begin source location.
void setUnmodifiedTInfo(TypeSourceInfo *TI) const
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
QualType getType() const
Return the type wrapped by this type source info.
void setNameLoc(SourceLocation Loc)
The base class of the type hierarchy.
bool isIncompleteOrObjectType() const
Return true if this is an incomplete or object type, in other words, not a function type.
bool isBlockPointerType() const
bool isBooleanType() const
QualType getRVVEltType(const ASTContext &Ctx) const
Returns the representative type for the element of an RVV builtin type.
bool isIncompleteArrayType() const
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
bool isUndeducedAutoType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
CXXRecordDecl * castAsCXXRecordDecl() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
NestedNameSpecifier getPrefix() const
If this type represents a qualified-id, this returns its nested name specifier.
bool isSizelessBuiltinType() const
bool isSveVLSBuiltinType() const
Determines if this is a sizeless type supported by the 'arm_sve_vector_bits' type attribute,...
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool canHaveNullability(bool ResultIfUnknown=true) const
Determine whether the given type can have a nullability specifier applied to it, i....
QualType getSveEltType(const ASTContext &Ctx) const
Returns the representative type for the element of an SVE builtin type.
bool isBitIntType() const
bool isBuiltinType() const
Helper methods to distinguish type categories.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isChar16Type() const
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
bool isWebAssemblyTableType() const
Returns true if this is a WebAssembly table type: either an array of reference types,...
bool isMemberPointerType() const
bool isAtomicType() const
bool isObjCObjectType() const
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
bool isFunctionType() const
bool isObjCObjectPointerType() const
bool isRVVVLSBuiltinType() const
Determines if this is a sizeless type supported by the 'riscv_rvv_vector_bits' type attribute,...
bool isRealFloatingType() const
Floating point categories.
bool isAnyPointerType() const
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
bool isObjCARCImplicitlyUnretainedType() const
Determines if this type, which must satisfy isObjCLifetimeType(), is implicitly __unsafe_unretained r...
bool isRecordType() const
bool isObjCRetainableType() const
std::optional< NullabilityKind > getNullability() const
Determine the nullability of the given type.
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Base class for declarations which introduce a typedef-name.
void setParensRange(SourceRange range)
void setTypeofLoc(SourceLocation Loc)
Wrapper of type source information for a type with no direct qualifiers.
TypeLocClass getTypeLocClass() const
UnionParsedType ConversionFunctionId
When Kind == IK_ConversionFunctionId, the type that the conversion function names.
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
void setNameLoc(SourceLocation Loc)
Represents a GCC generic vector type.
VectorKind getVectorKind() const
static DelayedDiagnostic makeForbiddenType(SourceLocation loc, unsigned diagnostic, QualType type, unsigned argument)
Retains information about a function, method, or block that is currently being parsed.
Defines the clang::TargetInfo interface.
const internal::VariadicDynCastAllOfMatcher< Decl, TypedefDecl > typedefDecl
Matches typedef declarations.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Decl, RecordDecl > recordDecl
Matches class, struct, and union declarations.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
bool isa(CodeGen::Address addr)
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
@ ExpectedParameterOrImplicitObjectParameter
@ ExpectedFunctionWithProtoType
void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
@ GNUAutoType
__auto_type (GNU extension)
@ DecltypeAuto
decltype(auto)
llvm::StringRef getParameterABISpelling(ParameterABI kind)
FunctionEffectMode
Used with attributes/effects with a boolean condition, e.g. nonblocking.
LLVM_READONLY bool isAsciiIdentifierContinue(unsigned char c)
NullabilityKind
Describes the nullability of a particular type.
@ Nullable
Values of this type can be null.
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
@ NonNull
Values of this type can never be null.
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
@ Success
Annotation was successful.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
@ IK_DeductionGuideName
A deduction-guide name (a template-name)
@ IK_ImplicitSelfParam
An implicit 'self' parameter.
@ IK_TemplateId
A template-id, e.g., f<int>.
@ IK_ConstructorTemplateId
A constructor named via a template-id.
@ IK_ConstructorName
A constructor name.
@ IK_LiteralOperatorId
A user-defined literal name, e.g., operator "" _i.
@ IK_Identifier
An identifier.
@ IK_DestructorName
A destructor name.
@ IK_OperatorFunctionId
An overloaded operator name, e.g., operator+.
@ IK_ConversionFunctionId
A conversion function name, e.g., operator int.
TypeOfKind
The kind of 'typeof' expression we're after.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
@ AANT_ArgumentIntegerConstant
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
ArraySizeModifier
Capture whether this is a normal array (e.g.
@ SwiftAsyncContext
This parameter (which must have pointer type) uses the special Swift asynchronous context-pointer ABI...
@ SwiftErrorResult
This parameter (which must have pointer-to-pointer type) uses the special Swift error-result ABI trea...
@ Ordinary
This parameter uses ordinary ABI rules for its type.
@ SwiftIndirectResult
This parameter (which must have pointer type) is a Swift indirect result parameter.
@ SwiftContext
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment.
const FunctionProtoType * T
bool supportsVariadicCall(CallingConv CC)
Checks whether the given calling convention supports variadic calls.
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
static bool isBlockPointer(Expr *Arg)
TagTypeKind
The kind of a tag type.
@ Interface
The "__interface" keyword.
@ Struct
The "struct" keyword.
@ Class
The "class" keyword.
@ Union
The "union" keyword.
@ Enum
The "enum" keyword.
LLVM_READONLY bool isWhitespace(unsigned char c)
Return true if this character is horizontal or vertical ASCII whitespace: ' ', '\t',...
@ Keyword
The name has been typo-corrected to a keyword.
@ Type
The name was classified as a type.
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ FirstTargetAddressSpace
MutableArrayRef< ParsedTemplateArgument > ASTTemplateArgsPtr
MSInheritanceModel
Assigned inheritance model for a class in the MS C++ ABI.
@ IgnoreTrivialABI
The triviality of a method unaffected by "trivial_abi".
@ Incomplete
Template argument deduction did not deduce a value for every template parameter.
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
CallingConv
CallingConv - Specifies the calling convention that a function uses.
@ AltiVecBool
is AltiVec 'vector bool ...'
@ SveFixedLengthData
is AArch64 SVE fixed-length data vector
@ AltiVecVector
is AltiVec vector
@ AltiVecPixel
is AltiVec 'vector Pixel'
@ Generic
not a target-specific vector type
@ RVVFixedLengthData
is RISC-V RVV fixed-length data vector
@ RVVFixedLengthMask
is RISC-V RVV fixed-length mask vector
@ NeonPoly
is ARM Neon polynomial vector
@ SveFixedLengthPredicate
is AArch64 SVE fixed-length predicate vector
U cast(CodeGen::Address addr)
LangAS getLangASFromTargetAS(unsigned TargetAS)
@ None
The alignment was not explicit in code.
@ ArrayBound
Array bound in array declarator or new-expression.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
ActionResult< Expr * > ExprResult
@ Parens
New-expression has a C++98 paren-delimited initializer.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_Uninstantiated
not instantiated yet
@ EST_Unparsed
not parsed yet
@ EST_NoThrow
Microsoft __declspec(nothrow) extension.
@ EST_None
no exception specification
@ EST_MSAny
Microsoft throw(...) extension.
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
@ Implicit
An implicit conversion.
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
unsigned isStar
True if this dimension was [*]. In this case, NumElts is null.
unsigned TypeQuals
The type qualifiers for the array: const/volatile/restrict/__unaligned/_Atomic.
unsigned hasStatic
True if this dimension included the 'static' keyword.
Expr * NumElts
This is the size of the array, or null if [] or [*] was specified.
unsigned TypeQuals
For now, sema will catch these as invalid.
unsigned isVariadic
isVariadic - If this function has a prototype, and if that proto ends with ',...)',...
SourceLocation getTrailingReturnTypeLoc() const
Get the trailing-return-type location for this function declarator.
SourceLocation getLParenLoc() const
bool hasTrailingReturnType() const
Determine whether this function declarator had a trailing-return-type.
TypeAndRange * Exceptions
Pointer to a new[]'d array of TypeAndRange objects that contain the types in the function's dynamic e...
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
unsigned RefQualifierIsLValueRef
Whether the ref-qualifier (if any) is an lvalue reference.
SourceLocation getExceptionSpecLocBeg() const
DeclSpec * MethodQualifiers
DeclSpec for the function with the qualifier related info.
SourceLocation getRefQualifierLoc() const
Retrieve the location of the ref-qualifier, if any.
SourceLocation getRParenLoc() const
SourceLocation getEllipsisLoc() const
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
unsigned getNumExceptions() const
Get the number of dynamic exception specifications.
bool hasMethodTypeQualifiers() const
Determine whether this method has qualifiers.
unsigned isAmbiguous
Can this declaration be a constructor-style initializer?
unsigned hasPrototype
hasPrototype - This is true if the function had at least one typed parameter.
bool hasRefQualifier() const
Determine whether this function declaration contains a ref-qualifier.
SourceRange getExceptionSpecRange() const
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
Expr * NoexceptExpr
Pointer to the expression in the noexcept-specifier of this function, if it has one.
unsigned TypeQuals
The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
SourceLocation StarLoc
Location of the '*' token.
const IdentifierInfo * Ident
SourceLocation RestrictQualLoc
The location of the restrict-qualifier, if any.
SourceLocation ConstQualLoc
The location of the const-qualifier, if any.
SourceLocation VolatileQualLoc
The location of the volatile-qualifier, if any.
SourceLocation UnalignedQualLoc
The location of the __unaligned-qualifier, if any.
unsigned TypeQuals
The type qualifiers: const/volatile/restrict/unaligned/atomic.
SourceLocation AtomicQualLoc
The location of the _Atomic-qualifier, if any.
bool LValueRef
True if this is an lvalue reference, false if it's an rvalue reference.
bool HasRestrict
The type qualifier: restrict. [GNU] C++ extension.
One instance of this struct is used for each type in a declarator that is parsed.
const ParsedAttributesView & getAttrs() const
If there are attributes applied to this declaratorchunk, return them.
SourceLocation EndLoc
EndLoc - If valid, the place where this chunck ends.
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl * > DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), SourceLocation TrailingReturnTypeLoc=SourceLocation(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
MemberPointerTypeInfo Mem
SourceLocation Loc
Loc - The place where this type was defined.
enum clang::DeclaratorChunk::@340323374315200305336204205154073066142310370142 Kind
Describes whether we've seen any nullability information for the given file.
SourceLocation PointerEndLoc
The end location for the first pointer declarator in the file.
SourceLocation PointerLoc
The first pointer declarator (of any pointer kind) in the file that does not have a corresponding nul...
bool SawTypeNullability
Whether we saw any type nullability annotations in the given file.
uint8_t PointerKind
Which kind of pointer declarator we saw.
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Holds information about the various types of exception specification.
Extra information about a function prototype.
ExceptionSpecInfo ExceptionSpec
FunctionTypeExtraAttributeInfo ExtraAttributeInfo
unsigned AArch64SMEAttributes
SourceLocation EllipsisLoc
FunctionEffectsRef FunctionEffects
const ExtParameterInfo * ExtParameterInfos
RefQualifierKind RefQualifier
unsigned HasTrailingReturn
void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable=true)
FunctionType::ExtInfo ExtInfo
TypeSourceInfo * ContainedTyInfo
SmallVector< NamedDecl *, 4 > TemplateParams
Store the list of the template parameters for a generic lambda or an abbreviated function template.
unsigned AutoTemplateParameterDepth
If this is a generic lambda or abbreviated function template, use this as the depth of each 'auto' pa...
static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
NestedNameSpecifier Prefix
Describes how types, statements, expressions, and declarations should be printed.
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
enum clang::Sema::CodeSynthesisContext::SynthesisKind Kind
@ Memoization
Added for Template instantiation observation.
Abstract class used to diagnose incomplete types.
virtual void diagnose(Sema &S, SourceLocation Loc, QualType T)=0
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
SplitQualType getSingleStepDesugaredType() const
const Type * Ty
The locally-unqualified type.
Qualifiers Quals
The local qualifiers.
llvm::DenseSet< std::tuple< Decl *, Decl *, int > > NonEquivalentDeclSet
Store declaration pairs already found to be non-equivalent.
bool IsEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
Information about a template-id annotation token.
const IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
unsigned NumArgs
NumArgs - The number of template arguments.
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.