public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/107646] RFE: can we reimplement gcc-python-plugin's cpychecker as a -fanalyzer plugin? Date: Fri, 11 Aug 2023 17:33:45 +0000 [thread overview] Message-ID: <bug-107646-4-kXatOTKLYn@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-107646-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107646 --- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Eric Feng <efric@gcc.gnu.org>: https://gcc.gnu.org/g:38c00edd65c39b07166aa0913c79adb9bcac943c commit r14-3162-g38c00edd65c39b07166aa0913c79adb9bcac943c Author: Eric Feng <ef2648@columbia.edu> Date: Fri Aug 11 12:30:43 2023 -0400 analyzer: More features for CPython analyzer plugin [PR107646] This patch adds known function subclasses for Python/C API functions PyList_New, PyLong_FromLong, and PyList_Append. It also adds new optional parameters for region_model::get_or_create_region_for_heap_alloc, allowing for the newly allocated region to immediately transition from the start state to the assumed non-null state in the malloc state machine if desired. Finally, it adds a new procedure, dg-require-python-h, intended as a directive in Python-related analyzer tests, to append necessary Python flags during the tests' build process. The main warnings we gain in this patch with respect to the known function subclasses mentioned are leak related. For example: rc3.c: In function âcreate_py_objectâ: â rc3.c:21:10: warning: leak of âitemâ [CWE-401] [-Wanalyzer-malloc-leak] â 21 | return list; â | ^~~~ â âcreate_py_objectâ: events 1-4 â | â | 4 | PyObject* item = PyLong_FromLong(10); â | | ^~~~~~~~~~~~~~~~~~~ â | | | â | | (1) allocated here â | | (2) when âPyLong_FromLongâ succeeds â | 5 | PyObject* list = PyList_New(2); â | | ~~~~~~~~~~~~~ â | | | â | | (3) when âPyList_Newâ fails â |...... â | 21 | return list; â | | ~~~~ â | | | â | | (4) âitemâ leaks here; was allocated at (1) â Some concessions were made to simplify the analysis process when comparing kf_PyList_Append with the real implementation. In particular, PyList_Append performs some optimization internally to try and avoid calls to realloc if possible. For simplicity, we assume that realloc is called every time. Also, we grow the size by just 1 (to ensure enough space for adding a new element) rather than abide by the heuristics that the actual implementation follows. gcc/analyzer/ChangeLog: PR analyzer/107646 * call-details.h: New function. * region-model.cc (region_model::get_or_create_region_for_heap_alloc): New optional parameters. * region-model.h (class region_model): New optional parameters. * sm-malloc.cc (on_realloc_with_move): New function. (region_model::transition_ptr_sval_non_null): New function. gcc/testsuite/ChangeLog: PR analyzer/107646 * gcc.dg/plugin/analyzer_cpython_plugin.c: Analyzer support for PyList_New, PyList_Append, PyLong_FromLong * gcc.dg/plugin/plugin.exp: New test. * lib/target-supports.exp: New procedure. * gcc.dg/plugin/cpython-plugin-test-2.c: New test. Signed-off-by: Eric Feng <ef2648@columbia.edu>
next prev parent reply other threads:[~2023-08-11 17:33 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-11 16:55 [Bug analyzer/107646] New: " dmalcolm at gcc dot gnu.org 2022-11-11 16:58 ` [Bug analyzer/107646] " dmalcolm at gcc dot gnu.org 2023-08-02 20:59 ` cvs-commit at gcc dot gnu.org 2023-08-11 17:33 ` cvs-commit at gcc dot gnu.org [this message] 2023-08-17 18:26 ` dmalcolm at gcc dot gnu.org 2023-08-17 18:45 ` dmalcolm at gcc dot gnu.org 2023-08-17 18:53 ` dmalcolm at gcc dot gnu.org 2023-08-17 18:53 ` dmalcolm at gcc dot gnu.org 2023-08-17 18:59 ` dmalcolm at gcc dot gnu.org 2023-08-17 19:46 ` dmalcolm at gcc dot gnu.org 2023-08-18 0:39 ` dmalcolm at gcc dot gnu.org 2023-08-30 22:06 ` cvs-commit at gcc dot gnu.org 2024-05-14 13:51 ` dmalcolm at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107646-4-kXatOTKLYn@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).