[cfe-commits] r113464 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp test/SemaObjC/nonnull.m

Ted Kremenek kremenek at apple.com
Wed Sep 8 18:17:32 PDT 2010


Author: kremenek
Date: Wed Sep  8 20:17:32 2010
New Revision: 113464

URL: http://llvm.org/viewvc/llvm-project?rev=113464&view=rev
Log:
Relax __attribute_((nonnull)) checking to allow the attribute on functions with no pointer arguments.  GCC doesn't warn
in this case, and the attribute is trivially satisfied (and benign).  Fixes <rdar://problem/8364828>.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/SemaObjC/nonnull.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=113464&r1=113463&r2=113464&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep  8 20:17:32 2010
@@ -1016,14 +1016,11 @@
   "type of machine mode does not match type of base type">;
 def err_attr_wrong_decl : Error<
   "'%0' attribute invalid on this declaration, requires typedef or value">;
-def warn_attribute_nonnull_no_pointers : Warning<
-  "'nonnull' attribute applied to function with no pointer arguments">;
 def warn_attribute_malloc_pointer_only : Warning<
   "'malloc' attribute only applies to functions returning a pointer type">;
 def warn_transparent_union_nonpointer : Warning<
   "'transparent_union' attribute support incomplete; only supported for "
   "pointer unions">;
-
 def warn_attribute_sentinel_named_arguments : Warning<
   "'sentinel' attribute requires named arguments">;
 def warn_attribute_sentinel_not_variadic : Warning<

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=113464&r1=113463&r2=113464&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Sep  8 20:17:32 2010
@@ -373,10 +373,10 @@
         NonNullArgs.push_back(I);
     }
 
-    if (NonNullArgs.empty()) {
-      S.Diag(Attr.getLoc(), diag::warn_attribute_nonnull_no_pointers);
+    // No pointer arguments?  The attribute in this case is
+    // trivially satisfied.
+    if (NonNullArgs.empty())
       return;
-    }
   }
 
   unsigned* start = &NonNullArgs[0];

Modified: cfe/trunk/test/SemaObjC/nonnull.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/nonnull.m?rev=113464&r1=113463&r2=113464&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/nonnull.m (original)
+++ cfe/trunk/test/SemaObjC/nonnull.m Wed Sep  8 20:17:32 2010
@@ -2,7 +2,7 @@
 
 @class NSObject;
 
-int f1(int x) __attribute__((nonnull)); // expected-warning{{'nonnull' attribute applied to function with no pointer arguments}}
+int f1(int x) __attribute__((nonnull)); //no-warning
 int f2(int *x) __attribute__ ((nonnull (1)));
 int f3(int *x) __attribute__ ((nonnull (0))); // expected-error {{'nonnull' attribute parameter 1 is out of bounds}}
 int f4(int *x, int *y) __attribute__ ((nonnull (1,2)));
@@ -44,4 +44,4 @@
   func7((NSObject*) 0); // no-warning
 }
 
-void func5(int) __attribute__((nonnull)); // expected-warning{{'nonnull' attribute applied to function with no pointer arguments}}
+void func5(int) __attribute__((nonnull)); // no-warning





More information about the cfe-commits mailing list