Author: ddunbar
Date: Tue Oct 27 14:21:30 2009
New Revision: 85275
URL: http://llvm.org/viewvc/llvm-project?rev=85275&view=rev
Log:
Fix crash when synthesizing property setters when the property type and ivar
type have mismatched Objective-C types.
- <rdar://problem/7336352> [irgen] crash in synthesized property construction
Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjC/synthesize_ivar.m
cfe/trunk/test/Coverage/objc-language-features.inc
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=85275&r1=85274&r2=85275&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Oct 27 14:21:30 2009
@@ -280,17 +280,29 @@
EmitCall(Types.getFunctionInfo(getContext().VoidTy, Args),
SetPropertyFn, Args);
} else {
+ // FIXME: Find a clean way to avoid AST node creation.
SourceLocation Loc = PD->getLocation();
ValueDecl *Self = OMD->getSelfDecl();
ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl();
DeclRefExpr Base(Self, Self->getType(), Loc);
ParmVarDecl *ArgDecl = *OMD->param_begin();
DeclRefExpr Arg(ArgDecl, ArgDecl->getType(), Loc);
- ObjCIvarRefExpr IvarRef(Ivar, Ivar->getType(), Loc, &Base,
- true, true);
- BinaryOperator Assign(&IvarRef, &Arg, BinaryOperator::Assign,
- Ivar->getType(), Loc);
- EmitStmt(&Assign);
+ ObjCIvarRefExpr IvarRef(Ivar, Ivar->getType(), Loc, &Base, true, true);
+
+ // The property type can differ from the ivar type in some situations with
+ // Objective-C pointer types, we can always bit cast the RHS in these
cases.
+ if (getContext().getCanonicalType(Ivar->getType()) !=
+ getContext().getCanonicalType(ArgDecl->getType())) {
+ ImplicitCastExpr ArgCasted(Ivar->getType(), CastExpr::CK_BitCast, &Arg,
+ false);
+ BinaryOperator Assign(&IvarRef, &ArgCasted, BinaryOperator::Assign,
+ Ivar->getType(), Loc);
+ EmitStmt(&Assign);
+ } else {
+ BinaryOperator Assign(&IvarRef, &Arg, BinaryOperator::Assign,
+ Ivar->getType(), Loc);
+ EmitStmt(&Assign);
+ }
}
FinishFunction();
Modified: cfe/trunk/test/CodeGenObjC/synthesize_ivar.m
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/synthesize_ivar.m?rev=85275&r1=85274&r2=85275&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/synthesize_ivar.m (original)
+++ cfe/trunk/test/CodeGenObjC/synthesize_ivar.m Tue Oct 27 14:21:30 2009
@@ -1,8 +1,6 @@
// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o %t %s
@interface I
-{
-}
@property int IP;
@end
@@ -25,3 +23,16 @@
@implementation OrganizerViolatorView
@synthesize bindingInfo;
@end
+
+// <rdar://problem/7336352> [irgen] crash in synthesized property construction
+
+...@interface I0 @end
+...@protocol P0 @end
+...@interface I1 {
+ I0<P0> *iv0;
+}
+...@property (assign, readwrite) id p0;
+...@end
+...@implementation I1
+...@synthesize p0 = iv0;
+...@end
Modified: cfe/trunk/test/Coverage/objc-language-features.inc
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/objc-language-features.inc?rev=85275&r1=85274&r2=85275&view=diff
==============================================================================
--- cfe/trunk/test/Coverage/objc-language-features.inc (original)
+++ cfe/trunk/test/Coverage/objc-language-features.inc Tue Oct 27 14:21:30 2009
@@ -14,6 +14,7 @@
@interface A : Root <P1> {
int iv0;
B *iv1;
+ B<P1> *iv2;
}
@property(readonly) int p0;
@@ -21,11 +22,16 @@
@property(copy) id p2;
@property(retain) id p3;
@property(assign, getter=getme, setter=setme:) id p4;
+...@property(assign, readwrite) id p5;
@end
@implementation A
@dynamic p0;
@synthesize p1 = iv0;
+
+// Property type can differ from ivar type.
+...@synthesize p5 = iv2;
+
+(void) fm0 {
[super fm0];
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits