8000 Multiple unused code warnings in `Python/generated_cases.c.h` · Issue #125515 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

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

Closed
sobolevn opened this issue Oct 15, 2024 · 3 comments
Closed

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

sobolevn opened this issue Oct 15, 2024 · 3 comments
Assignees
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

@sobolevn
Copy link
Member
sobolevn commented Oct 15, 2024

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:
    GO_TO_INSTRUCTION(LOAD_SUPER_ATTR);
    stack_pointer += -1;
    assert(WITHIN_STACK_BOUNDS());
    and
    return PyStackRef_AsPyObjectSteal(retval);
    stack_pointer += -1;
    assert(WITHIN_STACK_BOUNDS());
  2. some logical? problem with the loop definition

CC @Fidget-Spinner

Linked PRs

@markshannon
Copy link
Member

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.

@picnixz
Copy link
Member
picnixz commented Apr 25, 2025

Is there anything else to do here? I actually have new warnings but I'm unsure whether you want to be them part of this issue:

In file included from Python/ceval.c:1097:
Python/generated_cases.c.h:12157:13: warning: code will never be executed [-Wunreachable-code]
 12157 |             stack_pointer -= 3;
       |             ^~~~~~~~~~~~~
Python/generated_cases.c.h:12150:13: warning: code will never be executed [-Wunreachable-code]
 12150 |             stack_pointer -= 4;
       |             ^~~~~~~~~~~~~
Python/generated_cases.c.h:7462:13: warning: code will never be executed [-Wunreachable-code]
 7462 |             stack_pointer += -1;
      |             ^~~~~~~~~~~~~

I'm using clang-18 and the following configure:

./configure --with-undefined-behavior-sanitizer --prefix="$(pwd)/build" CC=clang LD=clang CFLAGS="-fsanitize=undefined -fno-sanitize-recover"  LDFLAGS="-fsanitize=undefined -fno-sanitize-recover" -q

@picnixz picnixz added the build The build process and cross-build label Apr 25, 2025
@freakboy3742
Copy link
Contributor

From a conversation with @brandtbucher, the first two can be resolved by commenting out the pop_4_error and pop3_error cases in bytecodes.c.

The last error is more complicated; the offending block is this one; the complication is that it's the only opcode that can return from inside the instruction. The "unreachable code" is the automatically injected content that is done for cleanup after the return. The suggestion was that the code generator needs to be taught about that edge case so it doesn't inject the stack cleanup code.

freakboy3742 pushed a commit that referenced this issue Apr 30, 2025
freakboy3742 added a commit that referenced this issue Apr 30, 2025
Remove two unused error branches in the generated bytecode handling.
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
0