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 <jakub@redhat.com>
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.
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;
}