From: Fariborz Jahanian Date: Mon, 17 Oct 2011 21:00:22 +0000 (+0000) Subject: obj-c++: Fix a IRGen crash when getter is a reference type. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d12505054130b24f7696440efdbd1aa660feb6f3;p=clang obj-c++: Fix a IRGen crash when getter is a reference type. Fix is in Sema. // rdar://10153365 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142249 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprMember.cpp b/lib/Sema/SemaExprMember.cpp index 26867c21a1..32a5194cec 100644 --- a/lib/Sema/SemaExprMember.cpp +++ b/lib/Sema/SemaExprMember.cpp @@ -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(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 index 0000000000..83d3b9320b --- /dev/null +++ b/test/CodeGenObjCXX/lvalue-reference-getter.mm @@ -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]]