Skip to content

Commit ecbda09

Browse files
committed
[clang][analyzer] Move 'alpha.core.FixedAddressDereference' out of alpha
1 parent 0753244 commit ecbda09

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 specific
108+
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)
@@ -2919,41 +2954,6 @@ Check for assignment of a fixed address to a pointer.
29192954
p = (int *) 0x10000; // warn
29202955
}
29212956
2922-
.. _alpha-core-FixedAddressDereference:
2923-
2924-
alpha.core.FixedAddressDereference (C, C++, ObjC)
2925-
"""""""""""""""""""""""""""""""""""""""""""""""""
2926-
Check for dereferences of fixed addresses.
2927-
2928-
A pointer contains a fixed address if it was set to a hard-coded value or it
2929-
becomes otherwise obvious that at that point it can have only a single specific
2930-
value.
2931-
2932-
.. code-block:: c
2933-
2934-
void test1() {
2935-
int *p = (int *)0x020;
2936-
int x = p[0]; // warn
2937-
}
2938-
2939-
void test2(int *p) {
2940-
if (p == (int *)-1)
2941-
*p = 0; // warn
2942-
}
2943-
2944-
void test3() {
2945-
int (*p_function)(char, char);
2946-
p_function = (int (*)(char, char))0x04080;
2947-
int x = (*p_function)('x', 'y'); // NO warning yet at functon pointer calls
2948-
}
2949-
2950-
If the analyzer option ``suppress-dereferences-from-any-address-space`` is set
2951-
to true (the default value), then this checker never reports dereference of
2952-
pointers with a specified address space. If the option is set to false, then
2953-
reports from the specific x86 address spaces 256, 257 and 258 are still
2954-
suppressed, but fixed address dereferences from other address spaces are
2955-
reported.
2956-
29572957
.. _alpha-core-PointerArithm:
29582958
29592959
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)