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"
64 if (
D.getContext() != DeclaratorContext::BlockLiteral ||
65 D.getDeclSpec().hasTypeSpecifier())
68 if (
D.getNumTypeObjects() == 0)
71 if (
D.getNumTypeObjects() == 1 &&
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();
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_AMDGPUKernelCall: \
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
149#define FUNCTION_TYPE_ATTRS_CASELIST \
150 case ParsedAttr::AT_NSReturnsRetained: \
151 case ParsedAttr::AT_NoReturn: \
152 case ParsedAttr::AT_NonBlocking: \
153 case ParsedAttr::AT_NonAllocating: \
154 case ParsedAttr::AT_Blocking: \
155 case ParsedAttr::AT_Allocating: \
156 case ParsedAttr::AT_Regparm: \
157 case ParsedAttr::AT_CmseNSCall: \
158 case ParsedAttr::AT_ArmStreaming: \
159 case ParsedAttr::AT_ArmStreamingCompatible: \
160 case ParsedAttr::AT_ArmPreserves: \
161 case ParsedAttr::AT_ArmIn: \
162 case ParsedAttr::AT_ArmOut: \
163 case ParsedAttr::AT_ArmInOut: \
164 case ParsedAttr::AT_AnyX86NoCallerSavedRegisters: \
165 case ParsedAttr::AT_AnyX86NoCfCheck: \
166 CALLING_CONV_ATTRS_CASELIST
169#define MS_TYPE_ATTRS_CASELIST \
170 case ParsedAttr::AT_Ptr32: \
171 case ParsedAttr::AT_Ptr64: \
172 case ParsedAttr::AT_SPtr: \
173 case ParsedAttr::AT_UPtr
176#define NULLABILITY_TYPE_ATTRS_CASELIST \
177 case ParsedAttr::AT_TypeNonNull: \
178 case ParsedAttr::AT_TypeNullable: \
179 case ParsedAttr::AT_TypeNullableResult: \
180 case ParsedAttr::AT_TypeNullUnspecified
185 class TypeProcessingState {
209 using TypeAttrPair = std::pair<const AttributedType*, const Attr*>;
211 bool AttrsForTypesSorted =
true;
215 llvm::DenseMap<const MacroQualifiedType *, SourceLocation> LocsForMacros;
223 bool ParsedHLSLParamMod;
227 : sema(sema), declarator(declarator),
229 ParsedHLSLParamMod(
false) {}
231 Sema &getSema()
const {
239 bool isProcessingDeclSpec()
const {
243 unsigned getCurrentChunkIndex()
const {
247 void setCurrentChunkIndex(
unsigned idx) {
253 if (isProcessingDeclSpec())
254 return getMutableDeclSpec().getAttributes();
259 void saveDeclSpecAttrs() {
261 if (!savedAttrs.empty())
264 DeclSpec &spec = getMutableDeclSpec();
265 llvm::append_range(savedAttrs,
272 ignoredTypeAttrs.push_back(&
attr);
278 for (
auto *
Attr : ignoredTypeAttrs)
288 AttrsForTypes.push_back({cast<AttributedType>(
T.getTypePtr()), A});
289 AttrsForTypesSorted =
false;
294 QualType getBTFTagAttributedType(
const BTFTypeTagAttr *BTFAttr,
306 auto *NewAttrTy = cast<AttributedType>(
T.getTypePtr());
307 for (TypeAttrPair &A : AttrsForTypes) {
308 if (A.first == AttrTy)
311 AttrsForTypesSorted =
false;
318 if (!AttrsForTypesSorted) {
319 llvm::stable_sort(AttrsForTypes, llvm::less_first());
320 AttrsForTypesSorted =
true;
325 for (
auto It = std::partition_point(
326 AttrsForTypes.begin(), AttrsForTypes.end(),
327 [=](
const TypeAttrPair &A) { return A.first < AT; });
328 It != AttrsForTypes.end() && It->first == AT; ++It) {
330 const Attr *Result = It->second;
331 It->second =
nullptr;
336 llvm_unreachable(
"no Attr* for AttributedType*");
341 auto FoundLoc = LocsForMacros.find(MQT);
342 assert(FoundLoc != LocsForMacros.end() &&
343 "Unable to find macro expansion location for MacroQualifedType");
344 return FoundLoc->second;
349 LocsForMacros[MQT] =
Loc;
352 void setParsedNoDeref(
bool parsed) { parsedNoDeref = parsed; }
354 bool didParseNoDeref()
const {
return parsedNoDeref; }
356 void setParsedHLSLParamMod(
bool Parsed) { ParsedHLSLParamMod = Parsed; }
358 bool didParseHLSLParamMod()
const {
return ParsedHLSLParamMod; }
360 ~TypeProcessingState() {
361 if (savedAttrs.empty())
364 getMutableDeclSpec().getAttributes().clearListOnly();
366 getMutableDeclSpec().getAttributes().addAtEnd(AL);
370 DeclSpec &getMutableDeclSpec()
const {
412 if (
attr.getKind() == ParsedAttr::AT_ObjCGC)
414 assert(
attr.getKind() == ParsedAttr::AT_ObjCOwnership);
429 bool onlyBlockPointers) {
435 for (; i != 0; --i) {
437 switch (fnChunk.
Kind) {
453 for (--i; i != 0; --i) {
455 switch (ptrChunk.
Kind) {
465 if (onlyBlockPointers)
474 llvm_unreachable(
"bad declarator chunk kind");
480 llvm_unreachable(
"bad declarator chunk kind");
497 Declarator &declarator = state.getDeclarator();
500 for (
unsigned i = state.getCurrentChunkIndex(); i != 0; --i) {
502 switch (chunk.
Kind) {
508 if (state.isProcessingDeclSpec() &&
509 attr.getKind() == ParsedAttr::AT_ObjCOwnership)
512 if (!destChunk) destChunk = &chunk;
525 if (state.isProcessingDeclSpec() &&
526 attr.getKind() == ParsedAttr::AT_ObjCOwnership) {
553 Declarator &declarator = state.getDeclarator();
557 unsigned innermost = -1U;
558 bool considerDeclSpec =
true;
561 switch (chunk.
Kind) {
575 considerDeclSpec =
false;
583 if (considerDeclSpec) {
588 state.saveDeclSpecAttrs();
597 if (innermost != -1U) {
605 state.addIgnoredTypeAttr(
attr);
614 Declarator &declarator = state.getDeclarator();
618 for (
unsigned i = state.getCurrentChunkIndex(); i != 0; --i) {
620 switch (chunk.
Kind) {
647 Declarator &declarator = state.getDeclarator();
667 state.saveDeclSpecAttrs();
671 state,
attr, state.getCurrentAttributes(), declSpecType, CFT))
676 state.addIgnoredTypeAttr(
attr);
687 Declarator &declarator = state.getDeclarator();
697 state.addIgnoredTypeAttr(
attr);
722 if (
attr.isStandardAttributeSyntax() ||
attr.isRegularKeywordAttribute())
725 switch (
attr.getKind()) {
742 case ParsedAttr::AT_ObjCKindOf:
755 Declarator &declarator = state.getDeclarator();
801 {}, loc, loc, declarator));
816 typedef std::pair<DeclSpec::TQ, SourceLocation> QualLoc;
821 if (!(RemoveTQs & Qual.first))
825 if (TypeQuals & Qual.first)
826 S.
Diag(Qual.second, DiagID)
831 TypeQuals &= ~Qual.first;
845 if (AL.isInvalid() || !AL.isTypeAttr())
848 diag::warn_block_literal_attributes_on_omitted_return_type)
850 ToBeRemoved.push_back(&AL);
860 diag::warn_block_literal_qualifiers_on_omitted_return_type);
866static OpenCLAccessAttr::Spelling
869 if (AL.getKind() == ParsedAttr::AT_OpenCLAccess)
870 return static_cast<OpenCLAccessAttr::Spelling
>(AL.getSemanticSpelling());
871 return OpenCLAccessAttr::Keyword_read_only;
877#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
879 return UnaryTransformType::Enum;
880#include "clang/Basic/TransformTypeTraits.def"
882 llvm_unreachable(
"attempted to parse a non-unary transform builtin");
896 Sema &S = state.getSema();
897 Declarator &declarator = state.getDeclarator();
917 "Unknown TSS value");
931 "Unknown TSS value");
940 "Unknown TSS value");
945 "Unknown TSS value");
950 "Unknown TSS value");
959 declarator.
getContext() == DeclaratorContext::LambdaExpr) {
963 }
else if (declarator.
getContext() == DeclaratorContext::LambdaExpr ||
978 S.
Diag(DeclLoc, diag::warn_missing_type_specifier)
987 S.
Diag(DeclLoc, diag::err_missing_type_specifier)
996 S.
Diag(DeclLoc, diag::err_missing_actual_pipe_type)
1001 "implicit int is disabled?");
1002 S.
Diag(DeclLoc, diag::ext_missing_type_specifier)
1012 case TypeSpecifierWidth::Unspecified:
1013 Result = Context.
IntTy;
1015 case TypeSpecifierWidth::Short:
1018 case TypeSpecifierWidth::Long:
1021 case TypeSpecifierWidth::LongLong:
1029 diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
1037 case TypeSpecifierWidth::Unspecified:
1040 case TypeSpecifierWidth::Short:
1043 case TypeSpecifierWidth::Long:
1046 case TypeSpecifierWidth::LongLong:
1054 diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
1069 if (Result.isNull()) {
1070 Result = Context.
IntTy;
1077 case TypeSpecifierWidth::Short:
1080 case TypeSpecifierWidth::Unspecified:
1083 case TypeSpecifierWidth::Long:
1086 case TypeSpecifierWidth::LongLong:
1087 llvm_unreachable(
"Unable to specify long long as _Accum width");
1100 case TypeSpecifierWidth::Short:
1103 case TypeSpecifierWidth::Unspecified:
1106 case TypeSpecifierWidth::Long:
1109 case TypeSpecifierWidth::LongLong:
1110 llvm_unreachable(
"Unable to specify long long as _Fract width");
1161 ?
"cl_khr_fp64 and __opencl_c_fp64"
1189 Result = Context.
IntTy;
1200 Result = Context.
IntTy;
1211 "No qualifiers on tag names!");
1227 "Can't handle qualifiers on typedef names yet!");
1229 if (Result.isNull()) {
1240 assert(!Result.isNull() &&
"Didn't get a type for typeof?");
1241 if (!Result->isDependentType())
1247 ? TypeOfKind::Unqualified
1248 : TypeOfKind::Qualified);
1253 assert(
E &&
"Didn't get an expression for typeof?");
1257 ? TypeOfKind::Unqualified
1258 : TypeOfKind::Qualified);
1259 if (Result.isNull()) {
1260 Result = Context.
IntTy;
1267 assert(
E &&
"Didn't get an expression for decltype?");
1270 if (Result.isNull()) {
1271 Result = Context.
IntTy;
1278 assert(
E &&
"Didn't get an expression for pack indexing");
1282 if (Result.isNull()) {
1284 Result = Context.
IntTy;
1289#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case DeclSpec::TST_##Trait:
1290#include "clang/Basic/TransformTypeTraits.def"
1292 assert(!Result.isNull() &&
"Didn't get a type for the transformation?");
1296 if (Result.isNull()) {
1297 Result = Context.
IntTy;
1305 ? AutoTypeKeyword::DecltypeAuto
1306 : AutoTypeKeyword::Auto;
1312 TypeConstraintConcept =
1313 cast<ConceptDecl>(TemplateId->Template.get().getAsTemplateDecl());
1318 TemplateId->NumArgs);
1320 for (
const auto &ArgLoc : TemplateArgsInfo.
arguments())
1321 TemplateArgs.push_back(ArgLoc.getArgument());
1328 TypeConstraintConcept, TemplateArgs);
1342 assert(!Result.isNull() &&
"Didn't get a type for _Atomic?");
1344 if (Result.isNull()) {
1345 Result = Context.
IntTy;
1350#define GENERIC_IMAGE_TYPE(ImgType, Id) \
1351 case DeclSpec::TST_##ImgType##_t: \
1352 switch (getImageAccess(DS.getAttributes())) { \
1353 case OpenCLAccessAttr::Keyword_write_only: \
1354 Result = Context.Id##WOTy; \
1356 case OpenCLAccessAttr::Keyword_read_write: \
1357 Result = Context.Id##RWTy; \
1359 case OpenCLAccessAttr::Keyword_read_only: \
1360 Result = Context.Id##ROTy; \
1362 case OpenCLAccessAttr::SpellingNotCalculated: \
1363 llvm_unreachable("Spelling not yet calculated"); \
1366#include "clang/Basic/OpenCLImageTypes.def"
1368#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1369 case DeclSpec::TST_##Name: \
1370 Result = Context.SingletonId; \
1372#include "clang/Basic/HLSLIntangibleTypes.def"
1375 Result = Context.
IntTy;
1383 if (Result->containsErrors())
1388 bool IsOpenCLC30Compatible =
1397 if ((Result->isImageType() || Result->isSamplerT()) &&
1398 (IsOpenCLC30Compatible &&
1401 << 0 << Result <<
"__opencl_c_images";
1403 }
else if (Result->isOCLImage3dWOType() &&
1408 << (IsOpenCLC30Compatible
1409 ?
"cl_khr_3d_image_writes and __opencl_c_3d_image_writes"
1410 :
"cl_khr_3d_image_writes");
1430 unsigned typeSize =
static_cast<unsigned>(Context.
getTypeSize(Result));
1431 assert(typeSize > 0 &&
"type size for vector must be greater than 0 bits");
1432 VectorKind VecKind = VectorKind::AltiVecVector;
1434 VecKind = VectorKind::AltiVecPixel;
1436 VecKind = VectorKind::AltiVecBool;
1437 Result = Context.
getVectorType(Result, 128/typeSize, VecKind);
1448 if (declarator.
getContext() == DeclaratorContext::BlockLiteral)
1462 if (AL.slidesFromDeclToDeclSpecLegacyBehavior()) {
1473 if (AL.isStandardAttributeSyntax() && AL.isClangScope() &&
1474 !(AL.getKind() == ParsedAttr::AT_MatrixType &&
1476 S.
Diag(AL.getLoc(), diag::warn_type_attribute_deprecated_on_decl)
1504 if (Result->isFunctionType()) {
1505 unsigned DiagId = diag::warn_typecheck_function_qualifiers_ignored;
1507 DiagId = diag::ext_typecheck_function_qualifiers_unspecified;
1523 if (TypeQuals && Result->isReferenceType()) {
1525 S, DS, TypeQuals, Result,
1527 diag::warn_typecheck_reference_qualifiers);
1534 && TypeQuals & Result.getCVRQualifiers()) {
1561 assert(!Result.isNull() &&
"This function should not return a null type");
1576 const auto *AT = dyn_cast<AutoType>(
T);
1577 return AT && AT->isGNUAutoType();
1594 unsigned DiagID = 0;
1610 DiagID = diag::err_typecheck_invalid_restrict_invalid_pointee;
1617 DiagID = diag::err_typecheck_invalid_restrict_not_pointer;
1631 unsigned CVRAU,
const DeclSpec *DS) {
1665 Split.Quals.addCVRQualifiers(CVR);
1683 if (!
type->isObjCLifetimeType() ||
1693 if (
type.isConstQualified()) {
1699 }
else if (
type->isObjCARCImplicitlyUnretainedType()) {
1717 diag::err_arc_indirect_no_ownership,
type, isReference));
1719 S.
Diag(loc, diag::err_arc_indirect_no_ownership) <<
type << isReference;
1723 assert(implicitLifetime &&
"didn't infer any lifetime!");
1764enum QualifiedFunctionKind { QFK_BlockPointer, QFK_Pointer, QFK_Reference };
1770 QualifiedFunctionKind QFK) {
1777 S.
Diag(
Loc, diag::err_compound_qualified_function_type)
1778 << QFK << isa<FunctionType>(
T.IgnoreParens()) <<
T
1789 Diag(
Loc, diag::err_qualified_function_typeid)
1808 Diag(
Loc, diag::err_illegal_decl_pointer_to_reference)
1816 Diag(
Loc, diag::err_opencl_function_pointer) << 0;
1821 Diag(
Loc, diag::err_hlsl_pointers_unsupported) << 0;
1840 if (
T.isWebAssemblyReferenceType()) {
1841 Diag(
Loc, diag::err_wasm_reference_pr) << 0;
1847 Diag(
Loc, diag::err_wasm_table_pr) << 0;
1860 "Unresolved overloaded function type");
1888 Diag(
Loc, diag::err_reference_to_void);
1893 Diag(
Loc, diag::err_hlsl_pointers_unsupported) << 1;
1903 Diag(
Loc, diag::err_opencl_function_pointer) << 1;
1916 T.isWebAssemblyReferenceType()) {
1917 Diag(
Loc, diag::err_wasm_reference_pr) << 1;
1921 Diag(
Loc, diag::err_wasm_table_pr) << 1;
1944 llvm::APSInt Bits(32);
1951 size_t NumBits = Bits.getZExtValue();
1952 if (!IsUnsigned && NumBits < 2) {
1953 Diag(
Loc, diag::err_bit_int_bad_size) << 0;
1957 if (IsUnsigned && NumBits < 1) {
1958 Diag(
Loc, diag::err_bit_int_bad_size) << 1;
1964 Diag(
Loc, diag::err_bit_int_max_size)
1978 llvm::APSInt &SizeVal,
unsigned VLADiag,
2003 VLADiagnoser(
unsigned VLADiag,
bool VLAIsError)
2004 : VLADiag(VLADiag), VLAIsError(VLAIsError) {}
2008 return S.
Diag(
Loc, diag::err_array_size_non_int) <<
T;
2013 IsVLA = !VLAIsError;
2019 return S.
Diag(
Loc, diag::ext_vla_folded_to_constant);
2021 } Diagnoser(VLADiag, VLAIsError);
2025 if (Diagnoser.IsVLA)
2039 if (Size.isMultipleOf(Alignment))
2042 Diag(
Loc, diag::err_array_element_alignment)
2043 << EltTy << Size.getQuantity() << Alignment.
getQuantity();
2048 Expr *ArraySize,
unsigned Quals,
2065 Diag(
Loc, diag::err_illegal_decl_array_of_references)
2071 Diag(
Loc, diag::err_array_incomplete_or_sizeless_type) << 0 <<
T;
2076 diag::err_array_of_abstract_type))
2083 if (!MPTy->getClass()->isDependentType())
2089 if (!
T.isWebAssemblyReferenceType() &&
2091 diag::err_array_incomplete_or_sizeless_type))
2097 const auto *ATy = dyn_cast<ArrayType>(
T);
2098 if (ATy && ATy->getElementType().isWebAssemblyReferenceType()) {
2099 Diag(
Loc, diag::err_wasm_reftype_multidimensional_array);
2105 Diag(
Loc, diag::err_array_incomplete_or_sizeless_type) << 1 <<
T;
2110 Diag(
Loc, diag::err_illegal_decl_array_of_functions)
2118 if (EltTy->getDecl()->hasFlexibleArrayMember())
2119 Diag(
Loc, diag::ext_flexible_array_in_array) <<
T;
2121 Diag(
Loc, diag::err_objc_array_of_interfaces) <<
T;
2132 ArraySize =
Result.get();
2136 if (ArraySize && !ArraySize->
isPRValue()) {
2141 ArraySize =
Result.get();
2164 if (
const auto *CondExpr = dyn_cast_if_present<ConditionalOperator>(
2166 std::optional<llvm::APSInt> LHS =
2167 CondExpr->getLHS()->getIntegerConstantExpr(
Context);
2168 std::optional<llvm::APSInt> RHS =
2169 CondExpr->getRHS()->getIntegerConstantExpr(
Context);
2170 return LHS && RHS && LHS->isNegative() != RHS->isNegative();
2180 VLADiag = diag::err_opencl_vla;
2183 VLADiag = diag::warn_vla_used;
2186 VLADiag = diag::err_vla_in_sfinae;
2189 VLADiag = diag::err_openmp_vla_in_task_untied;
2194 ? diag::ext_vla_cxx_in_gnu_mode_static_assert
2195 : diag::ext_vla_cxx_static_assert;
2197 VLADiag =
getLangOpts().GNUMode ? diag::ext_vla_cxx_in_gnu_mode
2198 : diag::ext_vla_cxx;
2201 VLADiag = diag::ext_vla;
2242 if (ConstVal.isSigned() && ConstVal.isNegative()) {
2249 diag::err_typecheck_negative_array_size)
2253 if (ConstVal == 0 && !
T.isWebAssemblyReferenceType()) {
2258 : diag::ext_typecheck_zero_array_size)
2263 unsigned ActiveSizeBits =
2267 : ConstVal.getActiveBits();
2283 IsCUDADevice ? diag::err_cuda_vla : diag::err_vla_unsupported)
2284 << (IsCUDADevice ? llvm::to_underlying(
CUDA().CurrentTarget()) : 0);
2288 FSI->setHasVLA(
Loc);
2296 : diag::ext_c99_array_usage)
2297 << llvm::to_underlying(ASM);
2307 Diag(
Loc, diag::err_opencl_invalid_type_array) << ArrType;
2317 bool ForMatrixType =
false) {
2320 if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8)
2321 return S.
Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
2322 << ForMatrixType << (NumBits < 8);
2335 Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << CurType;
2347 std::optional<llvm::APSInt> VecSize =
2350 Diag(AttrLoc, diag::err_attribute_argument_type)
2361 if (!VecSize->isIntN(61)) {
2363 Diag(AttrLoc, diag::err_attribute_size_too_large)
2367 uint64_t VectorSizeBits = VecSize->getZExtValue() * 8;
2370 if (VectorSizeBits == 0) {
2371 Diag(AttrLoc, diag::err_attribute_zero_size)
2376 if (!TypeSize || VectorSizeBits % TypeSize) {
2377 Diag(AttrLoc, diag::err_attribute_invalid_size)
2382 if (VectorSizeBits / TypeSize > std::numeric_limits<uint32_t>::max()) {
2383 Diag(AttrLoc, diag::err_attribute_size_too_large)
2407 Diag(AttrLoc, diag::err_attribute_invalid_vector_type) <<
T;
2416 std::optional<llvm::APSInt> vecSize =
2419 Diag(AttrLoc, diag::err_attribute_argument_type)
2425 if (!vecSize->isIntN(32)) {
2426 Diag(AttrLoc, diag::err_attribute_size_too_large)
2432 unsigned vectorSize =
static_cast<unsigned>(vecSize->getZExtValue());
2434 if (vectorSize == 0) {
2435 Diag(AttrLoc, diag::err_attribute_zero_size)
2449 "Should never build a matrix type when it is disabled");
2454 Diag(AttrLoc, diag::err_attribute_invalid_matrix_type) << ElementTy;
2468 std::optional<llvm::APSInt> ValueRows =
2470 std::optional<llvm::APSInt> ValueColumns =
2477 if (!ValueRows && !ValueColumns) {
2478 Diag(AttrLoc, diag::err_attribute_argument_type)
2486 Diag(AttrLoc, diag::err_attribute_argument_type)
2492 if (!ValueColumns) {
2493 Diag(AttrLoc, diag::err_attribute_argument_type)
2499 unsigned MatrixRows =
static_cast<unsigned>(ValueRows->getZExtValue());
2500 unsigned MatrixColumns =
static_cast<unsigned>(ValueColumns->getZExtValue());
2501 if (MatrixRows == 0 && MatrixColumns == 0) {
2502 Diag(AttrLoc, diag::err_attribute_zero_size)
2503 <<
"matrix" << RowRange << ColRange;
2506 if (MatrixRows == 0) {
2507 Diag(AttrLoc, diag::err_attribute_zero_size) <<
"matrix" << RowRange;
2510 if (MatrixColumns == 0) {
2511 Diag(AttrLoc, diag::err_attribute_zero_size) <<
"matrix" << ColRange;
2515 Diag(AttrLoc, diag::err_attribute_size_too_large)
2516 << RowRange <<
"matrix row";
2520 Diag(AttrLoc, diag::err_attribute_size_too_large)
2521 << ColRange <<
"matrix column";
2529 Diag(
Loc, diag::err_func_returning_array_function)
2537 Diag(
Loc, diag::err_parameters_retval_cannot_have_fp16_type) << 1 <<
2545 Diag(
Loc, diag::err_object_cannot_be_passed_returned_by_value)
2550 if (
T.hasNonTrivialToPrimitiveDestructCUnion() ||
2551 T.hasNonTrivialToPrimitiveCopyCUnion())
2558 Diag(
Loc, diag::warn_deprecated_volatile_return) <<
T;
2573 bool emittedError =
false;
2575 enum class RequiredCC { OnlySwift, SwiftOrSwiftAsync };
2576 auto checkCompatible = [&](
unsigned paramIndex, RequiredCC required) {
2578 (required == RequiredCC::OnlySwift)
2581 if (isCompatible || emittedError)
2583 S.
Diag(getParamLoc(paramIndex), diag::err_swift_param_attr_not_swiftcall)
2585 << (required == RequiredCC::OnlySwift);
2586 emittedError =
true;
2588 for (
size_t paramIndex = 0, numParams = paramTypes.size();
2589 paramIndex != numParams; ++paramIndex) {
2600 checkCompatible(paramIndex, RequiredCC::SwiftOrSwiftAsync);
2601 if (paramIndex != 0 &&
2604 S.
Diag(getParamLoc(paramIndex),
2605 diag::err_swift_indirect_result_not_first);
2610 checkCompatible(paramIndex, RequiredCC::SwiftOrSwiftAsync);
2619 checkCompatible(paramIndex, RequiredCC::OnlySwift);
2620 if (paramIndex == 0 ||
2623 S.
Diag(getParamLoc(paramIndex),
2624 diag::err_swift_error_result_not_after_swift_context);
2628 llvm_unreachable(
"bad ABI kind");
2640 for (
unsigned Idx = 0, Cnt = ParamTypes.size(); Idx < Cnt; ++Idx) {
2644 Diag(
Loc, diag::err_param_with_void_type);
2649 Diag(
Loc, diag::err_parameters_retval_cannot_have_fp16_type) << 0 <<
2653 Diag(
Loc, diag::err_wasm_table_as_function_parameter);
2660 Diag(
Loc, diag::warn_deprecated_volatile_param) << ParamType;
2662 ParamTypes[Idx] = ParamType;
2667 [=](
unsigned i) {
return Loc; });
2687 Diag(
Loc, diag::err_distant_exception_spec);
2694 Diag(
Loc, diag::err_illegal_decl_mempointer_to_reference)
2700 Diag(
Loc, diag::err_illegal_decl_mempointer_to_void)
2705 if (!
Class->isDependentType() && !
Class->isRecordType()) {
2706 Diag(
Loc, diag::err_mempointer_in_nonclass_type) <<
Class;
2713 Diag(
Loc, diag::err_opencl_function_pointer) << 0;
2718 Diag(
Loc, diag::err_hlsl_pointers_unsupported) << 0;
2737 Diag(
Loc, diag::err_nonfunction_block_type);
2753 if (TInfo) *TInfo =
nullptr;
2758 if (
const LocInfoType *LIT = dyn_cast<LocInfoType>(QT)) {
2759 QT = LIT->getType();
2760 DI = LIT->getTypeSourceInfo();
2763 if (TInfo) *TInfo = DI;
2769 unsigned chunkIndex);
2776 Sema &S = state.getSema();
2777 Declarator &declarator = state.getDeclarator();
2783 unsigned outermostPointerIndex = 0;
2785 unsigned numPointers = 0;
2787 unsigned chunkIndex = i;
2789 switch (chunk.
Kind) {
2799 outermostPointerIndex = chunkIndex;
2807 if (numPointers != 1)
return;
2809 outermostPointerIndex = chunkIndex;
2827 if (numPointers == 1) {
2845 }
else if (numPointers == 2) {
2858 if (AL.getKind() == ParsedAttr::AT_ObjCOwnership)
2862 outermostPointerIndex);
2884 }
const QualKinds[5] = {
2893 unsigned NumQuals = 0;
2898 for (
auto &
E : QualKinds) {
2899 if (Quals &
E.Mask) {
2900 if (!QualStr.empty()) QualStr +=
' ';
2917 << QualStr << NumQuals << FixIts[0] << FixIts[1] << FixIts[2] << FixIts[3];
2923 unsigned FunctionChunkIndex) {
2925 D.getTypeObject(FunctionChunkIndex).Fun;
2933 for (
unsigned OuterChunkIndex = FunctionChunkIndex + 1,
2934 End =
D.getNumTypeObjects();
2935 OuterChunkIndex != End; ++OuterChunkIndex) {
2937 switch (OuterChunk.
Kind) {
2944 diag::warn_qual_return_type,
2966 D.getIdentifierLoc());
2970 llvm_unreachable(
"unknown declarator chunk kind");
2982 D.getDeclSpec().getTypeQualifiers(),
2983 D.getIdentifierLoc(),
2984 D.getDeclSpec().getConstSpecLoc(),
2985 D.getDeclSpec().getVolatileSpecLoc(),
2986 D.getDeclSpec().getRestrictSpecLoc(),
2987 D.getDeclSpec().getAtomicSpecLoc(),
2988 D.getDeclSpec().getUnalignedSpecLoc());
2991static std::pair<QualType, TypeSourceInfo *>
2995 Sema &S = state.getSema();
2999 const unsigned AutoParameterPosition = Info.
TemplateParams.size();
3000 const bool IsParameterPack =
D.hasEllipsis();
3011 D.getDeclSpec().getTypeSpecTypeLoc(),
3012 D.getIdentifierLoc(),
3013 TemplateParameterDepth, AutoParameterPosition,
3015 D.getIdentifier(), AutoParameterPosition),
false,
3016 IsParameterPack,
Auto->isConstrained());
3021 if (
Auto->isConstrained()) {
3028 for (
unsigned Idx = 0; Idx < AutoLoc.
getNumArgs(); ++Idx) {
3029 if (
D.getEllipsisLoc().isInvalid() && !
Invalid &&
3041 InventedTemplateParam,
3043 D.getEllipsisLoc());
3057 if (
D.getEllipsisLoc().isInvalid()) {
3073 D.getDeclSpec().getTypeSpecScope().getWithLocInContext(S.
Context),
3078 USD ? cast<NamedDecl>(USD) : CD,
3080 InventedTemplateParam,
3082 D.getEllipsisLoc());
3092 QualType NewT = state.ReplaceAutoType(
T, Replacement);
3096 return {NewT, NewTSI};
3105 Sema &SemaRef = state.getSema();
3108 ReturnTypeInfo =
nullptr;
3111 TagDecl *OwnedTagDecl =
nullptr;
3121 if (!
D.isInvalidType() &&
D.getDeclSpec().isTypeSpecOwned()) {
3122 OwnedTagDecl = cast<TagDecl>(
D.getDeclSpec().getRepAsDecl());
3135 D.getMutableDeclSpec().getAttributes());
3162 bool DeducedIsTrailingReturnType =
false;
3163 if (Deduced && isa<AutoType>(Deduced) &&
D.hasTrailingReturnType()) {
3166 DeducedIsTrailingReturnType =
true;
3176 bool IsCXXAutoType =
3178 bool IsDeducedReturnType =
false;
3180 switch (
D.getContext()) {
3219 assert(Info &&
"No LambdaScopeInfo on the stack!");
3225 if (!DeducedIsTrailingReturnType)
3230 if (
D.isStaticMember() ||
D.isFunctionDeclarator())
3233 if (isa<ObjCContainerDecl>(SemaRef.
CurContext)) {
3236 switch (cast<TagDecl>(SemaRef.
CurContext)->getTagKind()) {
3238 llvm_unreachable(
"unhandled tag kind");
3240 Error = Cxx ? 1 : 2;
3243 Error = Cxx ? 3 : 4;
3253 if (
D.getDeclSpec().isFriendSpecified())
3262 if (isa<DeducedTemplateSpecializationType>(Deduced) &&
3274 if (isa<DeducedTemplateSpecializationType>(Deduced) &&
3275 !
D.getNumTypeObjects() &&
3288 if (!SemaRef.
getLangOpts().CPlusPlus14 || !IsCXXAutoType)
3290 IsDeducedReturnType =
true;
3293 if (!SemaRef.
getLangOpts().CPlusPlus14 || !IsCXXAutoType)
3295 IsDeducedReturnType =
true;
3298 if (isa<DeducedTemplateSpecializationType>(Deduced))
3300 if (SemaRef.
getLangOpts().CPlusPlus23 && IsCXXAutoType &&
3301 !
Auto->isDecltypeAuto())
3320 if (!IsCXXAutoType && !isa<DeducedTemplateSpecializationType>(Deduced))
3333 if (
D.isFunctionDeclarator() &&
3334 (!SemaRef.
getLangOpts().CPlusPlus11 || !IsCXXAutoType))
3337 SourceRange AutoRange =
D.getDeclSpec().getTypeSpecTypeLoc();
3344 switch (
Auto->getKeyword()) {
3350 assert(isa<DeducedTemplateSpecializationType>(Deduced) &&
3351 "unknown auto type");
3355 auto *DTST = dyn_cast<DeducedTemplateSpecializationType>(Deduced);
3358 SemaRef.
Diag(AutoRange.
getBegin(), diag::err_auto_not_allowed)
3360 <<
QualType(Deduced, 0) << AutoRange;
3365 D.setInvalidType(
true);
3371 ? diag::warn_cxx11_compat_generic_lambda
3372 : IsDeducedReturnType
3373 ? diag::warn_cxx11_compat_deduced_return_type
3374 : diag::warn_cxx98_compat_auto_type_specifier)
3383 unsigned DiagID = 0;
3384 switch (
D.getContext()) {
3389 llvm_unreachable(
"parser should not have allowed this");
3405 DiagID = diag::err_type_defined_in_alias_template;
3417 DiagID = diag::err_type_defined_in_type_specifier;
3427 DiagID = diag::err_type_defined_in_param_type;
3433 DiagID = diag::err_type_defined_in_condition;
3440 D.setInvalidType(
true);
3444 assert(!
T.isNull() &&
"This function should not return a null type");
3453 assert(FTI.
isAmbiguous &&
"no direct-initializer / function ambiguity");
3469 if (!
D.isFunctionDeclarator() ||
3483 FTI.
NumParams ? diag::warn_parens_disambiguated_as_function_declaration
3484 : diag::warn_empty_parens_are_function_decl)
3492 if (!
D.isFirstDeclarator() &&
D.getIdentifier()) {
3495 if (Comma.getFileID() != Name.getFileID() ||
3496 Comma.getSpellingLineNumber() != Name.getSpellingLineNumber()) {
3500 S.
Diag(
D.getCommaLoc(), diag::note_empty_parens_function_call)
3502 <<
D.getIdentifier();
3503 Result.suppressDiagnostics();
3516 S.
Diag(B, diag::note_additional_parens_for_variable_declaration)
3531 S.
Diag(DeclType.
Loc, diag::note_empty_parens_default_ctor)
3539 S.
Diag(DeclType.
Loc, diag::note_empty_parens_zero_initialize)
3550 "do not have redundant top-level parentheses");
3559 bool CouldBeTemporaryObject =
3560 S.
getLangOpts().CPlusPlus &&
D.isExpressionContext() &&
3561 !
D.isInvalidType() &&
D.getIdentifier() &&
3564 D.getDeclSpec().getTypeQualifiers() == 0 &&
D.isFirstDeclarator();
3566 bool StartsWithDeclaratorId =
true;
3567 for (
auto &
C :
D.type_objects()) {
3574 StartsWithDeclaratorId =
false;
3579 CouldBeTemporaryObject =
false;
3587 CouldBeTemporaryObject =
false;
3588 StartsWithDeclaratorId =
false;
3598 CouldBeTemporaryObject =
false;
3605 CouldBeTemporaryObject =
false;
3606 StartsWithDeclaratorId =
false;
3616 if (CouldBeTemporaryObject) {
3620 CouldBeTemporaryObject =
false;
3621 Result.suppressDiagnostics();
3626 if (!CouldBeTemporaryObject) {
3631 if (StartsWithDeclaratorId &&
D.getCXXScopeSpec().isValid()) {
3633 NNS = NNS->getPrefix()) {
3639 S.
Diag(
Paren.Loc, diag::warn_redundant_parens_around_declarator)
3645 S.
Diag(
Paren.Loc, diag::warn_parens_disambiguated_as_variable_declaration)
3646 << ParenRange <<
D.getIdentifier();
3648 if (!RD || !RD->hasDefinition() || RD->hasNonTrivialDestructor())
3649 S.
Diag(
Paren.Loc, diag::note_raii_guard_add_name)
3651 <<
D.getIdentifier();
3657 S.
Diag(
Paren.Loc, diag::note_remove_parens_for_variable_declaration)
3673 switch (AL.getKind()) {
3692 bool IsCXXInstanceMethod =
false;
3698 unsigned I = ChunkIndex;
3699 bool FoundNonParen =
false;
3700 while (I && !FoundNonParen) {
3703 FoundNonParen =
true;
3706 if (FoundNonParen) {
3709 IsCXXInstanceMethod =
3714 IsCXXInstanceMethod =
3718 assert(
D.isFunctionDeclarator());
3722 IsCXXInstanceMethod =
3723 D.isFirstDeclarationOfMember() &&
3725 !
D.isStaticMember();
3730 IsCXXInstanceMethod);
3737 for (
const ParsedAttr &AL :
D.getDeclSpec().getAttributes()) {
3738 if (AL.getKind() == ParsedAttr::AT_OpenCLKernel) {
3749 if (Triple.isSPIRV() && Triple.getVendor() != llvm::Triple::AMD) {
3750 for (
const ParsedAttr &AL :
D.getDeclSpec().getAttributes()) {
3751 if (AL.getKind() == ParsedAttr::AT_CUDAGlobal) {
3765 enum class SimplePointerKind {
3774 switch (nullability) {
3776 if (!Ident__Nonnull)
3778 return Ident__Nonnull;
3781 if (!Ident__Nullable)
3783 return Ident__Nullable;
3786 if (!Ident__Nullable_result)
3788 return Ident__Nullable_result;
3791 if (!Ident__Null_unspecified)
3793 return Ident__Null_unspecified;
3795 llvm_unreachable(
"Unknown nullability kind.");
3802 if (AL.getKind() == ParsedAttr::AT_TypeNonNull ||
3803 AL.getKind() == ParsedAttr::AT_TypeNullable ||
3804 AL.getKind() == ParsedAttr::AT_TypeNullableResult ||
3805 AL.getKind() == ParsedAttr::AT_TypeNullUnspecified)
3814 enum class PointerDeclaratorKind {
3822 MaybePointerToCFRef,
3826 NSErrorPointerPointer,
3832 enum class PointerWrappingDeclaratorKind {
3846static PointerDeclaratorKind
3848 PointerWrappingDeclaratorKind &wrappingKind) {
3849 unsigned numNormalPointers = 0;
3852 if (
type->isDependentType())
3853 return PointerDeclaratorKind::NonPointer;
3858 switch (chunk.
Kind) {
3860 if (numNormalPointers == 0)
3861 wrappingKind = PointerWrappingDeclaratorKind::Array;
3870 return numNormalPointers > 0 ? PointerDeclaratorKind::MultiLevelPointer
3871 : PointerDeclaratorKind::SingleLevelPointer;
3877 if (numNormalPointers == 0)
3878 wrappingKind = PointerWrappingDeclaratorKind::Reference;
3882 ++numNormalPointers;
3883 if (numNormalPointers > 2)
3884 return PointerDeclaratorKind::MultiLevelPointer;
3890 unsigned numTypeSpecifierPointers = 0;
3894 ++numNormalPointers;
3896 if (numNormalPointers > 2)
3897 return PointerDeclaratorKind::MultiLevelPointer;
3899 type = ptrType->getPointeeType();
3900 ++numTypeSpecifierPointers;
3906 return numNormalPointers > 0 ? PointerDeclaratorKind::MultiLevelPointer
3907 : PointerDeclaratorKind::SingleLevelPointer;
3912 return numNormalPointers > 0 ? PointerDeclaratorKind::MultiLevelPointer
3913 : PointerDeclaratorKind::SingleLevelPointer;
3918 ++numNormalPointers;
3919 ++numTypeSpecifierPointers;
3922 if (
auto objcClassDecl = objcObjectPtr->getInterfaceDecl()) {
3924 numNormalPointers == 2 && numTypeSpecifierPointers < 2) {
3925 return PointerDeclaratorKind::NSErrorPointerPointer;
3934 if (objcClass->getInterface()->getIdentifier() ==
3936 if (numNormalPointers == 2 && numTypeSpecifierPointers < 2)
3937 return PointerDeclaratorKind::NSErrorPointerPointer;
3944 if (numNormalPointers == 0)
3945 return PointerDeclaratorKind::NonPointer;
3951 if (numNormalPointers == 2 && numTypeSpecifierPointers < 2 &&
3953 return PointerDeclaratorKind::CFErrorRefPointer;
3961 switch (numNormalPointers) {
3963 return PointerDeclaratorKind::NonPointer;
3966 return PointerDeclaratorKind::SingleLevelPointer;
3969 return PointerDeclaratorKind::MaybePointerToCFRef;
3972 return PointerDeclaratorKind::MultiLevelPointer;
3981 if (ctx->isFunctionOrMethod())
3984 if (ctx->isFileContext())
3995 bool invalid =
false;
3997 if (invalid || !sloc.
isFile())
4015template <
typename DiagBuilderT>
4024 if (!FixItLoc.
isValid() || FixItLoc == PointerLoc)
4033 InsertionTextBuf +=
" ";
4034 StringRef InsertionText = InsertionTextBuf.str();
4037 InsertionText = InsertionText.drop_back();
4038 }
else if (NextChar[-1] ==
'[') {
4039 if (NextChar[0] ==
']')
4040 InsertionText = InsertionText.drop_back().drop_front();
4042 InsertionText = InsertionText.drop_front();
4045 InsertionText = InsertionText.drop_back().drop_front();
4052 SimplePointerKind PointerKind,
4057 if (PointerKind == SimplePointerKind::Array) {
4058 S.
Diag(PointerLoc, diag::warn_nullability_missing_array);
4060 S.
Diag(PointerLoc, diag::warn_nullability_missing)
4061 <<
static_cast<unsigned>(PointerKind);
4064 auto FixItLoc = PointerEndLoc.
isValid() ? PointerEndLoc : PointerLoc;
4065 if (FixItLoc.isMacroID())
4069 auto Diag = S.
Diag(FixItLoc, diag::note_nullability_fix_it);
4070 Diag << static_cast<unsigned>(Nullability);
4071 Diag << static_cast<unsigned>(PointerKind);
4100 if (pointerKind == SimplePointerKind::Array)
4101 diagKind = diag::warn_nullability_missing_array;
4103 diagKind = diag::warn_nullability_missing;
4109 fileNullability.
PointerKind =
static_cast<unsigned>(pointerKind);
4141 auto kind =
static_cast<SimplePointerKind
>(fileNullability.
PointerKind);
4156 unsigned i = endIndex;
4184template<
typename AttrT>
4187 return ::new (Ctx) AttrT(Ctx, AL);
4194 return createSimpleAttr<TypeNonNullAttr>(Ctx,
Attr);
4197 return createSimpleAttr<TypeNullableAttr>(Ctx,
Attr);
4200 return createSimpleAttr<TypeNullableResultAttr>(Ctx,
Attr);
4203 return createSimpleAttr<TypeNullUnspecifiedAttr>(Ctx,
Attr);
4205 llvm_unreachable(
"unknown NullabilityKind");
4216 if (ASOld != ASNew) {
4217 S.
Diag(AttrLoc, diag::err_attribute_address_multiple_qualifiers);
4222 diag::warn_attribute_address_multiple_identical_qualifiers);
4236 !isa<RecordType, TemplateSpecializationType>(
4247 Sema &S = state.getSema();
4253 if (
D.getIdentifier())
4254 Name =
D.getIdentifier();
4257 bool IsTypedefName =
4273 bool IsClassTemplateDeduction = isa<DeducedTemplateSpecializationType>(DT);
4275 for (
unsigned I = 0,
E =
D.getNumTypeObjects(); I !=
E; ++I) {
4276 unsigned Index =
E - I - 1;
4278 unsigned DiagId = IsClassTemplateDeduction
4279 ? diag::err_deduced_class_template_compound_type
4280 : diag::err_decltype_auto_compound_type;
4281 unsigned DiagKind = 0;
4282 switch (DeclChunk.
Kind) {
4285 if (IsClassTemplateDeduction) {
4291 if (IsClassTemplateDeduction) {
4296 if (
D.isFunctionDeclarationContext() &&
4297 D.isFunctionDeclarator(FnIndex) && FnIndex == Index)
4299 DiagId = diag::err_decltype_auto_function_declarator_not_declaration;
4317 S.
Diag(DeclChunk.
Loc, DiagId) << DiagKind;
4318 D.setInvalidType(
true);
4325 std::optional<NullabilityKind> inferNullability;
4326 bool inferNullabilityCS =
false;
4327 bool inferNullabilityInnerOnly =
false;
4328 bool inferNullabilityInnerOnlyComplete =
false;
4331 bool inAssumeNonNullRegion =
false;
4333 if (assumeNonNullLoc.
isValid()) {
4334 inAssumeNonNullRegion =
true;
4348 } complainAboutMissingNullability = CAMN_No;
4349 unsigned NumPointersRemaining = 0;
4350 auto complainAboutInferringWithinChunk = PointerWrappingDeclaratorKind::None;
4352 if (IsTypedefName) {
4356 complainAboutMissingNullability = CAMN_InnerPointers;
4360 ++NumPointersRemaining;
4363 for (
unsigned i = 0, n =
D.getNumTypeObjects(); i != n; ++i) {
4365 switch (chunk.
Kind) {
4373 ++NumPointersRemaining;
4381 ++NumPointersRemaining;
4386 bool isFunctionOrMethod =
false;
4387 switch (
auto context = state.getDeclarator().getContext()) {
4393 isFunctionOrMethod =
true;
4397 if (state.getDeclarator().isObjCIvar() && !isFunctionOrMethod) {
4398 complainAboutMissingNullability = CAMN_No;
4403 if (state.getDeclarator().isObjCWeakProperty()) {
4406 complainAboutMissingNullability = CAMN_No;
4407 if (inAssumeNonNullRegion) {
4417 complainAboutMissingNullability = CAMN_Yes;
4420 auto wrappingKind = PointerWrappingDeclaratorKind::None;
4422 case PointerDeclaratorKind::NonPointer:
4423 case PointerDeclaratorKind::MultiLevelPointer:
4427 case PointerDeclaratorKind::SingleLevelPointer:
4429 if (inAssumeNonNullRegion) {
4430 complainAboutInferringWithinChunk = wrappingKind;
4437 case PointerDeclaratorKind::CFErrorRefPointer:
4438 case PointerDeclaratorKind::NSErrorPointerPointer:
4441 if (isFunctionOrMethod && inAssumeNonNullRegion)
4445 case PointerDeclaratorKind::MaybePointerToCFRef:
4446 if (isFunctionOrMethod) {
4450 auto hasCFReturnsAttr =
4452 return AttrList.hasAttribute(ParsedAttr::AT_CFReturnsRetained) ||
4453 AttrList.hasAttribute(ParsedAttr::AT_CFReturnsNotRetained);
4455 if (
const auto *InnermostChunk =
D.getInnermostNonParenChunk()) {
4456 if (hasCFReturnsAttr(
D.getDeclarationAttributes()) ||
4457 hasCFReturnsAttr(
D.getAttributes()) ||
4458 hasCFReturnsAttr(InnermostChunk->getAttrs()) ||
4459 hasCFReturnsAttr(
D.getDeclSpec().getAttributes())) {
4461 inferNullabilityInnerOnly =
true;
4471 complainAboutMissingNullability = CAMN_Yes;
4499 auto isVaList = [&S](
QualType T) ->
bool {
4505 if (typedefTy->getDecl() == vaListTypedef)
4507 if (
auto *name = typedefTy->getDecl()->getIdentifier())
4508 if (name->isStr(
"va_list"))
4510 typedefTy = typedefTy->desugar()->getAs<
TypedefType>();
4511 }
while (typedefTy);
4517 auto inferPointerNullability =
4522 if (NumPointersRemaining > 0)
4523 --NumPointersRemaining;
4530 if (inferNullability && !inferNullabilityInnerOnlyComplete) {
4533 ? ParsedAttr::Form::ContextSensitiveKeyword()
4534 : ParsedAttr::Form::Keyword(
false ,
4540 attrs.addAtEnd(nullabilityAttr);
4542 if (inferNullabilityCS) {
4543 state.getDeclarator().getMutableDeclSpec().getObjCQualifiers()
4547 if (pointerLoc.isValid() &&
4548 complainAboutInferringWithinChunk !=
4549 PointerWrappingDeclaratorKind::None) {
4551 S.
Diag(pointerLoc, diag::warn_nullability_inferred_on_nested_type);
4552 Diag << static_cast<int>(complainAboutInferringWithinChunk);
4556 if (inferNullabilityInnerOnly)
4557 inferNullabilityInnerOnlyComplete =
true;
4558 return nullabilityAttr;
4563 switch (complainAboutMissingNullability) {
4567 case CAMN_InnerPointers:
4568 if (NumPointersRemaining == 0)
4584 if (NumPointersRemaining > 0)
4585 --NumPointersRemaining;
4587 SimplePointerKind pointerKind = SimplePointerKind::Pointer;
4589 pointerKind = SimplePointerKind::BlockPointer;
4591 pointerKind = SimplePointerKind::MemberPointer;
4593 if (
auto *
attr = inferPointerNullability(
4594 pointerKind,
D.getDeclSpec().getTypeSpecTypeLoc(),
4596 D.getMutableDeclSpec().getAttributes(),
4597 D.getMutableDeclSpec().getAttributePool())) {
4598 T = state.getAttributedType(
4604 if (complainAboutMissingNullability == CAMN_Yes &&
T->
isArrayType() &&
4608 D.getDeclSpec().getTypeSpecTypeLoc());
4612 bool ExpectNoDerefChunk =
4613 state.getCurrentAttributes().hasAttribute(ParsedAttr::AT_NoDeref);
4623 bool AreDeclaratorChunksValid =
true;
4624 for (
unsigned i = 0, e =
D.getNumTypeObjects(); i != e; ++i) {
4625 unsigned chunkIndex = e - i - 1;
4626 state.setCurrentChunkIndex(chunkIndex);
4629 switch (DeclType.
Kind) {
4637 if (!LangOpts.Blocks)
4638 S.
Diag(DeclType.
Loc, diag::err_blocks_disable) << LangOpts.OpenCL;
4641 inferPointerNullability(SimplePointerKind::BlockPointer, DeclType.
Loc,
4643 state.getDeclarator().getAttributePool());
4649 if (LangOpts.OpenCL)
4658 S.
Diag(
D.getIdentifierLoc(), diag::err_distant_exception_spec);
4659 D.setInvalidType(
true);
4664 inferPointerNullability(SimplePointerKind::Pointer, DeclType.
Loc,
4666 state.getDeclarator().getAttributePool());
4678 if (LangOpts.OpenCL) {
4681 S.
Diag(
D.getIdentifierLoc(), diag::err_opencl_pointer_to_type) <<
T;
4682 D.setInvalidType(
true);
4694 S.
Diag(
D.getIdentifierLoc(), diag::err_distant_exception_spec);
4695 D.setInvalidType(
true);
4708 S.
Diag(
D.getIdentifierLoc(), diag::err_distant_exception_spec);
4709 D.setInvalidType(
true);
4719 if (chunkIndex != 0 && !ArraySize &&
4720 D.getDeclSpec().getAttributes().hasMSPropertyAttr()) {
4738 S.
Diag(DeclType.
Loc, diag::err_array_star_outside_prototype);
4740 D.setInvalidType(
true);
4747 if (!(
D.isPrototypeContext() ||
4749 S.
Diag(DeclType.
Loc, diag::err_array_static_outside_prototype)
4751 :
"type qualifier");
4756 D.setInvalidType(
true);
4762 S.
Diag(DeclType.
Loc, diag::err_array_static_not_outermost)
4764 :
"type qualifier");
4768 D.setInvalidType(
true);
4774 if (complainAboutMissingNullability == CAMN_Yes &&
4790 IsQualifiedFunction =
4795 if (!
D.isInvalidType()) {
4799 return SS.isInvalid() ||
4821 ? dyn_cast_if_present<ParmVarDecl>(FTI.
Params[0].
Param)
4824 bool IsFunctionDecl =
D.getInnermostNonParenChunk() == &DeclType;
4825 if (
First &&
First->isExplicitObjectParameter() &&
4836 !IsClassType(
D.getCXXScopeSpec())) {
4839 diag::err_explicit_object_parameter_nonmember)
4841 <<
First->getSourceRange();
4844 diag::err_explicit_object_parameter_invalid)
4845 <<
First->getSourceRange();
4848 AreDeclaratorChunksValid =
false;