]> granicus.if.org Git - clang/commitdiff
objc-gc: More sema work for properties declared 'weak'
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 7 Sep 2011 16:24:21 +0000 (16:24 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 7 Sep 2011 16:24:21 +0000 (16:24 +0000)
in GC mode. // rdar://10073896

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/error-property-gc-attr.m

index e39a2c72f3882863e5fd385dab5f39ced1d6728e..a90849cc196940f62120047ff9db4e732612b036 100644 (file)
@@ -549,6 +549,9 @@ def err_arc_perform_selector_retains : Error<
 def warn_arc_perform_selector_leaks : Warning<
   "performSelector may cause a leak because its selector is unknown">,
   InGroup<DiagGroup<"arc-performSelector-leaks">>;
+def err_gc_weak_property_strong_type : Error<
+  "weak attribute declared on a __strong type property"
+  "in GC mode">;
 
 def error_synthesized_ivar_yet_not_supported : Error<
   "instance variable synthesis not yet supported"
index 9695b811ee57aad659c9efbfd8cbd0df30960151..9f50dea233bc5ea4214b67fbdfe6cdaf633ac795 100644 (file)
@@ -594,12 +594,18 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
     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.isObjCGCStrong())
-      PropType = Context.getObjCGCQualType(PropType, Qualifiers::Weak);
+    
+    if ((kind & ObjCPropertyDecl::OBJC_PR_weak) &&
+        !getLangOptions().ObjCAutoRefCount &&
+        getLangOptions().getGCMode() != LangOptions::NonGC) {
+      if (PropType.isObjCGCStrong()) {
+          Diag(PropertyLoc,
+               diag::err_gc_weak_property_strong_type);
+          Diag(property->getLocation(), diag::note_property_declare);    
+      }
+      else
+        PropType = Context.getObjCGCQualType(PropType, Qualifiers::Weak);
+    }
     QualType PropertyIvarType = PropType;
     if (PropType->isReferenceType())
       PropertyIvarType = cast<ReferenceType>(PropType)->getPointeeType();
@@ -721,6 +727,7 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
            getLangOptions().getGCMode() != LangOptions::NonGC)) {
         Diag(PropertyLoc, diag::error_weak_property)
         << property->getDeclName() << Ivar->getDeclName();
+        Diag(Ivar->getLocation(), diag::note_ivar_decl);
         // Fall thru - see previous comment
       }
       // Fall thru - see previous comment
index 829c082287474ecbee4dbcb6ceaa42f51eccca2e..25fee051174b3850fbccc86bb689e2cbc8c1191b 100644 (file)
@@ -3,7 +3,7 @@
 
 @interface INTF
 {
-  id IVAR;
+  id IVAR; // expected-note {{ivar is declared here}}
   __weak id II;
   __weak id WID;
   id ID;