[flang] [llvm] [flang] Implement SPLIT intrinsic subroutine with tests (PR #185584)
Peter Klausler via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 10 08:28:48 PDT 2026
================
@@ -992,6 +992,56 @@ static RT_API_ATTRS void TokenizePositionsImpl(Descriptor &first,
}
}
+// SPLIT - scans for the next separator character in STRING.
+// When BACK is false (or absent), returns the position of the leftmost
+// character in SET whose position in STRING is greater than POS, or
+// LEN(STRING)+1 if no such character exists.
+// When BACK is true, returns the position of the rightmost character in
+// SET whose position in STRING is less than POS, or 0 if no such
+// character exists.
+template <typename CHAR>
+static RT_API_ATTRS std::size_t SplitImpl(const CHAR *string,
+ std::size_t stringLen, const CHAR *set, std::size_t setLen, std::size_t pos,
+ bool back) {
+ if (back) {
----------------
klausler wrote:
Always use braced initialization in the parts of flang-new, like the runtime, that are in more modern C++. See `flang/docs/C++17.md`. It's especially important for code like this that's messing with mixed integer types.
You could use a signed stride of 1 or -1 and avoid having two implementations.
`SPLIT` is basically the same as the older `SCAN`. Can you have one implementation for both? Or can you write `SPLIT` in terms of `SCAN`?
https://github.com/llvm/llvm-project/pull/185584
More information about the llvm-commits
mailing list