Skip to content

[libcu++] Move argument bounds helpers to bound file#9276

Open
miscco wants to merge 1 commit into
NVIDIA:mainfrom
miscco:argument_move_bounds_features
Open

[libcu++] Move argument bounds helpers to bound file#9276
miscco wants to merge 1 commit into
NVIDIA:mainfrom
miscco:argument_move_bounds_features

Conversation

@miscco
Copy link
Copy Markdown
Contributor

@miscco miscco commented Jun 5, 2026

Put them where they belong

@miscco miscco requested a review from a team as a code owner June 5, 2026 08:50
@miscco miscco requested a review from Jacobfaib June 5, 2026 08:50
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jun 5, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jun 5, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

Walkthrough

Bounds validation logic is consolidated into argument_bounds.h by adding trait-based range checking, bounds composition, and element validation utilities. argument.h removes its inline helpers and delegates to the new functions. Tests update to verify the renamed intersection predicate.

Changes

Bounds Validation Consolidation

Layer / File(s) Summary
Trait updates and dependencies
libcudacxx/include/cuda/__argument/argument_bounds.h
Adds includes for remove_cvref, cmp, is_extended_arithmetic, and is_same; updates __is_static_bounds_cv_v and __is_runtime_bounds_cv_v to classify bounds after removing cv-qualifiers and references via remove_cvref_t.
Range validation utilities
libcudacxx/include/cuda/__argument/argument_bounds.h
Introduces __assert_in_range for runtime overflow checks, __runtime_bound_cast for validated casting, and __static_bound_in_range for compile-time/constexpr endpoint representability with integer vs arithmetic type handling.
Bounds composition and validation
libcudacxx/include/cuda/__argument/argument_bounds.h
Adds __valid_static_bounds_v predicate, wrapper functions for static lowest/highest (handling __no_bounds case), __effective_lowest/__effective_highest via static-runtime intersection, and __validate_bounds_intersection to enforce range overlap.
Element-level validation
libcudacxx/include/cuda/__argument/argument_bounds.h
Implements __validate_static_element_bounds and __validate_runtime_element_bounds to assert immediate and runtime element values within effective bounds, with conditional checks skipped when static bounds are __no_bounds.
Header consolidation and test update
libcudacxx/include/cuda/__argument/argument.h, libcudacxx/test/libcudacxx/cuda/argument/argument_bounds.pass.cpp
Removes 124 lines of bounds-checking helper templates from argument.h; updates test assertions from __has_bounds_intersection<...> to __valid_argument_bounds<...> for both positive and negative cases.

Possibly related PRs

  • NVIDIA/cccl#9246: Restructures bounds validation by moving effective-highest/intersection and range-check helpers into argument_bounds.h so argument.h can rely on them, overlapping with renaming and helper usage patterns.
  • NVIDIA/cccl#8875: Prior bounds machinery refactoring in cuda::argument that moves validation logic out of argument.h into argument_bounds.h, providing context for the bounds computation patterns used here.

Suggested reviewers

  • Jacobfaib
  • gevtushenko
  • davebayer

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Infer (1.2.0)
libcudacxx/test/libcudacxx/cuda/argument/argument_bounds.pass.cpp

libcudacxx/test/libcudacxx/cuda/argument/argument_bounds.pass.cpp:11:10: fatal error: 'cuda/_argument' file not found
11 | #include <cuda/_argument>
| ^~~~~~~~~~~~~~~~~~
1 error generated.
libcudacxx/test/libcudacxx/cuda/argument/argument_bounds.pass.cpp:74:3-81:3: ERROR translating statement 'CompoundStmt'
Aborting translation of method 'test' in file 'libcudacxx/test/libcudacxx/cuda/argument/argument_bounds.pass.cpp': "Assert_failure src/clang/cAst_utils.ml:249:53"
Uncaught Internal Error: "Assert_failure src/clang/cAst_utils.ml:249:53"
Error backtrace:
Raised at ClangFrontend__CAst_utils.get_decl_from_typ_ptr in file "src/clang/cAst_utils.ml", line 249, characters 53-65
Called from ClangFrontend__CTrans.CTrans_funct.get_destructor_decl_ref in file "src/clang/cTrans.ml", line 658, characters 12-59
Called from ClangFrontend__CTrans.CTrans_funct.destructor_calls.(fun) in file "src/clang/cTrans.ml", line 2048, characters 12-69
Called from Base__List.rev_filter_map.

... [truncated 2200 characters] ...

e 13, characters 2-50
Called from ClangFrontend__CTrans.CTrans_funct.instruction_log.(fun) in file "src/clang/cTrans.ml", line 4784, characters 10-1023
Called from ClangFrontend__CTrans.CTrans_funct.instruction in file "src/clang/cTrans.ml" (inlined), line 4765, characters 38-71
Called from ClangFrontend__CTrans.CTrans_funct.exec_with_node_creation in file "src/clang/cTrans.ml" (inlined), line 104, characters 20-38
Called from ClangFrontend__CTrans.CTrans_funct.get_clang_stmt_trans in file "src/clang/cTrans.ml" (inlined), line 5395, characters 4-69
Called from ClangFrontend__CTrans.CTrans_funct.get_custom_stmt_trans in file "src/clang/cTrans.ml", line 5401, characters 8-55
Called from ClangFrontend__CTrans.CTrans_funct.exec_trans_instrs.exec_trans_instrs_rev in file "src/clang/cTrans.ml" (


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
libcudacxx/test/libcudacxx/cuda/argument/argument_bounds.pass.cpp (1)

83-88: ⚡ Quick win

suggestion: This still only covers the old same-type intersection cases.

The refactor also moved mixed-type endpoint validation and remove_cvref-based bounds classification into argument_bounds.h, but this block only renames the old int overlap assertions. Add at least one cross-type case here and one reference-qualified __is_*_bounds_cv_v assertion so the newly moved behavior stays covered.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 361a363a-b9a2-4c45-8ad2-603e1e14b489

📥 Commits

Reviewing files that changed from the base of the PR and between 2b21bec and a718a60.

📒 Files selected for processing (3)
  • libcudacxx/include/cuda/__argument/argument.h
  • libcudacxx/include/cuda/__argument/argument_bounds.h
  • libcudacxx/test/libcudacxx/cuda/argument/argument_bounds.pass.cpp
💤 Files with no reviewable changes (1)
  • libcudacxx/include/cuda/__argument/argument.h

Comment on lines +152 to +165
template <class _To, class _From>
_CCCL_API constexpr void __assert_in_range([[maybe_unused]] _From __val) noexcept
{
if constexpr (::cuda::std::__cccl_is_integer_v<_To> && ::cuda::std::__cccl_is_integer_v<_From>)
{
_CCCL_ASSERT(::cuda::std::in_range<_To>(__val), "runtime bound value overflows the element type");
}
}

template <class _To, class _From>
[[nodiscard]] _CCCL_API constexpr _To __runtime_bound_cast(_From __val) noexcept
{
__assert_in_range<_To>(__val);
return static_cast<_To>(__val);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

important: Runtime bounds still narrow silently for non-integer sources.

__runtime_bound_cast only guards integer-to-integer conversions, but __immediate_sequence uses it to store user-supplied runtime bounds as __element_type. A mixed-type case like floating runtime bounds into an integral element type gets truncated before __validate_bounds_intersection runs, so validation happens on different endpoints than the caller passed. Please reject any arithmetic runtime bound that is not exactly representable in _To, not just integer/integer pairs.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

🥳 CI Workflow Results

🟩 Finished in 1h 05m: Pass: 100%/115 | Total: 18h 40m | Max: 41m 47s | Hits: 98%/343030

See results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants