Prhub

#45532 [BugFix] Fix clang spinloop mwaitx include

原始 PR 作者 johnnyychiu 合并时间 2026-07-29 03:00 文件变更 1 提交数 10 评论 3 代码增减 +1 / -1

执行摘要

修复 clang 下 spinloop 头文件包含错误

引用 Issue #45515:Building vLLM C/C++ extensions with clang as the host compiler fails on the spinloop target because rejects direct inclusion with a hard error. The fix is exactly what clang's diagnostic recommends: include instead.

该 PR 修复明确且无副作用,值得合并。对于使用非 GCC 编译器编译 vLLM 的团队,这是一个必要的兼容性修复。

讨论亮点

没有人员参与的 review 讨论。机器人生成了一条 pre-commit 检查失败的消息,要求运行 pre-commit --all-files,但作者后续通过合并 main 分支解决了此问题。最终维护者 njhill 批准了 PR。

实现拆解

仅需一步替换:在 csrc/spinloop.cpp 的条件编译块中,将 #include 替换为 #include 。该 umbrella 头文件会拉取 及其他 x86 内建头文件,因此 _mm_monitorx 和 _mm_mwaitx 函数的可用性不受影响。没有其他代码或测试变更。

文件 模块 状态 重要度
csrc/spinloop.cpp 自旋循环 modified 4.09

关键源码片段

csrc/spinloop.cpp dependency-wiring

唯一变更文件,修改了头文件包含指令以兼容 clang 编译器。

#include <Python.h>
​
extern "C" {
​
#include <stdbool.h>
#include <time.h>
​
#if defined(__i386__) || defined(__x86_64__)
  #include <cpuid.h>
  // 使用 umbrella header <x86intrin.h> 替代 <mwaitxintrin.h>,
  // 因为 Clang 禁止直接包含 <mwaitxintrin.h>,而 <x86intrin.h>
  // 在 GCC 和 Clang 下均可用,且提供相同的 MONITORX/MWAITX 内建函数。
  #include <x86intrin.h>
#endif
​
// 后续代码(determine_cpu_support 函数等)保持不变

评论区精华

pre-commit 检查失败 other

mergify 机器人提示 pre-commit 检查失败,要求运行 `pre-commit --all-files` 并提交。

结论:作者通过合并 main 分支解决了该问题(提交记录中有多次合并 main),PR 最终获得批准。 · 已解决

风险与影响

风险极低。替换后的头文件在 GCC 和 clang 下均受支持,不会影响原有功能。唯一潜在风险是某些极端编译环境中 可能不可用,但这与 的可用性相当,且 是标准推荐包含路径。

直接影响:使用 clang 作为宿主编译器(如 ROCm TheRock 工具链)的 vLLM 构建不再因 spinloop 目标失败。间接影响:无。受益用户主要是 ROCm 平台用户。影响程度:小范围修复。

低风险 编译兼容性

关联 Issue

#45515 [Build]: csrc/spinloop.cpp fails to compile under clang — direct #include <mwaitxintrin.h> rejected

完整报告

参与讨论