[cfe-commits] r173179 - in /cfe/trunk: include/clang/Parse/Parser.h include/clang/Sema/Sema.h lib/Parse/ParseObjc.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjC/selector-3.m
Fariborz Jahanian
fjahanian at apple.com
Tue Jan 22 10:35:43 PST 2013
Author: fjahanian
Date: Tue Jan 22 12:35:43 2013
New Revision: 173179
URL: http://llvm.org/viewvc/llvm-project?rev=173179&view=rev
Log:
objectiveC (take two): don't warn when in -Wselector mode and
an unimplemented selector is consumed by
"respondsToSelector:". // rdar://12938616
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/selector-3.m
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=173179&r1=173178&r2=173179&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Jan 22 12:35:43 2013
@@ -1410,8 +1410,7 @@
ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
- ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc,
- bool WarnSelector=true);
+ ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
bool isSimpleObjCMessageExpression();
ExprResult ParseObjCMessageExpression();
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=173179&r1=173178&r2=173179&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Jan 22 12:35:43 2013
@@ -4280,8 +4280,7 @@
SourceLocation AtLoc,
SourceLocation SelLoc,
SourceLocation LParenLoc,
- SourceLocation RParenLoc,
- bool WarnSelector);
+ SourceLocation RParenLoc);
/// ParseObjCProtocolExpression - Build protocol expression for \@protocol
ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
@@ -6392,7 +6391,7 @@
ParsedType Type,
SourceLocation RParenLoc,
Expr *SubExpr);
-
+
bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
/// \brief Check whether the given new method is a valid override of the
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=173179&r1=173178&r2=173179&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Jan 22 12:35:43 2013
@@ -2419,14 +2419,12 @@
// Parse objc-selector
SourceLocation Loc;
IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc);
-
+
SmallVector<IdentifierInfo *, 12> KeyIdents;
SmallVector<SourceLocation, 12> KeyLocs;
ExprVector KeyExprs;
if (Tok.is(tok::colon)) {
- bool RespondsToSelector =
- selIdent && selIdent->isStr("respondsToSelector");
while (1) {
// Each iteration parses a single keyword argument.
KeyIdents.push_back(selIdent);
@@ -2465,22 +2463,7 @@
return ExprError();
}
- ExprResult Res;
- if (RespondsToSelector) {
- if (Tok.is(tok::at)) {
- // Special handling for 'respondsToSelector:' which must not warn
- // on use of @selector expression as its sole argument.
- Token AfterAt = GetLookAheadToken(1);
- if (AfterAt.isObjCAtKeyword(tok::objc_selector)) {
- SourceLocation AtLoc = ConsumeToken();
- Res = ParseObjCSelectorExpression(AtLoc, false);
- }
- }
- RespondsToSelector = false;
- }
- if (!Res.get())
- Res = ParseAssignmentExpression();
-
+ ExprResult Res(ParseAssignmentExpression());
if (Res.isInvalid()) {
// We must manually skip to a ']', otherwise the expression skipper will
// stop at the ']' when it skips to the ';'. We want it to skip beyond
@@ -2560,7 +2543,7 @@
SkipUntil(tok::r_square);
return ExprError();
}
-
+
SourceLocation RBracLoc = ConsumeBracket(); // consume ']'
unsigned nKeys = KeyIdents.size();
@@ -2814,8 +2797,7 @@
/// objc-selector-expression
/// @selector '(' objc-keyword-selector ')'
-ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc,
- bool WarnSelector) {
+ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) {
SourceLocation SelectorLoc = ConsumeToken();
if (Tok.isNot(tok::l_paren))
@@ -2873,8 +2855,7 @@
Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]);
return Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc,
T.getOpenLocation(),
- T.getCloseLocation(),
- WarnSelector);
+ T.getCloseLocation());
}
void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) {
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=173179&r1=173178&r2=173179&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Tue Jan 22 12:35:43 2013
@@ -967,27 +967,24 @@
SourceLocation AtLoc,
SourceLocation SelLoc,
SourceLocation LParenLoc,
- SourceLocation RParenLoc,
- bool WarnSelector) {
- if (WarnSelector) {
- ObjCMethodDecl *Method = LookupInstanceMethodInGlobalPool(Sel,
- SourceRange(LParenLoc, RParenLoc), false, false);
- if (!Method)
- Method = LookupFactoryMethodInGlobalPool(Sel,
+ SourceLocation RParenLoc) {
+ ObjCMethodDecl *Method = LookupInstanceMethodInGlobalPool(Sel,
+ SourceRange(LParenLoc, RParenLoc), false, false);
+ if (!Method)
+ Method = LookupFactoryMethodInGlobalPool(Sel,
SourceRange(LParenLoc, RParenLoc));
- if (!Method)
- Diag(SelLoc, diag::warn_undeclared_selector) << Sel;
+ if (!Method)
+ Diag(SelLoc, diag::warn_undeclared_selector) << Sel;
- if (!Method ||
- Method->getImplementationControl() != ObjCMethodDecl::Optional) {
- llvm::DenseMap<Selector, SourceLocation>::iterator Pos
- = ReferencedSelectors.find(Sel);
- if (Pos == ReferencedSelectors.end())
- ReferencedSelectors.insert(std::make_pair(Sel, SelLoc));
- }
+ if (!Method ||
+ Method->getImplementationControl() != ObjCMethodDecl::Optional) {
+ llvm::DenseMap<Selector, SourceLocation>::iterator Pos
+ = ReferencedSelectors.find(Sel);
+ if (Pos == ReferencedSelectors.end())
+ ReferencedSelectors.insert(std::make_pair(Sel, AtLoc));
}
- // In ARC, forbid the user from using @selector for
+ // In ARC, forbid the user from using @selector for
// retain/release/autorelease/dealloc/retainCount.
if (getLangOpts().ObjCAutoRefCount) {
switch (Sel.getMethodFamily()) {
@@ -2464,6 +2461,18 @@
return MaybeBindToTemporary(Result);
}
+static void RemoveSelectorFromWarningCache(Sema &S, Expr* Arg) {
+ if (ObjCSelectorExpr *OSE =
+ dyn_cast<ObjCSelectorExpr>(Arg->IgnoreParenCasts())) {
+ Selector Sel = OSE->getSelector();
+ SourceLocation Loc = OSE->getAtLoc();
+ llvm::DenseMap<Selector, SourceLocation>::iterator Pos
+ = S.ReferencedSelectors.find(Sel);
+ if (Pos != S.ReferencedSelectors.end() && Pos->second == Loc)
+ S.ReferencedSelectors.erase(Pos);
+ }
+}
+
// ActOnInstanceMessage - used for both unary and keyword messages.
// ArgExprs is optional - if it is present, the number of expressions
// is obtained from Sel.getNumArgs().
@@ -2476,7 +2485,10 @@
MultiExprArg Args) {
if (!Receiver)
return ExprError();
-
+ IdentifierInfo *SelectorId = &Context.Idents.get("respondsToSelector");
+ if (Sel == Context.Selectors.getUnarySelector(SelectorId))
+ RemoveSelectorFromWarningCache(*this, Args[0]);
+
return BuildInstanceMessage(Receiver, Receiver->getType(),
/*SuperLoc=*/SourceLocation(), Sel, /*Method=*/0,
LBracLoc, SelectorLocs, RBracLoc, Args);
Modified: cfe/trunk/test/SemaObjC/selector-3.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/selector-3.m?rev=173179&r1=173178&r2=173179&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/selector-3.m (original)
+++ cfe/trunk/test/SemaObjC/selector-3.m Tue Jan 22 12:35:43 2013
@@ -76,5 +76,8 @@
if( [cnx respondsToSelector:@selector( _setQueueXX: )] ) // No warning here.
{
}
+ if( [cnx respondsToSelector:(@selector( _setQueueXX: ))] ) // No warning here.
+ {
+ }
}
@end
More information about the cfe-commits
mailing list