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
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index b7810da..c5f689f 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -824,6 +824,8 @@
 
 ObjCMethodDecl *Sema::getCurMethodDecl() {
   DeclContext *DC = getFunctionLevelDeclContext();
+  while (isa<RecordDecl>(DC))
+    DC = DC->getParent();
   return dyn_cast<ObjCMethodDecl>(DC);
 }
 
diff --git a/test/SemaObjC/ivar-lookup.m b/test/SemaObjC/ivar-lookup.m
index df9d8ba..a8620ca 100644
--- a/test/SemaObjC/ivar-lookup.m
+++ b/test/SemaObjC/ivar-lookup.m
@@ -80,3 +80,34 @@
   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
+