[clang] [llvm] Replace autoconversion with TextEncodingConverter converters (PR #206519)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 15 03:22:29 PDT 2026


================
@@ -448,6 +530,41 @@ ContentCache &SourceManager::createMemBufferContentCache(
   return *Entry;
 }
 
+llvm::ErrorOr<llvm::TextEncodingConverter *>
+SourceManager::getOrCreateConverter(llvm::StringRef SourceEncoding) {
+  // Use getKnownEncoding to get normalized encoding names
+  std::optional<llvm::TextEncoding> SourceKnown =
+      llvm::TextEncodingConverter::getKnownEncoding(SourceEncoding);
+
+  if (SourceKnown && *SourceKnown == llvm::TextEncoding::UTF8)
+    return nullptr;
+
+  // Create a cache key using canonical encoding name
+  llvm::StringRef CacheKey =
+      SourceKnown
+          ? llvm::TextEncodingConverter::getKnownEncodingName(*SourceKnown)
+          : SourceEncoding;
----------------
cor3ntin wrote:

can the second branch of that ternary ever been taken?
ie all the known encodings should have a name

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


More information about the cfe-commits mailing list