Index: clang/lib/Sema/SemaLookup.cpp =================================================================== --- clang/lib/Sema/SemaLookup.cpp +++ clang/lib/Sema/SemaLookup.cpp @@ -1313,6 +1313,9 @@ R.setShadowed(); continue; } + } else if (NameKind == LookupObjCImplicitSelfParam && + !isa(*I)) { + continue; } else { // We found something in this scope, we should not look at the // namespace scope Index: clang/test/CodeGenObjC/ivar-implicit-self-shadow.m =================================================================== --- /dev/null +++ clang/test/CodeGenObjC/ivar-implicit-self-shadow.m @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple x86_64-apple-iossimulator -fobjc-arc -x objective-c -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK +// RUN: %clang_cc1 -triple x86_64-apple-iossimulator -fobjc-arc -x objective-c++ -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK + +__attribute__((objc_root_class)) +@interface Foo +@end + +extern Foo *CreateObject(void) __attribute__((ns_returns_retained)); + +@implementation Foo { + int _ivar; +} + +// CHECK-LABEL: define{{.*}}-[Foo foo]"(ptr noundef %self, ptr noundef %_cmd) #0 { +- (void)foo { + { + Foo *self = CreateObject(); + _ivar = 42; + // CHECK: [[PTR:%.*]] = load ptr, ptr %self.addr, align 8 + // CHECK-NEXT: [[IVAR:%.*]] = load i64, ptr @"OBJC_IVAR_$_Foo._ivar", align 8, {{.*}} + // CHECK-NEXT: [[OFFSET:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 [[IVAR]] + // CHECK-NEXT: store i32 42, ptr [[OFFSET]] + } +} +@end +