[lld] [llvm] [GlobPattern] add AsLiteral to help lld determine if a symbol is literal (PR #215854)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 11:56:51 PDT 2026


================
@@ -61,6 +61,17 @@ class GlobPattern {
   /// \returns \p true if \p S matches this glob pattern
   LLVM_ABI bool match(StringRef S) const;
 
+  /// \returns the single string this pattern matches, if the pattern contains
+  /// no unescaped metacharacters; otherwise std::nullopt. Escapes are resolved,
+  /// so `a\*b` yields `a*b`. Characters that are only special in context (`]`,
+  /// `}`, `,`) do not make a pattern non-literal.
+  ///
+  /// \p Storage is used only when escapes have to be resolved; otherwise the
+  /// result aliases the text passed to create(). The result is valid for as
+  /// long as both remain alive.
+  LLVM_ABI std::optional<StringRef>
+  asLiteral(SmallVectorImpl<char> &Storage) const;
----------------
ellishg wrote:

```suggestion
  asLiteral(SmallString<> &Storage) const;
```

This allows us to use `+=` on characters

https://github.com/llvm/llvm-project/pull/215854


More information about the llvm-commits mailing list