diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-06-07 22:02:01 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-06-07 22:02:01 +0000 |
commit | e2a901a1883a74469bdcd22e38f52b3f877bc6ca (patch) | |
tree | 760917824764b222adfbc6e9a6e320a0301d9001 | |
parent | 19739ae839fd4ebe472da4bdb9d65df452313ae4 (diff) |
When using property-dot assignment syntax to call a setter method,
type of rhs need be compared to setter's argument and
not the getter type. Fixes radar 8062778
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105560 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGObjC.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 15 | ||||
-rw-r--r-- | test/CodeGenObjC/dot-syntax-2.m | 27 |
3 files changed, 44 insertions, 4 deletions
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 7c842a9498..95be0dd120 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -595,7 +595,8 @@ void CodeGenFunction::EmitObjCPropertySet(const Expr *Exp, Args); } else if (const ObjCImplicitSetterGetterRefExpr *E = dyn_cast<ObjCImplicitSetterGetterRefExpr>(Exp)) { - Selector S = E->getSetterMethod()->getSelector(); + const ObjCMethodDecl *SetterMD = E->getSetterMethod(); + Selector S = SetterMD->getSelector(); CallArgList Args; llvm::Value *Receiver; if (E->getInterfaceDecl()) { @@ -606,7 +607,8 @@ void CodeGenFunction::EmitObjCPropertySet(const Expr *Exp, return; } else Receiver = EmitScalarExpr(E->getBase()); - Args.push_back(std::make_pair(Src, E->getType())); + ObjCMethodDecl::param_iterator P = SetterMD->param_begin(); + Args.push_back(std::make_pair(Src, (*P)->getType())); CGM.getObjCRuntime().GenerateMessageSend(*this, ReturnValueSlot(), getContext().VoidTy, S, Receiver, diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 7152f04b88..3473ef0090 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -5796,11 +5796,22 @@ QualType Sema::CheckAssignmentOperands(Expr *LHS, Expr *&RHS, QualType LHSType = LHS->getType(); QualType RHSType = CompoundType.isNull() ? RHS->getType() : CompoundType; - AssignConvertType ConvTy; if (CompoundType.isNull()) { + QualType LHSTy(LHSType); // Simple assignment "x = y". - ConvTy = CheckSingleAssignmentConstraints(LHSType, RHS); + if (const ObjCImplicitSetterGetterRefExpr *OISGE = + dyn_cast<ObjCImplicitSetterGetterRefExpr>(LHS)) { + // If using property-dot syntax notation for assignment, and there is a + // setter, RHS expression is being passed to the setter argument. So, + // type conversion (and comparison) is RHS to setter's argument type. + if (const ObjCMethodDecl *SetterMD = OISGE->getSetterMethod()) { + ObjCMethodDecl::param_iterator P = SetterMD->param_begin(); + LHSTy = (*P)->getType(); + } + } + + ConvTy = CheckSingleAssignmentConstraints(LHSTy, RHS); // Special case of NSObject attributes on c-style pointer types. if (ConvTy == IncompatiblePointer && ((Context.isObjCNSObjectType(LHSType) && diff --git a/test/CodeGenObjC/dot-syntax-2.m b/test/CodeGenObjC/dot-syntax-2.m new file mode 100644 index 0000000000..020868a807 --- /dev/null +++ b/test/CodeGenObjC/dot-syntax-2.m @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -emit-llvm -o %t %s +// rdar: // 8062778 + +@interface NSDictionary @end + +@interface NSMutableDictionary : NSDictionary +@end + +@interface MutableMyClass +- (NSMutableDictionary *)myDict; +- (void)setMyDict:(NSDictionary *)myDict; + +- (NSMutableDictionary *)myLang; +- (void)setMyLang:(NSDictionary *)myLang; +@end + +@interface AnotherClass @end + +@implementation AnotherClass +- (void)foo +{ + MutableMyClass * myObject; + NSDictionary * newDict; + myObject.myDict = newDict; + myObject.myLang = newDict; +} +@end |