[libcu++] Recognize the contiguous iterators of the libstdc++ debug mode #12790
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
davebayer
Description
With the debug mode of libstdc++ (
_GLIBCXX_DEBUG), libcu++ mishandles the iterators of contiguous containers likestd::vector:std::vectoris__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<T, C>, S>. The overload of__iter_concept_fnfor them expected_Safe_iterator<T, S>, which cannot even be instantiated since GCC 9, so before C++20cuda::std::contiguous_iteratorwas false for them.cuda::std::to_addresscalledoperator->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:This PR matches the debug iterators by the
__normal_iteratorthey wrap, and specializescuda::std::pointer_traitsfor them, so thatcuda::std::to_addressunwraps them withbase()instead of callingoperator->. libc++ and the MSVC STL customizestd::to_addressfor 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_DEBUGon 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 modestd::arrayconflicts with the forward declaration ofstd::arrayin libcu++; #12789 fixes that.Checklist