[cfe-commits] r139203 - in /cfe/trunk: lib/Sema/SemaObjCProperty.cpp test/CodeGenObjC/gc-weak-attribute.m

Fariborz Jahanian fjahanian at apple.com
Tue Sep 6 16:32:40 PDT 2011


Author: fjahanian
Date: Tue Sep  6 18:32:40 2011
New Revision: 139203

URL: http://llvm.org/viewvc/llvm-project?rev=139203&view=rev
Log:
objc-gc: Adds support for  "weak" property attribute under GC.
// rdar://10073896

Added:
    cfe/trunk/test/CodeGenObjC/gc-weak-attribute.m
Modified:
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=139203&r1=139202&r2=139203&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Tue Sep  6 18:32:40 2011
@@ -594,6 +594,12 @@
     ObjCPropertyDecl::PropertyAttributeKind kind 
       = property->getPropertyAttributes();
     QualType PropType = Context.getCanonicalType(property->getType());
+    bool PropertyIsGCWeak = (kind & ObjCPropertyDecl::OBJC_PR_weak &&
+                             !getLangOptions().ObjCAutoRefCount &&
+                             getLangOptions().getGCMode() != 
+                             LangOptions::NonGC);
+    if (PropertyIsGCWeak)
+      PropType = Context.getObjCGCQualType(PropType, Qualifiers::Weak);
     QualType PropertyIvarType = PropType;
     if (PropType->isReferenceType())
       PropertyIvarType = cast<ReferenceType>(PropType)->getPointeeType();

Added: cfe/trunk/test/CodeGenObjC/gc-weak-attribute.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/gc-weak-attribute.m?rev=139203&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/gc-weak-attribute.m (added)
+++ cfe/trunk/test/CodeGenObjC/gc-weak-attribute.m Tue Sep  6 18:32:40 2011
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-gc -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck %s
+// rdar://10073896
+
+ at interface I
+{
+  __weak id wObject;
+}
+ at property (readwrite, weak) id representedObject;
+ at property (readwrite, weak) id wObject;
+ at property (readwrite, weak) __weak id wRandom;
+ at property (readwrite, assign) __weak id wAnother;
+ at end
+
+ at implementation I
+ at synthesize representedObject;
+ at synthesize wObject;
+ at synthesize wRandom;
+ at synthesize wAnother;
+ at end
+// CHECK:  call i8* @objc_read_weak
+// CHECK:  call i8* @objc_assign_weak
+// CHECK:  call i8* @objc_read_weak
+// CHECK:  call i8* @objc_assign_weak
+// CHECK:  call i8* @objc_read_weak
+// CHECK:  call i8* @objc_assign_weak
+// CHECK:  call i8* @objc_read_weak
+// CHECK:  call i8* @objc_assign_weak
+





More information about the cfe-commits mailing list