-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[mlir] Add [[lifetimebound]]
to Range classes.
#123091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-mlir-core Author: Christian Sigg (chsigg) ChangesThis prevents creating range class instances from temporaries. Full diff: https://github.com/llvm/llvm-project/pull/123091.diff 4 Files Affected:
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)) {}
|
@llvm/pr-subscribers-mlir Author: Christian Sigg (chsigg) ChangesThis prevents creating range class instances from temporaries. Full diff: https://github.com/llvm/llvm-project/pull/123091.diff 4 Files Affected:
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)) {}
|
mlir/include/mlir/IR/BlockSupport.h
Outdated
@@ -74,8 +74,8 @@ class SuccessorRange final | |||
public: | |||
using RangeBaseT::RangeBaseT; | |||
SuccessorRange(); | |||
SuccessorRange(Block *block); | |||
SuccessorRange(Operation *term); | |||
SuccessorRange(Block *block LLVM_LIFETIME_BOUND); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the value of adding it here? The address of these aren't taken, and these aren't really temporaries either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks River for noticing! Removed.
You can test this locally with the following command:git-clang-format --diff 0e13ce770bfbee7cfbc8086a038a950fe12c03d5 96d3695b05b3e59c77a0f226d994ab28b7c891a7 --extensions h -- mlir/include/mlir/IR/BlockSupport.h mlir/include/mlir/IR/Region.h mlir/include/mlir/IR/TypeRange.h mlir/include/mlir/IR/ValueRange.h View the diff from clang-format here.diff --git a/mlir/include/mlir/IR/TypeRange.h b/mlir/include/mlir/IR/TypeRange.h
index 9ee97cfe42..9c2fbb3884 100644
--- a/mlir/include/mlir/IR/TypeRange.h
+++ b/mlir/include/mlir/IR/TypeRange.h
@@ -46,7 +46,7 @@ public:
values.end().getCurrent()))) {}
template <typename Arg, typename = std::enable_if_t<std::is_constructible<
ArrayRef<Type>, Arg>::value>>
- TypeRange(Arg &&arg LLVM_LIFETIME_BOUND)
+ 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)) {}
|
This prevents creating range class instances from temporaries.