]> granicus.if.org Git - clang/commitdiff
__attribute__((nonnull)) can apply to reference-to-pointer
authorDouglas Gregor <dgregor@apple.com>
Wed, 15 Dec 2010 15:41:46 +0000 (15:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 15 Dec 2010 15:41:46 +0000 (15:41 +0000)
parameters. Fixes <rdar://problem/8769025>.

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

lib/Sema/SemaDeclAttr.cpp
test/SemaCXX/attr-nonnull.cpp

index 3453528d8a4d3ae4e6142c026bcc22daa116d1d1..e9f885e62f30ecf7fce5ae71f2ab79d8bb5d811d 100644 (file)
@@ -371,7 +371,7 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
     }
 
     // Is the function argument a pointer type?
-    QualType T = getFunctionOrMethodArgType(d, x);
+    QualType T = getFunctionOrMethodArgType(d, x).getNonReferenceType();
     if (!T->isAnyPointerType() && !T->isBlockPointerType()) {
       // FIXME: Should also highlight argument in decl.
       S.Diag(Attr.getLoc(), diag::warn_nonnull_pointers_only)
@@ -386,7 +386,7 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   // arguments have a nonnull attribute.
   if (NonNullArgs.empty()) {
     for (unsigned I = 0, E = getFunctionOrMethodNumArgs(d); I != E; ++I) {
-      QualType T = getFunctionOrMethodArgType(d, I);
+      QualType T = getFunctionOrMethodArgType(d, I).getNonReferenceType();
       if (T->isAnyPointerType() || T->isBlockPointerType())
         NonNullArgs.push_back(I);
       else if (const RecordType *UT = T->getAsUnionType()) {
index e5b5329ffca910272673100384be0413945c5107..19d6642eb553a287ad36d69e8991b5cd8651e5e7 100644 (file)
@@ -16,3 +16,14 @@ void test(S s) {
   s.g("", 0, ""); // expected-warning{{null passed}}
   s.g(0, "", 0);
 }
+
+namespace rdar8769025 {
+  __attribute__((nonnull)) void f0(int *&p);
+  __attribute__((nonnull)) void f1(int * const &p);
+  __attribute__((nonnull(2))) void f2(int i, int * const &p);
+
+  void test_f1() {
+    f1(0); // expected-warning{{null passed to a callee which requires a non-null argument}}
+    f2(0, 0); // expected-warning{{null passed to a callee which requires a non-null argument}}
+  }
+}