[PATCH] D154741: [llvm] Allow SMLoc to be used in constexpr context

wren romano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 11:45:40 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG47cf7a4ba54e: [llvm] Allow SMLoc to be used in constexpr context (authored by wrengr).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154741/new/

https://reviews.llvm.org/D154741

Files:
  llvm/include/llvm/Support/SMLoc.h
  mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h


Index: mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
===================================================================
--- mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
+++ mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
@@ -361,9 +361,9 @@
                     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; }
Index: llvm/include/llvm/Support/SMLoc.h
===================================================================
--- llvm/include/llvm/Support/SMLoc.h
+++ llvm/include/llvm/Support/SMLoc.h
@@ -24,14 +24,14 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154741.541165.patch
Type: text/x-patch
Size: 1577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230717/f98d0a29/attachment.bin>


More information about the llvm-commits mailing list