-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][analyzer] Add checker 'alpha.core.FixedAddressDereference' #127191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
1f2ad6d
d60d9c7
69f42e9
080431c
00ae0c6
3529c65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -118,19 +118,6 @@ core.NullDereference (C, C++, ObjC) | |||||||||||||||||||
| """"""""""""""""""""""""""""""""""" | ||||||||||||||||||||
| Check for dereferences of null pointers. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| This checker specifically does | ||||||||||||||||||||
| not report null pointer dereferences for x86 and x86-64 targets when the | ||||||||||||||||||||
| address space is 256 (x86 GS Segment), 257 (x86 FS Segment), or 258 (x86 SS | ||||||||||||||||||||
| segment). See `X86/X86-64 Language Extensions | ||||||||||||||||||||
| <https://clang.llvm.org/docs/LanguageExtensions.html#memory-references-to-specified-segments>`__ | ||||||||||||||||||||
| for reference. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| The ``SuppressAddressSpaces`` option suppresses | ||||||||||||||||||||
| warnings for null dereferences of all pointers with address spaces. You can | ||||||||||||||||||||
| disable this behavior with the option | ||||||||||||||||||||
| ``-analyzer-config core.NullDereference:SuppressAddressSpaces=false``. | ||||||||||||||||||||
| *Defaults to true*. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| .. code-block:: objc | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // C | ||||||||||||||||||||
|
|
@@ -170,6 +157,16 @@ disable this behavior with the option | |||||||||||||||||||
| obj->x = 1; // warn | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Null pointer dereferences of pointers with address spaces are not always defined | ||||||||||||||||||||
| as error. Specifically on x86/x86-64 target if the pointer address space is | ||||||||||||||||||||
| 256 (x86 GS Segment), 257 (x86 FS Segment), or 258 (x86 SS Segment), a null | ||||||||||||||||||||
| dereference is not defined as error. See `X86/X86-64 Language Extensions | ||||||||||||||||||||
| <https://clang.llvm.org/docs/LanguageExtensions.html#memory-references-to-specified-segments>`__ | ||||||||||||||||||||
| for reference. The ``suppress-all-address-spaces`` configuration option can be | ||||||||||||||||||||
| used to control if null dereferences with any address space or only with the | ||||||||||||||||||||
| specific x86 address spaces 256, 257, 258 are excluded from reporting as error. | ||||||||||||||||||||
| The default is all address spaces. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| .. _core-StackAddressEscape: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| core.StackAddressEscape (C) | ||||||||||||||||||||
|
|
@@ -2919,6 +2916,38 @@ Check for assignment of a fixed address to a pointer. | |||||||||||||||||||
| p = (int *) 0x10000; // warn | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| .. _alpha-core-FixedAddressDereference: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| alpha.core.FixedAddressDereference (C, C++, ObjC) | ||||||||||||||||||||
| """"""""""""""""""""""""""""""""""""""""""""""""" | ||||||||||||||||||||
| Check for dereferences of fixed addresses. | ||||||||||||||||||||
steakhal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
| A pointer contains a fixed address if it was set to a hard-coded value or it | ||||||||||||||||||||
| becomes otherwise obvious that at that point it can have only a single specific | ||||||||||||||||||||
| value. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| .. code-block:: c | ||||||||||||||||||||
|
|
||||||||||||||||||||
| void test1() { | ||||||||||||||||||||
| int *p = (int *)0x020; | ||||||||||||||||||||
| int x = p[0]; // warn | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| void test2(int *p) { | ||||||||||||||||||||
| if (p == (int *)-1) | ||||||||||||||||||||
| *p = 0; // warn | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| void test3() { | ||||||||||||||||||||
| int (*p_function)(char, char); | ||||||||||||||||||||
| p_function = (int (*)(char, char))0x04080; | ||||||||||||||||||||
| int x = (*p_function)('x', 'y'); // NO warning yet at functon pointer calls | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| The analyzer option ``suppress-all-address-spaces`` affects this checker. If it | ||||||||||||||||||||
| is set to true pointer dereferences with any address space are not reported as | ||||||||||||||||||||
| error. Otherwise only address spaces 256, 257, 258 on target x86/x86-64 are | ||||||||||||||||||||
| excluded from reporting as error. The default is all address spaces. | ||||||||||||||||||||
|
||||||||||||||||||||
| The analyzer option ``suppress-all-address-spaces`` affects this checker. If it | |
| is set to true pointer dereferences with any address space are not reported as | |
| error. Otherwise only address spaces 256, 257, 258 on target x86/x86-64 are | |
| excluded from reporting as error. The default is all address spaces. | |
| If the analyzer option ``suppress-all-address-spaces`` is set to true (the | |
| default value), then this checker never reports dereference of pointers with a | |
| specified address space. If the option is set to false, then reports from the | |
| specific x86 address spaces 256, 257 and 258 are still suppressed, but fixed | |
| address dereferences from other address spaces are reported. |
This is the same paragraph that I suggested for the NullDereference checker.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -395,6 +395,19 @@ ANALYZER_OPTION( | |
| "flex\" won't be analyzed.", | ||
| true) | ||
|
|
||
| ANALYZER_OPTION( | ||
| bool, ShouldSuppressAddressSpaces, "suppress-all-address-spaces", | ||
|
||
| "The analyzer does not report dereferences on memory that use " | ||
| "address space #256, #257, and #258. Those address spaces are used when " | ||
| "dereferencing address spaces relative to the GS, FS, and SS segments on " | ||
| "x86/x86-64 targets. Dereferencing a null pointer in these address spaces " | ||
| "is not defined as an error. All other null dereferences in other address " | ||
| "spaces are defined as an error unless explicitly defined. " | ||
| "When this option is turned on, the special behavior of address spaces " | ||
| "#256, #257, #258 is extended to all pointers with address spaces and on " | ||
| "any target.", | ||
| true) | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Unsigned analyzer options. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to mention "(the default value)" immediately when you describe it.