https://github.com/abhina-sree updated 
https://github.com/llvm/llvm-project/pull/196569

>From 7660b6cfd000ecd0acc8440cee38e105f06011f0 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <[email protected]>
Date: Fri, 8 May 2026 12:20:45 -0400
Subject: [PATCH 1/2] convert to exec-charset inside
 getPredefinedStringLiteralFromCache, test __builtin_FILE()

---
 clang/include/clang/Basic/TargetInfo.h |  2 ++
 clang/lib/AST/ASTContext.cpp           | 10 ++++++++++
 clang/lib/Basic/TargetInfo.cpp         |  3 +++
 clang/lib/Lex/TextEncoding.cpp         |  3 ++-
 clang/test/CodeGen/systemz-charset.cpp |  4 ++++
 5 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 7a3b803efd3bd..3fcad652d26d6 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -326,6 +326,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   llvm::TextEncodingConverter *FormatStrConverter;
 
+  llvm::TextEncodingConverter *ExecStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
     assert(TargetOpts && "Missing target options");
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a6eb87ab7d8aa..8fabef174bca5 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13847,6 +13847,16 @@ 
ASTContext::getPredefinedStringLiteralFromCache(StringRef Key) const {
         *this, Key, StringLiteralKind::Ordinary,
         /*Pascal*/ false, getStringLiteralArrayType(CharTy, Key.size()),
         SourceLocation());
+
+  llvm::TextEncodingConverter *Converter = getTargetInfo().ExecStrConverter;
+  if (Converter) {
+    SmallString<128> Converted;
+    Converter->convert(Result->getString(), Converted);
+    Result = StringLiteral::Create(
+        *this, Converted, StringLiteralKind::Ordinary, /*Pascal*/ false,
+        getStringLiteralArrayType(CharTy, Converted.size()), SourceLocation());
+  }
+
   return Result;
 }
 
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index ef239cec80ddb..c04c9081c4fec 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -197,6 +197,9 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
 
   FormatStrConverter = new llvm::TextEncodingConverter(
       std::move(*llvm::TextEncodingConverter::createNoopConverter()));
+
+  ExecStrConverter = new llvm::TextEncodingConverter(
+      std::move(*llvm::TextEncodingConverter::createNoopConverter()));
 }
 
 // Out of line virtual dtor for TargetInfo.
diff --git a/clang/lib/Lex/TextEncoding.cpp b/clang/lib/Lex/TextEncoding.cpp
index a3f0484ddde84..2e7e4ed1ac63f 100644
--- a/clang/lib/Lex/TextEncoding.cpp
+++ b/clang/lib/Lex/TextEncoding.cpp
@@ -38,7 +38,8 @@ TextEncoding::setConvertersFromOptions(TextEncoding &TE,
   if (ErrorOrConverter)
     TE.ToLiteralEncodingConverter =
         new TextEncodingConverter(std::move(*ErrorOrConverter));
-  else
+    TInfo.ExecStrConverter = TEC.ToLiteralEncodingConverter;
+  } else
     return ErrorOrConverter.getError();
 
   ErrorOrConverter = llvm::TextEncodingConverter::create(
diff --git a/clang/test/CodeGen/systemz-charset.cpp 
b/clang/test/CodeGen/systemz-charset.cpp
index 59c4ad550cd94..34571a25f0e2c 100644
--- a/clang/test/CodeGen/systemz-charset.cpp
+++ b/clang/test/CodeGen/systemz-charset.cpp
@@ -72,3 +72,7 @@ const char16_t *UnicodeUCNString16 = 
u"\u00E2\u00AC\U000000DF";
 const char32_t *UnicodeUCNString32 = U"\u00E2\u00AC\U000000DF";
 //CHECK: [4 x i32] [i32 226, i32 172, i32 223, i32 0]
 //CHECK=UTF8: [4 x i32] [i32 226, i32 172, i32 223, i32 0]
+
+const char *file = __builtin_FILE();
+//CHECK: {{.*}}\A2\A8\A2\A3\85\94\A9`\83\88\81\99\A2\85\A3K\83\97\97\00"
+//CHECK-UTF8: {{.*}}systemz-charset.cpp\00"

>From 0c3d2b459a7063febe9e5fc3f5e6bad5112227aa Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <[email protected]>
Date: Fri, 22 May 2026 08:51:37 -0400
Subject: [PATCH 2/2] Convert the key before cache lookup to prevent encoding
 differences

---
 clang/lib/AST/ASTContext.cpp   | 18 +++++++++---------
 clang/lib/Lex/TextEncoding.cpp |  4 ++--
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 8fabef174bca5..b353c5bd6753d 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13841,6 +13841,15 @@ QualType 
ASTContext::getStringLiteralArrayType(QualType EltTy,
 
 StringLiteral *
 ASTContext::getPredefinedStringLiteralFromCache(StringRef Key) const {
+  // Apply encoding conversion to the key before cache lookup to ensure
+  // proper deduplication when the same source location is used multiple times
+  SmallString<128> ConvertedKey;
+  llvm::TextEncodingConverter *Converter = getTargetInfo().ExecStrConverter;
+  if (Converter) {
+    Converter->convert(Key, ConvertedKey);
+    Key = ConvertedKey;
+  }
+
   StringLiteral *&Result = StringLiteralCache[Key];
   if (!Result)
     Result = StringLiteral::Create(
@@ -13848,15 +13857,6 @@ 
ASTContext::getPredefinedStringLiteralFromCache(StringRef Key) const {
         /*Pascal*/ false, getStringLiteralArrayType(CharTy, Key.size()),
         SourceLocation());
 
-  llvm::TextEncodingConverter *Converter = getTargetInfo().ExecStrConverter;
-  if (Converter) {
-    SmallString<128> Converted;
-    Converter->convert(Result->getString(), Converted);
-    Result = StringLiteral::Create(
-        *this, Converted, StringLiteralKind::Ordinary, /*Pascal*/ false,
-        getStringLiteralArrayType(CharTy, Converted.size()), SourceLocation());
-  }
-
   return Result;
 }
 
diff --git a/clang/lib/Lex/TextEncoding.cpp b/clang/lib/Lex/TextEncoding.cpp
index 2e7e4ed1ac63f..162df900e5864 100644
--- a/clang/lib/Lex/TextEncoding.cpp
+++ b/clang/lib/Lex/TextEncoding.cpp
@@ -35,10 +35,10 @@ TextEncoding::setConvertersFromOptions(TextEncoding &TE,
     return std::error_code();
   ErrorOr<TextEncodingConverter> ErrorOrConverter =
       llvm::TextEncodingConverter::create(UTF8, TE.LiteralEncoding);
-  if (ErrorOrConverter)
+  if (ErrorOrConverter) {
     TE.ToLiteralEncodingConverter =
         new TextEncodingConverter(std::move(*ErrorOrConverter));
-    TInfo.ExecStrConverter = TEC.ToLiteralEncodingConverter;
+    TInfo.ExecStrConverter = TE.ToLiteralEncodingConverter;
   } else
     return ErrorOrConverter.getError();
 

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to