How to suppress unused label warnings on Windows?

I have an open PR which retains TARGET_* labels when computed gotos aren’t used but Py_DEBUG is defined. I got things to compile on Mac and Linux (gcc and clang) without warnings, as desired. The Windows CI still reports warnings though. Here’s an example of the warning:

D:\a\cpython\cpython\Python\ceval.c(1169,9): warning C4102: 'TARGET_NOP': unreferenced label [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

I’ve never used Windows for software development and all the XML project files are just line noise to me. Can someone suggest how to suppress unused labels when Py_DEBUG is defined? For comparison, here’s the relevant chunk of configure.ac:

    case $ac_cv_prog_cc_g in
	yes)
	    if test "$Py_DEBUG" = 'true' ; then
		OPT="-g $PYDEBUG_CFLAGS -Wall -Wno-unused-label"
	    else
		OPT="-g $WRAP -O3 -Wall"
	    fi
	    ;;
	*)
	    OPT="-O3 -Wall"
	    ;;
	esac

Thanks…

Skip

I think that configure.ac is not used on Windows (unless it is Cygwin).

Correct, but I’m pretty sure Cygwin support is broken at the moment.

I wasn’t suggesting that a solution on Windows would use configure, just giving that as an example of how I accomplished that for Unix-like compilation environments. I assume Python on Windows is built using Windows-specific tools, but I have no experience with them. I was asking for help with that.

This is an example of how to suppress the warnings locally (around the entire function, I would guess): https://github.com/python/cpython/blob/main/Python/sysmodule.c#L1530 (ends at line 1613).

If we want to suppress the warnings for the whole build, it would go into https://github.com/python/cpython/blob/main/PCbuild/pyproject.props#L32 and look like this example.

I’d rather not only suppress warnings in debug builds[1] - they should show up consistently or be suppressed consistently.


  1. But if we were, there’s a ClCompile Condition="$(Configuration)=Debug" element a little further down in pyproject.props for this purpose. ↩︎

1 Like

Thanks. Where do I find mappings from those magic numbers to useful names? For example, you referenced

#pragma warning(disable:4996)

Based on the comment, I imagine 4996 is something to do with deprecations. How do I find what the magic number is for unused labels?

I’d be happy to always suppress the unused label warnings for the TARGET_* labels. If that is agreeable to other folks, I’d propose also modifying the relevant macros to always insert them, no matter the state of Py_DEBUG or USE_COMPUTED_GOTOS.

So the unused label one is 4102

Thanks Matti. That (of course) must be Microsoft-specific. Messing around, I settled on this:

/* TBD - what about other compilers? */
#ifdef __GNUC__
#  pragma GCC diagnostic push
#  pragma GCC diagnostic ignored "-Wunused-label"
#else /* MS_WINDOWS ? */
#  pragma warning(push)
#  pragma warning(disable:4102)
#endif
... affected code elided :-) ...
#ifdef __GNUC__
#  pragma GCC diagnostic pop
#else /* MS_WINDOWS ? */
#  pragma warning(pop)
#endif

I worried the #ifdef __GNUC__ might be too restrictive, hence the TBD comment, but it seems clang (at least) is happy with the construct. Now to push these changes and see if the MS compiler is happy…

Thanks for the help. PR has been updated…

You’ve got it now, but the easiest way is to add an unused label and see what number is in the warning message :wink: