]> granicus.if.org Git - clang/commitdiff
Handle some more fallout with the conversion of using PointerType for
authorTed Kremenek <kremenek@apple.com>
Wed, 15 Jul 2009 23:23:54 +0000 (23:23 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 15 Jul 2009 23:23:54 +0000 (23:23 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75856 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/SemaObjC/nonnull.m [moved from test/Sema/nonnull.c with 80% similarity]

index bdf6ca13a355acc295abe4d78e751b5e7b0143c0..f5babc19be1e28f4e38e957ac3eaee3e0badd5bb 100644 (file)
@@ -352,7 +352,7 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
 
     // 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 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   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);
     }
     
similarity index 80%
rename from test/Sema/nonnull.c
rename to test/SemaObjC/nonnull.m
index 3bed2feb5012b908b8aabf5460df3585dcff4828..869bbbd57e85e0cb0e58607b66f3b8a4dea965fd 100644 (file)
@@ -1,10 +1,15 @@
 // RUN: clang-cc -fblocks -fsyntax-only -verify %s
 
+@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 @@ foo (int i1, int i2, int i3, void (^cp1)(), void (^cp2)(), void (^cp3)())
   
   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
 }