Skip to content

Commit 48fa037

Browse files
committed
gh-157368: Fix clang-cl version in sys.version on Windows (GH-157369)
Co-authored-by: Stan Ulbrych <stan@python.org> (cherry picked from commit 0ba7be9) # Conflicts: # PC/pyconfig.h.in
1 parent 8404e15 commit 48fa037

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix truncated :data:`sys.version` in the case of clang-cl versions 22 or newer
2+
on Windows. Also fixes the Windows on Arm case, where the Microsoft
3+
compiler was reported instead of clang. Patch by Chris Eibl.

‎PC/pyconfig.h.in‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,24 @@ WIN32 is still required for the locale module.
138138
#define MS_WIN64
139139
#endif
140140

141+
#ifdef __clang__
142+
#define _Py_CLANG_COMPILER(platform) ( \
143+
"[Clang " _Py_STRINGIZE(__clang_major__) "." _Py_STRINGIZE(__clang_minor__) \
144+
"." _Py_STRINGIZE(__clang_patchlevel__) " " platform \
145+
" with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
146+
#endif
147+
141148
/* set the COMPILER and support tier
142149
*
143150
* win_amd64 MSVC (x86_64-pc-windows-msvc): 1
144151
* win32 MSVC (i686-pc-windows-msvc): 1
145152
* win_arm64 MSVC (aarch64-pc-windows-msvc): 3
146-
* other archs and ICC: 0
153+
* other archs and clang-cl/ICC: 0
147154
*/
148155
#ifdef MS_WIN64
149156
#if defined(_M_X64) || defined(_M_AMD64)
150157
#if defined(__clang__)
151-
#define COMPILER ("[Clang " __clang_version__ "] 64 bit (AMD64) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
158+
#define COMPILER _Py_CLANG_COMPILER("64 bit (AMD64)")
152159
#define PY_SUPPORT_TIER 0
153160
#elif defined(__INTEL_COMPILER)
154161
#define COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 64 bit (amd64) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
@@ -159,8 +166,13 @@ WIN32 is still required for the locale module.
159166
#endif /* __clang__ */
160167
#define PYD_PLATFORM_TAG "win_amd64"
161168
#elif defined(_M_ARM64)
169+
#if defined(__clang__)
170+
#define COMPILER _Py_CLANG_COMPILER("64 bit (ARM64)")
171+
#define PY_SUPPORT_TIER 0
172+
#else
162173
#define COMPILER _Py_PASTE_VERSION("64 bit (ARM64)")
163174
#define PY_SUPPORT_TIER 3
175+
#endif /* __clang__ */
164176
#define PYD_PLATFORM_TAG "win_arm64"
165177
#else
166178
#define COMPILER _Py_PASTE_VERSION("64 bit (Unknown)")
@@ -210,7 +222,7 @@ typedef _W64 int Py_ssize_t;
210222
#if defined(MS_WIN32) && !defined(MS_WIN64)
211223
#if defined(_M_IX86)
212224
#if defined(__clang__)
213-
#define COMPILER ("[Clang " __clang_version__ "] 32 bit (Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
225+
#define COMPILER _Py_CLANG_COMPILER("32 bit (Intel)")
214226
#define PY_SUPPORT_TIER 0
215227
#elif defined(__INTEL_COMPILER)
216228
#define COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 32 bit (Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")

0 commit comments

Comments
 (0)