Title: Enable `-fstrict-overflow` · Issue #96821 · python/cpython · GitHub
Open Graph Title: Enable `-fstrict-overflow` · Issue #96821 · python/cpython
X Title: Enable `-fstrict-overflow` · Issue #96821 · python/cpython
Description: At the moment we compile releases with -fwrapv which makes the code a bit safer, but disables certain optimizations. From the GCC docs: This option instructs the compiler to assume that signed arithmetic overflow of addition, subtraction...
Open Graph Description: At the moment we compile releases with -fwrapv which makes the code a bit safer, but disables certain optimizations. From the GCC docs: This option instructs the compiler to assume that signed arit...
X Description: At the moment we compile releases with -fwrapv which makes the code a bit safer, but disables certain optimizations. From the GCC docs: This option instructs the compiler to assume that signed arit...
Opengraph URL: https://github.com/python/cpython/issues/96821
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Enable `-fstrict-overflow`","articleBody":"At the moment we compile releases with `-fwrapv` which makes the code a bit safer, but disables certain optimizations. From the GCC docs:\r\n\r\n\u003e This option instructs the compiler to assume that signed arithmetic overflow of addition, subtraction and multiplication wraps around using twos-complement representation. This flag enables some optimizations and disables others.\r\n\r\nMy [experiments with running sanitisers](https://github.com/python/cpython/issues/96678#issuecomment-1243499193) seem to suggest that we are nearly already ready for `-fno-wrapv` (or `-fstrict-overflow` in general). Doing so could lead to quite a few speedups, but we would need to be more careful with the code we write.\r\n\r\nIt might be worthwhile to get a few benchmarks.\r\n\r\n(To be extra precise, we give `-fwrapv` for clang and gcc for any build that doesn't get `--with-pydebug`.)\r\n\r\n# Pitch\r\n\r\nMy plan right now is to adapt the build system so that only the modules that need it are build with `-fwrapv`, and the rest can be build with `-fstrict-overflow`.\r\n\r\nWe already have config machinery that can add specific `CFLAGS` for specific modules only.\r\n\r\nPerhaps the whole thing can be gated behind a configure flag, like `--with-strict-overflow`.\r\n\r\nIf everything goes well, and this improves performance we can consider adding this functionality to one of the standard optimization options.\r\n\r\nWe can also work on making more modules `-fstrict-overflow` safe.\r\n\r\n# Previous discussion\r\n\r\n@markshannon @ericsnowcurrently \r\n\r\nBrought up on https://github.com/faster-cpython/ideas/issues/458 and inspired by https://github.com/python/cpython/issues/96678\r\n\r\nSome previous issues around `-fwrapv`:\r\n\r\n* https://bugs.python.org/issue11149\r\n* https://bugs.python.org/issue1621\r\n* https://bugs.python.org/issue1608\r\n\r\nI'm sure there are more.\r\n\r\n# Progress so far\r\n\r\nAs far as is currently known, the three remaining modules that rely on defined integer overflow are fixed by:\r\n\r\n* `_struct`: https://github.com/python/cpython/pull/96739\r\n* `audioop`: https://github.com/python/cpython/pull/96923\r\n* `_ctypes`: https://github.com/python/cpython/pull/96925\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-96823\n* gh-139595\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/matthiasgoergens","@type":"Person","name":"matthiasgoergens"},"datePublished":"2022-09-14T09:33:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/96821/cpython/issues/96821"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c72570d7-8c28-9d19-4a65-5a9b26cff306 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9742:3AAB0D:908FAD:C0EE81:6969BE82 |
| html-safe-nonce | 0775b4fab6c21d5e91f78cbc0c8bde3d4d87615786c304d6dbf4a740b541e164 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzQyOjNBQUIwRDo5MDhGQUQ6QzBFRTgxOjY5NjlCRTgyIiwidmlzaXRvcl9pZCI6IjYxODAwNzQ3OTA5NzUwMjg4NjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3f9d71a007df6c3b25bf3046458d4fcb41c823bb42aa9c422b623bfccf7496b6 |
| hovercard-subject-tag | issue:1372663498 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/96821/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d4089f4f583f6081ec76d875406d3f2baf8324c7686c1bd0cd9b17e4e649f1a7/python/cpython/issues/96821 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d4089f4f583f6081ec76d875406d3f2baf8324c7686c1bd0cd9b17e4e649f1a7/python/cpython/issues/96821 |
| og:image:alt | At the moment we compile releases with -fwrapv which makes the code a bit safer, but disables certain optimizations. From the GCC docs: This option instructs the compiler to assume that signed arit... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | matthiasgoergens |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width