Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreachable code warnings while building latest main at 48c70b8 #128086

Open
srinivasreddy opened this issue Dec 19, 2024 · 17 comments
Open

Unreachable code warnings while building latest main at 48c70b8 #128086

srinivasreddy opened this issue Dec 19, 2024 · 17 comments
Labels
build The build process and cross-build interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@srinivasreddy
Copy link
Contributor

srinivasreddy commented Dec 19, 2024

Bug report

Bug description:

I ran the ./configure and make, here are the warnings shown.

gcc -c -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE -o Python/ast.o Python/ast.c
gcc -c -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE -o Python/ast_opt.o Python/ast_opt.c
gcc -c -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE -o Python/ast_unparse.o Python/ast_unparse.c
gcc -c -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE -o Python/bltinmodule.o Python/bltinmodule.c
gcc -c -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE -o Python/brc.o Python/brc.c
gcc -c -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE -o Python/ceval.o Python/ceval.c
In file included from Python/ceval.c:904:
Python/generated_cases.c.h:808:31: warning: code will never be executed [-Wunreachable-code]
  808 |                 for (int _i = oparg; --_i >= 0;) {
      |                               ^~~~~
Python/generated_cases.c.h:694:31: warning: code will never be executed [-Wunreachable-code]
  694 |                 for (int _i = oparg*2; --_i >= 0;) {
      |                               ^~~~~
2 warnings generated.

Operating System:

➜  cpython git:(main) uname -a
Darwin SREDDY- 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:02:27 PDT 2024; root:xnu-11215.41.3~2/RELEASE_X86_64 x86_64

Main branch commit : 48c70b8

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

@srinivasreddy srinivasreddy added the type-bug An unexpected behavior, bug, or error label Dec 19, 2024
@srinivasreddy srinivasreddy changed the title Warnings while building latest main Unreachable code warnings while building latest main at 48c70b8 Dec 19, 2024
@srinivasreddy
Copy link
Contributor Author

I have updated the tcl-tk to version 9.0.0_1, the warnings are gone. Please refer - build.log

@picnixz picnixz added build The build process and cross-build interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Dec 20, 2024
@erlend-aasland
Copy link
Contributor

I cannot reproduce this on my MacBook. The tcl-tk comment seems off-topic for this issue. Can you provide more information about your environment?

@erlend-aasland erlend-aasland added the pending The issue will be closed if no feedback is provided label Jan 3, 2025
@srinivasreddy
Copy link
Contributor Author

Like gcc compiler version? and ...?

@erlend-aasland
Copy link
Contributor

Include everything that is needed to reproduce the failure you are seeing. Are you still seeing these failures? Did you compile from a clean source tree (git clean -fdx)?

@srinivasreddy
Copy link
Contributor Author

➜  cpython git:(main) env
TERM_SESSION_ID=REDACTED
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.xFPWqTHwrg/Listeners
LC_TERMINAL_VERSION=3.5.10
COLORFGBG=7;0
ITERM_PROFILE=REDACTED
XPC_FLAGS=0x0
LANG=en_US.UTF-8
PWD=/Users/REDACTED/workspace/github_repos/cpython
SHELL=/bin/zsh
__CFBundleIdentifier=com.googlecode.iterm2
TERM_FEATURES=REDACTED
TERM_PROGRAM_VERSION=3.5.10
TERM_PROGRAM=iTerm.app
PATH=/Users/REDACTED/.nvm/versions/node/v20.17.0/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/REDACTED/.cargo/bin:/Applications/iTerm.app/Contents/Resources/utilities:/Users/REDACTED/.local/bin
LC_TERMINAL=iTerm2
COLORTERM=truecolor
COMMAND_MODE=unix2003
TERM=xterm-256color
TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
HOME=/Users/REDACTED
TMPDIR=/var/folders/6v/n8nm5d6136b0br85j6llcy3c0000gn/T/
USER=REDACTED
XPC_SERVICE_NAME=0
LOGNAME=REDACTED
ITERM_SESSION_ID=REDACTED
__CF_USER_TEXT_ENCODING=0x0:0:0
SHLVL=1
OLDPWD=/Users/REDACTED/workspace/github_repos
ZSH=/Users/REDACTED/.oh-my-zsh
PAGER=less
LESS=-R
LSCOLORS=Gxfxcxdxbxegedabagacad
NVM_DIR=/Users/REDACTED/.nvm
NVM_CD_FLAGS=-q
NVM_BIN=/Users/REDACTED/.nvm/versions/node/v20.17.0/bin
NVM_INC=/Users/REDACTED/.nvm/versions/node/v20.17.0/include/node
LC_ALL=en_US.UTF-8
_=/usr/bin/env
➜  cpython git:(main) sw_vers
ProductName:		macOS
ProductVersion:		15.1.1
BuildVersion:		24B91
➜  cpython git:(main) gcc --version
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: x86_64-apple-darwin24.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
➜  cpython git:(main) xcodebuild -version
Xcode 16.2
Build version 16C5032a
➜  cpython git:(main) clang --version
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: x86_64-apple-darwin24.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@erlend-aasland
Copy link
Contributor

Still unable to reproduce. I'm on the same macOS version and the same compiler.

@srinivasreddy
Copy link
Contributor Author

Here is the ./configure output i have captured.

config.log

@srinivasreddy
Copy link
Contributor Author

srinivasreddy commented Jan 3, 2025

Here is the make output i have capture with the command - make &> make.log. You should be able to see the warnings in the make.log file.

make.log

In file included from Python/ceval.c:904:
Python/generated_cases.c.h:808:31: warning: code will never be executed [-Wunreachable-code]
  808 |                 for (int _i = oparg; --_i >= 0;) {
      |                               ^~~~~
Python/generated_cases.c.h:694:31: warning: code will never be executed [-Wunreachable-code]
  694 |                 for (int _i = oparg*2; --_i >= 0;) {
      |                               ^~~~~
2 warnings generated.

Main branch at b4f799b

@picnixz
Copy link
Member

picnixz commented Jan 3, 2025

Try to also do a make distclean, make clean and make cleantest. Some files might be left.

@erlend-aasland
Copy link
Contributor

Actually, to be on the safe side, please do the following, then build again:

$ git reset --hard HEAD
$ git clean -fdx

@picnixz
Copy link
Member

picnixz commented Jan 3, 2025

FTR: git clean -fdx would also remove all files that you manually added to the CPython project but are not in .gitignore and not committed (I have some) so I'd advise using a different directory than the directory you're usually using for development.

@ned-deily
Copy link
Member

I also see unreachable-code warnings in generated_cases.c.h but only when not using --with-pydebug.

FTR, using the current HEAD of main using Apple-supplied clang. Environment is current macOS and Xcode releases. Also same warnings with a slightly older release of Xcode and clang.

$ git show
commit 1153e66e20124b8f3484bcaddbc0e252d31161a6 (HEAD -> main, upstream/main, upstream/HEAD)
Author: Victor Stinner <vstinner@python.org>
Date:   Tue Jan 14 11:18:52 2025 +0100

    gh-109959: Skip test_glob.test_selflink() flaky test (#128812)  
[...]
$ clang --version
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ xcodebuild -version
Xcode 16.2
Build version 16C5032a
$ sw_vers
ProductName:		macOS
ProductVersion:		15.2
BuildVersion:		24C101
$ CC=clang ./configure && make -j4
[...]
clang -c -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -Werror=unguarded-availability  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE -o Python/ceval.o Python/ceval.c
In file included from Python/ceval.c:906:
Python/generated_cases.c.h:4489:34: warning: code will never be executed [-Wunreachable-code]
                    for (int i = 0; i < total_args; i++) {
                                 ^
Python/generated_cases.c.h:965:34: warning: code will never be executed [-Wunreachable-code]
                    for (int i = 0; i < total_args; i++) {
                                 ^
Python/generated_cases.c.h:824:31: warning: code will never be executed [-Wunreachable-code]
                for (int _i = oparg; --_i >= 0;) {
                              ^~~~~
Python/generated_cases.c.h:710:31: warning: code will never be executed [-Wunreachable-code]
                for (int _i = oparg*2; --_i >= 0;) {
                              ^~~~~

@ned-deily ned-deily removed the pending The issue will be closed if no feedback is provided label Jan 14, 2025
@picnixz
Copy link
Member

picnixz commented Jan 14, 2025

cc @markshannon

@chris-eibl
Copy link
Contributor

Those are preceded by if (CONVERSION_FAILED(...)) which expands to if (0) in a "regular GIL" build, i.e. when Py_GIL_DISABLED is not defined. Interestingly, there are more such ifs, but not in all cases the warning is emitted for the following code line.

I think like unused labels are suppressed in generated code, these should be suppressed, too.
I've added # pragma GCC diagnostic ignored "-Wunreachable-code" to

cpython/Python/ceval.c

Lines 725 to 727 in f26daa9

#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-label"

and also added || defined(__clang_) to get rid of this warning in clang-cl based builds ...

@picnixz
Copy link
Member

picnixz commented Jan 14, 2025

For clang, can't we add #pragma clang diagnostic? Also, I believe we should patch Tools/generator_cases.py instead of ceval.c as this is the script responsible for generating Python/generated_cases.c.h and only patch it locally and not make a global #pragma (but I don't know if it's feasible)

@chris-eibl
Copy link
Contributor

"Regular" clangs react on __GNUC__, I only added __clang__ because I did not want to see those warnings in Windows using clang-cl, which does (must) not define __GNU__.

I agree that patching Tools/generator_cases.py would be even better if someone wants to bite that bullet :)

@srinivasreddy
Copy link
Contributor Author

srinivasreddy commented Jan 15, 2025

I’m still able to reproduce the warnings with this workflow, which effectively eliminates the possibility that any custom settings or files are causing interference.

git clone https://github.com/python/cpython.git cpython_dev --depth=1
cd cpython_dev
./configure
make

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants