[cfe-commits] r121864 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp test/SemaCXX/attr-nonnull.cpp

Douglas Gregor dgregor at apple.com
Wed Dec 15 07:41:46 PST 2010


Author: dgregor
Date: Wed Dec 15 09:41:46 2010
New Revision: 121864

URL: http://llvm.org/viewvc/llvm-project?rev=121864&view=rev
Log:
__attribute__((nonnull)) can apply to reference-to-pointer
parameters. Fixes <rdar://problem/8769025>.

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/SemaCXX/attr-nonnull.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=121864&r1=121863&r2=121864&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Dec 15 09:41:46 2010
@@ -371,7 +371,7 @@
     }
 
     // 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 @@
   // 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()) {

Modified: cfe/trunk/test/SemaCXX/attr-nonnull.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-nonnull.cpp?rev=121864&r1=121863&r2=121864&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-nonnull.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-nonnull.cpp Wed Dec 15 09:41:46 2010
@@ -16,3 +16,14 @@
   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}}
+  }
+}





More information about the cfe-commits mailing list