17 Commits

Author SHA1 Message Date
Balázs Kéri
b85fe40cb8
[clang][analyzer] Add missing stream related functions to StdLibraryFunctionsChecker. (#76979)
Some stream functions were recently added to `StreamChecker` that were
not modeled by `StdCLibraryFunctionsChecker`. To ensure consistency
these functions are added to the other checker too.
Some of the related tests are re-organized.
2024-02-08 11:09:57 +01:00
Ben Shi
ff05c3087b
[clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (#78895) 2024-01-27 09:46:05 +08:00
Ben Shi
02232307ce
[clang][analyzer] Improve modeling of 'fdopen' in StdLibraryFunctionsChecker (#78680) 2024-01-20 11:02:40 +08:00
Ben Shi
27d963a708
[clang][analyzer] Improve modeling of 'fseeko' and 'ftello' in StdLibraryFunctionsChecker (#77902) 2024-01-16 16:58:07 +08:00
Balázs Kéri
41fe5c9a08
[clang][analyzer] Improve StdLibraryFunctionsChecker 'readlink' modeling. (#71373)
The functions 'readlink' and 'readlinkat' do return 0 only if the
'bufsize' argument is 0.
2023-11-14 10:58:05 +01:00
Balázs Kéri
c202a17d02
[clang][analyzer] Move checker alpha.unix.StdCLibraryFunctions out of alpha. (#66207) 2023-10-16 14:51:05 +02:00
Balázs Kéri
52ac71f92d [clang][analyzer] Improve StdCLibraryFunctions socket send/recv functions.
The modeling of send, recv, sendmsg, recvmsg, sendto, recvfrom is changed:
These functions do not return 0, except if the message length is 0.
(In sendmsg, recvmsg the length is not checkable but it is more likely
that a message with 0 length is invalid for these functions.)

Reviewed By: donat.nagy

Differential Revision: https://reviews.llvm.org/D155715
2023-08-07 10:45:09 +02:00
Balázs Kéri
6dccf5b8d5 [clang][analyzer] Add all success/failure messages to StdLibraryFunctionsChecker.
Success or failure messages are now shown at all checked functions, if the call
(return value) is interesting.
Additionally new functions are added: open, openat, socket, shutdown

Reviewed By: donat.nagy

Differential Revision: https://reviews.llvm.org/D154423
2023-07-18 09:29:15 +02:00
Balázs Kéri
4f0436dd15 [clang][analyzer] Merge apiModeling.StdCLibraryFunctions and StdCLibraryFunctionArgs checkers into one.
Main reason for this change is that these checkers were implemented in the same class
but had different dependency ordering. (NonNullParamChecker should run before StdCLibraryFunctionArgs
to get more special warning about null arguments, but the apiModeling.StdCLibraryFunctions was a modeling
checker that should run before other non-modeling checkers. The modeling checker changes state in a way
that makes it impossible to detect a null argument by NonNullParamChecker.)
To make it more simple, the modeling part is removed as separate checker and can be only used if
checker StdCLibraryFunctions is turned on, that produces the warnings too. Modeling the functions
without bug detection (for invalid argument) is not possible. The modeling of standard functions
does not happen by default from this change on.

Reviewed By: Szelethus

Differential Revision: https://reviews.llvm.org/D151225
2023-06-01 09:54:35 +02:00
Balázs Kéri
80a21ea800 [clang][analyzer] Cleanup tests of StdCLibraryFunctionsChecker (NFC)
Function declarations are moved into common header that can be reused
to avoid repetitions in different test files.
Some small problems in the tests were found and fixed.

Reviewed By: steakhal

Differential Revision: https://reviews.llvm.org/D149158
2023-05-12 09:54:01 +02:00
Balázs Kéri
3c7fe7d09d [clang][analyzer] Add stream related functions to StdLibraryFunctionsChecker.
Additional stream handling functions are added.
These are partially evaluated by StreamChecker, result of the addition is
check for more preconditions and construction of success and failure branches
with specific errno handling.

Reviewed By: Szelethus

Differential Revision: https://reviews.llvm.org/D140387
2023-01-06 11:04:24 +01:00
Aaron Ballman
1ea584377e A significant number of our tests in C accidentally use functions
without prototypes. This patch converts the function signatures to have
a prototype for the situations where the test is not specific to K&R C
declarations. e.g.,

  void func();

becomes

  void func(void);

This is the ninth batch of tests being updated (there are a
significant number of other tests left to be updated).
2022-02-13 08:03:40 -05:00
Gabor Marton
b7586afc4d [analyzer][StdLibraryFunctionsChecker] Remove strcasecmp
There are 2 reasons to remove strcasecmp and strncasecmp.
1) They are also modeled in CStringChecker and the related argumentum
   contraints are checked there.
2) The argument constraints are checked in CStringChecker::evalCall.
   This is fundamentally flawed, they should be checked in checkPreCall.
   Even if we set up CStringChecker as a weak dependency for
   StdLibraryFunctionsChecker then the latter reports the warning always.
   Besides, CStringChecker fails to discover the constraint violation
   before the call, so, its evalCall returns with `true` and then
   StdCLibraryFunctions also tries to evaluate, this causes an assertion
   in CheckerManager.

Either we fix CStringChecker to handle the call prerequisites in
checkPreCall, or we must not evaluate any pure functions in
StdCLibraryFunctions that are also handled in CStringChecker.
We do the latter in this patch.

Differential Revision: https://reviews.llvm.org/D87239
2020-09-10 12:29:39 +02:00
Gabor Marton
d01280587d [analyzer][StdLibraryFunctionsChecker] Add POSIX pthread handling functions
Differential Revision: https://reviews.llvm.org/D84415
2020-09-07 17:47:01 +02:00
Gabor Marton
f0b9dbcfc7 [analyzer][StdLibraryFunctionsChecker] Add POSIX time handling functions
Differential Revision: https://reviews.llvm.org/D84248
2020-09-04 18:44:12 +02:00
Gabor Marton
3ff220de90 [analyzer][StdLibraryFunctionsChecker] Add POSIX networking functions
Summary:
Adding networking functions from the POSIX standard (2017). This includes
functions that deal with sockets from socket.h, netdb.h.

In 'socket.h' of some libc implementations (e.g. glibc) with C99, sockaddr
parameter is a transparent union of the underlying sockaddr_ family of pointers
instead of being a pointer to struct sockaddr. In these cases, the standardized
signature will not match, thus we try to match with another signature that has
the joker Irrelevant type. In the case of transparent unions, we also not add
those constraints which require pointer types for the sockaddr param.

Interestingly, in 'netdb.h' sockaddr is not handled as a transparent union.

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83407
2020-07-20 22:46:24 +02:00
Gabor Marton
db4d5f7048 [analyzer][StdLibraryFunctionsChecker] Add POSIX file handling functions
Adding file handling functions from the POSIX standard (2017).
A new checker option is introduced to enable them.
In follow-up patches I am going to upstream networking, pthread, and other
groups of POSIX functions.

Differential Revision: https://reviews.llvm.org/D82288
2020-07-02 14:28:05 +02:00