]> granicus.if.org Git - clang/commitdiff
obj-c++: Fix a IRGen crash when getter is a reference type.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 17 Oct 2011 21:00:22 +0000 (21:00 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 17 Oct 2011 21:00:22 +0000 (21:00 +0000)
Fix is in Sema. // rdar://10153365

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142249 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprMember.cpp
test/CodeGenObjCXX/lvalue-reference-getter.mm [new file with mode: 0644]

index 26867c21a1aa78d97b06b1c2751060fa6709ec56..32a5194cec4c572b9f2e67f626e37028de585373 100644 (file)
@@ -813,6 +813,15 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
       !SuppressQualifierCheck &&
       CheckQualifiedMemberReference(BaseExpr, BaseType, SS, R))
     return ExprError();
+  
+  // Perform a property load on the base regardless of whether we
+  // actually need it for the declaration.
+  if (BaseExpr && BaseExpr->getObjectKind() == OK_ObjCProperty) {
+    ExprResult Result = ConvertPropertyForRValue(BaseExpr);
+    if (Result.isInvalid())
+      return ExprError();
+    BaseExpr = Result.take();
+  }
 
   // Construct an unresolved result if we in fact got an unresolved
   // result.
@@ -870,15 +879,6 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
     return ExprError();
   }
 
-  // Perform a property load on the base regardless of whether we
-  // actually need it for the declaration.
-  if (BaseExpr->getObjectKind() == OK_ObjCProperty) {
-    ExprResult Result = ConvertPropertyForRValue(BaseExpr);
-    if (Result.isInvalid())
-      return ExprError();
-    BaseExpr = Result.take();
-  }
-
   if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl))
     return BuildFieldReferenceExpr(*this, BaseExpr, IsArrow,
                                    SS, FD, FoundDecl, MemberNameInfo);
diff --git a/test/CodeGenObjCXX/lvalue-reference-getter.mm b/test/CodeGenObjCXX/lvalue-reference-getter.mm
new file mode 100644 (file)
index 0000000..83d3b93
--- /dev/null
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
+// rdar://10153365
+
+static int gint;
+struct SetSection { 
+      int & at(int __n) { return gint; }
+      const int& at(int __n) const { return gint; }
+};
+
+static SetSection gSetSection;
+
+@interface SetShow
+- (SetSection&)sections;
+@end
+
+@implementation SetShow
+- (SetSection&) sections {
+//  [self sections].at(100);
+    self.sections.at(100);
+   return gSetSection;
+}
+@end
+
+// CHECK: [[SELF:%.*]] = alloca [[T6:%.*]]*, align
+// CHECK: [[T0:%.*]] = load {{.*}}* [[SELF]], align
+// CHECK: [[T1:%.*]] = load {{.*}}* @"\01L_OBJC_SELECTOR_REFERENCES_"
+// CHECK: [[C:%.*]] = call %struct.SetSection* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
+// CHECK: call i32* @_ZN10SetSection2atEi(%struct.SetSection* [[C]]