[flang-commits] [flang] 21de514 - [flang][NFC] static assert intrinsic table is sorted (#120399)

via flang-commits flang-commits at lists.llvm.org
Wed Dec 18 09:12:02 PST 2024


Author: jeanPerier
Date: 2024-12-18T18:11:56+01:00
New Revision: 21de514872fc80424fbfd159485d71978b973c73

URL: https://github.com/llvm/llvm-project/commit/21de514872fc80424fbfd159485d71978b973c73
DIFF: https://github.com/llvm/llvm-project/commit/21de514872fc80424fbfd159485d71978b973c73.diff

LOG: [flang][NFC] static assert intrinsic table is sorted (#120399)

This invariant is used below when searching for intrinsic
implementation. Currently, if the map is not sorted, the compiler will
just silently assume there is no such implementation.

Added: 
    

Modified: 
    flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index aad463e6d1e4a6..84fc77a1420f0e 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -684,6 +684,20 @@ static constexpr IntrinsicHandler handlers[]{
      /*isElemental=*/true},
 };
 
+template <std::size_t N>
+static constexpr bool isSorted(const IntrinsicHandler (&array)[N]) {
+  // Replace by std::sorted when C++20 is default (will be constexpr).
+  const IntrinsicHandler *lastSeen{nullptr};
+  bool isSorted{true};
+  for (const auto &x : array) {
+    if (lastSeen)
+      isSorted &= std::string_view{lastSeen->name} < std::string_view{x.name};
+    lastSeen = &x;
+  }
+  return isSorted;
+}
+static_assert(isSorted(handlers) && "map must be sorted");
+
 static const IntrinsicHandler *findIntrinsicHandler(llvm::StringRef name) {
   auto compare = [](const IntrinsicHandler &handler, llvm::StringRef name) {
     return name.compare(handler.name) > 0;


        


More information about the flang-commits mailing list