Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang][analyzer] Less redundant warnings from FixedAddressChecker #110458

Merged
merged 2 commits into from
Oct 3, 2024
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
6 changes: 6 additions & 0 deletions clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ void FixedAddressChecker::checkPreStmt(const BinaryOperator *B,
if (!T->isPointerType())
return;

// Omit warning if the RHS has already pointer type. Without this passing
// around one fixed value in several pointer variables would produce several
// redundant warnings.
if (B->getRHS()->IgnoreParenCasts()->getType()->isPointerType())
return;

SVal RV = C.getSVal(B->getRHS());

if (!RV.isConstant() || RV.isZeroConstant())
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Analysis/ptr-arith.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ domain_port (const char *domain_b, const char *domain_e,
void f4(void) {
int *p;
p = (int*) 0x10000; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms}}

int *p1;
p1 = p; // no warning

long x = 0x10100;
x += 10;
p = (int*) x; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms}}
Expand Down
Loading