◐ Shell
clean mode source ↗

GH-137959: fix warning 'visibility' attribute ignored in jit/trampoline.c by chris-eibl · Pull Request #140286 · python/cpython

Since #137961 we're getting this warning

/home/runner/work/cpython/cpython/Tools/jit/trampoline.c:13:13: warning: 'visibility' attribute ignored [-Wignored-attributes]
   13 |     typedef DECLARE_TARGET((*jit_func));
      |             ^
/home/runner/work/cpython/cpython/Tools/jit/jit.h:11:49: note: expanded from macro 'DECLARE_TARGET'
   11 |     _Py_CODEUNIT *__attribute__((preserve_none, visibility("hidden"))) \
      |                                                 ^
1 warning generated.

for all platforms, e.g.
https://github.com/python/cpython/actions/runs/18575809544/job/52961278295?pr=140233
except i686-pc-windows-msvc, where this warning has to be suppressed

elif re.fullmatch(r"i686-pc-windows-msvc", host):
host = "i686-pc-windows-msvc"
condition = "defined(_M_IX86)"
# -Wno-ignored-attributes: __attribute__((preserve_none)) is not supported here.
args = ["-DPy_NO_ENABLE_SHARED", "-Wno-ignored-attributes"]

to silence the many warnings we'd get otherwise, because preserve_none is not supported there.

I suggest to use

// To use preserve_none in JIT builds, we need to declare a separate function
// pointer with __attribute__((preserve_none)), since this attribute may not be
// supported by the compiler used to build the rest of the interpreter.
typedef jit_func __attribute__((preserve_none)) jit_func_preserve_none;

I've verified with a small Godbolt demo and by comparing the emit_trampoline in the generated jit_stencils.h that the generated code remains the same.