classification
Title: GCC 10 compiler warnings
Type: Stage: patch review
Components: Build Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: corona10, petdance, vstinner
Priority: normal Keywords: patch

Created on 2020-04-30 20:51 by vstinner, last changed 2020-05-17 09:04 by mark.dickinson.

Pull Requests
URL Status Linked Edit
PR 19852 merged corona10, 2020-05-02 02:50
Messages (8)
msg367785 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-04-30 20:51
GCC 10.0.1 on PPC64LE Fedora Rawhide LTO 3.x buildbot:
https://buildbot.python.org/all/#/builders/351/builds/406

Objects/longobject.c: In function β€˜_PyLong_Frexp’:
Objects/longobject.c:2928:33: warning: β€˜x_digits[0]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 2928 |                     x_digits[0] |= 1;
      |                                 ^~

In function β€˜assemble_lnotab’,
    inlined from β€˜assemble_emit’ at Python/compile.c:5709:25,
    inlined from β€˜assemble’ at Python/compile.c:6048:18:
Python/compile.c:5663:19: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 5663 |         *lnotab++ = k;
      |         ~~~~~~~~~~^~~
msg367809 - (view) Author: Andy Lester (petdance) * Date: 2020-04-30 23:46
Did you add any options to the ./configure call for cpython?  What were they?
msg367817 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-05-01 00:14
Andy Lester:
> Did you add any options to the ./configure call for cpython?  What were they?

I reported warnings that I saw on a buildbot build.

Extract of https://buildbot.python.org/all/#/builders/351/builds/406.

configure step:

    ./configure --prefix '$(PWD)/target' --with-lto

test.pythoninfo of the build says:

CC.version: gcc (GCC) 10.0.1 20200420 (Red Hat 10.0.1-0.12)

sysconfig[CCSHARED]: -fPIC
sysconfig[CC]: gcc -pthread
sysconfig[CFLAGS]: -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall
sysconfig[CONFIG_ARGS]: '--prefix' '/home/buildbot/buildarea/3.x.cstratak-fedora-rawhide-ppc64le.lto/build/target' '--with-lto'
sysconfig[OPT]: -DNDEBUG -g -fwrapv -O3 -Wall
sysconfig[PY_CFLAGS]: -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall
sysconfig[PY_CFLAGS_NODIST]: -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal
sysconfig[PY_CORE_LDFLAGS]: -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g
sysconfig[PY_LDFLAGS_NODIST]: -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g
sysconfig[PY_STDMODULE_CFLAGS]: -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include
msg367857 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-05-01 15:57
I'm fairly sure that that's a false positive for `longobject.c`. Do you know of a non-intrusive way to silence the warning?
msg367858 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-05-01 16:08
As to _why_ it's a false positive: at that point in the code, assuming 30-bit limbs and an IEEE 754 binary64 "double", we have (using Python notation for floor division)

    a_size == 1 + (a_bits - 1) // 30

and

    shift_digits == (a_bits - 55) // 30

from which it's clear that

    shift_digits <= (a_bits - 1) // 30 < a_size

so a_size - shift_digits is always strictly positive.

The above doesn't depend on the precise values 55 and 30 - any other positive values would have worked, so even with 15-bit digits and some other double format with fewer bits, we still have "shift_digits < a_size".

And now since the v_rshift call writes "a_size - shift_digits" digits to x, we're guaranteed that at least one digit is written, so `x[0]` is not uninitialised.
msg367864 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-05-01 17:06
@mark.dickinson @vstinner

I'd like to suggest this change.
There was no performance impact on my local machine.

--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -2852,7 +2852,8 @@ _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e)
 {
     Py_ssize_t a_size, a_bits, shift_digits, shift_bits, x_size;
     /* See below for why x_digits is always large enough. */
-    digit rem, x_digits[2 + (DBL_MANT_DIG + 1) / PyLong_SHIFT];
+    digit rem;
+    digit x_digits[2 + (DBL_MANT_DIG + 1) / PyLong_SHIFT] = {0,};
     double dx;
     /* Correction term for round-half-to-even rounding.  For a digit x,
        "x + half_even_correction[x & 7]" gives x rounded to the nearest
@@ -2903,8 +2904,6 @@ _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e)
         shift_digits = (DBL_MANT_DIG + 2 - a_bits) / PyLong_SHIFT;
         shift_bits = (DBL_MANT_DIG + 2 - a_bits) % PyLong_SHIFT;
         x_size = 0;
-        while (x_size < shift_digits)
-            x_digits[x_size++] = 0;
         rem = v_lshift(x_digits + x_size, a->ob_digit, a_size,
                        (int)shift_bits);
         x_size += a_size;
msg368048 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-05-04 13:32
New changeset b88cd585d36d6285a5aeb0b6fdb70c134062181e by Dong-hee Na in branch 'master':
bpo-40455: Remove gcc10 warning about x_digits (#19852)
https://github.com/python/cpython/commit/b88cd585d36d6285a5aeb0b6fdb70c134062181e
msg368054 - (view) Author: Andy Lester (petdance) * Date: 2020-05-04 14:33
For anyone following along, note that the PR above is different than the original suggestion.  The PR correctly sets x_size, not leaving it zero.
History
Date User Action Args
2020-05-17 09:04:17mark.dickinsonsetnosy: - mark.dickinson
2020-05-04 14:33:48petdancesetmessages: + msg368054
2020-05-04 13:32:49corona10setmessages: + msg368048
2020-05-02 02:50:25corona10setkeywords: + patch
stage: patch review
pull_requests: + pull_request19169
2020-05-01 17:06:24corona10setnosy: + corona10
messages: + msg367864
2020-05-01 16:08:41mark.dickinsonsetmessages: + msg367858
2020-05-01 15:57:41mark.dickinsonsetmessages: + msg367857
2020-05-01 15:52:22mark.dickinsonsetnosy: + mark.dickinson
2020-05-01 00:14:32vstinnersetmessages: + msg367817
2020-04-30 23:46:09petdancesetmessages: + msg367809
2020-04-30 22:11:51petdancesetnosy: + petdance
2020-04-30 20:51:08vstinnercreate