Skip to content

Commit 1701895

Browse files
authored
[clang][analyzer] Less redundant warnings from FixedAddressChecker (#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).
1 parent 944f4ad commit 1701895

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ void FixedAddressChecker::checkPreStmt(const BinaryOperator *B,
4343
if (!T->isPointerType())
4444
return;
4545

46+
// Omit warning if the RHS has already pointer type. Without this passing
47+
// around one fixed value in several pointer variables would produce several
48+
// redundant warnings.
49+
if (B->getRHS()->IgnoreParenCasts()->getType()->isPointerType())
50+
return;
51+
4652
SVal RV = C.getSVal(B->getRHS());
4753

4854
if (!RV.isConstant() || RV.isZeroConstant())

clang/test/Analysis/ptr-arith.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ domain_port (const char *domain_b, const char *domain_e,
4242
void f4(void) {
4343
int *p;
4444
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}}
45+
46+
int *p1;
47+
p1 = p; // no warning
48+
4549
long x = 0x10100;
4650
x += 10;
4751
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}}

0 commit comments

Comments
 (0)