Title: JIT: UB: unaligned store in `patch_*` functions · Issue #139269 · python/cpython · GitHub
Open Graph Title: JIT: UB: unaligned store in `patch_*` functions · Issue #139269 · python/cpython
X Title: JIT: UB: unaligned store in `patch_*` functions · Issue #139269 · python/cpython
Description: Bug report Bug description: Summary When the CPython main branch is compiled with Clang using the experimental JIT (--enable-experimental-jit) and memory sanitizers (-fsanitize=address,undefined), it reliably crashes during the test suit...
Open Graph Description: Bug report Bug description: Summary When the CPython main branch is compiled with Clang using the experimental JIT (--enable-experimental-jit) and memory sanitizers (-fsanitize=address,undefined), ...
X Description: Bug report Bug description: Summary When the CPython main branch is compiled with Clang using the experimental JIT (--enable-experimental-jit) and memory sanitizers (-fsanitize=address,undefined), ...
Opengraph URL: https://github.com/python/cpython/issues/139269
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"JIT: UB: unaligned store in `patch_*` functions","articleBody":"# Bug report\n\n### Bug description:\n\n#### Summary\n\nWhen the CPython `main` branch is compiled with Clang using the experimental JIT (`--enable-experimental-jit`) and memory sanitizers (`-fsanitize=address,undefined`), it reliably crashes during the test suite execution.\n\nThe crash is preceded by a clear UndefinedBehaviorSanitizer (UBSan) report indicating a misaligned memory store/load of a `uint64_t` within `Python/jit.c`. This undefined behavior immediately leads to a segmentation fault, which is caught by AddressSanitizer (ASan).\n\nThe issue has been reproduced with both **C11** and **C17** language standards, and with different optimization levels (`-O1`, `-O3`), confirming that this is a fundamental bug in the JIT's code generation or patching logic, not an artifact of a specific build configuration.\n\n#### Environment\n\n* **CPython Version:** `main` branch, commit `dd45179fa0`\n* **Operating System:** Linux (Ubuntu 24.04 based, Kernel 6.14.0-32-generic)\n* **Architecture:** x86_64\n* **Compiler:** Clang 20.1.2 (`Ubuntu clang version 20.1.2 (0ubuntu1)`)\n\n#### Configuration\n\nThe bug is reproducible with the following minimal debug configuration (PGO and LTO are not required to trigger the crash):\n\n**Environment Variables:**\n```sh\nexport CC=clang\nexport CXX=clang++\nexport CFLAGS=\"-std=c11 -g -O1 -fno-omit-frame-pointer -fsanitize=address,undefined\"\nexport LDFLAGS=\"-fsanitize=address,undefined\"\n```\n\n**Configure Command:**\n```sh\n./configure --with-pydebug \\\n --enable-experimental-jit \\\n --with-address-sanitizer \\\n --with-undefined-behavior-sanitizer\n```\n\n#### Steps to Reproduce\n\n1. Clone the CPython repository and check out the `main` branch.\n2. Create an out-of-tree build directory: `mkdir build && cd build`\n3. Run the `configure` command from the section above (e.g., `../configure ...`).\n4. Compile CPython: `make -j$(nproc)`\n5. Run a test known to trigger the issue (e.g., `test_array` or `test_asyncio`):\n ```sh\n ./python -m test test_array\n ```\n\n#### Expected Results\n\nThe test should run and pass without crashing the interpreter.\n\n#### Actual Results\n\nThe interpreter crashes with a segmentation fault. The sanitizers provide detailed reports just before the crash.\n\n**UBSan Report:**\nThe first error reported is from UBSan, indicating the root cause:\n```\n../../Python/jit.c:228:5: runtime error: store to misaligned address 0x7be05a2205ab for type 'uint64_t' (aka 'unsigned long'), which requires 8 byte alignment\n0x7be05a2205ab: note: pointer points here\n 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n ^\nSUMMARY: UndefinedBehaviorSanitizer: misaligned-pointer-use ../../Python/jit.c:228:5\n```\n\n**ASan and Faulthandler Report:**\nImmediately following the UBSan report, the program aborts, and ASan/faulthandler provide a stack trace of the crash:\n```\nFatal Python error: Aborted\n\nCurrent thread 0x00007be05a2d7380 [python] (most recent call first):\n File \"/home/shamil/oss/cpython/main/Lib/inspect.py\", line 1719 in _shadowed_dict\n ... (Python stack trace) ...\n File \"/home/shamil/oss/cpython/main/Lib/runpy.py\", line 198 in _run_module_as_main\n\nCurrent thread's C stack trace (most recent call first):\n ...\n #0 0x5ab05b94e8a9 in patch_64 /home/shamil/oss/cpython/main/build/jit_debug_c11/../../Python/jit.c:228:12\n #1 0x5ab05b94e8a9 in emit__COLD_EXIT /home/shamil/oss/cpython/main/build/jit_debug_c11/./jit_stencils-x86_64-unknown-linux-gnu.h:36611:5\n #2 0x5ab05ba01e43 in _PyJIT_Compile /home/shamil/oss/cpython/main/build/jit_debug_c11/../../Python/jit.c:542:9\n ... (C stack trace) ...\n```\n\n#### Full logs\n\n[logs.txt](https://github.com/user-attachments/files/22499004/logs.txt)\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-139271\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/ashm-dev","@type":"Person","name":"ashm-dev"},"datePublished":"2025-09-23T17:07:08Z","url":"https://github.com/python/cpython/issues/139269"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:6758970d-93f4-0468-7258-8c1b055d6fe6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A390:2412:2335CE:2E3F79:6B024F1A |
| html-safe-nonce | 91be92087ee59e3f03f1683a7abe94c8823606a264fd00d763d9ea88c727d588 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzkwOjI0MTI6MjMzNUNFOjJFM0Y3OTo2QjAyNEYxQSIsInZpc2l0b3JfaWQiOiI2ODk5MTEyNTc5MDM4MzM0NzQ2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8539a95593b35e99270a8f1343328165fa72fa4dce772b7035a5f2fb1d399d57 |
| hovercard-subject-tag | issue:3446055335 |
| 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/139269/issue_layout |
| twitter:image | https://opengraph.githubassets.com/10bc2677d01c57b95dbbd17050f64e6781935fa85b744a8b2481e2dec5d01190/python/cpython/issues/139269 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/10bc2677d01c57b95dbbd17050f64e6781935fa85b744a8b2481e2dec5d01190/python/cpython/issues/139269 |
| og:image:alt | Bug report Bug description: Summary When the CPython main branch is compiled with Clang using the experimental JIT (--enable-experimental-jit) and memory sanitizers (-fsanitize=address,undefined), ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ashm-dev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width