python / cpython

The Python programming language
https://www.python.org
Other
63.44k stars 30.38k forks source link

Multiple unused code warnings in `Python/generated_cases.c.h` #125515

Open sobolevn opened 4 weeks ago

sobolevn commented 4 weeks ago

Bug report

Link: https://github.com/python/cpython/actions/runs/11333284963/job/31517440086#step:6:1025

Report:

 In file included from Python/ceval.c:870:
Python/generated_cases.c.h:5062:13: warning: code will never be executed [-Wunreachable-code]
            stack_pointer += -1;
            ^~~~~~~~~~~~~
Python/generated_cases.c.h:4748:13: warning: code will never be executed [-Wunreachable-code]
            stack_pointer += -1;
            ^~~~~~~~~~~~~
Python/generated_cases.c.h:803:31: warning: code will never be executed [-Wunreachable-code]
clang -c -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall    -D_Py_TIER2=1 -D_Py_JIT -flto=thin -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -fprofile-instr-generate -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE -o Python/codegen.o Python/codegen.c
                for (int _i = oparg; --_i >= 0;) {
                              ^~~~~
Python/generated_cases.c.h:689:31: warning: code will never be executed [-Wunreachable-code]
                for (int _i = oparg*2; --_i >= 0;) {
                              ^~~~~

This looks like we have two different problems:

  1. stack manipulations are added after goto and return: https://github.com/python/cpython/blob/cc5a225cdc2a5d4e035dd08d59cef39182c10a6c/Python/generated_cases.c.h#L4747-L4749 and https://github.com/python/cpython/blob/cc5a225cdc2a5d4e035dd08d59cef39182c10a6c/Python/generated_cases.c.h#L5061-L5063
  2. some logical? problem with the loop definition

CC @Fidget-Spinner

Linked PRs

markshannon commented 3 weeks ago

I'm not sure what we can do about the compiler compiling about

if (CONVERSION_FAILED(x)) {
   ... // compiler complains this is unreachable
}

as CONVERSION_FAILED(x) is #defined as 0 in the with-gil build.