[Mlir-commits] [mlir] [mlir] Add `[[lifetimebound]]` to Range classes. (PR #123091)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jan 15 09:13:27 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Christian Sigg (chsigg)
<details>
<summary>Changes</summary>
This prevents creating range class instances from temporaries.
---
Full diff: https://github.com/llvm/llvm-project/pull/123091.diff
4 Files Affected:
- (modified) mlir/include/mlir/IR/BlockSupport.h (+4-4)
- (modified) mlir/include/mlir/IR/Region.h (+2-2)
- (modified) mlir/include/mlir/IR/TypeRange.h (+3-2)
- (modified) mlir/include/mlir/IR/ValueRange.h (+5-3)
``````````diff
diff --git a/mlir/include/mlir/IR/BlockSupport.h b/mlir/include/mlir/IR/BlockSupport.h
index ff508891ac2ffc..b28ba9b03d0ebf 100644
--- a/mlir/include/mlir/IR/BlockSupport.h
+++ b/mlir/include/mlir/IR/BlockSupport.h
@@ -74,8 +74,8 @@ class SuccessorRange final
public:
using RangeBaseT::RangeBaseT;
SuccessorRange();
- SuccessorRange(Block *block);
- SuccessorRange(Operation *term);
+ SuccessorRange(Block *block LLVM_LIFETIME_BOUND);
+ SuccessorRange(Operation *term LLVM_LIFETIME_BOUND);
private:
/// See `llvm::detail::indexed_accessor_range_base` for details.
@@ -110,9 +110,9 @@ class BlockRange final
BlockRange(SuccessorRange successors);
template <typename Arg, typename = std::enable_if_t<std::is_constructible<
ArrayRef<Block *>, Arg>::value>>
- BlockRange(Arg &&arg)
+ BlockRange(Arg &&arg LLVM_LIFETIME_BOUND)
: BlockRange(ArrayRef<Block *>(std::forward<Arg>(arg))) {}
- BlockRange(std::initializer_list<Block *> blocks)
+ BlockRange(std::initializer_list<Block *> blocks LLVM_LIFETIME_BOUND)
: BlockRange(ArrayRef<Block *>(blocks)) {}
private:
diff --git a/mlir/include/mlir/IR/Region.h b/mlir/include/mlir/IR/Region.h
index 93fc9dbb430eec..22cb7037772ddb 100644
--- a/mlir/include/mlir/IR/Region.h
+++ b/mlir/include/mlir/IR/Region.h
@@ -357,12 +357,12 @@ class RegionRange
template <typename Arg, typename = std::enable_if_t<std::is_constructible<
ArrayRef<std::unique_ptr<Region>>, Arg>::value>>
- RegionRange(Arg &&arg)
+ RegionRange(Arg &&arg LLVM_LIFETIME_BOUND)
: RegionRange(ArrayRef<std::unique_ptr<Region>>(std::forward<Arg>(arg))) {
}
template <typename Arg>
RegionRange(
- Arg &&arg,
+ Arg &&arg LLVM_LIFETIME_BOUND,
std::enable_if_t<std::is_constructible<ArrayRef<Region *>, Arg>::value>
* = nullptr)
: RegionRange(ArrayRef<Region *>(std::forward<Arg>(arg))) {}
diff --git a/mlir/include/mlir/IR/TypeRange.h b/mlir/include/mlir/IR/TypeRange.h
index 99fabab334f922..9c2fbb3884188e 100644
--- a/mlir/include/mlir/IR/TypeRange.h
+++ b/mlir/include/mlir/IR/TypeRange.h
@@ -46,8 +46,9 @@ class TypeRange : public llvm::detail::indexed_accessor_range_base<
values.end().getCurrent()))) {}
template <typename Arg, typename = std::enable_if_t<std::is_constructible<
ArrayRef<Type>, Arg>::value>>
- TypeRange(Arg &&arg) : TypeRange(ArrayRef<Type>(std::forward<Arg>(arg))) {}
- TypeRange(std::initializer_list<Type> types)
+ TypeRange(Arg &&arg LLVM_LIFETIME_BOUND)
+ : TypeRange(ArrayRef<Type>(std::forward<Arg>(arg))) {}
+ TypeRange(std::initializer_list<Type> types LLVM_LIFETIME_BOUND)
: TypeRange(ArrayRef<Type>(types)) {}
private:
diff --git a/mlir/include/mlir/IR/ValueRange.h b/mlir/include/mlir/IR/ValueRange.h
index 4b421c08d8418e..a807b77ad077f8 100644
--- a/mlir/include/mlir/IR/ValueRange.h
+++ b/mlir/include/mlir/IR/ValueRange.h
@@ -391,9 +391,11 @@ class ValueRange final
typename = std::enable_if_t<
std::is_constructible<ArrayRef<Value>, Arg>::value &&
!std::is_convertible<Arg, Value>::value>>
- ValueRange(Arg &&arg) : ValueRange(ArrayRef<Value>(std::forward<Arg>(arg))) {}
- ValueRange(const Value &value) : ValueRange(&value, /*count=*/1) {}
- ValueRange(const std::initializer_list<Value> &values)
+ ValueRange(Arg &&arg LLVM_LIFETIME_BOUND)
+ : ValueRange(ArrayRef<Value>(std::forward<Arg>(arg))) {}
+ ValueRange(const Value &value LLVM_LIFETIME_BOUND)
+ : ValueRange(&value, /*count=*/1) {}
+ ValueRange(const std::initializer_list<Value> &values LLVM_LIFETIME_BOUND)
: ValueRange(ArrayRef<Value>(values)) {}
ValueRange(iterator_range<OperandRange::iterator> values)
: ValueRange(OperandRange(values)) {}
``````````
</details>
https://github.com/llvm/llvm-project/pull/123091
More information about the Mlir-commits
mailing list