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

Fariborz Jahanian fjahanian at apple.com
Mon Sep 27 12:05:51 PDT 2010


Author: fjahanian
Date: Mon Sep 27 14:05:51 2010
New Revision: 114860

URL: http://llvm.org/viewvc/llvm-project?rev=114860&view=rev
Log:
Issue warning for trivial cases of nonnull attributes
(on functions with no pointer arguments) but only when
the attribute has not been coming from a macro 
instantiation in a header file. Fixes first part
of radar 6857843.

Added:
    cfe/trunk/test/SemaObjC/nonnull.h
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=114860&r1=114859&r2=114860&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 27 14:05:51 2010
@@ -1020,6 +1020,8 @@
   "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<

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=114860&r1=114859&r2=114860&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Sep 27 14:05:51 2010
@@ -375,8 +375,13 @@
 
     // No pointer arguments?  The attribute in this case is
     // trivially satisfied.
-    if (NonNullArgs.empty())
+    if (NonNullArgs.empty()) {
+      // Warn the trivial case only if attribute is not coming from a
+      // macro instantiation.
+      if (Attr.getLoc().isFileID())
+        S.Diag(Attr.getLoc(), diag::warn_attribute_nonnull_no_pointers);
       return;
+    }
   }
 
   unsigned* start = &NonNullArgs[0];

Added: cfe/trunk/test/SemaObjC/nonnull.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/nonnull.h?rev=114860&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/nonnull.h (added)
+++ cfe/trunk/test/SemaObjC/nonnull.h Mon Sep 27 14:05:51 2010
@@ -0,0 +1,2 @@
+// rdar: //6857843
+#define NONNULL_ATTR __attribute__((nonnull))

Modified: cfe/trunk/test/SemaObjC/nonnull.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/nonnull.m?rev=114860&r1=114859&r2=114860&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/nonnull.m (original)
+++ cfe/trunk/test/SemaObjC/nonnull.m Mon Sep 27 14:05:51 2010
@@ -1,8 +1,11 @@
+#include "nonnull.h"
+
 // RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s
 
 @class NSObject;
 
-int f1(int x) __attribute__((nonnull)); //no-warning
+NONNULL_ATTR
+int f1(int x); //  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 +47,4 @@
   func7((NSObject*) 0); // no-warning
 }
 
-void func5(int) __attribute__((nonnull)); // no-warning
+void func5(int) NONNULL_ATTR; //  no warning





More information about the cfe-commits mailing list