]> granicus.if.org Git - clang/commitdiff
Fix crash when synthesizing property setters when the property type and ivar
authorDaniel Dunbar <daniel@zuster.org>
Tue, 27 Oct 2009 19:21:30 +0000 (19:21 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 27 Oct 2009 19:21:30 +0000 (19:21 +0000)
type have mismatched Objective-C types.
  - <rdar://problem/7336352> [irgen] crash in synthesized property construction

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

lib/CodeGen/CGObjC.cpp
test/CodeGenObjC/synthesize_ivar.m
test/Coverage/objc-language-features.inc

index cadba328bf12ab92658c0d2c5bbfd0247e5a738b..2fe3f5b1b443430cf7508be531eb44ba601e2ebf 100644 (file)
@@ -280,17 +280,29 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP,
     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();
index 7646f707bf76192580263a255cd8184885c87cb3..e1746f1da136c1f184542dfdc0f0208eb3120e84 100644 (file)
@@ -1,8 +1,6 @@
 // RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o %t %s
 
 @interface I
-{
-}
 @property int IP;
 @end
 
 @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
index dd57dfbedd03798bd22a457e973b0319b3f25b7f..dbbf205fcd6b04dc0342af8fda7451354b57ecc1 100644 (file)
@@ -14,6 +14,7 @@
 @interface A : Root <P1> {
   int iv0;
   B *iv1;
+  B<P1> *iv2;
 }
 
 @property(readonly) int p0;
 @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];
 }