Skip to content

Commit ae54a00

Browse files
authored
[clang][analyzer] FixedAddressChecker: no warning if system macro is used (#108993)
1 parent f3111cc commit ae54a00

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ void FixedAddressChecker::checkPreStmt(const BinaryOperator *B,
4848
if (!RV.isConstant() || RV.isZeroConstant())
4949
return;
5050

51+
if (C.getSourceManager().isInSystemMacro(B->getRHS()->getBeginLoc()))
52+
return;
53+
5154
if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
5255
// FIXME: improve grammar in the following strings:
5356
constexpr llvm::StringLiteral Msg =

clang/test/Analysis/Inputs/system-header-simulator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,11 @@ void _Exit(int status) __attribute__ ((__noreturn__));
154154
#define EOF (-1)
155155

156156
#define offsetof(t, d) __builtin_offsetof(t, d)
157+
158+
struct sigaction {
159+
void (*sa_handler)(int);
160+
};
161+
#define SIGINT 2
162+
#define SIG_IGN (void (*)(int))1
163+
164+
int sigaction(int, const struct sigaction *restrict, struct sigaction *restrict);

clang/test/Analysis/ptr-arith.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// 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
22
// 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
33

4+
#include "Inputs/system-header-simulator.h"
5+
46
void clang_analyzer_eval(int);
57
void clang_analyzer_dump(int);
68

@@ -35,9 +37,20 @@ domain_port (const char *domain_b, const char *domain_e,
3537
return port;
3638
}
3739

40+
#define FIXED_VALUE (int*) 0x1111
41+
3842
void f4(void) {
3943
int *p;
4044
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+
long x = 0x10100;
46+
x += 10;
47+
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}}
48+
49+
struct sigaction sa;
50+
sa.sa_handler = SIG_IGN; // no warning (exclude macros defined in system header)
51+
sigaction(SIGINT, &sa, NULL);
52+
53+
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}}
4154
}
4255

4356
void f5(void) {

0 commit comments

Comments
 (0)