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

Unused code warning in _testembed.c #125517

Closed
sobolevn opened this issue Oct 15, 2024 · 1 comment
Closed

Unused code warning in _testembed.c #125517

sobolevn opened this issue Oct 15, 2024 · 1 comment
Assignees
Labels
tests Tests in the Lib/test dir 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:1315

Report:

./Programs/_testembed.c:1904:5: warning: code will never be executed [-Wunreachable-code]
    const char *err_msg;
    ^~~~~~~~~~~~~~~~~~~~
sed -e "s,/usr/bin/env python3,/usr/local/bin/python3.14," < ./Tools/scripts/pydoc3 > build/scripts-3.14/pydoc3.14
./Programs/_testembed.c:2052:5: warning: code will never be executed [-Wunreachable-code]
    const char *err_msg;
sed -e "s,@EXENAME@,/usr/local/bin/python3.14," < ./Misc/python-config.in >python-config.py
    ^~~~~~~~~~~~~~~~~~~~

Source of problem:

  • We cannot have goto targets on variable declarations.
  • So, they are declared right above:

    cpython/Programs/_testembed.c

    Lines 1903 to 1910 in cc5a225

    return 0;
    const char *err_msg;
    error:
    (void)PyInitConfig_GetError(config, &err_msg);
    printf("Python init failed: %s\n", err_msg);
    exit(1);
    }
  • So, this warning marks const char *err_msg; as unreachable code

I propose to declare this variable before the first goto. This way we can remove this warning. And since this is just a test, we can do that freely.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Oct 15, 2024
@sobolevn sobolevn self-assigned this Oct 15, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Oct 15, 2024
@sobolevn sobolevn changed the title Unused code warning in Unused code warning in _testembed.c Oct 15, 2024
@vstinner
Copy link
Member

On Fedora 40 with clang 18.1.8, I get the following warning:

./Programs/_testembed.c:1906:5: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
 1906 |     const char *err_msg;
      |     ^
1 warning generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants