diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst --- a/clang/docs/analyzer/checkers.rst +++ b/clang/docs/analyzer/checkers.rst @@ -2333,6 +2333,43 @@ alpha.unix ^^^^^^^^^^^ +.. _alpha-unix-StdCLibraryFunctionArgs: + +alpha.unix.StdCLibraryFunctionArgs (C) +"""""""""""""""""""""""""""""""""""""" +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``. + +.. code-block:: c + + void test_alnum_concrete(int v) { + int ret = isalnum(256); // \ + // warning: Function argument constraint is not satisfied + (void)ret; + } + +If the argument's value is unknown then the value is assumed to hold the proper value range. + +.. code-block:: c + + #define EOF -1 + void test_alnum_symbolic(int x) { + int ret = isalnum(x); + (void)ret; + clang_analyzer_eval(EOF <= x && x <= 255); // this reports TRUE + } + +If the user disables the checker then the argument violation warning is +suppressed. However, the assumption about the argument is still modeled (otherwise we +would be further analyzing an illformed program). + +The checker models functions (and emits diagnostics) from the C standard by +default. The ``ModelPOSIX`` option enables the checker to model (and emit +diagnostics) for functions that are defined in the POSIX standard. This option +is disabled by default. + .. _alpha-unix-BlockInCriticalSection: alpha.unix.BlockInCriticalSection (C) diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td --- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -552,7 +552,7 @@ "or is EOF.">, Dependencies<[StdCLibraryFunctionsChecker]>, WeakDependencies<[CallAndMessageChecker, NonNullParamChecker, StreamChecker]>, - Documentation; + Documentation; } // end "alpha.unix"