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,
110 Diag(S->
getLocStart(), diag::err_no_nsconstant_string_class) << NSIdent
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();
407 return Seq.Perform(S, Entity, Kind, Element);
410 Expr *OrigElement = Element;
416 Element = Result.
get();
421 bool Recovered =
false;
424 if (isa<IntegerLiteral>(OrigElement) ||
425 isa<CharacterLiteral>(OrigElement) ||
426 isa<FloatingLiteral>(OrigElement) ||
427 isa<ObjCBoolLiteralExpr>(OrigElement) ||
428 isa<CXXBoolLiteralExpr>(OrigElement)) {
429 if (S.
NSAPIObj->getNSNumberFactoryMethodKind(OrigElement->
getType())) {
430 int Which = isa<CharacterLiteral>(OrigElement) ? 1
431 : (isa<CXXBoolLiteralExpr>(OrigElement) ||
432 isa<ObjCBoolLiteralExpr>(OrigElement)) ? 2
441 if (Result.isInvalid())
444 Element = Result.get();
449 else if (
StringLiteral *String = dyn_cast<StringLiteral>(OrigElement)) {
450 if (String->isAscii()) {
456 if (Result.isInvalid())
459 Element = Result.get();
472 dyn_cast<ObjCStringLiteral>(OrigElement)) {
474 unsigned numConcat = SL->getNumConcatenated();
477 bool hasMacro =
false;
478 for (
unsigned i = 0; i < numConcat ; ++i)
479 if (SL->getStrTokenLoc(i).isMacroID()) {
485 diag::warn_concatenated_nsarray_literal)
508 ExprResult RValue = DefaultFunctionArrayLvalueConversion(ValueExpr);
513 ValueExpr = RValue.
get();
529 if (!StringWithUTF8StringMethod) {
534 BoxingMethod = NSStringDecl->lookupClassMethod(stringWithUTF8String);
535 if (!BoxingMethod && getLangOpts().DebuggerObjCLiteral) {
540 NSStringPointer, ReturnTInfo, NSStringDecl,
559 stringWithUTF8String, BoxingMethod))
562 StringWithUTF8StringMethod = BoxingMethod;
565 BoxingMethod = StringWithUTF8StringMethod;
566 BoxedType = NSStringPointer;
575 }
else if (ValueType->isBuiltinType()) {
583 dyn_cast<CharacterLiteral>(ValueExpr->
IgnoreParens())) {
586 switch (Char->getKind()) {
589 ValueType = Context.
CharTy;
609 BoxedType = NSNumberPointer;
611 if (!ET->getDecl()->isComplete()) {
612 Diag(Loc, diag::err_objc_incomplete_boxed_expression_type)
618 ET->getDecl()->getIntegerType());
619 BoxedType = NSNumberPointer;
620 }
else if (ValueType->isObjCBoxableRecordType()) {
638 if (!ValueWithBytesObjCTypeMethod) {
646 BoxingMethod = NSValueDecl->lookupClassMethod(ValueWithBytesObjCType);
647 if (!BoxingMethod && getLangOpts().DebuggerObjCLiteral) {
654 ValueWithBytesObjCType,
675 Params.push_back(bytes);
685 Params.push_back(type);
692 ValueWithBytesObjCType, BoxingMethod))
695 ValueWithBytesObjCTypeMethod = BoxingMethod;
698 if (!ValueType.isTriviallyCopyableType(Context)) {
699 Diag(Loc, diag::err_objc_non_trivially_copyable_boxed_expression_type)
704 BoxingMethod = ValueWithBytesObjCTypeMethod;
705 BoxedType = NSValuePointer;
709 Diag(Loc, diag::err_objc_illegal_boxed_expression_type)
714 DiagnoseUseOfDecl(BoxingMethod, Loc);
717 if (ValueType->isObjCBoxableRecordType()) {
719 ConvertedValueExpr = PerformCopyInitialization(IE, ValueExpr->
getExprLoc(),
726 ConvertedValueExpr = PerformCopyInitialization(IE,
SourceLocation(),
732 ValueExpr = ConvertedValueExpr.
get();
737 return MaybeBindToTemporary(BoxedExpr);
746 assert(!LangOpts.isSubscriptPointerArithmetic());
751 "base or index cannot have dependent type here");
755 ExprResult Result = CheckPlaceholderExpr(IndexExpr);
758 IndexExpr = Result.
get();
761 Result = DefaultLvalueConversion(BaseExpr);
764 BaseExpr = Result.
get();
769 getterMethod, setterMethod, RB);
785 if (!ArrayWithObjectsMethod) {
789 if (!Method && getLangOpts().DebuggerObjCLiteral) {
806 Params.push_back(objects);
814 Params.push_back(cnt);
829 diag::note_objc_literal_method_param)
836 if (!Method->
parameters()[1]->getType()->isIntegerType()) {
840 diag::note_objc_literal_method_param)
848 ArrayWithObjectsMethod = Method;
851 QualType ObjectsType = ArrayWithObjectsMethod->parameters()[0]->getType();
856 Expr **ElementsBuffer = Elements.data();
857 for (
unsigned I = 0, N = Elements.size(); I != N; ++I) {
864 ElementsBuffer[I] = Converted.
get();
871 return MaybeBindToTemporary(
873 ArrayWithObjectsMethod, SR));
880 if (!NSDictionaryDecl) {
883 if (!NSDictionaryDecl) {
891 if (!DictionaryWithObjectsMethod) {
892 Selector Sel = NSAPIObj->getNSDictionarySelector(
894 ObjCMethodDecl *Method = NSDictionaryDecl->lookupClassMethod(Sel);
895 if (!Method && getLangOpts().DebuggerObjCLiteral) {
914 Params.push_back(objects);
922 Params.push_back(keys);
930 Params.push_back(cnt);
946 diag::note_objc_literal_method_param)
960 if (QIDNSCopying.isNull()) {
974 if (!QIDNSCopying.isNull())
983 diag::note_objc_literal_method_param)
996 diag::note_objc_literal_method_param)
1003 DictionaryWithObjectsMethod = Method;
1006 QualType ValuesT = DictionaryWithObjectsMethod->parameters()[0]->getType();
1008 QualType KeysT = DictionaryWithObjectsMethod->parameters()[1]->getType();
1013 bool HasPackExpansions =
false;
1027 Element.Key = Key.
get();
1028 Element.Value = Value.
get();
1030 if (Element.EllipsisLoc.isInvalid())
1033 if (!Element.Key->containsUnexpandedParameterPack() &&
1034 !Element.Value->containsUnexpandedParameterPack()) {
1035 Diag(Element.EllipsisLoc,
1036 diag::err_pack_expansion_without_parameter_packs)
1038 Element.Value->getLocEnd());
1042 HasPackExpansions =
true;
1049 Context, Elements, HasPackExpansions, Ty,
1050 DictionaryWithObjectsMethod, SR));
1063 if (RequireCompleteType(AtLoc, EncodedType,
1064 diag::err_incomplete_type_objc_at_encode,
1071 if (!NotEncodedT.
isNull())
1072 Diag(AtLoc, diag::warn_incomplete_encoded_type)
1073 << EncodedType << NotEncodedT;
1079 if (getLangOpts().CPlusPlus || getLangOpts().ConstStrings)
1085 return new (Context)
ObjCEncodeExpr(StrTy, EncodedTypeInfo, AtLoc, RParenLoc);
1095 QualType EncodedType = GetTypeFromParser(ty, &TInfo);
1098 getLocForEndOfToken(LParenLoc));
1100 return BuildObjCEncodeExpression(AtLoc, TInfo, RParenLoc);
1110 bool Warned =
false;
1113 if (MatchingMethodDecl == Method ||
1121 S.
Diag(AtLoc, diag::warn_multiple_selectors)
1127 S.
Diag(MatchingMethodDecl->
getLocation(), diag::note_method_declared_at)
1138 bool WarnMultipleSelectors) {
1139 if (!WarnMultipleSelectors ||
1142 bool Warned =
false;
1143 for (Sema::GlobalMethodPool::iterator b = S.
MethodPool.begin(),
1148 Method, InstMethList))
1154 Method, ClsMethList) || Warned)
1164 bool WarnMultipleSelectors) {
1168 Method = LookupFactoryMethodInGlobalPool(Sel,
1171 if (
const ObjCMethodDecl *OM = SelectorsForTypoCorrection(Sel)) {
1172 Selector MatchedSel = OM->getSelector();
1175 Diag(SelLoc, diag::warn_undeclared_selector_with_typo)
1176 << Sel << MatchedSel
1180 Diag(SelLoc, diag::warn_undeclared_selector) << Sel;
1183 WarnMultipleSelectors);
1187 !getSourceManager().isInSystemHeader(Method->
getLocation()))
1188 ReferencedSelectors.insert(std::make_pair(Sel, AtLoc));
1192 if (getLangOpts().ObjCAutoRefCount) {
1199 Diag(AtLoc, diag::err_arc_illegal_selector) <<
1228 Diag(ProtoLoc, diag::err_undeclared_protocol) << ProtocolId;
1238 return new (Context)
ObjCProtocolExpr(Ty, PDecl, AtLoc, ProtoIdLoc, RParenLoc);
1284 bool isClassMessage,
1285 bool isSuperMessage) {
1286 assert(Method &&
"Must have a method");
1321 if (isSuperMessage) {
1324 return transferNullability(
1343 return transferNullability(ReceiverType);
1348 bool isClassMessage,
1349 bool isSuperMessage) {
1366 unsigned receiverNullabilityIdx = 0;
1368 receiverNullabilityIdx = 1 + static_cast<unsigned>(*nullability);
1370 unsigned resultNullabilityIdx = 0;
1372 resultNullabilityIdx = 1 + static_cast<unsigned>(*nullability);
1376 static const uint8_t None = 0;
1377 static const uint8_t
NonNull = 1;
1380 static const uint8_t nullabilityMap[4][4] = {
1382 { None, None, Nullable, None },
1383 { None, NonNull, Nullable, Unspecified },
1384 { Nullable, Nullable, Nullable, Nullable },
1385 { None, Unspecified, Nullable, Unspecified }
1388 unsigned newResultNullabilityIdx
1389 = nullabilityMap[receiverNullabilityIdx][resultNullabilityIdx];
1390 if (newResultNullabilityIdx == resultNullabilityIdx)
1396 if (
auto attributed = dyn_cast<AttributedType>(resultType.
getTypePtr())) {
1397 resultType = attributed->getModifiedType();
1404 if (newResultNullabilityIdx > 0) {
1409 resultType, resultType);
1428 dyn_cast<ObjCCategoryImplDecl>(impl)) {
1429 iface = catImpl->getCategoryDecl();
1431 iface = impl->getClassInterface();
1441 for (
unsigned i = 0, e = overrides.size(); i != e; ++i) {
1462 SourceRange range = overridden->getReturnTypeSourceRange();
1465 loc = overridden->getLocation();
1466 Diag(loc, diag::note_related_result_type_explicit)
1510 bool isClassMessage,
bool isSuperMessage,
1515 if (!SelectorLocs.empty() && SelectorLocs.front().isValid())
1516 SelLoc = SelectorLocs.front();
1522 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
1523 if (Args[i]->isTypeDependent())
1527 if (getLangOpts().DebuggerSupport) {
1529 result = checkUnknownAnyArg(SelLoc, Args[i], paramTy);
1531 result = DefaultArgumentPromotion(Args[i]);
1535 Args[i] = result.
get();
1539 if (getLangOpts().ObjCAutoRefCount)
1540 DiagID = diag::err_arc_method_not_found;
1542 DiagID = isClassMessage ? diag::warn_class_method_not_found
1543 : diag::warn_inst_method_not_found;
1544 if (!getLangOpts().DebuggerSupport) {
1545 const ObjCMethodDecl *OMD = SelectorsForTypoCorrection(Sel, ReceiverType);
1547 if (getLangOpts().ObjCAutoRefCount)
1548 DiagID = diag::err_method_not_found_with_typo;
1550 DiagID = isClassMessage ? diag::warn_class_method_not_found_with_typo
1551 : diag::warn_instance_method_not_found_with_typo;
1553 SourceRange SelectorRange(SelectorLocs.front(), SelectorLocs.back());
1555 Diag(SelLoc, DiagID)
1556 << Sel<< isClassMessage << MatchedSel
1559 Diag(SelLoc, DiagID) << Sel<< isClassMessage << MatchedSel;
1562 Diag(SelLoc, DiagID)
1563 << Sel << isClassMessage <<
SourceRange(SelectorLocs.front(),
1564 SelectorLocs.back());
1569 Diag(ThisClass->getLocation(), diag::note_receiver_class_declared);
1571 if (ThisClass->lookupClassMethod(Sel))
1572 Diag(RecRange.
getBegin(),diag::note_receiver_expr_here)
1574 ThisClass->getNameAsString());
1581 if (getLangOpts().DebuggerSupport) {
1590 ReturnType = getMessageSendResultType(ReceiverType, Method, isClassMessage,
1600 if (Args.size() < NumNamedArgs) {
1601 Diag(SelLoc, diag::err_typecheck_call_too_few_args)
1602 << 2 << NumNamedArgs << static_cast<unsigned>(Args.size());
1610 bool IsError =
false;
1611 for (
unsigned i = 0; i < NumNamedArgs; i++) {
1613 if (Args[i]->isTypeDependent())
1616 Expr *argExpr = Args[i];
1619 assert(argExpr &&
"CheckMessageArgumentTypes(): missing expression");
1621 if (param->
hasAttr<NoEscapeAttr>())
1622 if (
auto *BE = dyn_cast<BlockExpr>(
1624 BE->getBlockDecl()->setDoesNotEscape();
1629 !param->
hasAttr<CFConsumedAttr>())
1630 argExpr = stripARCUnbridgedCast(argExpr);
1636 ExprResult argE = checkUnknownAnyArg(SelLoc, argExpr, paramType);
1640 Args[i] = argE.
get();
1658 diag::err_call_incomplete_argument, argExpr))
1673 Args[i]->getType()->isBlockPointerType() &&
1676 maybeExtendBlockObject(arg);
1677 Args[i] = arg.
get();
1684 for (
unsigned i = NumNamedArgs, e = Args.size(); i < e; ++i) {
1685 if (Args[i]->isTypeDependent())
1688 ExprResult Arg = DefaultVariadicArgumentPromotion(Args[i], VariadicMethod,
1691 Args[i] = Arg.
get();
1695 if (Args.size() != NumNamedArgs) {
1696 Diag(Args[NumNamedArgs]->getLocStart(),
1697 diag::err_typecheck_call_too_many_args)
1698 << 2 << NumNamedArgs << static_cast<unsigned>(Args.size())
1701 Args.back()->getLocEnd());
1705 DiagnoseSentinelCalls(Method, SelLoc, Args);
1708 IsError |= CheckObjCMethodCall(
1709 Method, SelLoc, makeArrayRef(Args.data(), Args.size()));
1717 dyn_cast_or_null<ObjCMethodDecl>(CurContext->getNonClosureAncestor());
1718 return isSelfExpr(RExpr, Method);
1722 if (!method)
return false;
1725 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(receiver))
1737 if (
ObjCMethodDecl *method = iface->lookupMethod(sel, isInstance))
1742 if (
ObjCMethodDecl *method = iface->lookupPrivateMethod(sel, isInstance))
1747 for (
const auto *I : objType->
quals())
1761 for (
const auto *PROTO : OPT->
quals()) {
1762 if ((MD = PROTO->lookupMethod(Sel, Instance))) {
1782 Diag(MemberLoc, diag::err_invalid_property_name)
1792 diag::err_property_not_found_forward_class,
1793 MemberName, BaseRange))
1799 if (DiagnoseUseOfDecl(PD, MemberLoc))
1802 return new (Context)
1806 return new (Context)
1811 for (
const auto *I : OPT->
quals())
1815 if (DiagnoseUseOfDecl(PD, MemberLoc))
1821 SuperLoc, SuperType);
1823 return new (Context)
1833 Selector Sel = PP.getSelectorTable().getNullarySelector(Member);
1838 Getter = LookupMethodInQualifiedType(Sel, OPT,
true);
1846 if (DiagnoseUseOfDecl(Getter, MemberLoc))
1853 PP.getSelectorTable(), Member);
1858 Setter = LookupMethodInQualifiedType(SetterSel, OPT,
true);
1866 if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
1872 if (Setter && Setter->isImplicit() && Setter->isPropertyAccessor() &&
1880 diag::warn_property_access_suggest)
1881 << MemberName <<
QualType(OPT, 0) << PDecl->getName()
1886 if (Getter || Setter) {
1888 return new (Context)
1892 return new (Context)
1901 LookupOrdinaryName,
nullptr,
nullptr,
1902 llvm::make_unique<DeclFilterCCC<ObjCPropertyDecl>>(),
1903 CTK_ErrorRecovery, IFace,
false, OPT)) {
1909 Corrected.isKeyword() ? nullptr : Corrected.getFoundDecl();
1910 if (ChosenDecl && isa<ObjCPropertyDecl>(ChosenDecl))
1911 if (cast<ObjCPropertyDecl>(ChosenDecl)->isClassProperty()) {
1914 Diag(MemberLoc, diag::err_class_property_found) << MemberName
1921 diagnoseTypo(Corrected, PDiag(diag::err_property_not_found_suggest)
1922 << MemberName <<
QualType(OPT, 0));
1923 return HandleExprPropertyRefExpr(OPT, BaseExpr, OpLoc,
1924 TypoResult, MemberLoc,
1925 SuperLoc, SuperType, Super);
1934 if (RequireCompleteType(MemberLoc, OBJPT->getPointeeType(),
1935 diag::err_property_not_as_forward_class,
1936 MemberName, BaseExpr))
1940 diag::err_ivar_access_using_property_syntax_suggest)
1941 << MemberName <<
QualType(OPT, 0) << Ivar->getDeclName()
1946 Diag(MemberLoc, diag::err_property_not_found)
1949 Diag(Setter->getLocation(), diag::note_getter_unavailable)
1968 if (receiverNamePtr->
isStr(
"super")) {
1969 if (
ObjCMethodDecl *CurMethod = tryCaptureObjCSelf(receiverNameLoc)) {
1970 if (
auto classDecl = CurMethod->getClassInterface()) {
1971 SuperType =
QualType(classDecl->getSuperClassType(), 0);
1972 if (CurMethod->isInstanceMethod()) {
1973 if (SuperType.
isNull()) {
1975 Diag(receiverNameLoc, diag::err_root_class_cannot_use_super)
1976 << CurMethod->getClassInterface()->getIdentifier();
1986 receiverNameLoc, T,
true);
1997 Diag(receiverNameLoc, diag::err_expected_either) << tok::identifier
2007 GetterSel = PD->getGetterName();
2008 SetterSel = PD->getSetterName();
2010 GetterSel = PP.getSelectorTable().getNullarySelector(&propertyName);
2012 PP.getIdentifierTable(), PP.getSelectorTable(), &propertyName);
2025 if (DiagnoseUseOfDecl(Getter, propertyNameLoc))
2040 if (Setter && DiagnoseUseOfDecl(Setter, propertyNameLoc))
2043 if (Getter || Setter) {
2045 return new (Context)
2052 propertyNameLoc, receiverNameLoc, IFace);
2054 return ExprError(
Diag(propertyNameLoc, diag::err_property_not_found)
2068 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
2080 bool HasTrailingDot,
2082 ReceiverType =
nullptr;
2088 return HasTrailingDot? ObjCInstanceMessage : ObjCSuperMessage;
2090 LookupResult Result(*
this, Name, NameLoc, LookupOrdinaryName);
2091 LookupName(Result, S);
2100 if (!Method->getClassInterface()) {
2102 return ObjCInstanceMessage;
2106 if (Method->getClassInterface()->lookupInstanceVariable(Name,
2108 return ObjCInstanceMessage;
2119 return ObjCInstanceMessage;
2125 return ObjCInstanceMessage;
2134 DiagnoseUseOfDecl(
Type, NameLoc);
2137 return ObjCInstanceMessage;
2142 ReceiverType = CreateParsedType(T, TSInfo);
2143 return ObjCClassMessage;
2149 llvm::make_unique<ObjCInterfaceOrSuperCCC>(getCurMethodDecl()),
2150 CTK_ErrorRecovery,
nullptr,
false,
nullptr,
false)) {
2151 if (Corrected.isKeyword()) {
2154 diagnoseTypo(Corrected,
2155 PDiag(diag::err_unknown_receiver_suggest) << Name);
2156 return ObjCSuperMessage;
2161 diagnoseTypo(Corrected,
2162 PDiag(diag::err_unknown_receiver_suggest) << Name);
2165 ReceiverType = CreateParsedType(T, TSInfo);
2166 return ObjCClassMessage;
2171 return ObjCInstanceMessage;
2184 Diag(SuperLoc, diag::err_invalid_receiver_to_message_super);
2190 Diag(SuperLoc, diag::err_no_super_class_message)
2196 if (SuperTy.isNull()) {
2198 Diag(SuperLoc, diag::err_root_class_cannot_use_super)
2206 getCurFunction()->ObjCShouldCallSuper =
false;
2212 return BuildInstanceMessage(
nullptr, SuperTy, SuperLoc,
2214 LBracLoc, SelectorLocs, RBracLoc, Args);
2219 return BuildClassMessage(
nullptr,
2221 SuperLoc, Sel,
nullptr,
2222 LBracLoc, SelectorLocs, RBracLoc, Args);
2226 bool isSuperReceiver,
2232 if (!ReceiverType.
isNull())
2235 return BuildClassMessage(receiverTypeInfo, ReceiverType,
2237 Sel, Method, Loc, Loc, Loc, Args,
2251 if (refactor(Msg,*S.
NSAPIObj, ECommit)) {
2260 switch (Edit.
Kind) {
2288 bool IsClassObjectCall) {
2298 if (!IsClassObjectCall) {
2300 if (!OPT || !OPT->getInterfaceDecl())
2303 OPT->getInterfaceDecl()->lookupInstanceMethod(SE->getSelector());
2306 OPT->getInterfaceDecl()->lookupPrivateMethod(SE->getSelector());
2311 ImpliedMethod = IT->getDecl()->lookupClassMethod(SE->getSelector());
2314 IT->getDecl()->lookupPrivateClassMethod(SE->getSelector());
2321 S.
Diag(Loc, diag::warn_objc_unsafe_perform_selector)
2327 diag::note_objc_unsafe_perform_selector_method_declared_here)
2338 Expr **Args,
unsigned NumArgs) {
2340 bool Format =
false;
2354 if (!Format || NumArgs <= Idx)
2357 Expr *FormatExpr = Args[Idx];
2362 S.
Diag(FormatExpr->
getExprLoc(), diag::warn_objc_cdirective_format_string)
2412 Diag(Loc, diag::err_missing_open_square_message_send)
2417 if (!SelectorLocs.empty() && SelectorLocs.front().isValid())
2418 SelectorSlotLocs = SelectorLocs;
2420 SelectorSlotLocs = Loc;
2426 unsigned NumArgs = ArgsIn.size();
2427 Expr **Args = ArgsIn.data();
2428 assert(SuperLoc.
isInvalid() &&
"Message to super with dependent type");
2430 Context, ReceiverType,
VK_RValue, LBracLoc, ReceiverTypeInfo, Sel,
2431 SelectorLocs,
nullptr, makeArrayRef(Args, NumArgs), RBracLoc,
2438 if (!ClassType || !(Class = ClassType->
getInterface())) {
2439 Diag(Loc, diag::err_invalid_receiver_class_message)
2443 assert(Class &&
"We don't know which class we're messaging?");
2446 (void)DiagnoseUseOfDecl(Class, SelectorSlotLocs);
2453 (getLangOpts().ObjCAutoRefCount
2454 ? diag::err_arc_receiver_forward_class
2455 : diag::warn_receiver_forward_class),
2458 Method = LookupFactoryMethodInGlobalPool(Sel,
2460 if (Method && !getLangOpts().ObjCAutoRefCount)
2471 if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs))
2479 unsigned NumArgs = ArgsIn.size();
2480 Expr **Args = ArgsIn.data();
2481 if (CheckMessageArgumentTypes(ReceiverType,
MultiExprArg(Args, NumArgs),
2484 SuperLoc.
isValid(), LBracLoc, RBracLoc,
2491 diag::err_illegal_message_expr_incomplete_type))
2500 Diag(Loc, diag::warn_direct_initialize_call);
2508 Diag(Loc, diag::warn_direct_super_initialize_call);
2511 Diag(CurMeth->getLocation(), diag::note_method_declared_at)
2512 << CurMeth->getDeclName();
2524 ReceiverType, Sel, SelectorLocs,
2525 Method, makeArrayRef(Args, NumArgs),
2526 RBracLoc, isImplicit);
2529 ReceiverTypeInfo, Sel, SelectorLocs,
2530 Method, makeArrayRef(Args, NumArgs),
2531 RBracLoc, isImplicit);
2537 ReceiverType,
true);
2538 return MaybeBindToTemporary(Result);
2552 QualType ReceiverType = GetTypeFromParser(Receiver, &ReceiverTypeInfo);
2553 if (ReceiverType.
isNull())
2556 if (!ReceiverTypeInfo)
2559 return BuildClassMessage(ReceiverTypeInfo, ReceiverType,
2561 nullptr, LBracLoc, SelectorLocs, RBracLoc,
2571 return BuildInstanceMessage(Receiver, ReceiverType,
2573 Sel, Method, Loc, Loc, Loc, Args,
2584 if (
const auto *RootClass = dyn_cast_or_null<ObjCInterfaceDecl>(
2588 if (
P->getCanonicalDecl() == Protocol->getCanonicalDecl())
2633 assert((Receiver || SuperLoc.
isValid()) &&
"If the Receiver is null, the " 2634 "SuperLoc must be valid so we can " 2642 if (!SelectorLocs.empty() && SelectorLocs.front().isValid())
2643 SelectorSlotLocs = SelectorLocs;
2645 SelectorSlotLocs = Loc;
2649 Diag(Loc, diag::err_missing_open_square_message_send)
2660 Result = forceUnknownAnyToType(Receiver, Context.
getObjCIdType());
2662 Result = CheckPlaceholderExpr(Receiver);
2664 Receiver = Result.
get();
2670 unsigned NumArgs = ArgsIn.size();
2671 Expr **Args = ArgsIn.data();
2672 assert(SuperLoc.
isInvalid() &&
"Message to super with dependent type");
2675 SelectorLocs,
nullptr, makeArrayRef(Args, NumArgs),
2676 RBracLoc, isImplicit);
2681 ExprResult Result = DefaultFunctionArrayLvalueConversion(Receiver);
2684 Receiver = Result.
get();
2685 ReceiverType = Receiver->
getType();
2692 }
else if (!getLangOpts().ObjCAutoRefCount &&
2698 Diag(Loc, diag::warn_bad_receiver_type)
2702 Receiver = ImpCastExprToType(Receiver, Context.
getObjCIdType(),
2703 CK_CPointerToObjCPointerCast).
get();
2708 CastKind Kind = IsNull ? CK_NullToPointer : CK_IntegralToPointer;
2709 Receiver = ImpCastExprToType(Receiver, Context.
getObjCIdType(),
2712 ReceiverType = Receiver->
getType();
2715 if (RequireCompleteType(Loc, Receiver->
getType(),
2716 diag::err_incomplete_receiver_type))
2719 ExprResult result = PerformContextuallyConvertToObjCPointer(Receiver);
2721 Receiver = result.
get();
2722 ReceiverType = Receiver->
getType();
2728 Diag(Receiver->
getExprLoc(), diag::warn_messaging_unqualified_id);
2744 CollectMultipleMethodsInGlobalPool(Sel, Methods,
true,
2746 if (!Methods.empty()) {
2749 Method = Methods[0];
2753 Method = BestMethod;
2755 if (!AreMultipleMethodsInGlobalPool(Sel, Method,
2757 receiverIsIdLike, Methods))
2758 DiagnoseUseOfDecl(Method, SelectorSlotLocs);
2770 Method = LookupMethodInQualifiedType(Sel, QClassTy,
false);
2772 Method = LookupMethodInQualifiedType(Sel, QClassTy,
true);
2775 Diag(SelLoc, diag::warn_instance_method_on_class_found)
2785 Method = ClassDecl->lookupClassMethod(Sel);
2788 Method = ClassDecl->lookupPrivateClassMethod(Sel);
2790 if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs))
2795 if (!Receiver || !isSelfExpr(Receiver)) {
2799 CollectMultipleMethodsInGlobalPool(Sel, Methods,
2802 if (!Methods.empty()) {
2805 Method = Methods[0];
2811 if (
ID->getSuperClass())
2812 Diag(SelLoc, diag::warn_root_inst_method_not_found)
2820 Method = BestMethod;
2834 Method = LookupMethodInQualifiedType(Sel, QIdTy,
true);
2836 Method = LookupMethodInQualifiedType(Sel, QIdTy,
false);
2837 if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs))
2842 ClassDecl = OCIType->getInterfaceDecl();
2849 if (RequireCompleteType(Loc, OCIType->getPointeeType(),
2850 getLangOpts().ObjCAutoRefCount
2851 ? diag::err_arc_receiver_forward_instance
2852 : diag::warn_receiver_forward_instance,
2855 if (getLangOpts().ObjCAutoRefCount)
2858 forwardClass = OCIType->getInterfaceDecl();
2860 : SuperLoc, diag::note_receiver_is_id);
2868 Method = LookupMethodInQualifiedType(Sel, OCIType,
true);
2874 if (!Method && getLangOpts().ObjCAutoRefCount) {
2875 Diag(SelLoc, diag::err_arc_may_not_respond)
2876 << OCIType->getPointeeType() << Sel << RecRange
2877 <<
SourceRange(SelectorLocs.front(), SelectorLocs.back());
2881 if (!Method && (!Receiver || !isSelfExpr(Receiver))) {
2885 if (OCIType->qual_empty()) {
2887 CollectMultipleMethodsInGlobalPool(Sel, Methods,
2890 if (!Methods.empty()) {
2893 Method = Methods[0];
2898 Method = BestMethod;
2900 AreMultipleMethodsInGlobalPool(Sel, Method,
2905 if (Method && !forwardClass)
2906 Diag(SelLoc, diag::warn_maynot_respond)
2907 << OCIType->getInterfaceDecl()->getIdentifier()
2912 if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs, forwardClass))
2916 Diag(Loc, diag::err_bad_receiver_type)
2925 ? getEnclosingFunction() :
nullptr;
2927 if (DIFunctionScopeInfo &&
2929 (SuperLoc.
isValid() || isSelfExpr(Receiver))) {
2930 bool isDesignatedInitChain =
false;
2937 if (!
ID->declaresOrInheritsDesignatedInitializers() ||
2938 ID->isDesignatedInitializer(Sel)) {
2939 isDesignatedInitChain =
true;
2945 if (!isDesignatedInitChain) {
2949 assert(isDesignated && InitMethod);
2952 diag::warn_objc_designated_init_non_designated_init_call :
2953 diag::warn_objc_designated_init_non_super_designated_init_call);
2955 diag::note_objc_designated_init_marked_here);
2959 if (DIFunctionScopeInfo &&
2961 (SuperLoc.
isValid() || isSelfExpr(Receiver))) {
2963 Diag(SelLoc, diag::warn_objc_secondary_init_super_init_call);
2970 unsigned NumArgs = ArgsIn.size();
2971 Expr **Args = ArgsIn.data();
2976 if (CheckMessageArgumentTypes(ReceiverType,
MultiExprArg(Args, NumArgs),
2977 Sel, SelectorLocs, Method,
2978 ClassMessage, SuperLoc.
isValid(),
2979 LBracLoc, RBracLoc, RecRange, ReturnType, VK))
2984 diag::err_illegal_message_expr_incomplete_type))
2989 if (getLangOpts().ObjCAutoRefCount) {
2995 checkInitMethod(Method, ReceiverType);
3013 Diag(SelLoc, diag::err_arc_illegal_explicit_message)
3018 if (Method && NumArgs >= 1) {
3019 if (
const auto *SelExp =
3020 dyn_cast<ObjCSelectorExpr>(Args[0]->IgnoreParens())) {
3021 Selector ArgSel = SelExp->getSelector();
3023 LookupInstanceMethodInGlobalPool(ArgSel,
3024 SelExp->getSourceRange());
3027 LookupFactoryMethodInGlobalPool(ArgSel,
3028 SelExp->getSourceRange());
3031 switch (SelFamily) {
3038 if (!SelMethod->
hasAttr<NSReturnsNotRetainedAttr>()) {
3041 diag::err_arc_perform_selector_retains);
3048 if (SelMethod->
hasAttr<NSReturnsRetainedAttr>()) {
3051 diag::err_arc_perform_selector_retains);
3060 Diag(SelLoc, diag::warn_arc_perform_selector_leaks);
3061 Diag(Args[0]->getExprLoc(), diag::note_used_here);
3075 ReceiverType, Sel, SelectorLocs, Method,
3076 makeArrayRef(Args, NumArgs), RBracLoc,
3080 Receiver, Sel, SelectorLocs, Method,
3081 makeArrayRef(Args, NumArgs), RBracLoc,
3087 bool IsClassObjectCall = ClassMessage;
3092 if (Receiver && isSelfExpr(Receiver)) {
3094 if (OPT->getObjectType()->isObjCClass()) {
3095 if (
const auto *CurMeth = getCurMethodDecl()) {
3096 IsClassObjectCall =
true;
3104 ReceiverType, IsClassObjectCall);
3107 if (getLangOpts().ObjCAutoRefCount) {
3110 (SuperLoc.
isValid() || isSelfExpr(Receiver))) {
3124 checkRetainCycles(Result);
3127 if (getLangOpts().ObjCWeak) {
3128 if (!isImplicit && Method) {
3135 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, LBracLoc))
3136 getCurFunction()->recordUseOfWeak(Result, Prop);
3141 CheckObjCCircularContainer(Result);
3143 return MaybeBindToTemporary(Result);
3171 if (isa<ParenListExpr>(Receiver)) {
3172 ExprResult Result = MaybeConvertParenListExprToParenExpr(S, Receiver);
3174 Receiver = Result.
get();
3177 if (RespondsToSelectorSel.isNull()) {
3181 if (Sel == RespondsToSelectorSel)
3184 return BuildInstanceMessage(Receiver, Receiver->
getType(),
3186 nullptr, LBracLoc, SelectorLocs,
3220 bool isIndirect =
false;
3239 type =
QualType(array->getElementType()->getBaseElementTypeUnsafe(), 0);
3274 if (left == right)
return left;
3275 if (left == ACC_bottom)
return right;
3276 if (right == ACC_bottom)
return left;
3282 class ARCCastChecker :
public StmtVisitor<ARCCastChecker, ACCResult> {
3298 : Context(Context), SourceClass(source), TargetClass(target),
3299 Diagnose(diagnose) {}
3329 case CK_NullToPointer:
3333 case CK_LValueToRValue:
3335 case CK_CPointerToObjCPointerCast:
3336 case CK_BlockPointerToObjCPointerCast:
3337 case CK_AnyPointerToBlockPointerCast:
3352 return Visit(e->
getRHS());
3358 if (left == ACC_invalid)
return ACC_invalid;
3388 return ACC_plusZero;
3398 if (
ACCResult result = checkCallToFunction(fn))
3401 return super::VisitCallExpr(e);
3413 if (fn->
hasAttr<CFReturnsNotRetainedAttr>())
3414 return ACC_plusZero;
3419 if (fn->
hasAttr<CFReturnsRetainedAttr>())
3420 return Diagnose ? ACC_plusOne
3425 if (builtinID == Builtin::BI__builtin___CFStringMakeConstantString)
3429 if (!fn->
hasAttr<CFAuditedTransferAttr>())
3434 return Diagnose ? ACC_plusOne
3437 return ACC_plusZero;
3450 return checkCallToMethod(method);
3454 if (!method)
return ACC_invalid;
3463 if (method->
hasAttr<CFReturnsNotRetainedAttr>())
3464 return ACC_plusZero;
3468 if (method->
hasAttr<CFReturnsRetainedAttr>())
3480 return ACC_plusZero;
3491 return LookupName(R, TUScope,
false);
3501 const char *bridgeKeyword,
3502 const char *CFBridgeName) {
3518 NCE->getAngleBrackets().getEnd());
3522 char PrevChar = *SM.
getCharacterData(range.getBegin().getLocWithOffset(-1));
3526 BridgeCall += CFBridgeName;
3533 castedE = CCE->getSubExpr();
3544 BridgeCall += CFBridgeName;
3546 if (isa<ParenExpr>(castedE)) {
3564 std::string castCode =
"(";
3565 castCode += bridgeKeyword;
3569 NCE->getAngleBrackets().getEnd());
3573 std::string castCode =
"(";
3574 castCode += bridgeKeyword;
3579 if (isa<ParenExpr>(castedE)) {
3593 template <
typename T>
3601 return RD->getAttr<T>();
3609 TDNDecl = TD->getDecl();
3610 if (ObjCBridgeRelatedAttr *ObjCBAttr =
3611 getObjCBridgeAttr<ObjCBridgeRelatedAttr>(TD))
3628 UnavailableAttr::IR_ARCForbiddenConversion))
3641 unsigned srcKind = 0;
3665 S.
Diag(loc, diag::err_arc_cast_requires_bridge)
3675 ARCCastChecker(S.
Context, exprACTC, castACTC,
true).Visit(castExpr);
3676 assert(CreateRule != ACC_bottom &&
"This cast should already be accepted.");
3677 if (CreateRule != ACC_plusOne)
3681 : S.
Diag(noteLoc, diag::note_arc_cstyle_bridge);
3684 castType, castExpr, realCast,
"__bridge ",
3687 if (CreateRule != ACC_plusZero)
3691 S.
Diag(noteLoc, diag::note_arc_cstyle_bridge_transfer) << castExprType :
3693 diag::note_arc_bridge_transfer)
3694 << castExprType << br;
3697 castType, castExpr, realCast,
"__bridge_transfer ",
3698 br ?
"CFBridgingRelease" :
nullptr);
3707 S.
Diag(loc, diag::err_arc_cast_requires_bridge)
3716 ARCCastChecker(S.
Context, exprACTC, castACTC,
true).Visit(castExpr);
3717 assert(CreateRule != ACC_bottom &&
"This cast should already be accepted.");
3718 if (CreateRule != ACC_plusOne)
3722 : S.
Diag(noteLoc, diag::note_arc_cstyle_bridge);
3724 castType, castExpr, realCast,
"__bridge ",
3727 if (CreateRule != ACC_plusZero)
3731 S.
Diag(noteLoc, diag::note_arc_cstyle_bridge_retained) << castType :
3733 diag::note_arc_bridge_retained)
3737 castType, castExpr, realCast,
"__bridge_retained ",
3738 br ?
"CFBridgingRetain" :
nullptr);
3744 S.
Diag(loc, diag::err_arc_mismatched_cast)
3746 << srcKind << castExprType << castType
3750 template <
typename TB>
3752 bool &HadTheAttribute,
bool warn) {
3754 HadTheAttribute =
false;
3757 if (TB *ObjCBAttr = getObjCBridgeAttr<TB>(TD)) {
3759 HadTheAttribute =
true;
3760 if (Parm->isStr(
"id"))
3769 if (Target && isa<ObjCInterfaceDecl>(Target)) {
3774 = InterfacePointerType->getObjectType()->getInterface();
3775 if ((CastClass == ExprClass) ||
3784 castType, ExprClass)))
3792 << T << Target->
getName() << castType;
3800 S.
Diag(castExpr->
getLocStart(), diag::err_objc_cf_bridged_not_interface)
3801 << castExpr->
getType() << Parm;
3815 template <
typename TB>
3817 bool &HadTheAttribute,
bool warn) {
3819 HadTheAttribute =
false;
3822 if (TB *ObjCBAttr = getObjCBridgeAttr<TB>(TD)) {
3824 HadTheAttribute =
true;
3825 if (Parm->isStr(
"id"))
3834 if (Target && isa<ObjCInterfaceDecl>(Target)) {
3839 = InterfacePointerType->getObjectType()->getInterface();
3840 if ((CastClass == ExprClass) ||
3851 castExpr->
getType(), CastClass)))
3859 << castExpr->
getType() << castType;
3867 S.
Diag(castExpr->
getLocStart(), diag::err_objc_ns_bridged_invalid_cfobject)
3868 << castExpr->
getType() << castType;
3882 if (!getLangOpts().ObjC1)
3888 bool HasObjCBridgeAttr;
3889 bool ObjCBridgeAttrWillNotWarn =
3890 CheckObjCBridgeNSCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3892 if (ObjCBridgeAttrWillNotWarn && HasObjCBridgeAttr)
3894 bool HasObjCBridgeMutableAttr;
3895 bool ObjCBridgeMutableAttrWillNotWarn =
3896 CheckObjCBridgeNSCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3897 HasObjCBridgeMutableAttr,
false);
3898 if (ObjCBridgeMutableAttrWillNotWarn && HasObjCBridgeMutableAttr)
3901 if (HasObjCBridgeAttr)
3902 CheckObjCBridgeNSCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3904 else if (HasObjCBridgeMutableAttr)
3905 CheckObjCBridgeNSCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3906 HasObjCBridgeMutableAttr,
true);
3909 bool HasObjCBridgeAttr;
3910 bool ObjCBridgeAttrWillNotWarn =
3911 CheckObjCBridgeCFCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3913 if (ObjCBridgeAttrWillNotWarn && HasObjCBridgeAttr)
3915 bool HasObjCBridgeMutableAttr;
3916 bool ObjCBridgeMutableAttrWillNotWarn =
3917 CheckObjCBridgeCFCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3918 HasObjCBridgeMutableAttr,
false);
3919 if (ObjCBridgeMutableAttrWillNotWarn && HasObjCBridgeMutableAttr)
3922 if (HasObjCBridgeAttr)
3923 CheckObjCBridgeCFCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3925 else if (HasObjCBridgeMutableAttr)
3926 CheckObjCBridgeCFCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3927 HasObjCBridgeMutableAttr,
true);
3934 if (PRE->isExplicitProperty()) {
3936 SrcType = PDecl->getType();
3938 else if (PRE->isImplicitProperty()) {
3940 SrcType = Getter->getReturnType();
3948 CheckObjCBridgeRelatedConversions(castExpr->
getLocStart(),
3954 if (!getLangOpts().ObjC1)
3961 CheckTollFreeBridgeCast(castType, castExpr);
3963 : CK_CPointerToObjCPointerCast;
3975 bool CfToNs,
bool Diagnose) {
3976 QualType T = CfToNs ? SrcType : DestType;
3990 if (!LookupName(R, TUScope)) {
3992 Diag(Loc, diag::err_objc_bridged_related_invalid_class) << RCId
3993 << SrcType << DestType;
3999 if (Target && isa<ObjCInterfaceDecl>(Target))
4000 RelatedClass = cast<ObjCInterfaceDecl>(
Target);
4003 Diag(Loc, diag::err_objc_bridged_related_invalid_class_name) << RCId
4004 << SrcType << DestType;
4013 if (CfToNs && CMId) {
4018 Diag(Loc, diag::err_objc_bridged_related_known_method)
4019 << SrcType << DestType << Sel <<
false;
4027 if (!CfToNs && IMId) {
4029 InstanceMethod = RelatedClass->
lookupMethod(Sel,
true);
4030 if (!InstanceMethod) {
4032 Diag(Loc, diag::err_objc_bridged_related_known_method)
4033 << SrcType << DestType << Sel <<
true;
4045 Expr *&SrcExpr,
bool Diagnose) {
4050 if (!CfToNs && !NsToCf)
4057 if (!checkObjCBridgeRelatedComponents(Loc, DestType, SrcType, RelatedClass,
4058 ClassMethod, InstanceMethod, TDNDecl,
4066 std::string ExpressionString =
"[";
4068 ExpressionString +=
" ";
4072 Diag(Loc, diag::err_objc_bridged_related_known_method)
4073 << SrcType << DestType << ClassMethod->
getSelector() <<
false 4081 Expr *args[] = { SrcExpr };
4082 ExprResult msg = BuildClassMessageImplicit(receiverType,
false,
4086 SrcExpr = msg.
get();
4093 if (InstanceMethod) {
4095 std::string ExpressionString;
4097 getLocForEndOfToken(SrcExpr->
getLocEnd());
4102 ExpressionString =
".";
4103 ExpressionString += PDecl->getNameAsString();
4104 Diag(Loc, diag::err_objc_bridged_related_known_method)
4105 << SrcType << DestType << InstanceMethod->
getSelector() <<
true 4108 if (ExpressionString.empty()) {
4110 ExpressionString =
" ";
4112 ExpressionString +=
"]";
4114 Diag(Loc, diag::err_objc_bridged_related_known_method)
4115 << SrcType << DestType << InstanceMethod->
getSelector() <<
true 4123 BuildInstanceMessageImplicit(SrcExpr, SrcType,
4126 InstanceMethod, None);
4127 SrcExpr = msg.get();
4138 bool Diagnose,
bool DiagnoseCFAudited,
4150 if (exprACTC == castACTC) {
4154 (CCK == CCK_CStyleCast || CCK == CCK_OtherCast) &&
4155 castType != castExprType) {
4161 if (
const ParenType *PT = dyn_cast<ParenType>(DT))
4162 QDT = PT->desugar();
4163 else if (
const TypeOfType *TP = dyn_cast<TypeOfType>(DT))
4164 QDT = TP->desugar();
4165 else if (
const AttributedType *AT = dyn_cast<AttributedType>(DT))
4166 QDT = AT->desugar();
4167 if (QDT != castType &&
4172 Diag(loc, diag::err_arc_nolifetime_behavior);
4182 if (!getLangOpts().ObjCAutoRefCount)
4201 switch (ARCCastChecker(Context, exprACTC, castACTC,
false).Visit(castExpr)) {
4216 Cleanup.setExprNeedsCleanups(
true);
4224 return ACR_unbridged;
4230 ConversionToObjCStringLiteralCheck(castType, castExpr, Diagnose))
4240 (Opc == BO_NE || Opc == BO_EQ))) {
4243 castExpr, exprACTC, CCK);
4262 castType =
cast->getTypeAsWritten();
4263 CCK = CCK_CStyleCast;
4265 castRange =
cast->getTypeInfoAsWritten()->getTypeLoc().getSourceRange();
4266 castType =
cast->getTypeAsWritten();
4267 CCK = CCK_OtherCast;
4269 llvm_unreachable(
"Unexpected ImplicitCastExpr");
4287 if (
ParenExpr *pe = dyn_cast<ParenExpr>(e)) {
4288 Expr *sub = stripARCUnbridgedCast(pe->getSubExpr());
4289 return new (Context)
ParenExpr(pe->getLParen(), pe->getRParen(), sub);
4290 }
else if (
UnaryOperator *uo = dyn_cast<UnaryOperator>(e)) {
4291 assert(uo->getOpcode() == UO_Extension);
4292 Expr *sub = stripARCUnbridgedCast(uo->getSubExpr());
4293 return new (Context)
4294 UnaryOperator(sub, UO_Extension, sub->getType(), sub->getValueKind(),
4295 sub->getObjectKind(), uo->getOperatorLoc(),
false);
4297 assert(!gse->isResultDependent());
4299 unsigned n = gse->getNumAssocs();
4302 for (
unsigned i = 0; i != n; ++i) {
4303 subTypes[i] = gse->getAssocTypeSourceInfo(i);
4304 Expr *sub = gse->getAssocExpr(i);
4305 if (i == gse->getResultIndex())
4306 sub = stripARCUnbridgedCast(sub);
4311 gse->getControllingExpr(),
4313 gse->getDefaultLoc(),
4314 gse->getRParenLoc(),
4315 gse->containsUnexpandedParameterPack(),
4316 gse->getResultIndex());
4318 assert(isa<ImplicitCastExpr>(e) &&
"bad form of unbridged cast!");
4319 return cast<ImplicitCastExpr>(e)->getSubExpr();
4329 if (isa<ObjCObjectPointerType>(canCastType) &&
4335 return !ObjI->isArcWeakrefUnavailable();
4342 Expr *curExpr = e, *prevExpr =
nullptr;
4347 if (
auto *pe = dyn_cast<ParenExpr>(curExpr)) {
4349 curExpr = pe->getSubExpr();
4353 if (
auto *ce = dyn_cast<CastExpr>(curExpr)) {
4354 if (
auto *ice = dyn_cast<ImplicitCastExpr>(ce))
4355 if (ice->getCastKind() == CK_ARCReclaimReturnedObject) {
4357 return ice->getSubExpr();
4358 if (
auto *pe = dyn_cast<ParenExpr>(prevExpr))
4359 pe->setSubExpr(ice->getSubExpr());
4361 cast<CastExpr>(prevExpr)->setSubExpr(ice->getSubExpr());
4366 curExpr = ce->getSubExpr();
4382 ExprResult SubResult = UsualUnaryConversions(SubExpr);
4384 SubExpr = SubResult.
get();
4391 bool MustConsume =
false;
4398 : CK_CPointerToObjCPointerCast);
4404 bool br = isKnownName(
"CFBridgingRelease");
4405 Diag(BridgeKeywordLoc, diag::err_arc_bridge_cast_wrong_kind)
4412 Diag(BridgeKeywordLoc, diag::note_arc_bridge)
4414 Diag(BridgeKeywordLoc, diag::note_arc_bridge_transfer)
4417 br ?
"CFBridgingRelease " 4418 :
"__bridge_transfer ");
4442 CK_ARCProduceObject,
4447 bool br = isKnownName(
"CFBridgingRetain");
4448 Diag(BridgeKeywordLoc, diag::err_arc_bridge_cast_wrong_kind)
4456 Diag(BridgeKeywordLoc, diag::note_arc_bridge)
4458 Diag(BridgeKeywordLoc, diag::note_arc_bridge_retained)
4461 br ?
"CFBridgingRetain " :
"__bridge_retained");
4468 Diag(LParenLoc, diag::err_arc_bridge_cast_incompatible)
4469 << FromType << T << Kind
4480 Cleanup.setExprNeedsCleanups(
true);
4496 QualType T = GetTypeFromParser(Type, &TSInfo);
4498 CheckTollFreeBridgeCast(T, SubExpr);
4501 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.
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.
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.
SourceLocation getLocStart() const LLVM_READONLY
static StringLiteral * Create(const ASTContext &C, StringRef Str, StringKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumStrs)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
ObjCMethodDecl * getMethod() const
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...
SourceLocation getLocStart() const LLVM_READONLY
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
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
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 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.
SourceLocation getLocStart() const LLVM_READONLY
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)
bool CheckMessageArgumentTypes(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.
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...
ObjCStringFormatFamily getStringFormatFamily() const
Expr - 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 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.
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
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
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
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
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.
SourceLocation getLocStart() const LLVM_READONLY
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)
SourceLocation getLocStart() const LLVM_READONLY
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...
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.
SourceLocation getLocEnd() const LLVM_READONLY
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.
QualType getAttributedType(AttributedType::Kind attrKind, QualType modifiedType, QualType equivalentType)
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)
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
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.
DeclarationName - 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]).
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.
QualType getMessageSendResultType(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 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.