-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[clang][analyzer] Move checker alpha.unix.StdCLibraryFunctions out of alpha. #66207
Conversation
… alpha. This checker can be good enough to move out of alpha. I am not sure about the exact requirements, this review can be a place for discussion about what should be fixed (if any). Reviewed By: steakhal Differential Revision: https://reviews.llvm.org/D152436
@llvm/pr-subscribers-clang ChangesThe checker is good enough to move out of alpha. --Patch is 48.31 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/66207.diff 37 Files Affected:
<pre>
.. _release-notes-sanitizers: diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst +.. _unix-StdCLibraryFunctions:
+You can think of this checker as defining restrictions (pre- and postconditions)
+.. code-block:: c
+Additionally to the argument and return value conditions, this checker also adds osx -.. _alpha-unix-StdCLibraryFunctions:-alpha.unix.StdCLibraryFunctions (C)
|
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 started to nitpick the documentation text before I realized that it's just old content moved in from elsewhere. Probably it's better to handle these in a separate commit.)
clang/docs/analyzer/checkers.rst
Outdated
You can think of this checker as defining restrictions (pre- and postconditions) | ||
on standard library functions. Preconditions are checked, and when they are | ||
violated, a warning is emitted. Post conditions are added to the analysis, e.g. | ||
that the return value must be no greater than 255. |
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.
"the return value" of what? I think a function name is missing here.
clang/docs/analyzer/checkers.rst
Outdated
pointer and the null value of the argument can not be proven, the analyzer will | ||
assume that it is non-null. |
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.
pointer and the null value of the argument can not be proven, the analyzer will | |
assume that it is non-null. | |
pointer and the analyzer cannot prove that it is null, then it will assume that | |
it is non-null. |
"can not be proven" is stronger than "the analyzer cannot prove it"
I tested this commit on several open-source projects, comparing it and its parent with a configuration that enables the non-alpha checkers (so StdCLibraryFunctions becomes enabled when this commit moves it out of alpha). The results show that this checker doesn't produce random noise and can provide some useful results:
[1] One unix.StdCLibraryFunctions report and four very similar TOCTOU bugs reported by core.NonNullParamChecker (one example). These are all real issues, although it'd be very difficult to trigger them in practice. Note that we're testing stable versions of open-source projects, so it's not surprising that we don't see serious issues. |
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.
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 didn't spent much time on this, but I think it should be good.
Please check the docs with Grammarly to catch mistakes.
Also, please generate the HTML for the rst to verify how it looks.
I'm not sure if the release docs mentions this, but it definitely should. Make sure that's the case.
I approve this, assuming that these wrinkles are ironed.
clang/docs/analyzer/checkers.rst
Outdated
.. _unix-StdCLibraryFunctions: | ||
|
||
unix.StdCLibraryFunctions (C) | ||
""""""""""""""""""""""""""""""""""" |
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.
Align this with the section title.
clang/docs/analyzer/checkers.rst
Outdated
""""""""""""""""""""""""""""""""""" | ||
Check for calls of standard library functions that violate predefined argument | ||
constraints. For example, it is stated in the C standard that for the ``int | ||
isalnum(int ch)`` function the behavior is undefined if the value of ``ch`` is |
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.
The grammar feels odd here.
clang/docs/analyzer/checkers.rst
Outdated
|
||
You can think of this checker as defining restrictions (pre- and postconditions) | ||
on standard library functions. Preconditions are checked, and when they are | ||
violated, a warning is emitted. Post conditions are added to the analysis, e.g. |
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.
Here "post condition" is spelled as separate words, while previously there was a hyphen between the words.
clang/docs/analyzer/checkers.rst
Outdated
Check for calls of standard library functions that violate predefined argument | ||
constraints. For example, it is stated in the C standard that for the ``int | ||
isalnum(int ch)`` function the behavior is undefined if the value of ``ch`` is | ||
not representable as unsigned char and is not equal to ``EOF``. |
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.
Char and unsigned are not escaped like we usually do for code.
clang/docs/analyzer/checkers.rst
Outdated
@@ -2651,100 +2745,6 @@ For a more detailed description of configuration options, please see the | |||
alpha.unix | |||
^^^^^^^^^^^ |
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.
As we are here, could you align this with its section title as well?
default. The ``ModelPOSIX`` option enables modeling (and emit diagnostics) of | ||
additional functions that are defined in the POSIX standard. This option is | ||
disabled by default. | ||
|
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.
Do you think we should have an exhaustive list of the modeled functions here, or that wouldn't be useful?
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.
If I remember correctly the list of functions was already rejected by reviewers (because maintenance problems). Otherwise I think it is good to have an exact list of modeled functions.
"and apply relations between arguments and return value">, | ||
CheckerOptions<[ | ||
CmdLineOption<Boolean, | ||
"DisplayLoadedSummaries", |
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.
Could you confirm that this option is not advertised in the user facing docs.
@haoNoQ Could you check if this change is OK to merge? |
The checker is good enough to move out of alpha.