================
@@ -913,20 +912,28 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
 // Initialization Utilities
 
 bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input){
-  // Retrieve the converter to the internal charset if it exists.
-  llvm::TextEncodingConverter *Converter =
-      hasPreprocessor() ? getPreprocessor().getTextEncoding().getConverter(
-                              CA_FromInputEncoding)
-                        : nullptr;
-
-  return InitializeSourceManager(Input, Converter, getDiagnostics(),
-                                 getFileManager(), getSourceManager());
+  // Get the input encoding and add converter to cache if specified
+  std::string InputEncoding;
+  if (hasPreprocessor()) {
+    InputEncoding = getLangOpts().InputEncoding;
+    if (!InputEncoding.empty()) {
+      // Add the converter to SourceManager's cache
+      auto ConverterOrErr = 
getSourceManager().getOrCreateConverter(InputEncoding, "UTF-8");
+      // If converter creation fails, the error will be reported when 
createFileID tries to use it
+      (void)ConverterOrErr;
+    }
+  }
+  
+  return InitializeSourceManager(Input, getDiagnostics(),
----------------
azhan92 wrote:

Add a comment to explain why we only pass the InputEncoding if we have a 
preprocessor

https://github.com/llvm/llvm-project/pull/205163
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to