r178179 - Objective-C: Issue more precise warning when user
Fariborz Jahanian
fjahanian at apple.com
Wed Mar 27 14:19:26 PDT 2013
Author: fjahanian
Date: Wed Mar 27 16:19:25 2013
New Revision: 178179
URL: http://llvm.org/viewvc/llvm-project?rev=178179&view=rev
Log:
Objective-C: Issue more precise warning when user
is accessing 'isa' as an object pointer.
// rdar://13503456. FixIt to follow in another patch.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/test/Analysis/misc-ps-region-store.m
cfe/trunk/test/SemaObjC/warn-isa-ref.m
cfe/trunk/test/SemaObjCXX/instantiate-expr.mm
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=178179&r1=178178&r2=178179&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Mar 27 16:19:25 2013
@@ -187,6 +187,7 @@ def ObjCMissingSuperCalls : DiagGroup<"o
def ObjCRetainBlockProperty : DiagGroup<"objc-noncopy-retain-block-property">;
def ObjCReadonlyPropertyHasSetter : DiagGroup<"objc-readonly-with-setter-property">;
def ObjCRootClass : DiagGroup<"objc-root-class">;
+def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
def Packed : DiagGroup<"packed">;
def Padded : DiagGroup<"padded">;
def PointerArith : DiagGroup<"pointer-arith">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=178179&r1=178178&r2=178179&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 27 16:19:25 2013
@@ -634,9 +634,11 @@ def warn_objc_property_no_assignment_att
"'assign' is assumed">,
InGroup<ObjCPropertyNoAttribute>;
def warn_objc_isa_use : Warning<
- "direct access to Objective-C's isa is deprecated "
- "in favor of object_setClass() and object_getClass()">,
- InGroup<DiagGroup<"deprecated-objc-isa-usage">>;
+ "direct access to Objective-C's isa is deprecated in favor of "
+ "object_getClass()">, InGroup<DeprecatedObjCIsaUsage>;
+def warn_objc_isa_assign : Warning<
+ "assignemt to Objective-C's isa is deprecated in favor of "
+ "object_setClass()">, InGroup<DeprecatedObjCIsaUsage>;
def warn_objc_property_default_assign_on_object : Warning<
"default property attribute 'assign' not appropriate for non-GC object">,
InGroup<ObjCPropertyNoAttribute>;
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=178179&r1=178178&r2=178179&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Mar 27 16:19:25 2013
@@ -491,6 +491,8 @@ ExprResult Sema::DefaultLvalueConversion
}
CheckForNullPointerDereference(*this, E);
+ if (isa<ObjCIsaExpr>(E->IgnoreParens()))
+ 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
@@ -8535,6 +8537,9 @@ ExprResult Sema::CreateBuiltinBinOp(Sour
CheckArrayAccess(LHS.get());
CheckArrayAccess(RHS.get());
+ if (isa<ObjCIsaExpr>(LHS.get()->IgnoreParens()))
+ Diag(LHS.get()->getExprLoc(), diag::warn_objc_isa_assign);
+
if (CompResultTy.isNull())
return Owned(new (Context) BinaryOperator(LHS.take(), RHS.take(), Opc,
ResultTy, VK, OK, OpLoc,
Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=178179&r1=178178&r2=178179&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Wed Mar 27 16:19:25 2013
@@ -1130,12 +1130,9 @@ Sema::LookupMemberExpr(LookupResult &R,
// There's an implicit 'isa' ivar on all objects.
// But we only actually find it this way on objects of type 'id',
// apparently.
- if (OTy->isObjCId() && Member->isStr("isa")) {
- Diag(MemberLoc, diag::warn_objc_isa_use);
+ if (OTy->isObjCId() && Member->isStr("isa"))
return Owned(new (Context) ObjCIsaExpr(BaseExpr.take(), IsArrow, MemberLoc,
Context.getObjCClassType()));
- }
-
if (ShouldTryAgainWithRedefinitionType(*this, BaseExpr))
return LookupMemberExpr(R, BaseExpr, IsArrow, OpLoc, SS,
ObjCImpDecl, HasTemplateArgs);
Modified: cfe/trunk/test/Analysis/misc-ps-region-store.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.m?rev=178179&r1=178178&r2=178179&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-region-store.m (original)
+++ cfe/trunk/test/Analysis/misc-ps-region-store.m Wed Mar 27 16:19:25 2013
@@ -920,7 +920,7 @@ int rdar_7770737_pos(void)
void pr6302(id x, Class y) {
// This previously crashed the analyzer (reported in PR 6302)
- x->isa = y; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_setClass() and object_getClass()}}
+ x->isa = y; // expected-warning {{assignemt to Objective-C's isa is deprecated in favor of object_setClass()}}
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/test/SemaObjC/warn-isa-ref.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-isa-ref.m?rev=178179&r1=178178&r2=178179&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-isa-ref.m (original)
+++ cfe/trunk/test/SemaObjC/warn-isa-ref.m Wed Mar 27 16:19:25 2013
@@ -18,8 +18,8 @@ static void func() {
id x;
// rdar://8290002
- [(*x).isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_setClass() and object_getClass()}}
- [x->isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_setClass() and object_getClass()}}
+ [(*x).isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
+ [x->isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
Whatever *y;
Modified: cfe/trunk/test/SemaObjCXX/instantiate-expr.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/instantiate-expr.mm?rev=178179&r1=178178&r2=178179&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/instantiate-expr.mm (original)
+++ cfe/trunk/test/SemaObjCXX/instantiate-expr.mm Wed Mar 27 16:19:25 2013
@@ -21,7 +21,7 @@ void f(U value, V value2) {
get_an_A(N)->ivar = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}}
get_an_A(N).prop = value2; // expected-error{{assigning to 'int' from incompatible type 'double *'}}
T c = get_an_id(N)->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \
- // expected-warning 5 {{direct access to Objective-C's isa is deprecated in favor of object_setClass() and object_getClass()}}
+ // expected-warning 3 {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
}
template void f<6, Class>(int, int); // expected-note{{in instantiation of}}
@@ -46,7 +46,7 @@ template void f2(A*, int, double*); // e
template<typename T, typename U>
void f3(U ptr) {
T c = ptr->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \
- // expected-warning 2 {{direct access to Objective-C's isa is deprecated in favor of object_setClass() and object_getClass()}}
+ // expected-warning 1 {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
}
template void f3<Class>(id); // expected-note{{in instantiation of}}
More information about the cfe-commits
mailing list