From 458a7fbe7349c7906fa4ca96c09e6ceb02aa8ea7 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 7 Mar 2012 00:58:41 +0000 Subject: [PATCH] objective-c lldb support: don't perform ivar access control check when debugging. // rdar://10997647 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152187 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 3 +- lib/Sema/SemaExprMember.cpp | 19 +++---- test/SemaObjC/no-ivar-access-control.m | 70 ++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 test/SemaObjC/no-ivar-access-control.m diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index b7da4ced87..6b753a1342 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1748,7 +1748,8 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S, // Diagnose the use of an ivar outside of the declaring class. if (IV->getAccessControl() == ObjCIvarDecl::Private && - !declaresSameEntity(ClassDeclared, IFace)) + !declaresSameEntity(ClassDeclared, IFace) && + !getLangOptions().DebuggerSupport) Diag(Loc, diag::error_private_ivar_access) << IV->getDeclName(); // FIXME: This should use a new expr for a direct reference, don't diff --git a/lib/Sema/SemaExprMember.cpp b/lib/Sema/SemaExprMember.cpp index e0dfd677aa..64d5d6012c 100644 --- a/lib/Sema/SemaExprMember.cpp +++ b/lib/Sema/SemaExprMember.cpp @@ -1189,16 +1189,17 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr, dyn_cast(ObjCImpDecl)) ClassOfMethodDecl = CatImplClass->getClassInterface(); } - - if (IV->getAccessControl() == ObjCIvarDecl::Private) { - if (!declaresSameEntity(ClassDeclared, IDecl) || - !declaresSameEntity(ClassOfMethodDecl, ClassDeclared)) - Diag(MemberLoc, diag::error_private_ivar_access) + if (!getLangOptions().DebuggerSupport) { + if (IV->getAccessControl() == ObjCIvarDecl::Private) { + if (!declaresSameEntity(ClassDeclared, IDecl) || + !declaresSameEntity(ClassOfMethodDecl, ClassDeclared)) + Diag(MemberLoc, diag::error_private_ivar_access) + << IV->getDeclName(); + } else if (!IDecl->isSuperClassOf(ClassOfMethodDecl)) + // @protected + Diag(MemberLoc, diag::error_protected_ivar_access) << IV->getDeclName(); - } else if (!IDecl->isSuperClassOf(ClassOfMethodDecl)) - // @protected - Diag(MemberLoc, diag::error_protected_ivar_access) - << IV->getDeclName(); + } } if (getLangOptions().ObjCAutoRefCount) { Expr *BaseExp = BaseExpr.get()->IgnoreParenImpCasts(); diff --git a/test/SemaObjC/no-ivar-access-control.m b/test/SemaObjC/no-ivar-access-control.m new file mode 100644 index 0000000000..cf720992d4 --- /dev/null +++ b/test/SemaObjC/no-ivar-access-control.m @@ -0,0 +1,70 @@ +// RUN: %clang_cc1 -fsyntax-only -fdebugger-support -verify %s +// RUN: %clang_cc1 -x objective-c++ -fdebugger-support -fsyntax-only -verify %s +// rdar://10997647 + +@interface I +{ +@private +int ivar; +} +@end + +@implementation I +- (int) meth { + return self->ivar; +} +int foo1(I* p) { + return p->ivar; +} +@end + +int foo(I* p) { + return p->ivar; +} + +@interface B +@end + +@implementation B +- (int) meth : (I*) arg { + return arg->ivar; +} +@end + + +@interface I1 { + int protected_ivar; +} +@property int PROP_INMAIN; +@end + +@interface I1() { + int private_ivar; +} +@property int PROP_INCLASSEXT; +@end + +@implementation I1 +@synthesize PROP_INMAIN, PROP_INCLASSEXT; + +- (int) Meth { + PROP_INMAIN = 1; + PROP_INCLASSEXT = 2; + protected_ivar = 1; // OK + return private_ivar; // OK +} +@end + + +@interface DER : I1 +@end + +@implementation DER +- (int) Meth { + protected_ivar = 1; // OK + PROP_INMAIN = 1; + PROP_INCLASSEXT = 2; + return private_ivar; +} +@end + -- 2.40.0