Bug report
Bug description:
clang-cl incorrectly handles SEH exception handling: llvm/llvm-project#62606
E.g. in
|
int |
|
safe_memcpy(void *dest, const void *src, size_t count) |
|
{ |
|
HANDLE_INVALID_MEM( |
|
memcpy(dest, src, count); |
|
); |
|
return 0; |
|
} |
where
|
#define HANDLE_INVALID_MEM(sourcecode) \ |
|
do { \ |
|
EXCEPTION_RECORD record; \ |
|
__try { \ |
|
sourcecode \ |
|
} \ |
|
__except (filter_page_exception(GetExceptionInformation(), &record)) { \ |
|
assert(record.ExceptionCode == EXCEPTION_IN_PAGE_ERROR || \ |
|
record.ExceptionCode == EXCEPTION_ACCESS_VIOLATION); \ |
|
if (record.ExceptionCode == EXCEPTION_IN_PAGE_ERROR) { \ |
|
NTSTATUS status = (NTSTATUS) record.ExceptionInformation[2]; \ |
|
ULONG code = LsaNtStatusToWinError(status); \ |
|
PyErr_SetFromWindowsErr(code); \ |
|
} \ |
|
else if (record.ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { \ |
|
PyErr_SetFromWindowsErr(ERROR_NOACCESS); \ |
|
} \ |
|
return -1; \ |
|
} \ |
|
} while (0) |
This lets test_mmap.MmapTests.test_access_violations fail for clang-cl builds on Windows,
see e.g. https://github.com/python/cpython/actions/runs/14044831663/job/39323183797?pr=131690#step:4:566.
The suggestion in llvm/llvm-project#62606 (comment) is to use EHa,
the problem is that without /EHa, the compiler assumes memory accesses don't trap
which seems wrong, and clearly is a compatibility issue wrt to MSVC.
Since Python code is compiled in C mode, EHa would seem really weird to me. Even more weird workaround: wrap the "body" (here sourcecode) in a separate function and guard that via SEH.
I've tried both workarounds and they would fix the problem.
CPython versions tested on:
3.14
Operating systems tested on:
Windows
Linked PRs
Bug report
Bug description:
clang-cl incorrectly handles SEH exception handling: llvm/llvm-project#62606
E.g. in
cpython/Modules/mmapmodule.c
Lines 353 to 360 in 7c3692f
where
cpython/Modules/mmapmodule.c
Lines 297 to 316 in 7c3692f
This lets
test_mmap.MmapTests.test_access_violationsfail for clang-cl builds on Windows,see e.g. https://github.com/python/cpython/actions/runs/14044831663/job/39323183797?pr=131690#step:4:566.
The suggestion in llvm/llvm-project#62606 (comment) is to use
EHa,which seems wrong, and clearly is a compatibility issue wrt to MSVC.
Since Python code is compiled in C mode,
EHawould seem really weird to me. Even more weird workaround: wrap the "body" (heresourcecode) in a separate function and guard that via SEH.I've tried both workarounds and they would fix the problem.
CPython versions tested on:
3.14
Operating systems tested on:
Windows
Linked PRs