Skip to content

Commit 322b2fe

Browse files
authored
[clang][analyzer] Move 'alpha.core.FixedAddressDereference' out of alpha (#132404)
1 parent c419260 commit 322b2fe

File tree

8 files changed

+48
-46
lines changed

8 files changed

+48
-46
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,41 @@ core.DivideZero (C, C++, ObjC)
9797
.. literalinclude:: checkers/dividezero_example.c
9898
:language: c
9999

100+
.. _core-FixedAddressDereference:
101+
102+
core.FixedAddressDereference (C, C++, ObjC)
103+
"""""""""""""""""""""""""""""""""""""""""""
104+
Check for dereferences of fixed addresses.
105+
106+
A pointer contains a fixed address if it was set to a hard-coded value or it
107+
becomes otherwise obvious that at that point it can have only a single fixed
108+
numerical value.
109+
110+
.. code-block:: c
111+
112+
void test1() {
113+
int *p = (int *)0x020;
114+
int x = p[0]; // warn
115+
}
116+
117+
void test2(int *p) {
118+
if (p == (int *)-1)
119+
*p = 0; // warn
120+
}
121+
122+
void test3() {
123+
int (*p_function)(char, char);
124+
p_function = (int (*)(char, char))0x04080;
125+
int x = (*p_function)('x', 'y'); // NO warning yet at functon pointer calls
126+
}
127+
128+
If the analyzer option ``suppress-dereferences-from-any-address-space`` is set
129+
to true (the default value), then this checker never reports dereference of
130+
pointers with a specified address space. If the option is set to false, then
131+
reports from the specific x86 address spaces 256, 257 and 258 are still
132+
suppressed, but fixed address dereferences from other address spaces are
133+
reported.
134+
100135
.. _core-NonNullParamChecker:
101136

102137
core.NonNullParamChecker (C, C++, ObjC)
@@ -2971,41 +3006,6 @@ Check for assignment of a fixed address to a pointer.
29713006
p = (int *) 0x10000; // warn
29723007
}
29733008
2974-
.. _alpha-core-FixedAddressDereference:
2975-
2976-
alpha.core.FixedAddressDereference (C, C++, ObjC)
2977-
"""""""""""""""""""""""""""""""""""""""""""""""""
2978-
Check for dereferences of fixed addresses.
2979-
2980-
A pointer contains a fixed address if it was set to a hard-coded value or it
2981-
becomes otherwise obvious that at that point it can have only a single specific
2982-
value.
2983-
2984-
.. code-block:: c
2985-
2986-
void test1() {
2987-
int *p = (int *)0x020;
2988-
int x = p[0]; // warn
2989-
}
2990-
2991-
void test2(int *p) {
2992-
if (p == (int *)-1)
2993-
*p = 0; // warn
2994-
}
2995-
2996-
void test3() {
2997-
int (*p_function)(char, char);
2998-
p_function = (int (*)(char, char))0x04080;
2999-
int x = (*p_function)('x', 'y'); // NO warning yet at functon pointer calls
3000-
}
3001-
3002-
If the analyzer option ``suppress-dereferences-from-any-address-space`` is set
3003-
to true (the default value), then this checker never reports dereference of
3004-
pointers with a specified address space. If the option is set to false, then
3005-
reports from the specific x86 address spaces 256, 257 and 258 are still
3006-
suppressed, but fixed address dereferences from other address spaces are
3007-
reported.
3008-
30093009
.. _alpha-core-PointerArithm:
30103010
30113011
alpha.core.PointerArithm (C)

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ def DereferenceModeling : Checker<"DereferenceModeling">,
211211
Documentation<NotDocumented>,
212212
Hidden;
213213

214+
def FixedAddressDereferenceChecker
215+
: Checker<"FixedAddressDereference">,
216+
HelpText<"Check for dereferences of fixed addresses">,
217+
Documentation<HasDocumentation>,
218+
Dependencies<[DereferenceModeling]>;
219+
214220
def NullDereferenceChecker : Checker<"NullDereference">,
215221
HelpText<"Check for dereferences of null pointers">,
216222
Documentation<HasDocumentation>,
@@ -278,12 +284,6 @@ def FixedAddressChecker : Checker<"FixedAddr">,
278284
HelpText<"Check for assignment of a fixed address to a pointer">,
279285
Documentation<HasDocumentation>;
280286

281-
def FixedAddressDereferenceChecker
282-
: Checker<"FixedAddressDereference">,
283-
HelpText<"Check for dereferences of fixed addresses">,
284-
Documentation<HasDocumentation>,
285-
Dependencies<[DereferenceModeling]>;
286-
287287
def PointerArithChecker : Checker<"PointerArithm">,
288288
HelpText<"Check for pointer arithmetic on locations other than array "
289289
"elements">,

clang/test/Analysis/analyzer-enabled-checkers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// CHECK-NEXT: core.DereferenceModeling
1818
// CHECK-NEXT: core.DivideZero
1919
// CHECK-NEXT: core.DynamicTypePropagation
20+
// CHECK-NEXT: core.FixedAddressDereference
2021
// CHECK-NEXT: core.NonNullParamChecker
2122
// CHECK-NEXT: core.NonnilStringConstants
2223
// CHECK-NEXT: core.NullDereference

clang/test/Analysis/dtor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection,cplusplus -analyzer-config c++-inlining=destructors -Wno-null-dereference -Wno-inaccessible-base -verify -analyzer-config eagerly-assume=false %s
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection,cplusplus -analyzer-disable-checker=core.FixedAddressDereference -analyzer-config c++-inlining=destructors -Wno-null-dereference -Wno-inaccessible-base -verify -analyzer-config eagerly-assume=false %s
22

33
void clang_analyzer_eval(bool);
44
void clang_analyzer_checkInlined(bool);

clang/test/Analysis/fixed-address-notes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.FixedAddressDereference -analyzer-output=text -verify %s
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s
22

33
extern char *something();
44

clang/test/Analysis/misc-ps.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// NOTE: Use '-fobjc-gc' to test the analysis being run twice, and multiple reports are not issued.
2-
// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-disable-checker=alpha.core.FixedAddressDereference -Wno-strict-prototypes -Wno-pointer-to-int-cast -verify -fblocks -Wno-unreachable-code -Wno-null-dereference -Wno-objc-root-class %s
3-
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-disable-checker=alpha.core.FixedAddressDereference -Wno-strict-prototypes -Wno-pointer-to-int-cast -verify -fblocks -Wno-unreachable-code -Wno-null-dereference -Wno-objc-root-class %s
2+
// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-disable-checker=core.FixedAddressDereference -Wno-strict-prototypes -Wno-pointer-to-int-cast -verify -fblocks -Wno-unreachable-code -Wno-null-dereference -Wno-objc-root-class %s
3+
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-disable-checker=core.FixedAddressDereference -Wno-strict-prototypes -Wno-pointer-to-int-cast -verify -fblocks -Wno-unreachable-code -Wno-null-dereference -Wno-objc-root-class %s
44

55
#ifndef __clang_analyzer__
66
#error __clang_analyzer__ not defined

clang/test/Analysis/pr22954.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// At the moment the whole of the destination array content is invalidated.
44
// If a.s1 region has a symbolic offset, the whole region of 'a' is invalidated.
55
// Specific triple set to test structures of size 0.
6-
// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core,unix.Malloc,debug.ExprInspection -Wno-error=int-conversion -verify -analyzer-config eagerly-assume=false %s
6+
// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-disable-checker=core.FixedAddressDereference -Wno-error=int-conversion -verify -analyzer-config eagerly-assume=false %s
77

88
typedef __typeof(sizeof(int)) size_t;
99

clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
// CHECK-NEXT: core.DereferenceModeling
2626
// CHECK-NEXT: core.DivideZero
2727
// CHECK-NEXT: core.DynamicTypePropagation
28+
// CHECK-NEXT: core.FixedAddressDereference
2829
// CHECK-NEXT: core.NonNullParamChecker
2930
// CHECK-NEXT: core.NonnilStringConstants
3031
// CHECK-NEXT: core.NullDereference

0 commit comments

Comments
 (0)