Skip to content

Conversation

@jplehr
Copy link
Contributor

@jplehr jplehr commented Jan 23, 2026

Proposed changes

Clang enables new lifetime warnings in production and we see build errors due to this with the staging compiler.

The attributes added in this PR are suggested by the compiler. However, I'm not very familiar with the code base, so the changes may be incorrect.

Checklist

Please put an x into the boxes that apply. You can also fill these out after creating the PR. If you're not sure, please don't hesitate to ask.

  • I have added tests relevant to the introduced functionality, and the unit tests are passing locally
  • I have added the test to REGRESSION_TESTS list defined at the top of CMakeLists.txt in tests/CMakeLists.txt, IF the test takes more than 30 seconds to run.
  • I have added inline documentation which enables the maintainers with understanding the motivation
  • I have removed the stale documentation which is no longer relevant after this pull request
  • (If this change is user-facing) I have added release notes which provide the end users with a brief summary of the improvement from this pull request
  • I have run clang-format on all changed files
  • Any dependent changes have been merged

Discussion

Clang enables new lifetime warnings in production and we see build
errors due to this with the staging compiler.

The attributes added in this PR are suggested by the compiler. However,
I'm not very familiar with the code base, so the changes may be
incorrect.
@jplehr
Copy link
Contributor Author

jplehr commented Jan 23, 2026

I came across a couple of more instances of this issue. Will update the PR shortly.

@afagaj afagaj requested a review from Copilot January 23, 2026 16:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses new compiler warnings from Clang's lifetime analysis by adding [[clang::lifetimebound]] attributes to function parameters. The changes prevent potential dangling reference issues by annotating parameters whose lifetimes are bound to the returned reference.

Changes:

  • Added [[clang::lifetimebound]] attributes to function parameters that return references tied to input parameter lifetimes
  • Applied attributes to stream operator overloads and utility functions across multiple header files

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
include/ck/utility/tuple.hpp Added lifetimebound attribute to tuple element accessor function
include/ck/utility/scheduler_enum.hpp Added lifetimebound attribute to stream operator for LoopScheduler
include/ck/utility/pipeline_enum.hpp Added lifetimebound attribute to stream operator for PipelineVersion
include/ck/utility/amd_wave_read_first_lane.hpp Added lifetimebound attribute to copy_n function's output iterator
include/ck/tensor_operation/gpu/device/tensor_layout.hpp Added lifetimebound attribute to stream operator for Layout
include/ck/library/utility/host_tensor.hpp Added lifetimebound attribute to LogRange function's stream parameter
include/ck/host_utility/io.hpp Added lifetimebound attribute to stream operator for TensorDescriptor

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

template <typename InputIterator, typename Size, typename OutputIterator>
__device__ static OutputIterator copy_n(InputIterator from, Size size, OutputIterator to)
__device__ static OutputIterator
copy_n(InputIterator from, Size size, [[clang::lifetimebound]] OutputIterator to)
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

The [[clang::lifetimebound]] attribute on the OutputIterator parameter is incorrect. This function returns the iterator by value after advancing it, not a reference bound to the input parameter's lifetime. The lifetimebound attribute should only be applied when the return value's lifetime is directly tied to the parameter (e.g., returning a reference to data owned by the parameter). Remove this attribute as it doesn't apply to this pattern.

Suggested change
copy_n(InputIterator from, Size size, [[clang::lifetimebound]] OutputIterator to)
copy_n(InputIterator from, Size size, OutputIterator to)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants