summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-03-28 19:50:55 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-03-28 19:50:55 +0000
commit06bb7f7ef65a8aa953c65006df35b998029ee7f3 (patch)
tree0259b1a73d40f308c82d63f749718bb44e4aff8d /clang/lib/Sema/SemaExpr.cpp
parenta46059b74d276e392060a4c67125b0efe99d657d (diff)
downloadbcm5719-llvm-06bb7f7ef65a8aa953c65006df35b998029ee7f3.tar.gz
bcm5719-llvm-06bb7f7ef65a8aa953c65006df35b998029ee7f3.zip
Objective-C: Provide fixit suggestions when class object
is accessed via accessing 'isa' ivar to use object_getClass/object_setClass apis. // rdar://13503456 llvm-svn: 178282
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 54422e81ebb..238d833c389 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -491,8 +491,18 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) {
}
CheckForNullPointerDereference(*this, E);
- if (isa<ObjCIsaExpr>(E->IgnoreParens()))
- Diag(E->getExprLoc(), diag::warn_objc_isa_use);
+ if (const ObjCIsaExpr *OISA = dyn_cast<ObjCIsaExpr>(E->IgnoreParenCasts())) {
+ NamedDecl *ObjectGetClass = LookupSingleName(TUScope,
+ &Context.Idents.get("object_getClass"),
+ SourceLocation(), LookupOrdinaryName);
+ if (ObjectGetClass)
+ Diag(E->getExprLoc(), diag::warn_objc_isa_use) <<
+ FixItHint::CreateInsertion(OISA->getLocStart(), "object_getClass(") <<
+ FixItHint::CreateReplacement(
+ SourceRange(OISA->getOpLoc(), OISA->getIsaMemberLoc()), ")");
+ else
+ Diag(E->getExprLoc(), diag::warn_objc_isa_use);
+ }
// C++ [conv.lval]p1:
// [...] If T is a non-class type, the type of the prvalue is the
@@ -8537,8 +8547,20 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
CheckArrayAccess(LHS.get());
CheckArrayAccess(RHS.get());
- if (isa<ObjCIsaExpr>(LHS.get()->IgnoreParens()))
- Diag(LHS.get()->getExprLoc(), diag::warn_objc_isa_assign);
+ if (const ObjCIsaExpr *OISA = dyn_cast<ObjCIsaExpr>(LHS.get()->IgnoreParenCasts())) {
+ NamedDecl *ObjectSetClass = LookupSingleName(TUScope,
+ &Context.Idents.get("object_setClass"),
+ SourceLocation(), LookupOrdinaryName);
+ if (ObjectSetClass && isa<ObjCIsaExpr>(LHS.get())) {
+ SourceLocation RHSLocEnd = PP.getLocForEndOfToken(RHS.get()->getLocEnd());
+ Diag(LHS.get()->getExprLoc(), diag::warn_objc_isa_assign) <<
+ FixItHint::CreateInsertion(LHS.get()->getLocStart(), "object_setClass(") <<
+ FixItHint::CreateReplacement(SourceRange(OISA->getOpLoc(), OpLoc), ",") <<
+ FixItHint::CreateInsertion(RHSLocEnd, ")");
+ }
+ else
+ Diag(LHS.get()->getExprLoc(), diag::warn_objc_isa_assign);
+ }
if (CompResultTy.isNull())
return Owned(new (Context) BinaryOperator(LHS.take(), RHS.take(), Opc,
OpenPOWER on IntegriCloud