Skip to content

Commit 080431c

Browse files
committed
checker option moved to configuration option
1 parent 69f42e9 commit 080431c

File tree

8 files changed

+115
-64
lines changed

8 files changed

+115
-64
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,6 @@ core.NullDereference (C, C++, ObjC)
118118
"""""""""""""""""""""""""""""""""""
119119
Check for dereferences of null pointers.
120120

121-
This checker specifically does
122-
not report null pointer dereferences for x86 and x86-64 targets when the
123-
address space is 256 (x86 GS Segment), 257 (x86 FS Segment), or 258 (x86 SS
124-
segment). See `X86/X86-64 Language Extensions
125-
<https://clang.llvm.org/docs/LanguageExtensions.html#memory-references-to-specified-segments>`__
126-
for reference.
127-
128-
The ``SuppressAddressSpaces`` option suppresses
129-
warnings for null dereferences of all pointers with address spaces. You can
130-
disable this behavior with the option
131-
``-analyzer-config core.NullDereference:SuppressAddressSpaces=false``.
132-
Value of this option is also used for checker
133-
:ref:`_alpha-core-FixedAddressDereference`.
134-
*Defaults to true*.
135-
136121
.. code-block:: objc
137122
138123
// C
@@ -172,6 +157,16 @@ Value of this option is also used for checker
172157
obj->x = 1; // warn
173158
}
174159
160+
Null pointer dereferences of pointers with address spaces are not always defined
161+
as error. Specifically on x86/x86-64 target if the pointer address space is
162+
256 (x86 GS Segment), 257 (x86 FS Segment), or 258 (x86 SS Segment), a null
163+
dereference is not defined as error. See `X86/X86-64 Language Extensions
164+
<https://clang.llvm.org/docs/LanguageExtensions.html#memory-references-to-specified-segments>`__
165+
for reference. The ``suppress-all-address-spaces`` configuration option can be
166+
used to control if null dereferences with any address space or only with the
167+
specific x86 address spaces 256, 257, 258 are excluded from reporting as error.
168+
The default is all address spaces.
169+
175170
.. _core-StackAddressEscape:
176171
177172
core.StackAddressEscape (C)
@@ -2926,6 +2921,9 @@ Check for assignment of a fixed address to a pointer.
29262921
alpha.core.FixedAddressDereference (C, C++, ObjC)
29272922
"""""""""""""""""""""""""""""""""""""""""""""""""
29282923
Check for dereferences of fixed addresses.
2924+
A pointer contains a fixed address if it was set to a hard-coded value or it
2925+
becomes otherwise obvious that at that point it can have only a single specific
2926+
value.
29292927
29302928
.. code-block:: c
29312929
@@ -2945,17 +2943,10 @@ Check for dereferences of fixed addresses.
29452943
int x = (*p_function)('x', 'y'); // NO warning yet at functon pointer calls
29462944
}
29472945
2948-
Similarly to :ref:`_core-NullDereference`, the checker intentionally does
2949-
not report dereferences for x86 and x86-64 targets when the
2950-
address space is 256 (x86 GS Segment), 257 (x86 FS Segment), or 258 (x86 SS
2951-
Segment). (See `X86/X86-64 Language Extensions
2952-
<https://clang.llvm.org/docs/LanguageExtensions.html#memory-references-to-specified-segments>`__
2953-
for reference.)
2954-
2955-
If you want to disable this behavior, set the ``SuppressAddressSpaces`` option
2956-
of checker ``core.NullDereference`` to false, like
2957-
``-analyzer-config core.NullDereference:SuppressAddressSpaces=false``. The value
2958-
of this option is used for both checkers.
2946+
The analyzer option ``suppress-all-address-spaces`` affects this checker. If it
2947+
is set to true pointer dereferences with any address space are not reported as
2948+
error. Otherwise only address spaces 256, 257, 258 on target x86/x86-64 are
2949+
excluded from reporting as error. The default is all address spaces.
29592950
29602951
.. _alpha-core-PointerArithm:
29612952

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,6 @@ def DereferenceModeling : Checker<"DereferenceModeling">,
213213

214214
def NullDereferenceChecker : Checker<"NullDereference">,
215215
HelpText<"Check for dereferences of null pointers">,
216-
CheckerOptions<[
217-
CmdLineOption<Boolean,
218-
"SuppressAddressSpaces",
219-
"Suppresses warning when pointer dereferences an address space",
220-
"true",
221-
Released>
222-
]>,
223216
Documentation<HasDocumentation>,
224217
Dependencies<[DereferenceModeling]>;
225218

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,19 @@ ANALYZER_OPTION(
395395
"flex\" won't be analyzed.",
396396
true)
397397

398+
ANALYZER_OPTION(
399+
bool, ShouldSuppressAddressSpaces, "suppress-all-address-spaces",
400+
"The analyzer does not report dereferences on memory that use "
401+
"address space #256, #257, and #258. Those address spaces are used when "
402+
"dereferencing address spaces relative to the GS, FS, and SS segments on "
403+
"x86/x86-64 targets. Dereferencing a null pointer in these address spaces "
404+
"is not defined as an error. All other null dereferences in other address "
405+
"spaces are defined as an error unless explicitly defined. "
406+
"When this option is turned on, the special behavior of address spaces "
407+
"#256, #257, #258 is extended to all pointers with address spaces and on "
408+
"any target.",
409+
true)
410+
398411
//===----------------------------------------------------------------------===//
399412
// Unsigned analyzer options.
400413
//===----------------------------------------------------------------------===//

clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ class DereferenceChecker
5454
const LocationContext *LCtx,
5555
bool loadedFrom = false);
5656

57-
bool SuppressAddressSpaces = false;
58-
5957
bool CheckNullDereference = false;
6058
bool CheckFixedDereference = false;
6159

@@ -137,7 +135,7 @@ bool DereferenceChecker::suppressReport(CheckerContext &C,
137135
QualType Ty = E->getType();
138136
if (!Ty.hasAddressSpace())
139137
return false;
140-
if (SuppressAddressSpaces)
138+
if (C.getAnalysisManager().getAnalyzerOptions().ShouldSuppressAddressSpaces)
141139
return true;
142140

143141
const llvm::Triple::ArchType Arch =
@@ -405,8 +403,6 @@ bool ento::shouldRegisterDereferenceModeling(const CheckerManager &) {
405403
void ento::registerNullDereferenceChecker(CheckerManager &Mgr) {
406404
auto *Chk = Mgr.getChecker<DereferenceChecker>();
407405
Chk->CheckNullDereference = true;
408-
Chk->SuppressAddressSpaces = Mgr.getAnalyzerOptions().getCheckerBooleanOption(
409-
Mgr.getCurrentCheckerName(), "SuppressAddressSpaces");
410406
Chk->BT_Null.reset(new BugType(Mgr.getCurrentCheckerName(),
411407
"Dereference of null pointer",
412408
categories::LogicError));

clang/test/Analysis/analyzer-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
// CHECK-NEXT: core.CallAndMessage:NilReceiver = true
3838
// CHECK-NEXT: core.CallAndMessage:ParameterCount = true
3939
// CHECK-NEXT: core.CallAndMessage:UndefReceiver = true
40-
// CHECK-NEXT: core.NullDereference:SuppressAddressSpaces = true
4140
// CHECK-NEXT: cplusplus.Move:WarnOn = KnownsAndLocals
4241
// CHECK-NEXT: cplusplus.SmartPtrModeling:ModelSmartPtrDereference = false
4342
// CHECK-NEXT: crosscheck-with-z3 = false
@@ -124,6 +123,7 @@
124123
// CHECK-NEXT: silence-checkers = ""
125124
// CHECK-NEXT: stable-report-filename = false
126125
// CHECK-NEXT: support-symbolic-integer-casts = false
126+
// CHECK-NEXT: suppress-all-address-spaces = true
127127
// CHECK-NEXT: suppress-c++-stdlib = true
128128
// CHECK-NEXT: suppress-inlined-defensive-checks = true
129129
// CHECK-NEXT: suppress-null-return-paths = true

clang/test/Analysis/cast-value-notes.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
//
55
// RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
66
// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
7-
// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=false\
7+
// RUN: -analyzer-config suppress-all-address-spaces=false\
88
// RUN: -analyzer-output=text -verify -DX86 -DNOT_SUPPRESSED %s 2>&1 | FileCheck %s -check-prefix=X86-CHECK
99
//
1010
// RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
1111
// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
12-
// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=true\
12+
// RUN: -analyzer-config suppress-all-address-spaces=true\
1313
// RUN: -analyzer-output=text -verify -DX86 -DSUPPRESSED %s 2>&1 | FileCheck %s -check-prefix=X86-CHECK
1414
//
1515
// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown \
@@ -18,12 +18,12 @@
1818
//
1919
// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown \
2020
// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
21-
// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=true\
21+
// RUN: -analyzer-config suppress-all-address-spaces=true\
2222
// RUN: -analyzer-output=text -verify -DX86 -DSUPPRESSED %s 2>&1 | FileCheck %s --check-prefix=X86-CHECK-SUPPRESSED
2323
//
2424
// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown \
2525
// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
26-
// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=false\
26+
// RUN: -analyzer-config suppress-all-address-spaces=false\
2727
// RUN: -analyzer-output=text -verify -DX86 -DNOT_SUPPRESSED %s 2>&1 | FileCheck %s --check-prefix=X86-CHECK
2828
//
2929
// RUN: %clang_analyze_cc1 -std=c++14 -triple mips-unknown-unknown \
@@ -32,12 +32,12 @@
3232
//
3333
// RUN: %clang_analyze_cc1 -std=c++14 -triple mips-unknown-unknown \
3434
// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
35-
// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=false\
35+
// RUN: -analyzer-config suppress-all-address-spaces=false\
3636
// RUN: -analyzer-output=text -verify -DMIPS %s 2>&1
3737
//
3838
// RUN: %clang_analyze_cc1 -std=c++14 -triple mips-unknown-unknown \
3939
// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
40-
// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=true\
40+
// RUN: -analyzer-config suppress-all-address-spaces=true\
4141
// RUN: -analyzer-output=text -verify -DMIPS_SUPPRESSED %s
4242

4343
#include "Inputs/llvm.h"

clang/test/Analysis/concrete-address.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,3 @@ void f9() {
142142
// FIXME: there should be a warning from calling the function pointer with fixed address
143143
int x = (*p_function) ('x', 'y');
144144
}
145-
146-
#define AS_ATTRIBUTE volatile __attribute__((address_space(256)))
147-
#define _get_base() ((void * AS_ATTRIBUTE *)0x10)
148-
149-
void* test_address_space_array(unsigned long slot) {
150-
return _get_base()[slot]; // no-warning
151-
}
152-
void test_address_space_condition(int AS_ATTRIBUTE *cpu_data) {
153-
if (cpu_data == (int *)0x10) {
154-
*cpu_data = 3; // no-warning
155-
}
156-
}
157-
struct X { int member; };
158-
int test_address_space_member(void) {
159-
struct X AS_ATTRIBUTE *data = (struct X AS_ATTRIBUTE *)0x10UL;
160-
int ret;
161-
ret = data->member; // no-warning
162-
return ret;
163-
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core,alpha.core -std=gnu99 -analyzer-config suppress-all-address-spaces=false -verify=x86-nosuppress %s
2+
// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core,alpha.core -std=gnu99 -verify=x86-suppress %s
3+
// RUN: %clang_analyze_cc1 -triple arm-pc-linux-gnu -analyzer-checker=core,alpha.core -std=gnu99 -analyzer-config suppress-all-address-spaces=false -verify=other-nosuppress %s
4+
// RUN: %clang_analyze_cc1 -triple arm-pc-linux-gnu -analyzer-checker=core,alpha.core -std=gnu99 -verify=other-suppress %s
5+
6+
#define AS_ATTRIBUTE(_X) volatile __attribute__((address_space(_X)))
7+
8+
#define _get_base() ((void * AS_ATTRIBUTE(256) *)0)
9+
10+
void* test_address_space_array(unsigned long slot) {
11+
return _get_base()[slot]; // other-nosuppress-warning{{Dereference}}
12+
}
13+
14+
void test_address_space_condition(int AS_ATTRIBUTE(257) *cpu_data) {
15+
if (cpu_data == 0) {
16+
*cpu_data = 3; // other-nosuppress-warning{{Dereference}}
17+
}
18+
}
19+
20+
struct X { int member; };
21+
int test_address_space_member(void) {
22+
struct X AS_ATTRIBUTE(258) *data = (struct X AS_ATTRIBUTE(258) *)0UL;
23+
int ret;
24+
ret = data->member; // other-nosuppress-warning{{Dereference}}
25+
return ret;
26+
}
27+
28+
void test_other_address_space_condition(int AS_ATTRIBUTE(259) *cpu_data) {
29+
if (cpu_data == 0) {
30+
*cpu_data = 3; // other-nosuppress-warning{{Dereference}} \
31+
// x86-nosuppress-warning{{Dereference}}
32+
}
33+
}
34+
35+
void test_no_address_space_condition(int *cpu_data) {
36+
if (cpu_data == 0) {
37+
*cpu_data = 3; // other-nosuppress-warning{{Dereference}} \
38+
// x86-nosuppress-warning{{Dereference}} \
39+
// other-suppress-warning{{Dereference}} \
40+
// x86-suppress-warning{{Dereference}}
41+
}
42+
}
43+
44+
#define _fixed_get_base() ((void * AS_ATTRIBUTE(256) *)2)
45+
46+
void* fixed_test_address_space_array(unsigned long slot) {
47+
return _fixed_get_base()[slot]; // other-nosuppress-warning{{Dereference}}
48+
}
49+
50+
void fixed_test_address_space_condition(int AS_ATTRIBUTE(257) *cpu_data) {
51+
if (cpu_data == (int AS_ATTRIBUTE(257) *)2) {
52+
*cpu_data = 3; // other-nosuppress-warning{{Dereference}}
53+
}
54+
}
55+
56+
int fixed_test_address_space_member(void) {
57+
struct X AS_ATTRIBUTE(258) *data = (struct X AS_ATTRIBUTE(258) *)2UL;
58+
int ret;
59+
ret = data->member; // other-nosuppress-warning{{Dereference}}
60+
return ret;
61+
}
62+
63+
void fixed_test_other_address_space_condition(int AS_ATTRIBUTE(259) *cpu_data) {
64+
if (cpu_data == (int AS_ATTRIBUTE(259) *)2) {
65+
*cpu_data = 3; // other-nosuppress-warning{{Dereference}} \
66+
// x86-nosuppress-warning{{Dereference}}
67+
}
68+
}
69+
70+
void fixed_test_no_address_space_condition(int *cpu_data) {
71+
if (cpu_data == (int *)2) {
72+
*cpu_data = 3; // other-nosuppress-warning{{Dereference}} \
73+
// x86-nosuppress-warning{{Dereference}} \
74+
// other-suppress-warning{{Dereference}} \
75+
// x86-suppress-warning{{Dereference}}
76+
}
77+
}

0 commit comments

Comments
 (0)