aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBalázs Kéri <balazs.keri@ericsson.com>2024-09-26 09:49:29 +0200
committerGitHub <noreply@github.com>2024-09-26 09:49:29 +0200
commitae54a00cc1eb64a0300e190ccdc46ae9b31d2835 (patch)
tree20f813779e78ff20feb4be76f488ed729ee5f4e3
parentf3111cc77bea8d4f6b3ca90ee5457cff5faeb3fc (diff)
downloadllvm-ae54a00cc1eb64a0300e190ccdc46ae9b31d2835.zip
llvm-ae54a00cc1eb64a0300e190ccdc46ae9b31d2835.tar.gz
llvm-ae54a00cc1eb64a0300e190ccdc46ae9b31d2835.tar.bz2
[clang][analyzer] FixedAddressChecker: no warning if system macro is used (#108993)
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp3
-rw-r--r--clang/test/Analysis/Inputs/system-header-simulator.h8
-rw-r--r--clang/test/Analysis/ptr-arith.c13
3 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
index 7aefcdc..e7fde3e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
@@ -48,6 +48,9 @@ void FixedAddressChecker::checkPreStmt(const BinaryOperator *B,
if (!RV.isConstant() || RV.isZeroConstant())
return;
+ if (C.getSourceManager().isInSystemMacro(B->getRHS()->getBeginLoc()))
+ return;
+
if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
// FIXME: improve grammar in the following strings:
constexpr llvm::StringLiteral Msg =
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h b/clang/test/Analysis/Inputs/system-header-simulator.h
index 8fd5144..fadc09f 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -154,3 +154,11 @@ void _Exit(int status) __attribute__ ((__noreturn__));
#define EOF (-1)
#define offsetof(t, d) __builtin_offsetof(t, d)
+
+struct sigaction {
+ void (*sa_handler)(int);
+};
+#define SIGINT 2
+#define SIG_IGN (void (*)(int))1
+
+int sigaction(int, const struct sigaction *restrict, struct sigaction *restrict);
diff --git a/clang/test/Analysis/ptr-arith.c b/clang/test/Analysis/ptr-arith.c
index f99dfab..020a500 100644
--- a/clang/test/Analysis/ptr-arith.c
+++ b/clang/test/Analysis/ptr-arith.c
@@ -1,6 +1,8 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.FixedAddr,alpha.core.PointerArithm,debug.ExprInspection -Wno-pointer-to-int-cast -verify -triple x86_64-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config eagerly-assume=false %s
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.FixedAddr,alpha.core.PointerArithm,debug.ExprInspection -Wno-pointer-to-int-cast -verify -triple i686-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config eagerly-assume=false %s
+#include "Inputs/system-header-simulator.h"
+
void clang_analyzer_eval(int);
void clang_analyzer_dump(int);
@@ -35,9 +37,20 @@ domain_port (const char *domain_b, const char *domain_e,
return port;
}
+#define FIXED_VALUE (int*) 0x1111
+
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}}
+ 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}}
+
+ struct sigaction sa;
+ sa.sa_handler = SIG_IGN; // no warning (exclude macros defined in system header)
+ sigaction(SIGINT, &sa, NULL);
+
+ p = FIXED_VALUE; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms}}
}
void f5(void) {