Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/Analysis/UnsafeBufferUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}
Expand Down Expand Up @@ -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];
Expand Down