28 #include "llvm/ADT/SmallString.h" 30 using namespace clang;
32 using llvm::makeArrayRef;
43 if (Strings.size() != 1) {
48 for (
Expr *E : Strings) {
49 S = cast<StringLiteral>(E);
68 assert(CAT &&
"String literal not of constant array type!");
73 false, StrTy, &StrLocs[0],
77 return BuildObjCStringLiteral(AtLocs[0], S);
82 if (CheckObjCString(S))
92 }
else if (getLangOpts().NoConstantCFStrings) {
94 std::string StringClass(getLangOpts().ObjCConstantStringClass);
96 if (StringClass.empty())
97 NSIdent = &Context.
Idents.
get(
"NSConstantString");
99 NSIdent = &Context.
Idents.
get(StringClass);
101 NamedDecl *IF = LookupSingleName(TUScope, NSIdent, AtLoc,
116 NamedDecl *IF = LookupSingleName(TUScope, NSIdent, AtLoc,
151 S.
Diag(Loc, diag::err_undeclared_boxing_method) << Sel << Class->
getName();
158 S.
Diag(Loc, diag::err_objc_literal_method_sig)
171 switch (LiteralKind) {
189 llvm_unreachable(
"LiteralKind can't be converted into a ClassKind");
201 S.
Diag(Loc, diag::err_undeclared_objc_literal_class)
202 << II->
getName() << LiteralKind;
205 S.
Diag(Loc, diag::err_undeclared_objc_literal_class)
206 << Decl->
getName() << LiteralKind;
246 S.
NSAPIObj->getNSNumberFactoryMethodKind(NumberType);
250 S.
Diag(Loc, diag::err_invalid_nsnumber_type)
283 if (!Method && S.
getLangOpts().DebuggerObjCLiteral) {
320 switch (Char->getKind()) {
323 NumberType = Context.
CharTy;
352 ExprResult ConvertedNumber = PerformCopyInitialization(Entity,
357 Number = ConvertedNumber.
get();
360 return MaybeBindToTemporary(
370 Inner = ActOnCXXBoolLiteral(ValueLoc, Value? tok::kw_true : tok::kw_false);
374 Inner = ActOnIntegerConstant(ValueLoc, Value? 1 : 0);
375 Inner = ImpCastExprToType(Inner.
get(), Context.
BoolTy,
376 CK_IntegralToBoolean);
379 return BuildObjCNumericLiteral(AtLoc, Inner.
get());
386 bool ArrayLiteral =
false) {
394 Element = Result.
get();
406 return Seq.Perform(S, Entity, Kind, Element);
409 Expr *OrigElement = Element;
415 Element = Result.
get();
420 bool Recovered =
false;
423 if (isa<IntegerLiteral>(OrigElement) ||
424 isa<CharacterLiteral>(OrigElement) ||
425 isa<FloatingLiteral>(OrigElement) ||
426 isa<ObjCBoolLiteralExpr>(OrigElement) ||
427 isa<CXXBoolLiteralExpr>(OrigElement)) {
428 if (S.
NSAPIObj->getNSNumberFactoryMethodKind(OrigElement->
getType())) {
429 int Which = isa<CharacterLiteral>(OrigElement) ? 1
430 : (isa<CXXBoolLiteralExpr>(OrigElement) ||
431 isa<ObjCBoolLiteralExpr>(OrigElement)) ? 2
440 if (Result.isInvalid())
443 Element = Result.get();
448 else if (
StringLiteral *String = dyn_cast<StringLiteral>(OrigElement)) {
449 if (String->isAscii()) {
455 if (Result.isInvalid())
458 Element = Result.get();
471 dyn_cast<ObjCStringLiteral>(OrigElement)) {
473 unsigned numConcat = SL->getNumConcatenated();
476 bool hasMacro =
false;
477 for (
unsigned i = 0; i < numConcat ; ++i)
478 if (SL->getStrTokenLoc(i).isMacroID()) {
484 diag::warn_concatenated_nsarray_literal)
507 ExprResult RValue = DefaultFunctionArrayLvalueConversion(ValueExpr);
512 ValueExpr = RValue.
get();
528 if (!StringWithUTF8StringMethod) {
533 BoxingMethod = NSStringDecl->lookupClassMethod(stringWithUTF8String);
534 if (!BoxingMethod && getLangOpts().DebuggerObjCLiteral) {
539 NSStringPointer, ReturnTInfo, NSStringDecl,
558 stringWithUTF8String, BoxingMethod))
561 StringWithUTF8StringMethod = BoxingMethod;
564 BoxingMethod = StringWithUTF8StringMethod;
565 BoxedType = NSStringPointer;
574 }
else if (ValueType->isBuiltinType()) {
582 dyn_cast<CharacterLiteral>(ValueExpr->
IgnoreParens())) {
585 switch (Char->getKind()) {
588 ValueType = Context.
CharTy;
608 BoxedType = NSNumberPointer;
610 if (!ET->getDecl()->isComplete()) {
611 Diag(Loc, diag::err_objc_incomplete_boxed_expression_type)
617 ET->getDecl()->getIntegerType());
618 BoxedType = NSNumberPointer;
619 }
else if (ValueType->isObjCBoxableRecordType()) {
637 if (!ValueWithBytesObjCTypeMethod) {
645 BoxingMethod = NSValueDecl->lookupClassMethod(ValueWithBytesObjCType);
646 if (!BoxingMethod && getLangOpts().DebuggerObjCLiteral) {
653 ValueWithBytesObjCType,
674 Params.push_back(bytes);
684 Params.push_back(type);
691 ValueWithBytesObjCType, BoxingMethod))
694 ValueWithBytesObjCTypeMethod = BoxingMethod;
697 if (!ValueType.isTriviallyCopyableType(Context)) {
698 Diag(Loc, diag::err_objc_non_trivially_copyable_boxed_expression_type)
703 BoxingMethod = ValueWithBytesObjCTypeMethod;
704 BoxedType = NSValuePointer;
708 Diag(Loc, diag::err_objc_illegal_boxed_expression_type)
713 DiagnoseUseOfDecl(BoxingMethod, Loc);
716 if (ValueType->isObjCBoxableRecordType()) {
718 ConvertedValueExpr = PerformCopyInitialization(IE, ValueExpr->
getExprLoc(),
725 ConvertedValueExpr = PerformCopyInitialization(IE,
SourceLocation(),
731 ValueExpr = ConvertedValueExpr.
get();
736 return MaybeBindToTemporary(BoxedExpr);
745 assert(!LangOpts.isSubscriptPointerArithmetic());
750 "base or index cannot have dependent type here");
754 ExprResult Result = CheckPlaceholderExpr(IndexExpr);
757 IndexExpr = Result.
get();
760 Result = DefaultLvalueConversion(BaseExpr);
763 BaseExpr = Result.
get();
768 getterMethod, setterMethod, RB);
784 if (!ArrayWithObjectsMethod) {
788 if (!Method && getLangOpts().DebuggerObjCLiteral) {
805 Params.push_back(objects);
813 Params.push_back(cnt);
828 diag::note_objc_literal_method_param)
835 if (!Method->
parameters()[1]->getType()->isIntegerType()) {
839 diag::note_objc_literal_method_param)
847 ArrayWithObjectsMethod = Method;
850 QualType ObjectsType = ArrayWithObjectsMethod->parameters()[0]->getType();
855 Expr **ElementsBuffer = Elements.data();
856 for (
unsigned I = 0, N = Elements.size(); I != N; ++I) {
863 ElementsBuffer[I] = Converted.
get();
870 return MaybeBindToTemporary(
872 ArrayWithObjectsMethod, SR));
879 if (!NSDictionaryDecl) {
882 if (!NSDictionaryDecl) {
890 if (!DictionaryWithObjectsMethod) {
891 Selector Sel = NSAPIObj->getNSDictionarySelector(
893 ObjCMethodDecl *Method = NSDictionaryDecl->lookupClassMethod(Sel);
894 if (!Method && getLangOpts().DebuggerObjCLiteral) {
913 Params.push_back(objects);
921 Params.push_back(keys);
929 Params.push_back(cnt);
945 diag::note_objc_literal_method_param)
959 if (QIDNSCopying.isNull()) {
973 if (!QIDNSCopying.isNull())
982 diag::note_objc_literal_method_param)
995 diag::note_objc_literal_method_param)
1002 DictionaryWithObjectsMethod = Method;
1005 QualType ValuesT = DictionaryWithObjectsMethod->parameters()[0]->getType();
1007 QualType KeysT = DictionaryWithObjectsMethod->parameters()[1]->getType();
1012 bool HasPackExpansions =
false;
1026 Element.Key = Key.
get();
1027 Element.Value = Value.
get();
1029 if (Element.EllipsisLoc.isInvalid())
1032 if (!Element.Key->containsUnexpandedParameterPack() &&
1033 !Element.Value->containsUnexpandedParameterPack()) {
1034 Diag(Element.EllipsisLoc,
1035 diag::err_pack_expansion_without_parameter_packs)
1037 Element.Value->getEndLoc());
1041 HasPackExpansions =
true;
1048 Context, Elements, HasPackExpansions, Ty,
1049 DictionaryWithObjectsMethod, SR));
1062 if (RequireCompleteType(AtLoc, EncodedType,
1063 diag::err_incomplete_type_objc_at_encode,
1070 if (!NotEncodedT.
isNull())
1071 Diag(AtLoc, diag::warn_incomplete_encoded_type)
1072 << EncodedType << NotEncodedT;
1078 if (getLangOpts().CPlusPlus || getLangOpts().ConstStrings)
1084 return new (Context)
ObjCEncodeExpr(StrTy, EncodedTypeInfo, AtLoc, RParenLoc);
1094 QualType EncodedType = GetTypeFromParser(ty, &TInfo);
1097 getLocForEndOfToken(LParenLoc));
1099 return BuildObjCEncodeExpression(AtLoc, TInfo, RParenLoc);
1109 bool Warned =
false;
1112 if (MatchingMethodDecl == Method ||
1120 S.
Diag(AtLoc, diag::warn_multiple_selectors)
1126 S.
Diag(MatchingMethodDecl->
getLocation(), diag::note_method_declared_at)
1137 bool WarnMultipleSelectors) {
1138 if (!WarnMultipleSelectors ||
1141 bool Warned =
false;
1142 for (Sema::GlobalMethodPool::iterator b = S.
MethodPool.begin(),
1147 Method, InstMethList))
1153 Method, ClsMethList) || Warned)
1163 bool WarnMultipleSelectors) {
1167 Method = LookupFactoryMethodInGlobalPool(Sel,
1170 if (
const ObjCMethodDecl *OM = SelectorsForTypoCorrection(Sel)) {
1171 Selector MatchedSel = OM->getSelector();
1174 Diag(SelLoc, diag::warn_undeclared_selector_with_typo)
1175 << Sel << MatchedSel
1179 Diag(SelLoc, diag::warn_undeclared_selector) << Sel;
1182 WarnMultipleSelectors);
1186 !getSourceManager().isInSystemHeader(Method->
getLocation()))
1187 ReferencedSelectors.insert(std::make_pair(Sel, AtLoc));
1191 if (getLangOpts().ObjCAutoRefCount) {
1198 Diag(AtLoc, diag::err_arc_illegal_selector) <<
1227 Diag(ProtoLoc, diag::err_undeclared_protocol) << ProtocolId;
1231 Diag(ProtoLoc, diag::err_atprotocol_protocol) << PDecl;
1241 return new (Context)
ObjCProtocolExpr(Ty, PDecl, AtLoc, ProtoIdLoc, RParenLoc);
1287 bool isClassMessage,
1288 bool isSuperMessage) {
1289 assert(Method &&
"Must have a method");
1324 if (isSuperMessage) {
1327 return transferNullability(
1346 return transferNullability(ReceiverType);
1352 bool isClassMessage,
1353 bool isSuperMessage) {
1361 if (isClassMessage) {
1373 cast<ImplicitParamDecl>(
1375 ->getDeclContext());
1382 NewResultType, NewResultType);
1383 return NewResultType;
1395 unsigned receiverNullabilityIdx = 0;
1397 receiverNullabilityIdx = 1 + static_cast<unsigned>(*nullability);
1399 unsigned resultNullabilityIdx = 0;
1401 resultNullabilityIdx = 1 + static_cast<unsigned>(*nullability);
1405 static const uint8_t None = 0;
1406 static const uint8_t
NonNull = 1;
1409 static const uint8_t nullabilityMap[4][4] = {
1411 { None, None, Nullable, None },
1412 { None, NonNull, Nullable, Unspecified },
1413 { Nullable, Nullable, Nullable, Nullable },
1414 { None, Unspecified, Nullable, Unspecified }
1417 unsigned newResultNullabilityIdx
1418 = nullabilityMap[receiverNullabilityIdx][resultNullabilityIdx];
1419 if (newResultNullabilityIdx == resultNullabilityIdx)
1425 if (
auto attributed = dyn_cast<AttributedType>(resultType.
getTypePtr())) {
1426 resultType = attributed->getModifiedType();
1433 if (newResultNullabilityIdx > 0) {
1438 resultType, resultType);
1457 dyn_cast<ObjCCategoryImplDecl>(impl)) {
1458 iface = catImpl->getCategoryDecl();
1460 iface = impl->getClassInterface();
1470 for (
unsigned i = 0, e = overrides.size(); i != e; ++i) {
1491 SourceRange range = overridden->getReturnTypeSourceRange();
1494 loc = overridden->getLocation();
1495 Diag(loc, diag::note_related_result_type_explicit)
1541 if (!SelectorLocs.empty() && SelectorLocs.front().isValid())
1542 SelLoc = SelectorLocs.front();
1548 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
1549 if (Args[i]->isTypeDependent())
1553 if (getLangOpts().DebuggerSupport) {
1555 result = checkUnknownAnyArg(SelLoc, Args[i], paramTy);
1557 result = DefaultArgumentPromotion(Args[i]);
1561 Args[i] = result.
get();
1565 if (getLangOpts().ObjCAutoRefCount)
1566 DiagID = diag::err_arc_method_not_found;
1568 DiagID = isClassMessage ? diag::warn_class_method_not_found
1569 : diag::warn_inst_method_not_found;
1570 if (!getLangOpts().DebuggerSupport) {
1571 const ObjCMethodDecl *OMD = SelectorsForTypoCorrection(Sel, ReceiverType);
1573 if (getLangOpts().ObjCAutoRefCount)
1574 DiagID = diag::err_method_not_found_with_typo;
1576 DiagID = isClassMessage ? diag::warn_class_method_not_found_with_typo
1577 : diag::warn_instance_method_not_found_with_typo;
1579 SourceRange SelectorRange(SelectorLocs.front(), SelectorLocs.back());
1581 Diag(SelLoc, DiagID)
1582 << Sel<< isClassMessage << MatchedSel
1585 Diag(SelLoc, DiagID) << Sel<< isClassMessage << MatchedSel;
1588 Diag(SelLoc, DiagID)
1589 << Sel << isClassMessage <<
SourceRange(SelectorLocs.front(),
1590 SelectorLocs.back());
1595 Diag(ThisClass->getLocation(), diag::note_receiver_class_declared);
1597 if (ThisClass->lookupClassMethod(Sel))
1598 Diag(RecRange.
getBegin(),diag::note_receiver_expr_here)
1600 ThisClass->getNameAsString());
1607 if (getLangOpts().DebuggerSupport) {
1616 ReturnType = getMessageSendResultType(Receiver, ReceiverType, Method,
1617 isClassMessage, isSuperMessage);
1626 if (Args.size() < NumNamedArgs) {
1627 Diag(SelLoc, diag::err_typecheck_call_too_few_args)
1628 << 2 << NumNamedArgs << static_cast<unsigned>(Args.size());
1636 bool IsError =
false;
1637 for (
unsigned i = 0; i < NumNamedArgs; i++) {
1639 if (Args[i]->isTypeDependent())
1642 Expr *argExpr = Args[i];
1645 assert(argExpr &&
"CheckMessageArgumentTypes(): missing expression");
1647 if (param->
hasAttr<NoEscapeAttr>())
1648 if (
auto *BE = dyn_cast<BlockExpr>(
1650 BE->getBlockDecl()->setDoesNotEscape();
1655 !param->
hasAttr<CFConsumedAttr>())
1656 argExpr = stripARCUnbridgedCast(argExpr);
1662 ExprResult argE = checkUnknownAnyArg(SelLoc, argExpr, paramType);
1666 Args[i] = argE.
get();
1684 diag::err_call_incomplete_argument, argExpr))
1699 Args[i]->getType()->isBlockPointerType() &&
1702 maybeExtendBlockObject(arg);
1703 Args[i] = arg.
get();
1710 for (
unsigned i = NumNamedArgs, e = Args.size(); i < e; ++i) {
1711 if (Args[i]->isTypeDependent())
1714 ExprResult Arg = DefaultVariadicArgumentPromotion(Args[i], VariadicMethod,
1717 Args[i] = Arg.
get();
1721 if (Args.size() != NumNamedArgs) {
1722 Diag(Args[NumNamedArgs]->getBeginLoc(),
1723 diag::err_typecheck_call_too_many_args)
1724 << 2 << NumNamedArgs << static_cast<unsigned>(Args.size())
1727 Args.back()->getEndLoc());
1731 DiagnoseSentinelCalls(Method, SelLoc, Args);
1734 IsError |= CheckObjCMethodCall(
1735 Method, SelLoc, makeArrayRef(Args.data(), Args.size()));
1743 dyn_cast_or_null<ObjCMethodDecl>(CurContext->getNonClosureAncestor());
1744 return isSelfExpr(RExpr, Method);
1748 if (!method)
return false;
1751 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(receiver))
1763 if (
ObjCMethodDecl *method = iface->lookupMethod(sel, isInstance))
1768 if (
ObjCMethodDecl *method = iface->lookupPrivateMethod(sel, isInstance))
1773 for (
const auto *I : objType->
quals())
1787 for (
const auto *PROTO : OPT->
quals()) {
1788 if ((MD = PROTO->lookupMethod(Sel, Instance))) {
1808 Diag(MemberLoc, diag::err_invalid_property_name)
1818 diag::err_property_not_found_forward_class,
1819 MemberName, BaseRange))
1825 if (DiagnoseUseOfDecl(PD, MemberLoc))
1828 return new (Context)
1832 return new (Context)
1837 for (
const auto *I : OPT->
quals())
1841 if (DiagnoseUseOfDecl(PD, MemberLoc))
1847 SuperLoc, SuperType);
1849 return new (Context)
1859 Selector Sel = PP.getSelectorTable().getNullarySelector(Member);
1864 Getter = LookupMethodInQualifiedType(Sel, OPT,
true);
1872 if (DiagnoseUseOfDecl(Getter, MemberLoc))
1879 PP.getSelectorTable(), Member);
1884 Setter = LookupMethodInQualifiedType(SetterSel, OPT,
true);
1892 if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
1898 if (Setter && Setter->isImplicit() && Setter->isPropertyAccessor() &&
1906 diag::warn_property_access_suggest)
1907 << MemberName <<
QualType(OPT, 0) << PDecl->getName()
1912 if (Getter || Setter) {
1914 return new (Context)
1918 return new (Context)
1927 LookupOrdinaryName,
nullptr,
nullptr,
1928 llvm::make_unique<DeclFilterCCC<ObjCPropertyDecl>>(),
1929 CTK_ErrorRecovery, IFace,
false, OPT)) {
1935 Corrected.isKeyword() ? nullptr : Corrected.getFoundDecl();
1936 if (ChosenDecl && isa<ObjCPropertyDecl>(ChosenDecl))
1937 if (cast<ObjCPropertyDecl>(ChosenDecl)->isClassProperty()) {
1940 Diag(MemberLoc, diag::err_class_property_found) << MemberName
1947 diagnoseTypo(Corrected, PDiag(diag::err_property_not_found_suggest)
1948 << MemberName <<
QualType(OPT, 0));
1949 return HandleExprPropertyRefExpr(OPT, BaseExpr, OpLoc,
1950 TypoResult, MemberLoc,
1951 SuperLoc, SuperType, Super);
1960 if (RequireCompleteType(MemberLoc, OBJPT->getPointeeType(),
1961 diag::err_property_not_as_forward_class,
1962 MemberName, BaseExpr))
1966 diag::err_ivar_access_using_property_syntax_suggest)
1967 << MemberName <<
QualType(OPT, 0) << Ivar->getDeclName()
1972 Diag(MemberLoc, diag::err_property_not_found)
1975 Diag(Setter->getLocation(), diag::note_getter_unavailable)
1994 if (receiverNamePtr->
isStr(
"super")) {
1995 if (
ObjCMethodDecl *CurMethod = tryCaptureObjCSelf(receiverNameLoc)) {
1996 if (
auto classDecl = CurMethod->getClassInterface()) {
1997 SuperType =
QualType(classDecl->getSuperClassType(), 0);
1998 if (CurMethod->isInstanceMethod()) {
1999 if (SuperType.
isNull()) {
2001 Diag(receiverNameLoc, diag::err_root_class_cannot_use_super)
2002 << CurMethod->getClassInterface()->getIdentifier();
2012 receiverNameLoc, T,
true);
2023 Diag(receiverNameLoc, diag::err_expected_either) << tok::identifier
2033 GetterSel = PD->getGetterName();
2034 SetterSel = PD->getSetterName();
2036 GetterSel = PP.getSelectorTable().getNullarySelector(&propertyName);
2038 PP.getIdentifierTable(), PP.getSelectorTable(), &propertyName);
2051 if (DiagnoseUseOfDecl(Getter, propertyNameLoc))
2066 if (Setter && DiagnoseUseOfDecl(Setter, propertyNameLoc))
2069 if (Getter || Setter) {
2071 return new (Context)
2078 propertyNameLoc, receiverNameLoc, IFace);
2080 return ExprError(
Diag(propertyNameLoc, diag::err_property_not_found)
2094 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
2106 bool HasTrailingDot,
2108 ReceiverType =
nullptr;
2114 return HasTrailingDot? ObjCInstanceMessage : ObjCSuperMessage;
2116 LookupResult Result(*
this, Name, NameLoc, LookupOrdinaryName);
2117 LookupName(Result, S);
2126 if (!Method->getClassInterface()) {
2128 return ObjCInstanceMessage;
2132 if (Method->getClassInterface()->lookupInstanceVariable(Name,
2134 return ObjCInstanceMessage;
2145 return ObjCInstanceMessage;
2151 return ObjCInstanceMessage;
2160 DiagnoseUseOfDecl(
Type, NameLoc);
2163 return ObjCInstanceMessage;
2168 ReceiverType = CreateParsedType(T, TSInfo);
2169 return ObjCClassMessage;
2175 llvm::make_unique<ObjCInterfaceOrSuperCCC>(getCurMethodDecl()),
2176 CTK_ErrorRecovery,
nullptr,
false,
nullptr,
false)) {
2177 if (Corrected.isKeyword()) {
2180 diagnoseTypo(Corrected,
2181 PDiag(diag::err_unknown_receiver_suggest) << Name);
2182 return ObjCSuperMessage;
2187 diagnoseTypo(Corrected,
2188 PDiag(diag::err_unknown_receiver_suggest) << Name);
2191 ReceiverType = CreateParsedType(T, TSInfo);
2192 return ObjCClassMessage;
2197 return ObjCInstanceMessage;
2210 Diag(SuperLoc, diag::err_invalid_receiver_to_message_super);
2216 Diag(SuperLoc, diag::err_no_super_class_message)
2222 if (SuperTy.isNull()) {
2224 Diag(SuperLoc, diag::err_root_class_cannot_use_super)
2232 getCurFunction()->ObjCShouldCallSuper =
false;
2238 return BuildInstanceMessage(
nullptr, SuperTy, SuperLoc,
2240 LBracLoc, SelectorLocs, RBracLoc, Args);
2245 return BuildClassMessage(
nullptr,
2247 SuperLoc, Sel,
nullptr,
2248 LBracLoc, SelectorLocs, RBracLoc, Args);
2252 bool isSuperReceiver,
2258 if (!ReceiverType.
isNull())
2261 return BuildClassMessage(receiverTypeInfo, ReceiverType,
2263 Sel, Method, Loc, Loc, Loc, Args,
2277 if (refactor(Msg,*S.
NSAPIObj, ECommit)) {
2286 switch (Edit.
Kind) {
2314 bool IsClassObjectCall) {
2324 if (!IsClassObjectCall) {
2326 if (!OPT || !OPT->getInterfaceDecl())
2329 OPT->getInterfaceDecl()->lookupInstanceMethod(SE->getSelector());
2332 OPT->getInterfaceDecl()->lookupPrivateMethod(SE->getSelector());
2337 ImpliedMethod = IT->getDecl()->lookupClassMethod(SE->getSelector());
2340 IT->getDecl()->lookupPrivateClassMethod(SE->getSelector());
2347 S.
Diag(Loc, diag::warn_objc_unsafe_perform_selector)
2353 diag::note_objc_unsafe_perform_selector_method_declared_here)
2364 Expr **Args,
unsigned NumArgs) {
2366 bool Format =
false;
2380 if (!Format || NumArgs <= Idx)
2383 Expr *FormatExpr = Args[Idx];
2388 S.
Diag(FormatExpr->
getExprLoc(), diag::warn_objc_cdirective_format_string)
2438 Diag(Loc, diag::err_missing_open_square_message_send)
2443 if (!SelectorLocs.empty() && SelectorLocs.front().isValid())
2444 SelectorSlotLocs = SelectorLocs;
2446 SelectorSlotLocs = Loc;
2452 unsigned NumArgs = ArgsIn.size();
2453 Expr **Args = ArgsIn.data();
2454 assert(SuperLoc.
isInvalid() &&
"Message to super with dependent type");
2456 Context, ReceiverType,
VK_RValue, LBracLoc, ReceiverTypeInfo, Sel,
2457 SelectorLocs,
nullptr, makeArrayRef(Args, NumArgs), RBracLoc,
2464 if (!ClassType || !(Class = ClassType->
getInterface())) {
2465 Diag(Loc, diag::err_invalid_receiver_class_message)
2469 assert(Class &&
"We don't know which class we're messaging?");
2472 (void)DiagnoseUseOfDecl(Class, SelectorSlotLocs);
2479 (getLangOpts().ObjCAutoRefCount
2480 ? diag::err_arc_receiver_forward_class
2481 : diag::warn_receiver_forward_class),
2484 Method = LookupFactoryMethodInGlobalPool(Sel,
2486 if (Method && !getLangOpts().ObjCAutoRefCount)
2497 if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs,
2498 nullptr,
false,
false, Class))
2506 unsigned NumArgs = ArgsIn.size();
2507 Expr **Args = ArgsIn.data();
2508 if (CheckMessageArgumentTypes(
nullptr, ReceiverType,
2510 Method,
true, SuperLoc.
isValid(), LBracLoc,
2516 diag::err_illegal_message_expr_incomplete_type))
2525 Diag(Loc, diag::warn_direct_initialize_call);
2533 Diag(Loc, diag::warn_direct_super_initialize_call);
2536 Diag(CurMeth->getLocation(), diag::note_method_declared_at)
2537 << CurMeth->getDeclName();
2549 ReceiverType, Sel, SelectorLocs,
2550 Method, makeArrayRef(Args, NumArgs),
2551 RBracLoc, isImplicit);
2554 ReceiverTypeInfo, Sel, SelectorLocs,
2555 Method, makeArrayRef(Args, NumArgs),
2556 RBracLoc, isImplicit);
2562 ReceiverType,
true);
2563 return MaybeBindToTemporary(Result);
2577 QualType ReceiverType = GetTypeFromParser(Receiver, &ReceiverTypeInfo);
2578 if (ReceiverType.
isNull())
2581 if (!ReceiverTypeInfo)
2584 return BuildClassMessage(ReceiverTypeInfo, ReceiverType,
2586 nullptr, LBracLoc, SelectorLocs, RBracLoc,
2596 return BuildInstanceMessage(Receiver, ReceiverType,
2598 Sel, Method, Loc, Loc, Loc, Args,
2609 if (
const auto *RootClass = dyn_cast_or_null<ObjCInterfaceDecl>(
2613 if (
P->getCanonicalDecl() == Protocol->getCanonicalDecl())
2658 assert((Receiver || SuperLoc.
isValid()) &&
"If the Receiver is null, the " 2659 "SuperLoc must be valid so we can " 2667 if (!SelectorLocs.empty() && SelectorLocs.front().isValid())
2668 SelectorSlotLocs = SelectorLocs;
2670 SelectorSlotLocs = Loc;
2674 Diag(Loc, diag::err_missing_open_square_message_send)
2685 Result = forceUnknownAnyToType(Receiver, Context.
getObjCIdType());
2687 Result = CheckPlaceholderExpr(Receiver);
2689 Receiver = Result.
get();
2695 unsigned NumArgs = ArgsIn.size();
2696 Expr **Args = ArgsIn.data();
2697 assert(SuperLoc.
isInvalid() &&
"Message to super with dependent type");
2700 SelectorLocs,
nullptr, makeArrayRef(Args, NumArgs),
2701 RBracLoc, isImplicit);
2706 ExprResult Result = DefaultFunctionArrayLvalueConversion(Receiver);
2709 Receiver = Result.
get();
2710 ReceiverType = Receiver->
getType();
2717 }
else if (!getLangOpts().ObjCAutoRefCount &&
2723 Diag(Loc, diag::warn_bad_receiver_type)
2727 Receiver = ImpCastExprToType(Receiver, Context.
getObjCIdType(),
2728 CK_CPointerToObjCPointerCast).
get();
2733 CastKind Kind = IsNull ? CK_NullToPointer : CK_IntegralToPointer;
2734 Receiver = ImpCastExprToType(Receiver, Context.
getObjCIdType(),
2737 ReceiverType = Receiver->
getType();
2740 if (RequireCompleteType(Loc, Receiver->
getType(),
2741 diag::err_incomplete_receiver_type))
2744 ExprResult result = PerformContextuallyConvertToObjCPointer(Receiver);
2746 Receiver = result.
get();
2747 ReceiverType = Receiver->
getType();
2753 Diag(Receiver->
getExprLoc(), diag::warn_messaging_unqualified_id);
2769 CollectMultipleMethodsInGlobalPool(Sel, Methods,
true,
2771 if (!Methods.empty()) {
2774 Method = Methods[0];
2778 Method = BestMethod;
2780 if (!AreMultipleMethodsInGlobalPool(Sel, Method,
2782 receiverIsIdLike, Methods))
2783 DiagnoseUseOfDecl(Method, SelectorSlotLocs);
2795 Method = LookupMethodInQualifiedType(Sel, QClassTy,
false);
2797 Method = LookupMethodInQualifiedType(Sel, QClassTy,
true);
2800 Diag(SelLoc, diag::warn_instance_method_on_class_found)
2813 Method = ClassDecl->lookupClassMethod(Sel);
2816 Method = ClassDecl->lookupPrivateClassMethod(Sel);
2818 if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs,
nullptr,
2819 false,
false, ClassDecl))
2825 if (!Receiver || !isSelfExpr(Receiver)) {
2829 CollectMultipleMethodsInGlobalPool(Sel, Methods,
2832 if (!Methods.empty()) {
2835 Method = Methods[0];
2841 if (
ID->getSuperClass())
2842 Diag(SelLoc, diag::warn_root_inst_method_not_found)
2850 Method = BestMethod;
2864 Method = LookupMethodInQualifiedType(Sel, QIdTy,
true);
2866 Method = LookupMethodInQualifiedType(Sel, QIdTy,
false);
2867 if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs))
2872 ClassDecl = OCIType->getInterfaceDecl();
2879 if (RequireCompleteType(Loc, OCIType->getPointeeType(),
2880 getLangOpts().ObjCAutoRefCount
2881 ? diag::err_arc_receiver_forward_instance
2882 : diag::warn_receiver_forward_instance,
2885 if (getLangOpts().ObjCAutoRefCount)
2888 forwardClass = OCIType->getInterfaceDecl();
2890 diag::note_receiver_is_id);
2898 Method = LookupMethodInQualifiedType(Sel, OCIType,
true);
2904 if (!Method && getLangOpts().ObjCAutoRefCount) {
2905 Diag(SelLoc, diag::err_arc_may_not_respond)
2906 << OCIType->getPointeeType() << Sel << RecRange
2907 <<
SourceRange(SelectorLocs.front(), SelectorLocs.back());
2911 if (!Method && (!Receiver || !isSelfExpr(Receiver))) {
2915 if (OCIType->qual_empty()) {
2917 CollectMultipleMethodsInGlobalPool(Sel, Methods,
2920 if (!Methods.empty()) {
2923 Method = Methods[0];
2928 Method = BestMethod;
2930 AreMultipleMethodsInGlobalPool(Sel, Method,
2935 if (Method && !forwardClass)
2936 Diag(SelLoc, diag::warn_maynot_respond)
2937 << OCIType->getInterfaceDecl()->getIdentifier()
2942 if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs, forwardClass))
2946 Diag(Loc, diag::err_bad_receiver_type)
2955 ? getEnclosingFunction() :
nullptr;
2957 if (DIFunctionScopeInfo &&
2959 (SuperLoc.
isValid() || isSelfExpr(Receiver))) {
2960 bool isDesignatedInitChain =
false;
2967 if (!
ID->declaresOrInheritsDesignatedInitializers() ||
2968 ID->isDesignatedInitializer(Sel)) {
2969 isDesignatedInitChain =
true;
2975 if (!isDesignatedInitChain) {
2979 assert(isDesignated && InitMethod);
2982 diag::warn_objc_designated_init_non_designated_init_call :
2983 diag::warn_objc_designated_init_non_super_designated_init_call);
2985 diag::note_objc_designated_init_marked_here);
2989 if (DIFunctionScopeInfo &&
2991 (SuperLoc.
isValid() || isSelfExpr(Receiver))) {
2993 Diag(SelLoc, diag::warn_objc_secondary_init_super_init_call);
3000 unsigned NumArgs = ArgsIn.size();
3001 Expr **Args = ArgsIn.data();
3006 if (CheckMessageArgumentTypes(Receiver, ReceiverType,
3008 Method, ClassMessage, SuperLoc.
isValid(),
3009 LBracLoc, RBracLoc, RecRange, ReturnType, VK))
3014 diag::err_illegal_message_expr_incomplete_type))
3019 if (getLangOpts().ObjCAutoRefCount) {
3025 checkInitMethod(Method, ReceiverType);
3043 Diag(SelLoc, diag::err_arc_illegal_explicit_message)
3048 if (Method && NumArgs >= 1) {
3049 if (
const auto *SelExp =
3050 dyn_cast<ObjCSelectorExpr>(Args[0]->IgnoreParens())) {
3051 Selector ArgSel = SelExp->getSelector();
3053 LookupInstanceMethodInGlobalPool(ArgSel,
3054 SelExp->getSourceRange());
3057 LookupFactoryMethodInGlobalPool(ArgSel,
3058 SelExp->getSourceRange());
3061 switch (SelFamily) {
3068 if (!SelMethod->
hasAttr<NSReturnsNotRetainedAttr>()) {
3071 diag::err_arc_perform_selector_retains);
3078 if (SelMethod->
hasAttr<NSReturnsRetainedAttr>()) {
3081 diag::err_arc_perform_selector_retains);
3090 Diag(SelLoc, diag::warn_arc_perform_selector_leaks);
3091 Diag(Args[0]->getExprLoc(), diag::note_used_here);
3105 ReceiverType, Sel, SelectorLocs, Method,
3106 makeArrayRef(Args, NumArgs), RBracLoc,
3110 Receiver, Sel, SelectorLocs, Method,
3111 makeArrayRef(Args, NumArgs), RBracLoc,
3117 bool IsClassObjectCall = ClassMessage;
3122 if (Receiver && isSelfExpr(Receiver)) {
3124 if (OPT->getObjectType()->isObjCClass()) {
3125 if (
const auto *CurMeth = getCurMethodDecl()) {
3126 IsClassObjectCall =
true;
3134 ReceiverType, IsClassObjectCall);
3137 if (getLangOpts().ObjCAutoRefCount) {
3140 (SuperLoc.
isValid() || isSelfExpr(Receiver))) {
3154 checkRetainCycles(Result);
3157 if (getLangOpts().ObjCWeak) {
3158 if (!isImplicit && Method) {
3164 if (IsWeak && !isUnevaluatedContext() &&
3165 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, LBracLoc))
3166 getCurFunction()->recordUseOfWeak(Result, Prop);
3171 CheckObjCCircularContainer(Result);
3173 return MaybeBindToTemporary(Result);
3201 if (isa<ParenListExpr>(Receiver)) {
3202 ExprResult Result = MaybeConvertParenListExprToParenExpr(S, Receiver);
3204 Receiver = Result.
get();
3207 if (RespondsToSelectorSel.isNull()) {
3211 if (Sel == RespondsToSelectorSel)
3214 return BuildInstanceMessage(Receiver, Receiver->
getType(),
3216 nullptr, LBracLoc, SelectorLocs,
3250 bool isIndirect =
false;
3269 type =
QualType(array->getElementType()->getBaseElementTypeUnsafe(), 0);
3304 if (left == right)
return left;
3305 if (left == ACC_bottom)
return right;
3306 if (right == ACC_bottom)
return left;
3312 class ARCCastChecker :
public StmtVisitor<ARCCastChecker, ACCResult> {
3328 : Context(Context), SourceClass(source), TargetClass(target),
3329 Diagnose(diagnose) {}
3359 case CK_NullToPointer:
3363 case CK_LValueToRValue:
3365 case CK_CPointerToObjCPointerCast:
3366 case CK_BlockPointerToObjCPointerCast:
3367 case CK_AnyPointerToBlockPointerCast:
3382 return Visit(e->
getRHS());
3388 if (left == ACC_invalid)
return ACC_invalid;
3418 return ACC_plusZero;
3428 if (
ACCResult result = checkCallToFunction(fn))
3431 return super::VisitCallExpr(e);
3443 if (fn->
hasAttr<CFReturnsNotRetainedAttr>())
3444 return ACC_plusZero;
3449 if (fn->
hasAttr<CFReturnsRetainedAttr>())
3450 return Diagnose ? ACC_plusOne
3455 if (builtinID == Builtin::BI__builtin___CFStringMakeConstantString)
3459 if (!fn->
hasAttr<CFAuditedTransferAttr>())
3464 return Diagnose ? ACC_plusOne
3467 return ACC_plusZero;
3480 return checkCallToMethod(method);
3484 if (!method)
return ACC_invalid;
3493 if (method->
hasAttr<CFReturnsNotRetainedAttr>())
3494 return ACC_plusZero;
3498 if (method->
hasAttr<CFReturnsRetainedAttr>())
3510 return ACC_plusZero;
3521 return LookupName(R, TUScope,
false);
3531 const char *bridgeKeyword,
3532 const char *CFBridgeName) {
3548 NCE->getAngleBrackets().getEnd());
3552 char PrevChar = *SM.
getCharacterData(range.getBegin().getLocWithOffset(-1));
3556 BridgeCall += CFBridgeName;
3563 castedE = CCE->getSubExpr();
3574 BridgeCall += CFBridgeName;
3576 if (isa<ParenExpr>(castedE)) {
3594 std::string castCode =
"(";
3595 castCode += bridgeKeyword;
3599 NCE->getAngleBrackets().getEnd());
3603 std::string castCode =
"(";
3604 castCode += bridgeKeyword;
3609 if (isa<ParenExpr>(castedE)) {
3623 template <
typename T>
3631 return RD->getAttr<T>();
3639 TDNDecl = TD->getDecl();
3640 if (ObjCBridgeRelatedAttr *ObjCBAttr =
3641 getObjCBridgeAttr<ObjCBridgeRelatedAttr>(TD))
3658 UnavailableAttr::IR_ARCForbiddenConversion))
3671 unsigned srcKind = 0;
3695 S.
Diag(loc, diag::err_arc_cast_requires_bridge)
3705 ARCCastChecker(S.
Context, exprACTC, castACTC,
true).Visit(castExpr);
3706 assert(CreateRule != ACC_bottom &&
"This cast should already be accepted.");
3707 if (CreateRule != ACC_plusOne)
3711 : S.
Diag(noteLoc, diag::note_arc_cstyle_bridge);
3714 castType, castExpr, realCast,
"__bridge ",
3717 if (CreateRule != ACC_plusZero)
3721 S.
Diag(noteLoc, diag::note_arc_cstyle_bridge_transfer) << castExprType :
3723 diag::note_arc_bridge_transfer)
3724 << castExprType << br;
3727 castType, castExpr, realCast,
"__bridge_transfer ",
3728 br ?
"CFBridgingRelease" :
nullptr);
3737 S.
Diag(loc, diag::err_arc_cast_requires_bridge)
3746 ARCCastChecker(S.
Context, exprACTC, castACTC,
true).Visit(castExpr);
3747 assert(CreateRule != ACC_bottom &&
"This cast should already be accepted.");
3748 if (CreateRule != ACC_plusOne)
3752 : S.
Diag(noteLoc, diag::note_arc_cstyle_bridge);
3754 castType, castExpr, realCast,
"__bridge ",
3757 if (CreateRule != ACC_plusZero)
3761 S.
Diag(noteLoc, diag::note_arc_cstyle_bridge_retained) << castType :
3763 diag::note_arc_bridge_retained)
3767 castType, castExpr, realCast,
"__bridge_retained ",
3768 br ?
"CFBridgingRetain" :
nullptr);
3774 S.
Diag(loc, diag::err_arc_mismatched_cast)
3776 << srcKind << castExprType << castType
3780 template <
typename TB>
3782 bool &HadTheAttribute,
bool warn) {
3784 HadTheAttribute =
false;
3787 if (TB *ObjCBAttr = getObjCBridgeAttr<TB>(TD)) {
3789 HadTheAttribute =
true;
3790 if (Parm->isStr(
"id"))
3799 if (Target && isa<ObjCInterfaceDecl>(Target)) {
3804 = InterfacePointerType->getObjectType()->getInterface();
3805 if ((CastClass == ExprClass) ||
3814 castType, ExprClass)))
3822 << T << Target->
getName() << castType;
3831 diag::err_objc_cf_bridged_not_interface)
3832 << castExpr->
getType() << Parm;
3846 template <
typename TB>
3848 bool &HadTheAttribute,
bool warn) {
3850 HadTheAttribute =
false;
3853 if (TB *ObjCBAttr = getObjCBridgeAttr<TB>(TD)) {
3855 HadTheAttribute =
true;
3856 if (Parm->isStr(
"id"))
3865 if (Target && isa<ObjCInterfaceDecl>(Target)) {
3870 = InterfacePointerType->getObjectType()->getInterface();
3871 if ((CastClass == ExprClass) ||
3876 diag::warn_objc_invalid_bridge_to_cf)
3883 castExpr->
getType(), CastClass)))
3891 diag::warn_objc_invalid_bridge_to_cf)
3892 << castExpr->
getType() << castType;
3901 diag::err_objc_ns_bridged_invalid_cfobject)
3902 << castExpr->
getType() << castType;
3916 if (!getLangOpts().ObjC)
3922 bool HasObjCBridgeAttr;
3923 bool ObjCBridgeAttrWillNotWarn =
3924 CheckObjCBridgeNSCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3926 if (ObjCBridgeAttrWillNotWarn && HasObjCBridgeAttr)
3928 bool HasObjCBridgeMutableAttr;
3929 bool ObjCBridgeMutableAttrWillNotWarn =
3930 CheckObjCBridgeNSCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3931 HasObjCBridgeMutableAttr,
false);
3932 if (ObjCBridgeMutableAttrWillNotWarn && HasObjCBridgeMutableAttr)
3935 if (HasObjCBridgeAttr)
3936 CheckObjCBridgeNSCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3938 else if (HasObjCBridgeMutableAttr)
3939 CheckObjCBridgeNSCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3940 HasObjCBridgeMutableAttr,
true);
3943 bool HasObjCBridgeAttr;
3944 bool ObjCBridgeAttrWillNotWarn =
3945 CheckObjCBridgeCFCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3947 if (ObjCBridgeAttrWillNotWarn && HasObjCBridgeAttr)
3949 bool HasObjCBridgeMutableAttr;
3950 bool ObjCBridgeMutableAttrWillNotWarn =
3951 CheckObjCBridgeCFCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3952 HasObjCBridgeMutableAttr,
false);
3953 if (ObjCBridgeMutableAttrWillNotWarn && HasObjCBridgeMutableAttr)
3956 if (HasObjCBridgeAttr)
3957 CheckObjCBridgeCFCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3959 else if (HasObjCBridgeMutableAttr)
3960 CheckObjCBridgeCFCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3961 HasObjCBridgeMutableAttr,
true);
3968 if (PRE->isExplicitProperty()) {
3970 SrcType = PDecl->getType();
3972 else if (PRE->isImplicitProperty()) {
3974 SrcType = Getter->getReturnType();
3982 CheckObjCBridgeRelatedConversions(castExpr->
getBeginLoc(), castType, SrcType,
3988 if (!getLangOpts().ObjC)
3995 CheckTollFreeBridgeCast(castType, castExpr);
3997 : CK_CPointerToObjCPointerCast;
4009 bool CfToNs,
bool Diagnose) {
4010 QualType T = CfToNs ? SrcType : DestType;
4024 if (!LookupName(R, TUScope)) {
4026 Diag(Loc, diag::err_objc_bridged_related_invalid_class) << RCId
4027 << SrcType << DestType;
4033 if (Target && isa<ObjCInterfaceDecl>(Target))
4034 RelatedClass = cast<ObjCInterfaceDecl>(Target);
4037 Diag(Loc, diag::err_objc_bridged_related_invalid_class_name) << RCId
4038 << SrcType << DestType;
4047 if (CfToNs && CMId) {
4052 Diag(Loc, diag::err_objc_bridged_related_known_method)
4053 << SrcType << DestType << Sel <<
false;
4061 if (!CfToNs && IMId) {
4063 InstanceMethod = RelatedClass->
lookupMethod(Sel,
true);
4064 if (!InstanceMethod) {
4066 Diag(Loc, diag::err_objc_bridged_related_known_method)
4067 << SrcType << DestType << Sel <<
true;
4079 Expr *&SrcExpr,
bool Diagnose) {
4084 if (!CfToNs && !NsToCf)
4091 if (!checkObjCBridgeRelatedComponents(Loc, DestType, SrcType, RelatedClass,
4092 ClassMethod, InstanceMethod, TDNDecl,
4100 std::string ExpressionString =
"[";
4102 ExpressionString +=
" ";
4105 getLocForEndOfToken(SrcExpr->
getEndLoc());
4107 Diag(Loc, diag::err_objc_bridged_related_known_method)
4108 << SrcType << DestType << ClassMethod->
getSelector() <<
false 4117 Expr *args[] = { SrcExpr };
4118 ExprResult msg = BuildClassMessageImplicit(receiverType,
false,
4122 SrcExpr = msg.
get();
4129 if (InstanceMethod) {
4131 std::string ExpressionString;
4133 getLocForEndOfToken(SrcExpr->
getEndLoc());
4138 ExpressionString =
".";
4139 ExpressionString += PDecl->getNameAsString();
4140 Diag(Loc, diag::err_objc_bridged_related_known_method)
4141 << SrcType << DestType << InstanceMethod->
getSelector() <<
true 4144 if (ExpressionString.empty()) {
4146 ExpressionString =
" ";
4148 ExpressionString +=
"]";
4150 Diag(Loc, diag::err_objc_bridged_related_known_method)
4151 << SrcType << DestType << InstanceMethod->
getSelector() <<
true 4159 BuildInstanceMessageImplicit(SrcExpr, SrcType,
4162 InstanceMethod, None);
4163 SrcExpr = msg.get();
4174 bool Diagnose,
bool DiagnoseCFAudited,
4186 if (exprACTC == castACTC) {
4190 (CCK == CCK_CStyleCast || CCK == CCK_OtherCast) &&
4191 castType != castExprType) {
4197 if (
const ParenType *PT = dyn_cast<ParenType>(DT))
4198 QDT = PT->desugar();
4199 else if (
const TypeOfType *TP = dyn_cast<TypeOfType>(DT))
4200 QDT = TP->desugar();
4201 else if (
const AttributedType *AT = dyn_cast<AttributedType>(DT))
4202 QDT = AT->desugar();
4203 if (QDT != castType &&
4208 Diag(loc, diag::err_arc_nolifetime_behavior);
4218 if (!getLangOpts().ObjCAutoRefCount)
4237 switch (ARCCastChecker(Context, exprACTC, castACTC,
false).Visit(castExpr)) {
4252 Cleanup.setExprNeedsCleanups(
true);
4260 return ACR_unbridged;
4266 ConversionToObjCStringLiteralCheck(castType, castExpr, Diagnose))
4276 (Opc == BO_NE || Opc == BO_EQ))) {
4279 castExpr, exprACTC, CCK);
4298 castType =
cast->getTypeAsWritten();
4299 CCK = CCK_CStyleCast;
4301 castRange =
cast->getTypeInfoAsWritten()->getTypeLoc().getSourceRange();
4302 castType =
cast->getTypeAsWritten();
4303 CCK = CCK_OtherCast;
4305 llvm_unreachable(
"Unexpected ImplicitCastExpr");
4323 if (
ParenExpr *pe = dyn_cast<ParenExpr>(e)) {
4324 Expr *sub = stripARCUnbridgedCast(pe->getSubExpr());
4325 return new (Context)
ParenExpr(pe->getLParen(), pe->getRParen(), sub);
4326 }
else if (
UnaryOperator *uo = dyn_cast<UnaryOperator>(e)) {
4327 assert(uo->getOpcode() == UO_Extension);
4328 Expr *sub = stripARCUnbridgedCast(uo->getSubExpr());
4329 return new (Context)
4330 UnaryOperator(sub, UO_Extension, sub->getType(), sub->getValueKind(),
4331 sub->getObjectKind(), uo->getOperatorLoc(),
false);
4333 assert(!gse->isResultDependent());
4335 unsigned n = gse->getNumAssocs();
4338 for (
unsigned i = 0; i != n; ++i) {
4339 subTypes[i] = gse->getAssocTypeSourceInfo(i);
4340 Expr *sub = gse->getAssocExpr(i);
4341 if (i == gse->getResultIndex())
4342 sub = stripARCUnbridgedCast(sub);
4347 gse->getControllingExpr(),
4349 gse->getDefaultLoc(),
4350 gse->getRParenLoc(),
4351 gse->containsUnexpandedParameterPack(),
4352 gse->getResultIndex());
4354 assert(isa<ImplicitCastExpr>(e) &&
"bad form of unbridged cast!");
4355 return cast<ImplicitCastExpr>(e)->getSubExpr();
4365 if (isa<ObjCObjectPointerType>(canCastType) &&
4371 return !ObjI->isArcWeakrefUnavailable();
4378 Expr *curExpr = e, *prevExpr =
nullptr;
4383 if (
auto *pe = dyn_cast<ParenExpr>(curExpr)) {
4385 curExpr = pe->getSubExpr();
4389 if (
auto *ce = dyn_cast<CastExpr>(curExpr)) {
4390 if (
auto *ice = dyn_cast<ImplicitCastExpr>(ce))
4391 if (ice->getCastKind() == CK_ARCReclaimReturnedObject) {
4393 return ice->getSubExpr();
4394 if (
auto *pe = dyn_cast<ParenExpr>(prevExpr))
4395 pe->setSubExpr(ice->getSubExpr());
4397 cast<CastExpr>(prevExpr)->setSubExpr(ice->getSubExpr());
4402 curExpr = ce->getSubExpr();
4418 ExprResult SubResult = UsualUnaryConversions(SubExpr);
4420 SubExpr = SubResult.
get();
4427 bool MustConsume =
false;
4434 : CK_CPointerToObjCPointerCast);
4440 bool br = isKnownName(
"CFBridgingRelease");
4441 Diag(BridgeKeywordLoc, diag::err_arc_bridge_cast_wrong_kind)
4448 Diag(BridgeKeywordLoc, diag::note_arc_bridge)
4450 Diag(BridgeKeywordLoc, diag::note_arc_bridge_transfer)
4453 br ?
"CFBridgingRelease " 4454 :
"__bridge_transfer ");
4478 CK_ARCProduceObject,
4483 bool br = isKnownName(
"CFBridgingRetain");
4484 Diag(BridgeKeywordLoc, diag::err_arc_bridge_cast_wrong_kind)
4492 Diag(BridgeKeywordLoc, diag::note_arc_bridge)
4494 Diag(BridgeKeywordLoc, diag::note_arc_bridge_retained)
4497 br ?
"CFBridgingRetain " :
"__bridge_retained");
4504 Diag(LParenLoc, diag::err_arc_bridge_cast_incompatible)
4505 << FromType << T << Kind
4516 Cleanup.setExprNeedsCleanups(
true);
4532 QualType T = GetTypeFromParser(Type, &TSInfo);
4534 CheckTollFreeBridgeCast(T, SubExpr);
4537 return BuildObjCBridgedCast(LParenLoc, Kind, BridgeKeywordLoc, TSInfo,
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
ObjCMethodDecl * LookupMethodInQualifiedType(Selector Sel, const ObjCObjectPointerType *OPT, bool IsInstance)
LookupMethodInQualifiedType - Lookups up a method in protocol qualifier list of a qualified objective...
const ObjCInterfaceType * getInterfaceType() const
If this pointer points to an Objective C @interface type, gets the type for that interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
ObjCMethodDecl * lookupPrivateClassMethod(const Selector &Sel)
bool hasDefinition() const
Determine whether this class has been defined.
QualType withConst() const
Retrieves a version of this type with const applied.
bool isClassMethod() const
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
Represents a function declaration or definition.
Name lookup found a set of overloaded functions that met the criteria.
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.
bool isSelfExpr(Expr *RExpr)
Private Helper predicate to check for 'self'.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
static ObjCArrayLiteral * Create(const ASTContext &C, ArrayRef< Expr *> Elements, QualType T, ObjCMethodDecl *Method, SourceRange SR)
Smart pointer class that efficiently represents Objective-C method names.
QualType getObjCIdType() const
Represents the Objective-CC id type.
static void checkFoundationAPI(Sema &S, SourceLocation Loc, const ObjCMethodDecl *Method, ArrayRef< Expr *> Args, QualType ReceiverType, bool IsClassObjectCall)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isBlockPointerType() const
QualType substObjCTypeArgs(ASTContext &ctx, ArrayRef< QualType > typeArgs, ObjCSubstitutionContext context) const
Substitute type arguments for the Objective-C type parameters used in the subject type...
Simple class containing the result of Sema::CorrectTypo.
unsigned param_size() const
Selector getSelector() const
ObjCInterfaceDecl * getClassInterface()
ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, Selector Sel, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args)
A cast other than a C-style cast.
void* might be a normal C type, or it might a CF type.
void AddFixItHint(const FixItHint &Hint) const
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
ObjCBridgeCastKind
The kind of bridging performed by the Objective-C bridge cast.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
CompoundStmt * getSubStmt()
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false)
Perform unqualified name lookup starting from a given scope.
ObjCMessageKind
Describes the kind of message expression indicated by a message send that starts with an identifier...
Stmt - This represents one statement.
NullabilityKind
Describes the nullability of a particular type.
static void diagnoseObjCARCConversion(Sema &S, SourceRange castRange, QualType castType, ARCConversionTypeClass castACTC, Expr *castExpr, Expr *realCast, ARCConversionTypeClass exprACTC, Sema::CheckedConversionKind CCK)
bool isObjCClassOrClassKindOfType() const
Whether the type is Objective-C 'Class' or a __kindof type of an Class type, e.g., __kindof Class <NSCopying>.
ARCConversionResult CheckObjCConversion(SourceRange castRange, QualType castType, Expr *&op, CheckedConversionKind CCK, bool Diagnose=true, bool DiagnoseCFAudited=false, BinaryOperatorKind Opc=BO_PtrMemD)
Checks for invalid conversions and casts between retainable pointers and other pointer kinds for ARC ...
Bridging via __bridge, which does nothing but reinterpret the bits.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
ObjCMethodDecl * LookupMethodInObjectType(Selector Sel, QualType Ty, bool IsInstance)
LookupMethodInType - Look up a method in an ObjCObjectType.
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
static bool CheckObjCBridgeNSCast(Sema &S, QualType castType, Expr *castExpr, bool &HadTheAttribute, bool warn)
void addConst()
Add the const type qualifier to this QualType.
bool isObjCARCBridgableType() const
Determine whether the given type T is a "bridgable" Objective-C type, which is either an Objective-C ...
bool isRecordType() const
static InitializedEntity InitializeParameter(ASTContext &Context, const ParmVarDecl *Parm)
Create the initialization entity for a parameter.
const ObjCObjectType * getAsObjCInterfaceType() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getBeginLoc() const LLVM_READONLY
static bool HelperToDiagnoseMismatchedMethodsInGlobalPool(Sema &S, SourceLocation AtLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, ObjCMethodDecl *Method, ObjCMethodList &MethList)
SmallVectorImpl< Edit >::const_iterator edit_iterator
bool isExtVectorType() const
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
ParenExpr - This represents a parethesized expression, e.g.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
The base class of the type hierarchy.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
static void RemoveSelectorFromWarningCache(Sema &S, Expr *Arg)
Represents an array type, per C99 6.7.5.2 - Array Declarators.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
ExprResult ActOnObjCBridgedCast(Scope *S, SourceLocation LParenLoc, ObjCBridgeCastKind Kind, SourceLocation BridgeKeywordLoc, ParsedType Type, SourceLocation RParenLoc, Expr *SubExpr)
static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc, CharSourceRange FromRange, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code from FromRange at a specific location...
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
const ObjCObjectPointerType * getAsObjCInterfacePointerType() const
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
QualType withConst() const
A container of type source information.
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
ObjCMethodDecl * getMethod() const
QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType, ObjCMethodDecl *Method, bool isClassMessage, bool isSuperMessage)
Determine the result of a message send expression based on the type of the receiver, the method expected to receive the message, and the form of the message send.
void setDelegateInitCall(bool isDelegate)
QualType getElementType() const
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
Retains information about a function, method, or block that is currently being parsed.
An Objective-C array/dictionary subscripting which reads an object or writes at the subscripted array...
Represents a variable declaration or definition.
QualType getReturnType() const
DiagnosticsEngine & Diags
ObjCMethodDecl * tryCaptureObjCSelf(SourceLocation Loc)
Try to capture an implicit reference to 'self'.
const T * getAs() const
Member-template getAs<specific type>'.
bool isInObjcMethodScope() const
isInObjcMethodScope - Return true if this scope is, or is contained in, an Objective-C method body...
ObjCMethodDecl - Represents an instance or class method declaration.
DeclClass * getCorrectionDeclAs() const
bool isInvalidDecl() const
static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)
Lookup a property by name in the specified DeclContext.
static const ObjCMethodDecl * findExplicitInstancetypeDeclarer(const ObjCMethodDecl *MD, QualType instancetype)
Look for an ObjC method whose result type exactly matches the given type.
llvm::MapVector< Selector, SourceLocation > ReferencedSelectors
Method selectors used in a @selector expression.
static StringRef bytes(const std::vector< T, Allocator > &v)
Represents a parameter to a function.
ObjCPropertyDecl * getExplicitProperty() const
bool canHaveNullability(bool ResultIfUnknown=true) const
Determine whether the given type can have a nullability specifier applied to it, i.e., if it is any kind of pointer type.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
Represents a struct/union/class.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Selector getUnarySelector(IdentifierInfo *ID)
One of these records is kept for each identifier that is lexed.
std::unique_ptr< NSAPI > NSAPIObj
Caches identifiers/selectors for NSFoundation APIs.
bool isObjCIdOrObjectKindOfType(const ASTContext &ctx, const ObjCObjectType *&bound) const
Whether the type is Objective-C 'id' or a __kindof type of an object type, e.g., __kindof NSView * or...
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Expr * getFalseExpr() const
An element in an Objective-C dictionary literal.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Represents a class type in Objective C.
edit_iterator edit_end() const
ObjCMethodDecl * lookupInstanceMethod(Selector Sel) const
Lookup an instance method for a given selector.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl)
ObjCMethodFamily
A family of Objective-C methods.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
bool isExplicitProperty() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool isObjCIdType() const
void diagnoseARCUnbridgedCast(Expr *e)
Given that we saw an expression with the ARCUnbridgedCastTy placeholder type, complain bitterly...
static ObjCMessageExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, SourceLocation LBracLoc, SourceLocation SuperLoc, bool IsInstanceSuper, QualType SuperType, Selector Sel, ArrayRef< SourceLocation > SelLocs, ObjCMethodDecl *Method, ArrayRef< Expr *> Args, SourceLocation RBracLoc, bool isImplicit)
Create a message send to super.
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
const ObjCObjectPointerType * getAsObjCQualifiedIdType() const
bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, QualType DestType, QualType SrcType, Expr *&SrcExpr, bool Diagnose=true)
ExprResult BuildClassMessageImplicit(QualType ReceiverType, bool isSuperReceiver, SourceLocation Loc, Selector Sel, ObjCMethodDecl *Method, MultiExprArg Args)
ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind)
ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals.
LookupResultKind getResultKind() const
static ObjCBridgeRelatedAttr * ObjCBridgeRelatedAttrFromType(QualType T, TypedefNameDecl *&TDNDecl)
bool isObjCQualifiedClassType() const
void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr)
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl)
ObjCObjectAdoptsQTypeProtocols - Checks that protocols in IC's protocol list adopt all protocols in Q...
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Values of this type can be null.
bool isUnarySelector() const
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
static Selector constructSetterSelector(IdentifierTable &Idents, SelectorTable &SelTable, const IdentifierInfo *Name)
Return the default setter selector for the given identifier.
bool followsCreateRule(const FunctionDecl *FD)
Selector getNullarySelector(IdentifierInfo *ID)
Represents the results of name lookup.
static ObjCInterfaceDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, ObjCTypeParamList *typeParamList, ObjCInterfaceDecl *PrevDecl, SourceLocation ClassLoc=SourceLocation(), bool isInternal=false)
ObjCContainerDecl - Represents a container for method declarations.
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number)
BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the numeric literal expression...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
static void applyCocoaAPICheck(Sema &S, const ObjCMessageExpr *Msg, unsigned DiagID, bool(*refactor)(const ObjCMessageExpr *, const NSAPI &, edit::Commit &))
Whether values of this type can be null is (explicitly) unspecified.
QualType getObjCNSStringType() const
SourceLocation getBeginLoc() const LLVM_READONLY
const ObjCObjectPointerType * getAsObjCQualifiedClassType() const
GlobalMethodPool MethodPool
Method Pool - allows efficient lookup when typechecking messages to "id".
Represents a declaration of a type.
A builtin binary operation expression such as "x + y" or "x <= y".
CanQualType PseudoObjectTy
tokloc_iterator tokloc_end() const
A conversion for an operand of a builtin overloaded operator.
CheckedConversionKind
The kind of conversion being performed.
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
ObjCStringLiteral, used for Objective-C string literals i.e.
Values of this type can never be null.
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Scope - A scope is a transient data structure that is used while parsing the program.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
void getOverriddenMethods(SmallVectorImpl< const ObjCMethodDecl *> &Overridden) const
Return overridden methods for the given Method.
ObjCMethodDecl * lookupClassMethod(Selector Sel) const
Lookup a class method for a given selector.
void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr)
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Represents an Objective-C protocol declaration.
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
ObjCInterfaceDecl * NSNumberDecl
The declaration of the Objective-C NSNumber class.
const LangOptions & getLangOpts() const
ExprResult BuildObjCDictionaryLiteral(SourceRange SR, MutableArrayRef< ObjCDictionaryElement > Elements)
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Represents an ObjC class declaration.
Bridging via __bridge_transfer, which transfers ownership of an Objective-C pointer into ARC...
QualType getReturnType() const
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
QualType getObjCProtoType() const
Retrieve the type of the Objective-C Protocol class.
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl *> Params, ArrayRef< SourceLocation > SelLocs=llvm::None)
Sets the method's parameters and selector source locations.
const LangOptions & LangOpts
bool isObjCSelfExpr() const
Check if this expression is the ObjC 'self' implicit parameter.
bool isKnownName(StringRef name)
ObjCMethodDecl * getCategoryClassMethod(Selector Sel) const
static bool isAnyRetainable(ARCConversionTypeClass ACTC)
ConditionalOperator - The ?: ternary operator.
Sema - This implements semantic analysis and AST building for C.
RecordDecl * getMostRecentDecl()
StringRef getString() const
CharSourceRange getFileRange(SourceManager &SM) const
void EmitRelatedResultTypeNoteForReturn(QualType destType)
Given that we had incompatible pointer types in a return statement, check whether we're in a method w...
A little helper class used to produce diagnostics.
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
Expr * IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY
IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the value (including ptr->int ...
ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, SourceLocation BridgeKeywordLoc, TypeSourceInfo *TSInfo, Expr *SubExpr)
CastKind
CastKind - The kind of operation required for a conversion.
static bool validateBoxingMethod(Sema &S, SourceLocation Loc, const ObjCInterfaceDecl *Class, Selector Sel, const ObjCMethodDecl *Method)
Emits an error if the given method does not exist, or if the return type is not an Objective-C object...
static ObjCInterfaceDecl * LookupObjCInterfaceDeclForLiteral(Sema &S, SourceLocation Loc, Sema::ObjCLiteralKind LiteralKind)
Looks up ObjCInterfaceDecl of a given NSClassIdKindKind.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
bool hasDefinition() const
Determine whether this protocol has a definition.
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumConcatenated)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
ObjCStringFormatFamily getStringFormatFamily() const
This represents one expression.
ObjCMethodList * getNext() const
static ObjCMethodDecl * Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, bool isInstance=true, bool isVariadic=false, bool isPropertyAccessor=false, bool isImplicitlyDeclared=false, bool isDefined=false, ImplementationControl impControl=None, bool HasRelatedResultType=false)
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Expr * stripARCUnbridgedCast(Expr *e)
stripARCUnbridgedCast - Given an expression of ARCUnbridgedCast type, remove the placeholder cast...
bool checkObjCBridgeRelatedComponents(SourceLocation Loc, QualType DestType, QualType SrcType, ObjCInterfaceDecl *&RelatedClass, ObjCMethodDecl *&ClassMethod, ObjCMethodDecl *&InstanceMethod, TypedefNameDecl *&TDNDecl, bool CfToNs, bool Diagnose=true)
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
static Kind getNullabilityAttrKind(NullabilityKind kind)
Retrieve the attribute kind corresponding to the given nullability kind.
const T * castAs() const
Member-template castAs<specific type>.
static bool isAnyCLike(ARCConversionTypeClass ACTC)
bool isObjCRetainableType() const
static ARCConversionTypeClass classifyTypeForARCConversion(QualType type)
static QualType stripObjCInstanceType(ASTContext &Context, QualType T)
bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType, MultiExprArg Args, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, bool isClassMessage, bool isSuperMessage, SourceLocation lbrac, SourceLocation rbrac, SourceRange RecRange, QualType &ReturnType, ExprValueKind &VK)
CheckMessageArgumentTypes - Check types in an Obj-C message send.
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver's type...
Defines the clang::Preprocessor interface.
bool isObjCClassType() const
DeclContext * getDeclContext()
edit_iterator edit_begin() const
ObjCInterfaceDecl * getSuperClass() const
ObjCSelectorExpr used for @selector in Objective-C.
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
static ObjCDictionaryLiteral * Create(const ASTContext &C, ArrayRef< ObjCDictionaryElement > VK, bool HasPackExpansions, QualType T, ObjCMethodDecl *method, SourceRange SR)
QualType NSNumberPointer
Pointer to NSNumber type (NSNumber *).
Defines the clang::TypeLoc interface and its subclasses.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
DefinitionKind hasDefinition(ASTContext &) const
Check whether this variable is defined in this translation unit.
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared)
bool isIdentifier() const
Predicate functions for querying what type of name this is.
ObjCMessageKind getObjCMessageKind(Scope *S, IdentifierInfo *Name, SourceLocation NameLoc, bool IsSuper, bool HasTrailingDot, ParsedType &ReceiverType)
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
An expression that sends a message to the given Objective-C object or class.
ObjCMethodDecl * getImplicitPropertyGetter() const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
SourceLocation getEnd() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
bool isInstanceMethod() const
ArraySizeModifier getSizeModifier() const
bool rewriteObjCRedundantCallWithLiteral(const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
unsigned getNumArgs() const
Selector getSelector() const
bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, CastKind &Kind)
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=NotForRedeclaration)
Look up a name, looking for a single declaration.
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr.cast]), which uses the syntax (Type)expr.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
ImplicitParamDecl * getSelfDecl() const
SourceLocation getEndLoc() const LLVM_READONLY
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType)
bool isConstQualified() const
Determine whether this type is const-qualified.
ExprResult ParseObjCProtocolExpression(IdentifierInfo *ProtocolName, SourceLocation AtLoc, SourceLocation ProtoLoc, SourceLocation LParenLoc, SourceLocation ProtoIdLoc, SourceLocation RParenLoc)
ParseObjCProtocolExpression - Build protocol expression for @protocol.
QualType getWideCharType() const
Return the type of wide characters.
There is no lifetime qualification on this type.
static bool isMethodDeclaredInRootProtocol(Sema &S, const ObjCMethodDecl *M)
std::string getAsString() const
Derive the full selector name (e.g.
SelectorTable & Selectors
bool QIdProtocolsAdoptObjCObjectProtocols(QualType QT, ObjCInterfaceDecl *IDecl)
QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in QT's qualified-id protocol list adopt...
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
Encodes a location in the source.
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Sugar for parentheses used when specifying types.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Expr * getSubExpr() const
Represents typeof(type), a GCC extension.
Interfaces are the core concept in Objective-C for object oriented design.
CastKind getCastKind() const
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
ObjCMethodFamily getMethodFamily() const
MutableArrayRef< Expr * > MultiExprArg
ExprResult ActOnClassMessage(Scope *S, ParsedType Receiver, Selector Sel, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args)
bool makeUnavailableInSystemHeader(SourceLocation loc, UnavailableAttr::ImplicitReason reason)
makeUnavailableInSystemHeader - There is an error in the current context.
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
bool ObjCWarnForNoDesignatedInitChain
This starts true for a method marked as designated initializer and will be set to false if there is a...
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements)
ExprResult DefaultLvalueConversion(Expr *E)
bool CheckObjCARCUnavailableWeakConversion(QualType castType, QualType ExprType)
bool isLiteral(TokenKind K)
Return true if this is a "literal" kind, like a numeric constant, string, etc.
Name lookup found an unresolvable value declaration and cannot yet complete.
static bool isCast(CheckedConversionKind CCK)
Specifies that a value-dependent expression should be considered to never be a null pointer constant...
ObjCProtocolExpr used for protocol expression in Objective-C.
Describes the kind of initialization being performed, along with location information for tokens rela...
SourceLocation getBeginLoc() const LLVM_READONLY
ExprResult ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, IdentifierInfo &propertyName, SourceLocation receiverNameLoc, SourceLocation propertyNameLoc)
bool isObjCObjectPointerType() const
static ExprResult CheckObjCCollectionLiteralElement(Sema &S, Expr *Element, QualType T, bool ArrayLiteral=false)
Check that the given expression is a valid element of an Objective-C collection literal.
bool FormatStringHasSArg(const StringLiteral *FExpr)
Represents one property declaration in an Objective-C interface.
ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args, bool isImplicit=false)
Build an Objective-C class message expression.
bool isSuperClassOf(const ObjCInterfaceDecl *I) const
isSuperClassOf - Return true if this class is the specified class or is a super class of the specifie...
No entity found met the criteria.
bool ObjCIsDesignatedInit
True when this is a method marked as a designated initializer.
static QualType getBaseMessageSendResultType(Sema &S, QualType ReceiverType, ObjCMethodDecl *Method, bool isClassMessage, bool isSuperMessage)
Determine the result type of a message send based on the receiver type, method, and the kind of messa...
const ObjCMethodDecl * getMethodDecl() const
bool isVectorType() const
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
ObjCBoxedExpr - used for generalized expression boxing.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
ExprResult ParseObjCSelectorExpression(Selector Sel, SourceLocation AtLoc, SourceLocation SelLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, bool WarnMultipleSelectors)
ParseObjCSelectorExpression - Build selector expression for @selector.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
static Expr * maybeUndoReclaimObject(Expr *e)
Look for an ObjCReclaimReturnedObject cast and destroy it.
bool isDesignatedInitializerForTheInterface(const ObjCMethodDecl **InitMethod=nullptr) const
Returns true if the method selector resolves to a designated initializer in the class's interface...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
QualType getObjCInstanceType()
Retrieve the Objective-C "instancetype" type, if already known; otherwise, returns a NULL type;...
Represents a C11 generic selection.
StringRef getName() const
Return the actual identifier string.
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers...
Base class for declarations which introduce a typedef-name.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
CanQualType ObjCBuiltinIdTy
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
tokloc_iterator tokloc_begin() const
ObjCMethodDecl * lookupPrivateMethod(const Selector &Sel, bool Instance=true) const
Lookup a method in the classes implementation hierarchy.
ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S)
ObjCPropertyDecl * FindPropertyDeclaration(const IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyDeclaration - Finds declaration of the property given its name in 'PropertyId' and return...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
ObjCMethodDecl * NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]
The Objective-C NSNumber methods used to create NSNumber literals.
static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx)
bool isCommitable() const
static void addFixitForObjCARCConversion(Sema &S, DiagnosticBuilder &DiagB, Sema::CheckedConversionKind CCK, SourceLocation afterLParen, QualType castType, Expr *castExpr, Expr *realCast, const char *bridgeKeyword, const char *CFBridgeName)
CharSourceRange getInsertFromRange(SourceManager &SM) const
bool ObjCIsSecondaryInit
True when this is an initializer method not marked as a designated initializer within a class that ha...
QualType getUnderlyingType() const
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
The name of a declaration.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
U cast(CodeGen::Address addr)
bool ObjCWarnForNoInitDelegation
This starts true for a secondary initializer method and will be set to false if there is an invocatio...
ExplicitCastExpr - An explicit cast written in the source code.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Bridging via __bridge_retain, which makes an ARC object available as a +1 C pointer.
ACCResult
A result from the cast checker.
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
ExprResult BuildInstanceMessage(Expr *Receiver, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args, bool isImplicit=false)
Build an Objective-C instance message expression.
Represents a pointer to an Objective C object.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Name lookup found a single declaration that met the criteria.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, TypeSourceInfo *EncodedTypeInfo, SourceLocation RParenLoc)
static void DiagnoseCStringFormatDirectiveInObjCAPI(Sema &S, ObjCMethodDecl *Method, Selector Sel, Expr **Args, unsigned NumArgs)
Diagnose use of s directive in an NSString which is being passed as formatting string to formatting m...
unsigned getIndexTypeCVRQualifiers() const
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface...
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
CanQualType UnsignedLongTy
ObjCEncodeExpr, used for @encode in Objective-C.
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the '@' prefixed parenthesized expression...
void getObjCEncodingForType(QualType T, std::string &S, const FieldDecl *Field=nullptr, QualType *NotEncodedT=nullptr) const
Emit the Objective-CC type encoding for the given type T into S.
ExprResult HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, Expr *BaseExpr, SourceLocation OpLoc, DeclarationName MemberName, SourceLocation MemberLoc, SourceLocation SuperLoc, QualType SuperType, bool Super)
HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an objective C interface...
Expr * IgnoreParenLValueCasts() LLVM_READONLY
Ignore parentheses and lvalue casts.
Base for LValueReferenceType and RValueReferenceType.
ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, SourceLocation EncodeLoc, SourceLocation LParenLoc, ParsedType Ty, SourceLocation RParenLoc)
Optional< ArrayRef< QualType > > getObjCSubstitutions(const DeclContext *dc) const
Retrieve the set of substitutions required when accessing a member of the Objective-C receiver type t...
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.
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
ObjCMethodDecl * lookupMethod(Selector Sel, bool isInstance, bool shallowCategoryLookup=false, bool followSuper=true, const ObjCCategoryDecl *C=nullptr) const
lookupMethod - This method returns an instance/class method by looking in the class, its categories, and its super classes (using a linear search).
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
QualType getObjCConstantStringInterface() const
SourceManager & getSourceManager()
static bool isIdentifierBodyChar(char c, const LangOptions &LangOpts)
Returns true if the given character could appear in an identifier.
ImplementationControl getImplementationControl() const
static NSAPI::NSClassIdKindKind ClassKindFromLiteralKind(Sema::ObjCLiteralKind LiteralKind)
Maps ObjCLiteralKind to NSClassIdKindKind.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
TypedefNameDecl * getDecl() const
Reading or writing from this object requires a barrier call.
No particular method family.
void setObjCNSStringType(QualType T)
An attributed type is a type to which a type attribute has been applied.
const ObjCPropertyDecl * findPropertyDecl(bool CheckOverrides=true) const
Returns the property associated with this method's selector.
TranslationUnitDecl * getTranslationUnitDecl() const
Describes the sequence of initializations required to initialize a given object or reference with a s...
ExprResult ActOnInstanceMessage(Scope *S, Expr *Receiver, Selector Sel, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args)
Expr * getTrueExpr() const
unsigned getBuiltinID() const
Returns a value indicating whether this function corresponds to a builtin function.
bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, const ObjCMethodDecl *PrevMethod, MethodMatchStrategy strategy=MMS_strict)
MatchTwoMethodDeclarations - Checks if two methods' type match and returns true, or false...
The parameter type of a method or function.
ObjCIvarDecl - Represents an ObjC instance variable.
static bool CheckObjCBridgeCFCast(Sema &S, QualType castType, Expr *castExpr, bool &HadTheAttribute, bool warn)
QualType getSendResultType() const
Determine the type of an expression that sends a message to this function.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
static T * getObjCBridgeAttr(const TypedefType *TD)
SourceManager & getSourceManager() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
ExprResult BuildInstanceMessageImplicit(Expr *Receiver, QualType ReceiverType, SourceLocation Loc, Selector Sel, ObjCMethodDecl *Method, MultiExprArg Args)
StringLiteral - This represents a string literal expression, e.g.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
SourceLocation getBeginLoc() const LLVM_READONLY
a linked list of methods with the same selector name but different signatures.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
void EmitRelatedResultTypeNote(const Expr *E)
If the given expression involves a message send to a method with a related result type...
Abstract class common to all of the C++ "named"/"keyword" casts.
The top declaration context.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
static bool ValidateObjCLiteralInterfaceDecl(Sema &S, ObjCInterfaceDecl *Decl, SourceLocation Loc, Sema::ObjCLiteralKind LiteralKind)
Validates ObjCInterfaceDecl availability.
A reference to a declared variable, function, enum, etc.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
bool isPointerType() const
SourceManager & SourceMgr
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
An l-value expression is a reference to an object with independent storage.
A trivial tuple used to represent a source range.
ObjCMethodDecl * getMethod(Selector Sel, bool isInstance, bool AllowHidden=false) const
ObjCMethodDecl * getGetterMethodDecl() const
static void DiagnoseMismatchedSelectors(Sema &S, SourceLocation AtLoc, ObjCMethodDecl *Method, SourceLocation LParenLoc, SourceLocation RParenLoc, bool WarnMultipleSelectors)
This represents a decl that may have a name.
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, Expr *IndexExpr, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
Build an ObjC subscript pseudo-object expression, given that that's supported by the runtime...
static ObjCMethodDecl * getNSNumberFactoryMethod(Sema &S, SourceLocation Loc, QualType NumberType, bool isLiteral=false, SourceRange R=SourceRange())
Retrieve the NSNumber factory method that should be used to create an Objective-C literal for the giv...
bool isPropertyAccessor() const
static bool isObjCNSObjectType(QualType Ty)
Return true if this is an NSObject object with its NSObject attribute set.
Describes an entity that is being initialized.
void setType(QualType newType)
SourceLocation getBegin() const
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
This class handles loading and caching of source files into memory.
Represents the canonical version of C arrays with a specified constant size.
static void checkCocoaAPI(Sema &S, const ObjCMessageExpr *Msg)
SourceLocation getLocation() const
QualType getType() const
Return the type wrapped by this type source info.
ArrayRef< ParmVarDecl * > parameters() const
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, ArrayRef< Expr *> Strings)
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.