Skip to content

static_assert with commas break c-analyzer #162182

Open

Description

@cmaloney

Bug report

On gh-162173 the c-analyzer is failing on the following code. It seems to be because it can't handle a static_assert condition containing a comma (the offsetof args).

#define MAX_DIGITS_FOR_FREELIST \
    ((Py_ssize_t)((sizeof(PyLongObject) - \
                   offsetof(PyLongObject, long_value.ob_digit)) / sizeof(digit)))
static_assert(MAX_DIGITS_FOR_FREELIST >= 1,
              "int freelist blocks must hold at least one digit");
Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython/./Tools/c-analyzer/check-c-globals.py", line 39, in <module>
    main(cmd, cmd_kwargs)
    ~~~~^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/__main__.py", line 498, in main
    run_cmd(**cmd_kwargs)
    ~~~~~~~^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/__main__.py", line 159, in cmd_check
    c_analyzer.cmd_check(
    ~~~~~~~~~~~~~~~~~~~~^
        filenames,
        ^^^^^^^^^^
    ...<4 lines>...
        **kwargs
        ^^^^^^^^
    )
    ^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__main__.py", line 325, in cmd_check
    analyzed = _analyze(filenames, **kwargs)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 152, in analyze
    analysis = Analysis.from_results(results)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/info.py", line 281, in from_results
    for info, resolved in results:
                          ^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__init__.py", line 59, in analyze_decls
    decls = list(decls)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 165, in iter_decls
    for decl in decls:
                ^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__init__.py", line 43, in iter_decls
    for item in parsed:
                ^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/match.py", line 136, in filter_by_kind
    for item in items:
                ^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_parser.py", line 420, in parse_files
    yield from _parse_files(
    ...<5 lines>...
    )
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/__init__.py", line 26, in parse_files
    yield from _parse_file(
            filename, match_kind, get_file_preprocessor, file_maxsizes)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/__init__.py", line 47, in _parse_file
    for item in _parse(srclines, **srckwargs):
                ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/parser/__init__.py", line 130, in parse
    for result in _parse(srclines, anon_name, **srckwargs):
                  ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/parser/__init__.py", line 161, in _parse
    for result in parse_globals(source, anon_name):
                  ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/parser/_global.py", line 46, in parse_globals
    yield from parse_body(source)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/parser/_global.py", line 153, in parse_body
    yield from parse_function_body(source, name, anon_name)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/parser/_func_body.py", line 207, in parse_function_statics
    yield from parse_body(source)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/parser/_func_body.py", line 240, in parse_body
    for item in _parse_body(source, anon_name, ident):
                ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/parser/_compound_decl_body.py", line 33, in parse_struct_body
    for srcinfo in source:
                   ^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/parser/__init__.py", line 234, in _iter_source
    raise RuntimeError(textwrap.dedent(msg))
RuntimeError: 
too many lines, try to increase MAX_SIZES[MAXLINES] in cpython/_parser.py
/home/runner/work/cpython/cpython/Objects/longobject.c starting at line 167 to 368
has code with number of lines 201 greater than 200:
int long_value.ob_digit ) ) / sizeof(digit))) >= 1 ) ? 2 : -1; })] ; (((void) sizeof (__assert_single_arg ( size >= 0 )),  size >= 0 ) ? (void) (0) : __assert_fail ( "size >= 0" , "/home/runner/work/cpython/cpython/Objects/longobject.c", 169,  __PRETTY_FUNCTION__)) ; PyLongObject *result =  ((void *)0) ; if (size > (Py_ssize_t)(( (9223372036854775807L) -1) / 30)) { PyErr_SetString(PyExc_OverflowError, "too many digits in integer"); return  ((void *)0) ; } Py_ssize_t ndigits = size ? size : 1; si...

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. self-assigned this
    on Nov 17, 2026
  2. added
    type-bugAn unexpected behavior, bug, or error
    infraCI, GitHub Actions, buildbots, Dependabot, etc.
    on Nov 17, 2026
  3. added a commit that references this issue on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

infraCI, GitHub Actions, buildbots, Dependabot, etc.type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions