[cfe-commits] r132731 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaObjC/objc2-warn-weak-decl.m

Fariborz Jahanian fjahanian at apple.com
Tue Jun 7 13:15:46 PDT 2011


Author: fjahanian
Date: Tue Jun  7 15:15:46 2011
New Revision: 132731

URL: http://llvm.org/viewvc/llvm-project?rev=132731&view=rev
Log:
More coherent diagnostic when a stack variable is
declared __weak objc-gc mode.  // rdar://9666091.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaObjC/objc2-warn-weak-decl.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=132731&r1=132730&r2=132731&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jun  7 15:15:46 2011
@@ -1178,6 +1178,8 @@
   "%select{functions|Objective-C method}1 without return value">;
 def warn_attribute_weak_on_field : Warning<
   "__weak attribute cannot be specified on a field declaration">;
+def warn_gc_attribute_weak_on_local : Warning<
+  "Objective-C GC does not allow weak variables on the stack">;
 def warn_attribute_weak_on_local : Warning<
   "__weak attribute cannot be specified on an automatic variable">;
 def warn_weak_identifier_undeclared : Warning<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=132731&r1=132730&r2=132731&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jun  7 15:15:46 2011
@@ -3850,8 +3850,12 @@
   }
 
   if (NewVD->hasLocalStorage() && T.isObjCGCWeak()
-      && !NewVD->hasAttr<BlocksAttr>())
-    Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local);
+      && !NewVD->hasAttr<BlocksAttr>()) {
+    if (getLangOptions().getGCMode() != LangOptions::NonGC)
+      Diag(NewVD->getLocation(), diag::warn_gc_attribute_weak_on_local);
+    else
+      Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local);
+  }
   
   bool isVM = T->isVariablyModifiedType();
   if (isVM || NewVD->hasAttr<CleanupAttr>() ||

Modified: cfe/trunk/test/SemaObjC/objc2-warn-weak-decl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc2-warn-weak-decl.m?rev=132731&r1=132730&r2=132731&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objc2-warn-weak-decl.m (original)
+++ cfe/trunk/test/SemaObjC/objc2-warn-weak-decl.m Tue Jun  7 15:15:46 2011
@@ -6,6 +6,6 @@
 
 int main ()
 {
-  __weak id  local;  // expected-warning {{__weak attribute cannot be specified on an automatic variable}}
+  __weak id  local;  // expected-warning {{Objective-C GC does not allow weak variables on the stack}}
 }
 





More information about the cfe-commits mailing list