[cfe-commits] r75856 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp test/Sema/nonnull.c test/SemaObjC/nonnull.m

Ted Kremenek kremenek at apple.com
Wed Jul 15 16:23:56 PDT 2009


Author: kremenek
Date: Wed Jul 15 18:23:54 2009
New Revision: 75856

URL: http://llvm.org/viewvc/llvm-project?rev=75856&view=rev
Log:
Handle some more fallout with the conversion of using PointerType for
Objective-C pointers to using ObjCObjectPointerType.

Now the checking for 'attribute ((nonnull))' in Sema doesn't emit an error when
trying to apply that attribute to a parameter that is an Objective-C pointer
(this is a regression).

To prevent this regression from occuring in the future, the 'nonnull.c' test was
moved to test/SemaObjC and renamed 'nonnull.m'. I also enhanced the tests to
show that function calls involved a NULL Objective-C pointer constant does not
trigger a warning. This is consistent with GCC, but should likely be fixed.

Added:
    cfe/trunk/test/SemaObjC/nonnull.m
      - copied, changed from r75851, cfe/trunk/test/Sema/nonnull.c
Removed:
    cfe/trunk/test/Sema/nonnull.c
Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Jul 15 18:23:54 2009
@@ -352,7 +352,7 @@
 
     // Is the function argument a pointer type?
     QualType T = getFunctionOrMethodArgType(d, x);    
-    if (!T->isPointerType() && !T->isBlockPointerType()) {
+    if (!T->isAnyPointerType() && !T->isBlockPointerType()) {
       // FIXME: Should also highlight argument in decl.
       S.Diag(Attr.getLoc(), diag::err_nonnull_pointers_only)
         << "nonnull" << Ex->getSourceRange();
@@ -367,7 +367,7 @@
   if (NonNullArgs.empty()) {
     for (unsigned I = 0, E = getFunctionOrMethodNumArgs(d); I != E; ++I) {
       QualType T = getFunctionOrMethodArgType(d, I);
-      if (T->isPointerType() || T->isBlockPointerType())
+      if (T->isAnyPointerType() || T->isBlockPointerType())
         NonNullArgs.push_back(I);
     }
     

Removed: cfe/trunk/test/Sema/nonnull.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/nonnull.c?rev=75855&view=auto

==============================================================================
--- cfe/trunk/test/Sema/nonnull.c (original)
+++ cfe/trunk/test/Sema/nonnull.c (removed)
@@ -1,32 +0,0 @@
-// RUN: clang-cc -fblocks -fsyntax-only -verify %s
-
-int f1(int x) __attribute__((nonnull)); // expected-warning{{'nonnull' attribute applied to function with no pointer arguments}}
-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)));
-int f5(int *x, int *y) __attribute__ ((nonnull (2,1)));
-
-extern void func1 (void (^block1)(), void (^block2)(), int) __attribute__((nonnull));
-
-extern void func3 (void (^block1)(), int, void (^block2)(), int)
-__attribute__((nonnull(1,3)));
-
-extern void func4 (void (^block1)(), void (^block2)()) __attribute__((nonnull(1)))
-__attribute__((nonnull(2)));
-
-void
-foo (int i1, int i2, int i3, void (^cp1)(), void (^cp2)(), void (^cp3)())
-{
-  func1(cp1, cp2, i1);
-  
-  func1(0, cp2, i1);  // expected-warning {{null passed to a callee which requires a non-null argument}}
-  func1(cp1, 0, i1);  // expected-warning {{null passed to a callee which requires a non-null argument}}
-  func1(cp1, cp2, 0);
-  
-  
-  func3(0, i2, cp3, i3); // expected-warning {{null passed to a callee which requires a non-null argument}}
-  func3(cp3, i2, 0, i3);  // expected-warning {{null passed to a callee which requires a non-null argument}}
-  
-  func4(0, cp1); // expected-warning {{null passed to a callee which requires a non-null argument}}
-  func4(cp1, 0); // expected-warning {{null passed to a callee which requires a non-null argument}}
-}

Copied: cfe/trunk/test/SemaObjC/nonnull.m (from r75851, cfe/trunk/test/Sema/nonnull.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/nonnull.m?p2=cfe/trunk/test/SemaObjC/nonnull.m&p1=cfe/trunk/test/Sema/nonnull.c&r1=75851&r2=75856&rev=75856&view=diff

==============================================================================
--- cfe/trunk/test/Sema/nonnull.c (original)
+++ cfe/trunk/test/SemaObjC/nonnull.m Wed Jul 15 18:23:54 2009
@@ -1,10 +1,15 @@
 // RUN: clang-cc -fblocks -fsyntax-only -verify %s
 
+ at class NSObject;
+
 int f1(int x) __attribute__((nonnull)); // expected-warning{{'nonnull' attribute applied to function with no pointer arguments}}
 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)));
 int f5(int *x, int *y) __attribute__ ((nonnull (2,1)));
+int f6(NSObject *x) __attribute__ ((nonnull (1))); // no-warning
+int f7(NSObject *x) __attribute__ ((nonnull)); // no-warning
+
 
 extern void func1 (void (^block1)(), void (^block2)(), int) __attribute__((nonnull));
 
@@ -29,4 +34,9 @@
   
   func4(0, cp1); // expected-warning {{null passed to a callee which requires a non-null argument}}
   func4(cp1, 0); // expected-warning {{null passed to a callee which requires a non-null argument}}
+  
+  // Shouldn't these emit warnings?  Clang doesn't, and neither does GCC.  It
+  // seems that the checking should handle Objective-C pointers.
+  func6((NSObject*) 0); // no-warning
+  func7((NSObject*) 0); // no-warning
 }





More information about the cfe-commits mailing list