https://gcc.gnu.org/g:bc615c0d69e5587f7336c55cfb61f51f74429b60
commit r16-7980-gbc615c0d69e5587f7336c55cfb61f51f74429b60 Author: Jakub Jelinek <[email protected]> Date: Tue Mar 10 13:26:09 2026 +0100 testsuite: Fix up gcc.dg/plugin/analyzer_cpython_plugin.cc [PR112520] The recent r16-7938 PR112520 fix hasn't changed much in the testsuite results for me: @@ -154,41 +151,34 @@ FAIL: gcc.dg/plugin/cpython-plugin-test- FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_Append.c -fplugin=./analyzer_cpython_plugin.so (test for warnings, line 42) FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_Append.c -fplugin=./analyzer_cpython_plugin.so at line 18 (test for warnings, line 17) FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_Append.c -fplugin=./analyzer_cpython_plugin.so at line 43 (test for warnings, line 42) -FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_Append.c -fplugin=./analyzer_cpython_plugin.so (internal compiler error: Segmentation fault) +FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_Append.c -fplugin=./analyzer_cpython_plugin.so (internal compiler error: tree check: expected record_type or union_type or qual_union_type, have integer_type in get_field_by_name, at /home/jakub/src/gcc/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc:62) FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_Append.c -fplugin=./analyzer_cpython_plugin.so (test for excess errors) FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_New.c -fplugin=./analyzer_cpython_plugin.so (test for warnings, line 17) FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_New.c -fplugin=./analyzer_cpython_plugin.so (test for warnings, line 18) FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_New.c -fplugin=./analyzer_cpython_plugin.so (test for warnings, line 21) FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_New.c -fplugin=./analyzer_cpython_plugin.so (test for warnings, line 29) FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_New.c -fplugin=./analyzer_cpython_plugin.so at line 37 (test for warnings, line 36) -FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_New.c -fplugin=./analyzer_cpython_plugin.so (internal compiler error: Segmentation fault) +FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_New.c -fplugin=./analyzer_cpython_plugin.so (internal compiler error: tree check: expected record_type or union_type or qual_union_type, have integer_type in get_field_by_name, at /home/jakub/src/gcc/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc:62) FAIL: gcc.dg/plugin/cpython-plugin-test-PyList_New.c -fplugin=./analyzer_cpython_plugin.so (test for excess errors) FAIL: gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c -fplugin=./analyzer_cpython_plugin.so (test for warnings, line 17) FAIL: gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c -fplugin=./analyzer_cpython_plugin.so (test for warnings, line 18) FAIL: gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c -fplugin=./analyzer_cpython_plugin.so (test for warnings, line 21) FAIL: gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c -fplugin=./analyzer_cpython_plugin.so (test for warnings, line 29) FAIL: gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c -fplugin=./analyzer_cpython_plugin.so at line 37 (test for warnings, line 36) -FAIL: gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c -fplugin=./analyzer_cpython_plugin.so (internal compiler error: Segmentation fault) +FAIL: gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c -fplugin=./analyzer_cpython_plugin.so (internal compiler error: tree check: expected record_type or union_type or qual_union_type, have integer_type in get_field_by_name, at /home/jakub/src/gcc/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc:62) FAIL: gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c -fplugin=./analyzer_cpython_plugin.so (test for excess errors) ... The problem is that get_field_by_name now recurses on TREE_TYPE of everything in TYPE_FIELDS (which can be FIELD_DECL but many other things (though primarily for C++ and other languages)). More importantly, it recurses even for FIELD_DECLs with scalar (e.g. INTEGER_TYPE) types and using TYPE_FIELDS on such types results in checking ICE. The following patch fixes that by only recursing on anonymous struct/union FIELD_DECLs. For C those have NULL DECL_NAME, for C++ they would have IDENTIFIER_ANON_P IDENTIFIER_NODE as DECL_NAME (but it seems this plugin is only used for C). No FAILs from plugin.exp now: Running /usr/src/gcc/gcc/testsuite/gcc.dg/plugin/plugin.exp ... === gcc Summary === 2026-03-10 Jakub Jelinek <[email protected]> PR testsuite/112520 * gcc.dg/plugin/analyzer_cpython_plugin.cc (get_field_by_name): If name is "ob_refcnt", recurse only for types of FIELD_DECLs with no DECL_NAME and record or union type. Diff: --- gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc b/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc index 5aa79b1e6412..da1eed95cc3b 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc @@ -69,11 +69,14 @@ get_field_by_name (tree type, const char *name, bool complain = true) return field; } - /* Prior to python 3.11, ob_refcnt a field of PyObject. + /* Prior to python 3.11, ob_refcnt was a field of PyObject. In Python 3.11 ob_refcnt was moved to an anonymous union within PyObject (as part of PEP 683 "Immortal Objects, Using a Fixed Refcount"). */ - if (0 == strcmp (name, "ob_refcnt")) + if (strcmp (name, "ob_refcnt") == 0 + && TREE_CODE (field) == FIELD_DECL + && DECL_NAME (field) == NULL_TREE + && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))) if (tree subfield = get_field_by_name (TREE_TYPE (field), name, false)) return subfield; }
