From 69f86d92ae940c5c8d979951d9c55fe9111627a0 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 31 May 2013 21:51:12 +0000 Subject: [PATCH] Objective-C: Fixes an ivar lookup bug where 'ivar' was used inside a record/union used as argument to __typeof. // rdar14037151 pr5984 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183048 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/Sema.cpp | 2 ++ test/SemaObjC/ivar-lookup.m | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index b7810da98e..c5f689fe49 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -824,6 +824,8 @@ FunctionDecl *Sema::getCurFunctionDecl() { ObjCMethodDecl *Sema::getCurMethodDecl() { DeclContext *DC = getFunctionLevelDeclContext(); + while (isa(DC)) + DC = DC->getParent(); return dyn_cast(DC); } diff --git a/test/SemaObjC/ivar-lookup.m b/test/SemaObjC/ivar-lookup.m index df9d8bac90..a8620caf21 100644 --- a/test/SemaObjC/ivar-lookup.m +++ b/test/SemaObjC/ivar-lookup.m @@ -80,3 +80,34 @@ extern struct foo x; int IVAR; // expected-error {{instance variable is already declared}} } @end + +// PR5984 +// rdar://14037151 +@interface Radar14037151 { + int myStatus; +} +- (int) test; +@end + +@implementation Radar14037151 +- (int) test +{ + myStatus = 1; // works + __typeof(myStatus) __in; // works. + union U { + __typeof(myStatus) __in; // fails. + }; + struct S { + __typeof(myStatus) __in; // fails. + struct S1 { + __typeof(myStatus) __in; // fails. + struct S { + __typeof(myStatus) __in; // fails. + }; + }; + }; + + return 0; +} +@end + -- 2.40.0