[clang] 1701895 - [clang][analyzer] Less redundant warnings from FixedAddressChecker (#110458)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 3 00:17:54 PDT 2024
Author: Balázs Kéri
Date: 2024-10-03T09:17:51+02:00
New Revision: 1701895c362176cb898eba509b18e8d72d8095c9
URL: https://github.com/llvm/llvm-project/commit/1701895c362176cb898eba509b18e8d72d8095c9
DIFF: https://github.com/llvm/llvm-project/commit/1701895c362176cb898eba509b18e8d72d8095c9.diff
LOG: [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).
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
clang/test/Analysis/ptr-arith.c
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
index e7fde3edc7f9ee..f7fd92db7757e5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
@@ -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())
diff --git a/clang/test/Analysis/ptr-arith.c b/clang/test/Analysis/ptr-arith.c
index 020a5006292306..b5ccd2c207ead1 100644
--- a/clang/test/Analysis/ptr-arith.c
+++ b/clang/test/Analysis/ptr-arith.c
@@ -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}}
More information about the cfe-commits
mailing list