Skip to content

Commit bbeb946

Browse files
committed
[clang][analyzer] Change value of checker option in unix.StdCLibraryFunctions (second try). (#80457)
Default value of checker option `ModelPOSIX` is changed to `true`. Documentation is updated. This is a re-apply of commit 7af4e8b that was reverted because a test failure (this is fixed now).
1 parent c1d8d0a commit bbeb946

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,10 +1320,23 @@ range of the argument.
13201320
13211321
**Parameters**
13221322
1323-
The checker models functions (and emits diagnostics) from the C standard by
1324-
default. The ``ModelPOSIX`` option enables modeling (and emit diagnostics) of
1325-
additional functions that are defined in the POSIX standard. This option is
1326-
disabled by default.
1323+
The ``ModelPOSIX`` option controls if functions from the POSIX standard are
1324+
recognized by the checker.
1325+
1326+
With ``ModelPOSIX=true``, many POSIX functions are modeled according to the
1327+
`POSIX standard`_. This includes ranges of parameters and possible return
1328+
values. Furthermore the behavior related to ``errno`` in the POSIX case is
1329+
often that ``errno`` is set only if a function call fails, and it becomes
1330+
undefined after a successful function call.
1331+
1332+
With ``ModelPOSIX=false``, this checker follows the C99 language standard and
1333+
only models the functions that are described there. It is possible that the
1334+
same functions are modeled differently in the two cases because differences in
1335+
the standards. The C standard specifies less aspects of the functions, for
1336+
example exact ``errno`` behavior is often unspecified (and not modeled by the
1337+
checker).
1338+
1339+
Default value of the option is ``true``.
13271340
13281341
.. _osx-checkers:
13291342

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
578578
"ModelPOSIX",
579579
"If set to true, the checker models additional functions "
580580
"from the POSIX standard.",
581-
"false",
581+
"true",
582582
InAlpha>
583583
]>,
584584
WeakDependencies<[CallAndMessageChecker, NonNullParamChecker]>,

clang/test/Analysis/analyzer-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
// CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false
130130
// CHECK-NEXT: unix.Errno:AllowErrnoReadOutsideConditionExpressions = true
131131
// CHECK-NEXT: unix.StdCLibraryFunctions:DisplayLoadedSummaries = false
132-
// CHECK-NEXT: unix.StdCLibraryFunctions:ModelPOSIX = false
132+
// CHECK-NEXT: unix.StdCLibraryFunctions:ModelPOSIX = true
133133
// CHECK-NEXT: unroll-loops = false
134134
// CHECK-NEXT: verbose-report-filename = false
135135
// CHECK-NEXT: widen-loops = false

clang/test/Analysis/std-c-library-functions.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: -analyzer-checker=unix.StdCLibraryFunctions \
44
// RUN: -analyzer-checker=debug.ExprInspection \
55
// RUN: -analyzer-config eagerly-assume=false \
6+
// RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=false \
67
// RUN: -triple i686-unknown-linux \
78
// RUN: -verify
89

@@ -11,6 +12,7 @@
1112
// RUN: -analyzer-checker=unix.StdCLibraryFunctions \
1213
// RUN: -analyzer-checker=debug.ExprInspection \
1314
// RUN: -analyzer-config eagerly-assume=false \
15+
// RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=false \
1416
// RUN: -triple x86_64-unknown-linux \
1517
// RUN: -verify
1618

@@ -19,6 +21,7 @@
1921
// RUN: -analyzer-checker=unix.StdCLibraryFunctions \
2022
// RUN: -analyzer-checker=debug.ExprInspection \
2123
// RUN: -analyzer-config eagerly-assume=false \
24+
// RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=false \
2225
// RUN: -triple armv7-a15-linux \
2326
// RUN: -verify
2427

@@ -27,6 +30,7 @@
2730
// RUN: -analyzer-checker=unix.StdCLibraryFunctions \
2831
// RUN: -analyzer-checker=debug.ExprInspection \
2932
// RUN: -analyzer-config eagerly-assume=false \
33+
// RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=false \
3034
// RUN: -triple thumbv7-a15-linux \
3135
// RUN: -verify
3236

@@ -36,6 +40,7 @@
3640
// RUN: -analyzer-config unix.StdCLibraryFunctions:DisplayLoadedSummaries=true \
3741
// RUN: -analyzer-checker=debug.ExprInspection \
3842
// RUN: -analyzer-config eagerly-assume=false \
43+
// RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=false \
3944
// RUN: -triple i686-unknown-linux 2>&1 | FileCheck %s
4045

4146
// CHECK: Loaded summary for: int isalnum(int)

0 commit comments

Comments
 (0)