Jakub Jelinek 206cb6c105 analyzer: Handle nonnull_if_nonzero attribute [PR117023]
On top of the
https://gcc.gnu.org/pipermail/gcc-patches/2024-November/668554.html
patch which introduces the nonnull_if_nonzero attribute (because
C2Y is allowing NULL arguments on various calls like memcpy, memset,
strncpy etc. as long as the count is 0) the following patch adds just
limited handling of the attribute in the analyzer.

For nonnull attribute(s) we have the get_nonnull_args helper which
returns a bitmap, for nonnull_if_nonzero a function would need to
return a hash_map or something similar, I think it is better to
handle the attributes one by one.  This patch just handles the
non-zero INTEGER_CST (integer_nonzerop) count arguments, in other places
the above patch uses ranger to some extent, but I'm not familiar enough
with the analyzer to know if one can use the ranger, or should somehow
explain in data structures the conditional nature of the nonnull property,
the argument is nonnull only if some other argument is nonzero.

Also, analyzer uses get_nonnull_args in another spot when entering a frame,
not sure if anything can be done there (note the conditional nonnull
somehow, pass from callers if the argument is nonzero, ...).

Note, the testsuite changes aren't strictly necessary with just
the above and this patch, but will be with a patch I'm going to post
soon.

2025-02-24  Jakub Jelinek  <jakub@redhat.com>

	PR c/117023
gcc/analyzer/
	* sm-malloc.cc (malloc_state_machine::handle_nonnull): New private
	method.
	(malloc_state_machine::on_stmt): Use it for nonnull attribute arguments.
	Handle also nonnull_if_nonzero attributes.
gcc/testsuite/
	* c-c++-common/analyzer/call-summaries-malloc.c
	(test_use_without_check): Pass 4 rather than sz to memset.
	* c-c++-common/analyzer/strncpy-1.c (test_null_dst,
	test_null_src): Pass 42 rather than count to strncpy.
2025-02-24 09:18:27 +01:00
2025-02-12 00:17:11 +00:00
2025-02-11 00:17:27 +00:00
2025-02-15 00:18:03 +00:00
2025-02-19 00:18:02 +00:00
2025-02-22 00:17:38 +00:00
2025-02-23 00:17:00 +00:00
2025-02-12 00:17:11 +00:00
2025-02-23 00:17:00 +00:00
2025-02-20 00:18:17 +00:00

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.
Description
No description provided
Readme 4.2 GiB
Languages
C++ 30.7%
C 30.2%
Ada 14.4%
D 6.1%
Go 5.7%
Other 12.4%