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

Fariborz Jahanian fjahanian at apple.com
Sat Feb 21 11:44:03 PST 2009


Author: fjahanian
Date: Sat Feb 21 13:44:02 2009
New Revision: 65240

URL: http://llvm.org/viewvc/llvm-project?rev=65240&view=rev
Log:
Warn on use of __weak attribute on local
variable (objc2 gc specific).

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=65240&r1=65239&r2=65240&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Sat Feb 21 13:44:02 2009
@@ -361,6 +361,8 @@
      "%0 attribute ignored")
 DIAG(warn_attribute_weak_on_field, WARNING,
      "__weak attribute cannot be specified on a field declaration")
+DIAG(warn_attribute_weak_on_local, WARNING,
+     "__weak attribute cannot be specified on an automatic variable")
 DIAG(warn_attribute_wrong_decl_type, WARNING,
      "'%0' attribute only applies to %select{function|union|"
      "variable and function|function or method}1 types")

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=65240&r1=65239&r2=65240&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Feb 21 13:44:02 2009
@@ -1592,6 +1592,11 @@
     Diag(D.getIdentifierLoc(), diag::err_as_qualified_auto_decl);
     InvalidDecl = true;
   }
+
+  if (NewVD->hasLocalStorage() && NewVD->getType().isObjCGCWeak()) {
+    Diag(D.getIdentifierLoc(), diag::warn_attribute_weak_on_local);
+  }
+
   // Merge the decl with the existing one if appropriate. If the decl is
   // in an outer scope, it isn't the same thing.
   if (PrevDecl && isDeclInScope(PrevDecl, DC, S)) {

Added: 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=65240&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/objc2-warn-weak-decl.m (added)
+++ cfe/trunk/test/SemaObjC/objc2-warn-weak-decl.m Sat Feb 21 13:44:02 2009
@@ -0,0 +1,10 @@
+// RUN: clang -fsyntax-only -fobjc-gc -verify %s
+struct S {
+	__weak id  p;  // expected-warning {{__weak attribute cannot be specified on a field declaration}}
+};
+
+int main ()
+{
+  __weak id  local;  // expected-warning {{__weak attribute cannot be specified on an automatic variable}}
+}
+





More information about the cfe-commits mailing list