8000 GCC -Wsign-conversion compiler warning for Include/cpython/longintrepr.h · Issue #112353 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
GCC -Wsign-conversion compiler warning for Include/cpython/longintrepr.h #112353
Closed as not planned
@stratakis

Description

@stratakis

Bug report

Bug description:

When testing cffi with Python 3.12 on Centos Stream 8, with GCC version 8.5.0, the tests were failing as they are using -Werror and -Wsign-conversion.

More specifically they were failing with:

./Include/cpython/longintrepr.h: In function ‘_PyLong_CompactValue’:
./Include/cpython/longintrepr.h:121:23: warning: conversion to ‘Py_ssize_t’ {aka ‘long int’} from ‘long unsigned int’ may change the sign of the result [-Wsign-conversion]
     Py_ssize_t sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);

The offending line was introduced in 9392379 for Python> = 3.12

However that wasn't the case with later compiler versions so after a little digging I was pointed to https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=c77074d05691053ee7347d9e44ab89b3adb23fb1 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

That means that for GCC >= 10, the same warning can be seen again by using -Wsign-conversion and -Warith-conversion together.

The issue is easily fixed by casting to Py_ssize_t however, as indicated by the gcc bugzilla, it's debatable if there should even be a warning for those cases.

Would a fix even be considered for this case?

See also: #112301

CPython versions tested on:

3.12, 3.13, CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0