From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 089753858419; Wed, 30 Aug 2023 22:06:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 089753858419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693433172; bh=Nnkvbj6TGc1yewUUVoWUbsz3hRxQOTJDm4BmKNgbdZc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cK3GPYtDBZ+X0pkXduQRSNGZvtHwvGtcCpGGY36ysixqjCIVn69LG2KcAeRci+UW7 HQ3GytUuS//+rl06aep0IkMvmR0FZ5g+Pn2oHNO6P7sftELJ8SzR7oBKLtgKN6LS4g +X+ZrlBcx2gBQLnsuVLawYXykgujU/vAZIAQYGQw= From: "cvs-commit at gcc dot 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: Wed, 30 Aug 2023 22:06:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: efric at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107646 --- Comment #10 from CVS Commits --- The trunk branch has been updated by Eric Feng : https://gcc.gnu.org/g:597b9ec69bca8acb7a3d65641c0a730de8b27ed4 commit r14-3580-g597b9ec69bca8acb7a3d65641c0a730de8b27ed4 Author: Eric Feng Date: Wed Aug 30 17:52:24 2023 -0400 analyzer: implement reference count checking for CPython plugin [PR1076= 46] This patch introduces initial support for reference count checking of PyObjects in relation to the Python/C API for the CPython plugin. Additionally, the core analyzer underwent several modifications to accommodate this feature. These include: - Introducing support for callbacks at the end of region_model::pop_frame. This is our current point of validation for the reference count of PyObjects. - An added optional custom stmt_finder parameter to region_model_context::warn. This aids in emitting a diagnostic concerning the reference count, especially when the stmt_finder is NULL, which is currently the case during region_model::pop_frame. The current diagnostic we emit relating to the reference count appears as follows: rc3.c:23:10: warning: expected =C3=A2item=C3=A2 to have reference count= : =C3=A21=C3=A2 but ob_refcnt field is: =C3=A22=C3=A2 23 | return list; | ^~~~ =C3=A2create_py_object=C3=A2: events 1-4 | | 4 | PyObject* item =3D PyLong_FromLong(3); | | ^~~~~~~~~~~~~~~~~~ | | | | | (1) when =C3=A2PyLong_FromLong=C3=A2 su= cceeds | 5 | PyObject* list =3D PyList_New(1); | | ~~~~~~~~~~~~~ | | | | | (2) when =C3=A2PyList_New=C3=A2 succeeds |...... | 14 | PyList_Append(list, item); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) when =C3=A2PyList_Append=C3=A2 succeeds, moving buff= er |...... | 23 | return list; | | ~~~~ | | | | | (4) here | This is a WIP in several ways: - Currently, functions returning PyObject * are assumed to always produce a new reference. - The validation of reference count is only for PyObjects created within a function body. Verifying reference counts for PyObjects passed as parameters is not supported in this patch. gcc/analyzer/ChangeLog: PR analyzer/107646 * engine.cc (impl_region_model_context::warn): New optional parameter. * exploded-graph.h (class impl_region_model_context): Likewise. * region-model.cc (region_model::pop_frame): New callback feature for region_model::pop_frame. * region-model.h (struct append_regions_cb_data): Likewise. (class region_model): Likewise. (class region_model_context): New optional parameter. (class region_model_context_decorator): Likewise. gcc/testsuite/ChangeLog: PR analyzer/107646 * gcc.dg/plugin/analyzer_cpython_plugin.c: Implements reference count checking for PyObjects. * gcc.dg/plugin/cpython-plugin-test-2.c: Moved to... * gcc.dg/plugin/cpython-plugin-test-PyList_Append.c: ...here (and added more tests). * gcc.dg/plugin/cpython-plugin-test-1.c: Moved to... * gcc.dg/plugin/cpython-plugin-test-no-Python-h.c: ...here (and added more tests). * gcc.dg/plugin/plugin.exp: New tests. * gcc.dg/plugin/cpython-plugin-test-PyList_New.c: New test. * gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c: New test. Signed-off-by: Eric Feng =