[cfe-commits] r82183 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CGValue.h test/CodeGenObjC/objc2-write-barrier-2.m

Fariborz Jahanian fjahanian at apple.com
Thu Sep 17 17:04:01 PDT 2009


Author: fjahanian
Date: Thu Sep 17 19:04:00 2009
New Revision: 82183

URL: http://llvm.org/viewvc/llvm-project?rev=82183&view=rev
Log:
Fixed a bug in generation of the new write-barriers when 
array syntax is used to derefernce and assign to ivar pointee.


Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGValue.h
    cfe/trunk/test/CodeGenObjC/objc2-write-barrier-2.m

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=82183&r1=82182&r2=82183&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Sep 17 19:04:00 2009
@@ -697,6 +697,7 @@
   
   if (isa<ObjCIvarRefExpr>(E)) {
     LV.SetObjCIvar(LV, true);
+    LV.SetObjCIvarArray(LV, E->getType()->isArrayType());
     return;
   }
   if (const DeclRefExpr *Exp = dyn_cast<DeclRefExpr>(E)) {
@@ -714,10 +715,19 @@
     setObjCGCLValueClass(Ctx, Exp->getSubExpr(), LV);
   else if (const CStyleCastExpr *Exp = dyn_cast<CStyleCastExpr>(E))
     setObjCGCLValueClass(Ctx, Exp->getSubExpr(), LV);
-  else if (const ArraySubscriptExpr *Exp = dyn_cast<ArraySubscriptExpr>(E))
+  else if (const ArraySubscriptExpr *Exp = dyn_cast<ArraySubscriptExpr>(E)) {
     setObjCGCLValueClass(Ctx, Exp->getBase(), LV);
+    if (LV.isObjCIvar() && !LV.isObjCIvarArray()) {
+      // Using array syntax to assigning to what an ivar points to is not 
+      // same as assigning to the ivar itself. {id *Names;} Names[i] = 0;
+      LV.SetObjCIvar(LV, false); 
+    }
+  }
   else if (const MemberExpr *Exp = dyn_cast<MemberExpr>(E)) {
     setObjCGCLValueClass(Ctx, Exp->getBase(), LV);
+    // We don't know if member is an 'ivar', but this flag is looked at
+    // only in the context of LV.isObjCIvar().
+    LV.SetObjCIvarArray(LV, E->getType()->isArrayType());
   }
 }
 

Modified: cfe/trunk/lib/CodeGen/CGValue.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGValue.h?rev=82183&r1=82182&r2=82183&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGValue.h (original)
+++ cfe/trunk/lib/CodeGen/CGValue.h Thu Sep 17 19:04:00 2009
@@ -152,6 +152,9 @@
 
   // objective-c's ivar
   bool Ivar:1;
+  
+  // objective-c's ivar is an array
+  bool IvarArray:1;
 
   // LValue is non-gc'able for any reason, including being a parameter or local
   // variable.
@@ -173,7 +176,7 @@
     // FIXME: Convenient place to set objc flags to 0. This should really be
     // done in a user-defined constructor instead.
     R.ObjCType = None;
-    R.Ivar = R.NonGC = R.GlobalObjCRef = false;
+    R.Ivar = R.IvarArray = R.NonGC = R.GlobalObjCRef = false;
   }
 
 public:
@@ -192,6 +195,7 @@
   }
 
   bool isObjCIvar() const { return Ivar; }
+  bool isObjCIvarArray() const { return IvarArray; }
   bool isNonGC () const { return NonGC; }
   bool isGlobalObjCRef() const { return GlobalObjCRef; }
   bool isObjCWeak() const { return ObjCType == Weak; }
@@ -202,7 +206,9 @@
   static void SetObjCIvar(LValue& R, bool iValue) {
     R.Ivar = iValue;
   }
-
+  static void SetObjCIvarArray(LValue& R, bool iValue) {
+    R.IvarArray = iValue;
+  }
   static void SetGlobalObjCRef(LValue& R, bool iValue) {
     R.GlobalObjCRef = iValue;
   }

Modified: cfe/trunk/test/CodeGenObjC/objc2-write-barrier-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/objc2-write-barrier-2.m?rev=82183&r1=82182&r2=82183&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenObjC/objc2-write-barrier-2.m (original)
+++ cfe/trunk/test/CodeGenObjC/objc2-write-barrier-2.m Thu Sep 17 19:04:00 2009
@@ -1,7 +1,7 @@
 // RUN: clang-cc -fnext-runtime -fobjc-gc -fobjc-newgc-api -emit-llvm -o %t %s &&
 // RUN: grep -F '@objc_assign_global' %t  | count 7 &&
-// RUN: grep -F '@objc_assign_ivar' %t  | count 4 &&
-// RUN: grep -F '@objc_assign_strongCast' %t  | count 4 &&
+// RUN: grep -F '@objc_assign_ivar' %t  | count 5 &&
+// RUN: grep -F '@objc_assign_strongCast' %t  | count 8 &&
 // RUN: true
 
 extern id **somefunc(void);
@@ -50,3 +50,31 @@
     *ppptr = somefunc2(); 
 }
 
+typedef const struct __CFString * CFStringRef;
+ at interface DSATextSearch {
+__strong CFStringRef *_documentNames;
+  struct {
+    id *innerNames;
+    struct {
+      id *nestedDeeperNames; 
+      struct I {
+         id *is1;
+         id is2[5];
+      } arrI [3];
+    } inner_most;
+  } inner;
+
+}
+- filter;
+ at end
+ at implementation DSATextSearch
+- filter {
+  int filteredPos = 0;
+  _documentNames[filteredPos] = 0; // storing into an element of array ivar. objc_assign_strongCast is needed.
+  inner.innerNames[filteredPos] = 0;
+  inner.inner_most.nestedDeeperNames[filteredPos] = 0;
+  inner.inner_most.arrI[3].is1[5] = 0;
+  inner.inner_most.arrI[3].is2[5] = 0;
+}
+ at end
+





More information about the cfe-commits mailing list