forked from OSchip/llvm-project
__attribute__((nonnull)) can apply to reference-to-pointer
parameters. Fixes <rdar://problem/8769025>. llvm-svn: 121864
This commit is contained in:
parent
03007d79fe
commit
1e2cdf5933
|
@ -371,7 +371,7 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the function argument a pointer type?
|
// Is the function argument a pointer type?
|
||||||
QualType T = getFunctionOrMethodArgType(d, x);
|
QualType T = getFunctionOrMethodArgType(d, x).getNonReferenceType();
|
||||||
if (!T->isAnyPointerType() && !T->isBlockPointerType()) {
|
if (!T->isAnyPointerType() && !T->isBlockPointerType()) {
|
||||||
// FIXME: Should also highlight argument in decl.
|
// FIXME: Should also highlight argument in decl.
|
||||||
S.Diag(Attr.getLoc(), diag::warn_nonnull_pointers_only)
|
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.
|
// arguments have a nonnull attribute.
|
||||||
if (NonNullArgs.empty()) {
|
if (NonNullArgs.empty()) {
|
||||||
for (unsigned I = 0, E = getFunctionOrMethodNumArgs(d); I != E; ++I) {
|
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())
|
if (T->isAnyPointerType() || T->isBlockPointerType())
|
||||||
NonNullArgs.push_back(I);
|
NonNullArgs.push_back(I);
|
||||||
else if (const RecordType *UT = T->getAsUnionType()) {
|
else if (const RecordType *UT = T->getAsUnionType()) {
|
||||||
|
|
|
@ -16,3 +16,14 @@ void test(S s) {
|
||||||
s.g("", 0, ""); // expected-warning{{null passed}}
|
s.g("", 0, ""); // expected-warning{{null passed}}
|
||||||
s.g(0, "", 0);
|
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}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue