diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index 87d9c1c2bf4a5..ad6cc55c1f264 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -1034,7 +1034,8 @@ static bool isCountAttributedPointerArgumentSafeImpl( PtrArgNoImp = DAE->getExpr()->IgnoreParenImpCasts(); // check form 0: - if (PtrArgNoImp->getType()->isNullPtrType()) { + if (PtrArgNoImp->isNullPointerConstant(Context, + Expr::NPC_ValueDependentIsNotNull)) { if (isOrNull) return true; if (CountArg) diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-count-attributed-pointer-argument.cpp b/clang/test/SemaCXX/warn-unsafe-buffer-usage-count-attributed-pointer-argument.cpp index 83ca260ac1a09..82aa3803f2be9 100644 --- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-count-attributed-pointer-argument.cpp +++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-count-attributed-pointer-argument.cpp @@ -81,7 +81,7 @@ void cb_cint_42(const int *__counted_by(42) p); // expected-note@+1 6{{consider using 'std::span' and passing '.first(...).data()' to the parameter 'p'}} void cb_cint_multi(const int *__counted_by((a + b) * (c - d)) p, int a, int b, int c, int d); -// expected-note@+1 3{{consider using a safe container and passing '.data()' to the parameter 'p' and '.size()' to its dependent parameter 'size' or 'std::span' and passing '.first(...).data()' to the parameter 'p'}} +// expected-note@+1 +{{consider using a safe container and passing '.data()' to the parameter 'p' and '.size()' to its dependent parameter 'size' or 'std::span' and passing '.first(...).data()' to the parameter 'p'}} void sb_void(void *__sized_by(size) p, size_t size); // expected-note@+1 13{{consider using a safe container and passing '.data()' to the parameter 'p' and '.size()' to its dependent parameter 'size' or 'std::span' and passing '.first(...).data()' to the parameter 'p'}} @@ -416,6 +416,24 @@ void nullptr_as_arg(size_t n) { sbn_void(nullptr, n); } +void zero_as_arg(size_t n) { + cb_int(0, 0); + cb_int(0, 42); // expected-warning{{unsafe assignment to function parameter of count-attributed type}} + cb_int(0, n); // expected-warning{{unsafe assignment to function parameter of count-attributed type}} + + sb_void(0, 0); + sb_void(0, 42); // expected-warning{{unsafe assignment to function parameter of count-attributed type}} + sb_void(0, n); // expected-warning{{unsafe assignment to function parameter of count-attributed type}} + + cbn_int(0, 0); + cbn_int(0, 42); + cbn_int(0, n); + + sbn_void(0, 0); + sbn_void(0, 42); + sbn_void(0, n); +} + void single_variable() { int Var; int Arr[10];