Skip to content

Commit

Permalink
[clang][analyzer] Less redundant warnings from FixedAddressChecker (#…
Browse files Browse the repository at this point in the history
…110458)

If a fixed value is assigned to a pointer variable, the checker did emit
a warning. If the pointer variable is assigned to another pointer
variable, this resulted in another warning. The checker now emits
warning only if a value with non-pointer type is assigned (to a pointer
variable).
  • Loading branch information
balazske authored Oct 3, 2024
1 parent 944f4ad commit 1701895
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit 1701895

Please sign in to comment.