Closed
Description
From #106173 I understand that the C-analyzer (Tools/c-analyzer, our tool that looks for mutable static globals in C code) only works with GCC. When I run it on macOS (i.e. in clang land) I get a long message that doesn't explain this, plus a traceback. Maybe it should detect that you're using clang (even if it's aliased to gcc
) and print a shorter message without a traceback?
~/cpython$ make check-c-globals
python3.12 ./Tools/c-analyzer/check-c-globals.py \
--format summary \
--traceback
analyzing files...
.# requested file: </Users/guido/cpython/Include/pystats.h>
-------------------------
Non-constant global variables are generally not supported
in the CPython repo. We use a tool to analyze the C code
and report if any unsupported globals are found. The tool
may be run manually with:
./python Tools/c-analyzer/check-c-globals.py --format summary [FILE]
Occasionally the tool is unable to parse updated code.
If this happens then add the file to the "EXCLUDED" list
in Tools/c-analyzer/cpython/_parser.py and create a new
issue for fixing the tool (and CC ericsnowcurrently
on the issue).
If the tool reports an unsupported global variable and
it is actually const (and thus supported) then first try
fixing the declaration appropriately in the code. If that
doesn't work then add the variable to the "should be const"
section of Tools/c-analyzer/cpython/ignored.tsv.
If the tool otherwise reports an unsupported global variable
then first try to make it non-global, possibly adding to
PyInterpreterState (for core code) or module state (for
extension modules). In an emergency, you can add the
variable to Tools/c-analyzer/cpython/globals-to-fix.tsv
to get CI passing, but doing so should be avoided. If
this course it taken, be sure to create an issue for
eliminating the global (and CC ericsnowcurrently).
Traceback (most recent call last):
File "/Users/guido/cpython/./Tools/c-analyzer/check-c-globals.py", line 39, in <module>
main(cmd, cmd_kwargs)
File "/Users/guido/cpython/Tools/c-analyzer/cpython/__main__.py", line 498, in main
run_cmd(**cmd_kwargs)
File "/Users/guido/cpython/Tools/c-analyzer/cpython/__main__.py", line 159, in cmd_check
c_analyzer.cmd_check(
File "/Users/guido/cpython/Tools/c-analyzer/c_analyzer/__main__.py", line 325, in cmd_check
analyzed = _analyze(filenames, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/guido/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 149, in analyze
analysis = Analysis.from_results(results)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/guido/cpython/Tools/c-analyzer/c_analyzer/info.py", line 281, in from_results
for info, resolved in results:
File "/Users/guido/cpython/Tools/c-analyzer/c_analyzer/__init__.py", line 59, in analyze_decls
decls = list(decls)
^^^^^^^^^^^
File "/Users/guido/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 162, in iter_decls
for decl in decls:
File "/Users/guido/cpython/Tools/c-analyzer/c_analyzer/__init__.py", line 43, in iter_decls
for item in parsed:
File "/Users/guido/cpython/Tools/c-analyzer/c_parser/match.py", line 136, in filter_by_kind
for item in items:
File "/Users/guido/cpython/Tools/c-analyzer/cpython/_parser.py", line 399, in parse_files
yield from _parse_files(
File "/Users/guido/cpython/Tools/c-analyzer/c_parser/__init__.py", line 26, in parse_files
yield from _parse_file(
File "/Users/guido/cpython/Tools/c-analyzer/c_parser/__init__.py", line 47, in _parse_file
for item in _parse(srclines, **srckwargs):
File "/Users/guido/cpython/Tools/c-analyzer/c_parser/parser/__init__.py", line 128, in parse
for result in _parse(srclines, anon_name, **srckwargs):
File "/Users/guido/cpython/Tools/c-analyzer/c_parser/parser/__init__.py", line 159, in _parse
for result in parse_globals(source, anon_name):
File "/Users/guido/cpython/Tools/c-analyzer/c_parser/parser/_global.py", line 38, in parse_globals
for srcinfo in source:
File "/Users/guido/cpython/Tools/c-analyzer/c_parser/parser/__init__.py", line 173, in _iter_source
for fileinfo, line in lines:
File "/Users/guido/cpython/Tools/c-analyzer/c_parser/__init__.py", line 46, in <genexpr>
srclines = ((l.file, l.data) for l in preprocessed if l.kind == 'source')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/guido/cpython/Tools/c-analyzer/c_parser/preprocessor/gcc.py", line 94, in _iter_lines
raise NotImplementedError((line, expected))
NotImplementedError: ('# 1 "<built-in>" 1', '# 1 "<built-in>"')
make: *** [check-c-globals] Error 1
~/cpython$