diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-12-15 15:41:46 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-12-15 15:41:46 +0000 |
commit | de43632a5951abf3f357e2f79dcddda4dc6ec8ff (patch) | |
tree | 4062ae1e036c9e7ae72cf1896c939d6923e0b7ca | |
parent | fb7b36327c4cd14c9454e0e9c26f8c44ba8207c0 (diff) |
__attribute__((nonnull)) can apply to reference-to-pointer
parameters. Fixes <rdar://problem/8769025>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121864 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 4 | ||||
-rw-r--r-- | test/SemaCXX/attr-nonnull.cpp | 11 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 3453528d8a..e9f885e62f 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -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()) { diff --git a/test/SemaCXX/attr-nonnull.cpp b/test/SemaCXX/attr-nonnull.cpp index e5b5329ffc..19d6642eb5 100644 --- a/test/SemaCXX/attr-nonnull.cpp +++ b/test/SemaCXX/attr-nonnull.cpp @@ -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}} + } +} |