Issue36791
Created on 2019-05-04 05:54 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 13080 | merged | serhiy.storchaka, 2019-05-04 05:57 | |
| PR 13262 | merged | miss-islington, 2019-05-12 09:18 | |
| Messages (5) | |||
|---|---|---|---|
| msg341374 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2019-05-04 05:54 | |
sum() assumes that an arithmetic operation on signed longs will wrap modulo 2**(bits_in_long) on overflow. However, signed overflow causes undefined behaviour according to the C standards (e.g., C99 6.5, para. 5), and gcc is known to assume that signed overflow never occurs in correct code, and to make use of this assumption when optimizing. See also issue7406. |
|||
| msg341384 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2019-05-04 13:52 | |
I tested few cases (all positive, all negative, mixed), and did not found any performance difference after this change. ./python -m perf timeit -s "a = list(range(10**4))" -- "sum(a)" ./python -m perf timeit -s "a = [-i for i in range(10**4)]" -- "sum(a)" ./python -m perf timeit -s "a = [i*(-1)**i for i in range(10**4)]" -- "sum(a)" |
|||
| msg341430 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2019-05-05 11:26 | |
New changeset 29500737d45cbca9604d9ce845fb2acc3f531401 by Serhiy Storchaka in branch 'master': bpo-36791: Safer detection of integer overflow in sum(). (GH-13080) https://github.com/python/cpython/commit/29500737d45cbca9604d9ce845fb2acc3f531401 |
|||
| msg342248 - (view) | Author: Mark Dickinson (mark.dickinson) * ![]() |
Date: 2019-05-12 09:12 | |
Can this be closed, or does the fix need to be backported? |
|||
| msg342250 - (view) | Author: miss-islington (miss-islington) | Date: 2019-05-12 09:37 | |
New changeset b7e483b6d07081d5f81860258e95785975a7cbf8 by Miss Islington (bot) in branch '3.7': bpo-36791: Safer detection of integer overflow in sum(). (GH-13080) https://github.com/python/cpython/commit/b7e483b6d07081d5f81860258e95785975a7cbf8 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:14 | admin | set | github: 80972 |
| 2019-05-12 09:39:22 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019-05-12 09:37:19 | miss-islington | set | nosy:
+ miss-islington messages: + msg342250 |
| 2019-05-12 09:18:10 | miss-islington | set | pull_requests: + pull_request13172 |
| 2019-05-12 09:12:33 | mark.dickinson | set | messages: + msg342248 |
| 2019-05-05 11:26:27 | serhiy.storchaka | set | messages: + msg341430 |
| 2019-05-04 13:52:41 | serhiy.storchaka | set | messages: + msg341384 |
| 2019-05-04 05:57:28 | serhiy.storchaka | set | keywords:
+ patch stage: patch review pull_requests: + pull_request12995 |
| 2019-05-04 05:54:49 | serhiy.storchaka | create | |
