[cfe-commits] r82472 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CGValue.h test/CodeGenObjC/objc2-new-gc-api-strongcast.m

Fariborz Jahanian fjahanian at apple.com
Mon Sep 21 11:54:29 PDT 2009


Author: fjahanian
Date: Mon Sep 21 13:54:29 2009
New Revision: 82472

URL: http://llvm.org/viewvc/llvm-project?rev=82472&view=rev
Log:
Miscellanous fixes in generatation of objc gc's write-barriers.


Added:
    cfe/trunk/test/CodeGenObjC/objc2-new-gc-api-strongcast.m
Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGValue.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Sep 21 13:54:29 2009
@@ -697,7 +697,7 @@
   
   if (isa<ObjCIvarRefExpr>(E)) {
     LV.SetObjCIvar(LV, true);
-    LV.SetObjCIvarArray(LV, E->getType()->isArrayType());
+    LV.SetObjCArray(LV, E->getType()->isArrayType());
     return;
   }
   if (const DeclRefExpr *Exp = dyn_cast<DeclRefExpr>(E)) {
@@ -706,6 +706,7 @@
           VD->isFileVarDecl())
         LV.SetGlobalObjCRef(LV, true);
     }
+    LV.SetObjCArray(LV, E->getType()->isArrayType());
   }
   else if (const UnaryOperator *Exp = dyn_cast<UnaryOperator>(E))
     setObjCGCLValueClass(Ctx, Exp->getSubExpr(), LV);
@@ -717,17 +718,20 @@
     setObjCGCLValueClass(Ctx, Exp->getSubExpr(), LV);
   else if (const ArraySubscriptExpr *Exp = dyn_cast<ArraySubscriptExpr>(E)) {
     setObjCGCLValueClass(Ctx, Exp->getBase(), LV);
-    if (LV.isObjCIvar() && !LV.isObjCIvarArray()) {
+    if (LV.isObjCIvar() && !LV.isObjCArray()) 
       // 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 (LV.isGlobalObjCRef() && !LV.isObjCArray())
+      // Using array syntax to assigning to what global points to is not 
+      // same as assigning to the global itself. {id *G;} G[i] = 0;
+      LV.SetGlobalObjCRef(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());
+    LV.SetObjCArray(LV, E->getType()->isArrayType());
   }
 }
 
@@ -1130,19 +1134,11 @@
   }
   if (Field->getType()->isReferenceType())
     V = Builder.CreateLoad(V, "tmp");
-
-  QualType::GCAttrTypes attr = QualType::GCNone;
-  if (CGM.getLangOptions().ObjC1 &&
-      CGM.getLangOptions().getGCMode() != LangOptions::NonGC) {
-    QualType Ty = Field->getType();
-    attr = Ty.getObjCGCAttr();
-    if (attr != QualType::GCNone) {
-      // __weak attribute on a field is ignored.
-      if (attr == QualType::Weak)
-        attr = QualType::GCNone;
-    } else if (Ty->isObjCObjectPointerType())
-      attr = QualType::Strong;
-  }
+  QualType::GCAttrTypes attr = getContext().getObjCGCAttrKind(Field->getType());
+  // __weak attribute on a field is ignored.
+  if (attr == QualType::Weak)
+    attr = QualType::GCNone;
+  
   LValue LV =
     LValue::MakeAddr(V,
                      Field->getType().getCVRQualifiers()|CVRQualifiers,

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGValue.h (original)
+++ cfe/trunk/lib/CodeGen/CGValue.h Mon Sep 21 13:54:29 2009
@@ -154,7 +154,7 @@
   bool Ivar:1;
   
   // objective-c's ivar is an array
-  bool IvarArray:1;
+  bool ObjIsArray:1;
 
   // LValue is non-gc'able for any reason, including being a parameter or local
   // variable.
@@ -176,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.IvarArray = R.NonGC = R.GlobalObjCRef = false;
+    R.Ivar = R.ObjIsArray = R.NonGC = R.GlobalObjCRef = false;
   }
 
 public:
@@ -195,7 +195,7 @@
   }
 
   bool isObjCIvar() const { return Ivar; }
-  bool isObjCIvarArray() const { return IvarArray; }
+  bool isObjCArray() const { return ObjIsArray; }
   bool isNonGC () const { return NonGC; }
   bool isGlobalObjCRef() const { return GlobalObjCRef; }
   bool isObjCWeak() const { return ObjCType == Weak; }
@@ -206,8 +206,8 @@
   static void SetObjCIvar(LValue& R, bool iValue) {
     R.Ivar = iValue;
   }
-  static void SetObjCIvarArray(LValue& R, bool iValue) {
-    R.IvarArray = iValue;
+  static void SetObjCArray(LValue& R, bool iValue) {
+    R.ObjIsArray = iValue;
   }
   static void SetGlobalObjCRef(LValue& R, bool iValue) {
     R.GlobalObjCRef = iValue;

Added: cfe/trunk/test/CodeGenObjC/objc2-new-gc-api-strongcast.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/objc2-new-gc-api-strongcast.m?rev=82472&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/objc2-new-gc-api-strongcast.m (added)
+++ cfe/trunk/test/CodeGenObjC/objc2-new-gc-api-strongcast.m Mon Sep 21 13:54:29 2009
@@ -0,0 +1,26 @@
+// RUN: clang-cc -triple x86_64-apple-darwin10 -fblocks -fnext-runtime -fobjc-gc -fobjc-newgc-api -emit-llvm -o %t %s &&
+// RUN: grep -F '@objc_assign_strongCast' %t  | count 4 &&
+// RUN: true
+
+ at interface DSATextSearch @end
+
+DSATextSearch **_uniqueIdToIdentifierArray = ((void *)0);
+void foo (int _nextId)
+{
+	_uniqueIdToIdentifierArray[_nextId] = 0;  // objc_assign_strongCast
+}
+
+typedef struct {
+    unsigned long state;
+    id *itemsPtr;
+    void (^bp)();
+    unsigned long *mutationsPtr;
+    unsigned long extra[5];
+} NSFastEnumerationState;
+
+void foo1 (NSFastEnumerationState * state)
+{
+   state->itemsPtr = 0;
+   state->bp = ^{};
+}
+





More information about the cfe-commits mailing list