← Back to Pull requests

fix(hip): do not leak the windows.h min/max macros from public headers #44

Merged
psamfass merged 3 files (103 lines) on Nov 26, 2026 14:13 UTC
View on GitHub
psamfass psamfass commented on Nov 25, 2026 16:28 UTC
Author

Description

On Windows, include/cuda/std/__thread/threading_support_win32.h includes <windows.h> without NOMINMAX. The Windows SDK then defines the function-like macros min(a, b) and max(a, b). libhipcxx's own protection (_CCCL_PUSH_MACROS / __cccl/prologue.h) is included after <windows.h> and only saves and undefines macros that are already defined, so the macros are restored as defined at the end and leak into whatever header the user includes next.

Any broad libhipcxx include that reaches this file (<cuda/std/atomic>, <cuda/barrier>, <cuda/memory_resource>, ...) can therefore break unrelated code that uses std::min(...) or std::numeric_limits<T>::max(). A concrete case is hipCUB 3.1: its util_env.hpp includes <cuda/memory_resource>, which reaches threading_support_win32.h, and the following rocPRIM headers then fail to parse on Windows.

Fix

Define NOMINMAX only around the <windows.h> include and restore the includer's own NOMINMAX state afterwards:

#pragma push_macro("NOMINMAX")
#ifndef NOMINMAX
#  define NOMINMAX
#endif
#include <windows.h>
#pragma pop_macro("NOMINMAX")

  • Applied in threading_support_win32.h (the actual leak).

  • Applied the same way to cuda/__driver/driver_api.h for consistency (not active on HIP, so not part of this failure).

  • This protects all consumers (hipCUB, rocThrust, user code), not just a single project.
  • Testing

  • Added test/libcudacxx/libcxx/macros/windows_no_minmax_leak.compile.pass.cpp. It #undefs NOMINMAX (the lit config passes -DNOMINMAX on Windows, which hid this problem in the existing tests), includes <cuda/std/atomic>, <cuda/std/latch> and <cuda/std/semaphore>, and #errors if min/max are defined afterwards or if NOMINMAX is left defined.

  • Verified on Linux with a stub windows.h that mimics the SDK behaviour (defines min/max unless NOMINMAX), forcing _CCCL_HAS_THREAD_API_WIN32: the original header leaks the macros, the fixed header does not.

  • Not yet verified on a real Windows host with the Windows SDK. Confirmation from a Windows build (for example the hipCUB/torchaudio build) would be appreciated.
  • Checklist


  • New or existing tests cover these changes.

  • The documentation is up to date with these changes.
  • Diff: 103 lines (+103 / -0) across 3 files Reviewer: stanleytsang-amd Review duration: 1304m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.34) × (1 − Review Confidence (0.78)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.34 · 103 lines diff across 3 files
    0.34
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.65 · 2 substantive comment(s)
    0.65
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    78%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.278
    Real PR Conversation Timeline
    5 items
    github-actions[bot] github-actions[bot] commented on Nov 25, 2026 16:30 UTC
    Bot

    <!-- rocm-security-gh:pr-findings:v1 -->

    <details>
    <summary><b>Security scan found no critical or high findings on lines changed by this pull request</b></summary>

    View the security scan run for complete reports.

    _“New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta._

    </details>

    obersteiner obersteiner commented on Nov 25, 2026 18:22 UTC
    Reviewer

    lgtm thanks!

    stanleytsang-amd stanleytsang-amd approved these changes on Nov 25, 2026 19:21 UTC
    Approved Reviewer

    Approved these changes.

    stanleytsang-amd stanleytsang-amd commented on Nov 25, 2026 19:21 UTC
    Contributor
    Assignees
    psamfass psamfass
    Labels
    risk: low confidence: 78.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 33.7% (LOW) · Higher = larger blast radius
    33.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 78.3% · Lower = rushed or shallow review
    78.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7.3% · Safe to merge
    7.3%
    Repository