← Back to Pull requests

[libcu++] Recognize the contiguous iterators of the libstdc++ debug mode #12790

Closed
unknown closed this pull request without merging on Nov 25, 2026 13:21 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 13:12 UTC
Author

Description

With the debug mode of libstdc++ (_GLIBCXX_DEBUG), libcu++ mishandles the iterators of contiguous containers like std::vector:

  • The debug containers wrap the iterators of the normal containers, so the iterator of the debug std::vector is __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<T, C>, S>. The overload of __iter_concept_fn for them expected _Safe_iterator<T, S>, which cannot even be instantiated since GCC 9, so before C++20 cuda::std::contiguous_iterator was false for them.

  • cuda::std::to_address called operator-> on them, which verifies that the iterator is dereferenceable, so it aborted for end iterators. That already happens in C++20, where libstdc++ advertises these iterators as contiguous:
  • /usr/include/c++/12/debug/safe_iterator.h:318:
    In function:
        gnu_debug::_Safe_iterator<_Iterator, _Sequence, _Category>::pointer
        gnu_debug::_Safe_iterator<_Iterator, _Sequence, _Category>::operator->() const [...]
    
    Error: attempt to dereference a past-the-end iterator.
    

    This PR matches the debug iterators by the __normal_iterator they wrap, and specializes cuda::std::pointer_traits for them, so that cuda::std::to_address unwraps them with base() instead of calling operator->. libc++ and the MSVC STL customize std::to_address for their own iterators the same way. It takes the declarations of the debug iterators from <debug/formatter.h> instead of including <iterator> or <debug/safe_iterator.h>, and only declares them itself before libstdc++ 9, where <debug/formatter.h> does not declare __normal_iterator.

    The new test defines _GLIBCXX_DEBUG on the command line, because nvcc includes the CUDA runtime, and with it libstdc++, before the first line of the test. It is unsupported before GCC 11, where the debug mode std::array conflicts with the forward declaration of std::array in libcu++; #12789 fixes that.

    Checklist


  • New or existing tests cover these changes.

  • The documentation is up to date with these changes.
  • Diff: 255 lines (+191 / -64) across 3 files Reviewer: davebayer Review duration: 1448m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 255 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.332
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #12790"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 39.1% (MEDIUM) · Higher = larger blast radius
    39.1%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 15.4% · Safe to merge
    15.4%
    Repository