[Mlir-commits] [mlir] 47cf7a4 - [llvm] Allow SMLoc to be used in constexpr context
wren romano
llvmlistbot at llvm.org
Mon Jul 17 11:45:29 PDT 2023
Author: wren romano
Date: 2023-07-17T11:45:22-07:00
New Revision: 47cf7a4ba54edf7c2a78503d7cca8a003f194d32
URL: https://github.com/llvm/llvm-project/commit/47cf7a4ba54edf7c2a78503d7cca8a003f194d32
DIFF: https://github.com/llvm/llvm-project/commit/47cf7a4ba54edf7c2a78503d7cca8a003f194d32.diff
LOG: [llvm] Allow SMLoc to be used in constexpr context
Since `StringRef::empty` can be used in constexpr context, it seems reasonable that `SMLoc::isValid` should be too. The default-ctor and `operator==` are made constexpr for consistency.
In particular, the `constexpr` keyword is needed for silencing warnings on Windows (whereas Linux allows constexpr usage without the keyword).
Reviewed By: jpienaar
Differential Revision: https://reviews.llvm.org/D154741
Added:
Modified:
llvm/include/llvm/Support/SMLoc.h
mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/SMLoc.h b/llvm/include/llvm/Support/SMLoc.h
index 60b052a3b86351..d7dde81ce0be7e 100644
--- a/llvm/include/llvm/Support/SMLoc.h
+++ b/llvm/include/llvm/Support/SMLoc.h
@@ -24,14 +24,14 @@ class SMLoc {
const char *Ptr = nullptr;
public:
- SMLoc() = default;
+ constexpr SMLoc() = default;
- bool isValid() const { return Ptr != nullptr; }
+ constexpr bool isValid() const { return Ptr != nullptr; }
- bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
- bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
+ constexpr bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
+ constexpr bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
- const char *getPointer() const { return Ptr; }
+ constexpr const char *getPointer() const { return Ptr; }
static SMLoc getFromPointer(const char *Ptr) {
SMLoc L;
diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
index 24dd631dba1bc4..f381d46a2cd58a 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
@@ -361,9 +361,9 @@ class VarInfo final {
std::optional<Var::Num> n = {})
: name(name), loc(loc), id(id), num(n), kind(vk) {
assert(!name.empty() && "null StringRef");
+ assert(loc.isValid() && "null SMLoc");
assert(isWF(vk) && "unknown VarKind");
assert((!n || Var::isWF_Num(*n)) && "Var::Num is too large");
- // NOTE TO Wren: windows did not like loc.isValid constexpr
}
constexpr StringRef getName() const { return name; }
More information about the Mlir-commits
mailing list