[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-03 Thread Abhina Sree via llvm-branch-commits

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

>From da9c4b541dc4fee7a3769643df2e39c23ec24c7e Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 55663cdc072da..641234c8ceb9f 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -26,7 +26,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-03 Thread Abhina Sree via llvm-branch-commits

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

>From da9c4b541dc4fee7a3769643df2e39c23ec24c7e Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 55663cdc072da..641234c8ceb9f 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -26,7 +26,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-03 Thread Abhina Sree via llvm-branch-commits

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

>From 6a1b32a90ca47138979bba2dfb8e4af2a0ef9118 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 55663cdc072da..641234c8ceb9f 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -26,7 +26,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-03 Thread Abhina Sree via llvm-branch-commits

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

>From 6a1b32a90ca47138979bba2dfb8e4af2a0ef9118 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 55663cdc072da..641234c8ceb9f 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -26,7 +26,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-03 Thread Abhina Sree via llvm-branch-commits

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

>From 685da0f33ab9af18fd00ddaa3a9b0a016eed2e41 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 55663cdc072da..641234c8ceb9f 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -26,7 +26,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-03 Thread Abhina Sree via llvm-branch-commits

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

>From 685da0f33ab9af18fd00ddaa3a9b0a016eed2e41 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 55663cdc072da..641234c8ceb9f 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -26,7 +26,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-02 Thread Abhina Sree via llvm-branch-commits

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

>From 71fdbc941b38f83fbfb33e08c926dc0c77b53ebc Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-02 Thread Abhina Sree via llvm-branch-commits

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

>From 71fdbc941b38f83fbfb33e08c926dc0c77b53ebc Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-02 Thread Abhina Sree via llvm-branch-commits

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

>From 42abfa5854e4ee0b25031476dff76fa537204de5 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-02 Thread Abhina Sree via llvm-branch-commits

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

>From 42abfa5854e4ee0b25031476dff76fa537204de5 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-02 Thread Abhina Sree via llvm-branch-commits

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

>From 8dd304a70ddd300c4184f86afd58224817be2d3c Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-07-02 Thread Abhina Sree via llvm-branch-commits

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

>From 8dd304a70ddd300c4184f86afd58224817be2d3c Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ad735d7b0b0e5..7a3b803efd3bd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-30 Thread Abhina Sree via llvm-branch-commits

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

>From 23c7a502eb0fb1fb81180b3b158b56a268cac1da Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 47bed8e021264..73b055a76dda7 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-30 Thread Abhina Sree via llvm-branch-commits

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

>From 23c7a502eb0fb1fb81180b3b158b56a268cac1da Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 47bed8e021264..73b055a76dda7 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-26 Thread Abhina Sree via llvm-branch-commits

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

>From f1cad4651da6a6a00e6f66a8bb3b38bb460fe58d Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 47bed8e021264..73b055a76dda7 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-26 Thread Abhina Sree via llvm-branch-commits

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

>From f1cad4651da6a6a00e6f66a8bb3b38bb460fe58d Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 47bed8e021264..73b055a76dda7 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-26 Thread Abhina Sree via llvm-branch-commits

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

>From 73570aa3b482b66d39152aeab3e68fe7b58c2f1e Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 47bed8e021264..73b055a76dda7 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-26 Thread Abhina Sree via llvm-branch-commits

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

>From 73570aa3b482b66d39152aeab3e68fe7b58c2f1e Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 47bed8e021264..73b055a76dda7 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-26 Thread Abhina Sree via llvm-branch-commits

https://github.com/abhina-sree edited 
https://github.com/llvm/llvm-project/pull/196568
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-26 Thread Abhina Sree via llvm-branch-commits

https://github.com/abhina-sree edited 
https://github.com/llvm/llvm-project/pull/196568
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-26 Thread Abhina Sree via llvm-branch-commits

https://github.com/abhina-sree edited 
https://github.com/llvm/llvm-project/pull/196568
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-19 Thread Abhina Sree via llvm-branch-commits

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

>From 37f6827fd64a651a4e44b4cdb66db571e0269e8a Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a4984cffc430a..909bde840d3fa 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-19 Thread Abhina Sree via llvm-branch-commits

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

>From 37f6827fd64a651a4e44b4cdb66db571e0269e8a Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 2c91e18491b1e..740b41d0b7743 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -20,6 +20,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -764,7 +765,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -780,10 +782,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a4984cffc430a..909bde840d3fa 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index c892d1fadbc38..f525b06cff37b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index a7569701352b3..54c3ff18bdfe5 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -34,8 +34,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -43,7 +44,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -76,21 +77,22 @@ static bool ParseWidthModifier(const char *&I, const char 
*E,
 }
 
 OptionalAmount clang::analyze_format_string::ParseNonPositionA

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-19 Thread Abhina Sree via llvm-branch-commits

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

>From debd0182db40d0aebf12da43b6e26e497b8fbd63 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 19 Jun 2026 08:50:48 -0400
Subject: [PATCH 1/9] use LiteralEncoding internally, address other comments

---
 clang/include/clang/Basic/DiagnosticLexKinds.td |  2 +-
 clang/include/clang/Basic/LangOptions.h |  4 ++--
 clang/include/clang/Lex/TextEncoding.h  |  8 
 clang/include/clang/Options/Options.td  |  4 ++--
 clang/lib/Frontend/CompilerInstance.cpp |  2 +-
 clang/lib/Frontend/InitPreprocessor.cpp | 12 ++--
 clang/lib/Lex/LiteralSupport.cpp|  2 +-
 clang/lib/Lex/TextEncoding.cpp  | 16 
 clang/lib/Sema/SemaExpr.cpp |  2 +-
 clang/test/CodeGen/systemz-charset-diag.cpp |  2 +-
 clang/test/CodeGen/systemz-charset.c| 10 ++
 11 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index f12fa0205b650..3b0b4d87fc006 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -288,7 +288,7 @@ def ext_string_too_long : Extension<"string literal of 
length %0 exceeds "
 def err_character_too_large : Error<
   "character too large for enclosing character literal type">;
 def err_exec_charset_conversion_failed
-: Error<"conversion to execution encoding failed: '%0'">;
+: Error<"conversion to literal encoding failed: '%0'">;
 def warn_c99_compat_unicode_literal : Warning<
   "unicode literals are incompatible with C99">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 5ec31b356d059..bbf47c34b306a 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -618,8 +618,8 @@ class LangOptions : public LangOptionsBase {
   /// The allocation token mode.
   std::optional AllocTokenMode;
 
-  /// Name of the execution encoding to convert the internal encoding to.
-  std::string ExecEncoding;
+  /// Name of the literal encoding to convert the internal encoding to.
+  std::string LiteralEncoding;
 
   LangOptions();
 
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 770cb3c5eff1a..c892d1fadbc38 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -13,18 +13,18 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/TextEncoding.h"
 
-enum ConversionAction { CA_NoConversion, CA_ToExecEncoding };
+enum ConversionAction { CA_NoConversion, CA_ToLiteralEncoding };
 
 class TextEncoding {
-  llvm::StringRef ExecEncoding;
-  llvm::TextEncodingConverter *ToExecEncodingConverter = nullptr;
+  llvm::StringRef LiteralEncoding;
+  llvm::TextEncodingConverter *ToLiteralEncodingConverter = nullptr;
 
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
 
-  llvm::StringRef getExecEncoding() { return ExecEncoding; }
+  llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
 };
 
 #endif
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 92b62fa8fceb4..bad318f703935 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7537,10 +7537,10 @@ def tune_cpu : Separate<["-"], "tune-cpu">,
   HelpText<"Tune for a specific cpu type">,
   MarshallingInfoString>;
 def fexec_charset : Separate<["-"], "fexec-charset">, 
MetaVarName<"">,
-  HelpText<"Set the execution  for ordinary string and character 
literals. "
+  HelpText<"Set the  for ordinary string and character literals. "
"Supported character encodings include ISO-8859-1, UTF-8, IBM1047, "
"and possibly those supported by ICU or the host iconv library.">,
-  MarshallingInfoString>;
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 952eb73c210ff..f4e0f09035fff 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -558,7 +558,7 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
   if (auto EC = TextEncoding::setConvertersFromOptions(PP->getTextEncoding(),
getLangOpts()))
 PP->getDiagnostics().Report(clang::diag::err_fe_text_encoding_config)
-<< PP->getTextEncoding().getExecEncoding();
+<< PP->getTextEncoding().getLiteralEncoding();
 }
 
 // ASTContext
dif

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-17 Thread Abhina Sree via llvm-branch-commits

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

>From 7d22a0e1057052c55248632557285d8157b84fc0 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a4984cffc430a..909bde840d3fa 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 770cb3c5eff1a..ea149888b1e63 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
 }
 
 OptionalAmount clang::analyze_format_string::Pars

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-17 Thread Abhina Sree via llvm-branch-commits

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

>From 7d22a0e1057052c55248632557285d8157b84fc0 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a4984cffc430a..909bde840d3fa 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 770cb3c5eff1a..ea149888b1e63 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
 }
 
 OptionalAmount clang::analyze_format_string::Pars

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-08 Thread Abhina Sree via llvm-branch-commits

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

>From 3a543fefaacbee19ca58379d2329a019a9751594 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a4984cffc430a..909bde840d3fa 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 770cb3c5eff1a..ea149888b1e63 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
 }
 
 OptionalAmount clang::analyze_format_string::Pars

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-06-08 Thread Abhina Sree via llvm-branch-commits

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

>From 3a543fefaacbee19ca58379d2329a019a9751594 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 ++--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncoding.h   |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ---
 clang/lib/AST/FormatStringParsing.h  | 36 +++---
 clang/lib/AST/PrintfFormatString.cpp | 89 +++-
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++---
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  4 +-
 clang/lib/Lex/TextEncoding.cpp   | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 --
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 233 insertions(+), 120 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a4984cffc430a..909bde840d3fa 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncoding.h 
b/clang/include/clang/Lex/TextEncoding.h
index 770cb3c5eff1a..ea149888b1e63 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -22,7 +22,8 @@ class TextEncoding {
 public:
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
-  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts);
+  setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
 }
 
 OptionalAmount clang::analyze_format_string::Pars

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-28 Thread Abhina Sree via llvm-branch-commits

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

>From e13462cb7dac57066c6bc233b458398d537e Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 232 insertions(+), 119 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 779093f963bc1..41ad751c4b769 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 9e1e7649d65c4..97fffd38d28c5 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -23,7 +23,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmou

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-28 Thread Abhina Sree via llvm-branch-commits

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

>From e13462cb7dac57066c6bc233b458398d537e Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/3] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 232 insertions(+), 119 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 779093f963bc1..41ad751c4b769 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 9e1e7649d65c4..97fffd38d28c5 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -23,7 +23,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmou

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-25 Thread Abhina Sree via llvm-branch-commits

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

>From 719e1d23651b5d6b8252b44a37a0a4fa5256ed62 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/2] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 232 insertions(+), 119 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 779093f963bc1..41ad751c4b769 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 9e1e7649d65c4..97fffd38d28c5 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -23,7 +23,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmou

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-25 Thread Abhina Sree via llvm-branch-commits

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

>From df73c0b90414acfa0cd88a5c9d74e292ef81ec9d Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/2] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 232 insertions(+), 119 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 779093f963bc1..41ad751c4b769 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 9e1e7649d65c4..97fffd38d28c5 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -23,7 +23,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmou

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-25 Thread Abhina Sree via llvm-branch-commits

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

>From df73c0b90414acfa0cd88a5c9d74e292ef81ec9d Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/2] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 232 insertions(+), 119 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 779093f963bc1..41ad751c4b769 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 9e1e7649d65c4..97fffd38d28c5 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -23,7 +23,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmou

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-25 Thread Abhina Sree via llvm-branch-commits

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

>From 719e1d23651b5d6b8252b44a37a0a4fa5256ed62 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/2] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 232 insertions(+), 119 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 779093f963bc1..41ad751c4b769 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 9e1e7649d65c4..97fffd38d28c5 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -23,7 +23,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmou

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-23 Thread Abhina Sree via llvm-branch-commits

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

>From f4c945ce457f42c0e98f159d78689a8760772251 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH 1/2] Add format string handling

---
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 13 files changed, 232 insertions(+), 119 deletions(-)

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index cc226403877e2..2385a059557a7 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 09967a81beeed..f4ef578eb2991 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -26,7 +26,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 7e1ac0de6dcaf..0d449fb5f0904 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -33,8 +33,9 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 
//===--===//
 
-OptionalAmount clang::analyze_format_string::ParseAmount(const char *&Beg,
- const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+const char *&Beg, const char *E,
+const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn UpdateBeg(Beg, I);
 
@@ -42,7 +43,7 @@ OptionalAmount 
clang::analyze_format_string::ParseAmount(const char *&Beg,
   bool hasDigits = false;
 
   for (; I != E; ++I) {
-char c = *I;
+char c = FormatStrConverter.convert(*I);
 if (c >= '0' && c <= '9') {
   hasDigits = true;
   accumulator = (accumulator * 10) + (c - '0');
@@ -60,21 +61,22 @@ OptionalAmount 
clang::analyze_format_string::ParseAmou

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-12 Thread Abhina Sree via llvm-branch-commits

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

>From a95fbc99ab8bc1428c80799705a73458082cecb1 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH] Add format string handling

---
 clang/include/clang/AST/Expr.h   |  6 ++
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/Expr.cpp   | 14 +++
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 clang/lib/Sema/SemaExpr.cpp  |  5 +-
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 16 files changed, 255 insertions(+), 121 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 393fe275c6269..d01afcff4095d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SyncScope.h"
 #include "clang/Basic/TypeTraits.h"
+#include "clang/Lex/TextEncodingConfig.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -2066,6 +2067,11 @@ class PredefinedExpr final
 return getIdentKindName(getIdentKind());
   }
 
+  static std::string
+  ComputeNameAndTranslate(PredefinedIdentKind IK, const Decl *CurrentDecl,
+  TextEncodingConfig &TEC,
+  bool ForceElaboratedPrinting = false);
+
   static std::string ComputeName(PredefinedIdentKind IK,
  const Decl *CurrentDecl,
  bool ForceElaboratedPrinting = false);
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9f7d2a17a0f8a..ec7d4fcd4d8e3 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 09967a81beeed..f4ef578eb2991 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -26,7 +26,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --gi

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-12 Thread Abhina Sree via llvm-branch-commits

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

>From a95fbc99ab8bc1428c80799705a73458082cecb1 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH] Add format string handling

---
 clang/include/clang/AST/Expr.h   |  6 ++
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/Expr.cpp   | 14 +++
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 clang/lib/Sema/SemaExpr.cpp  |  5 +-
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 16 files changed, 255 insertions(+), 121 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 393fe275c6269..d01afcff4095d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SyncScope.h"
 #include "clang/Basic/TypeTraits.h"
+#include "clang/Lex/TextEncodingConfig.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -2066,6 +2067,11 @@ class PredefinedExpr final
 return getIdentKindName(getIdentKind());
   }
 
+  static std::string
+  ComputeNameAndTranslate(PredefinedIdentKind IK, const Decl *CurrentDecl,
+  TextEncodingConfig &TEC,
+  bool ForceElaboratedPrinting = false);
+
   static std::string ComputeName(PredefinedIdentKind IK,
  const Decl *CurrentDecl,
  bool ForceElaboratedPrinting = false);
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9f7d2a17a0f8a..ec7d4fcd4d8e3 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 09967a81beeed..f4ef578eb2991 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -26,7 +26,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { return ExecEncoding; }
 };
diff --gi

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-12 Thread Abhina Sree via llvm-branch-commits

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

>From c977a6585cb22772a05018661d159130be76d8c2 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH] Add format string handling

---
 clang/include/clang/AST/Expr.h   |  6 ++
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/Expr.cpp   | 14 +++
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 clang/lib/Sema/SemaExpr.cpp  |  5 +-
 clang/test/CodeGen/systemz-charset.c |  2 +
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 17 files changed, 257 insertions(+), 121 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 393fe275c6269..d01afcff4095d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SyncScope.h"
 #include "clang/Basic/TypeTraits.h"
+#include "clang/Lex/TextEncodingConfig.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -2066,6 +2067,11 @@ class PredefinedExpr final
 return getIdentKindName(getIdentKind());
   }
 
+  static std::string
+  ComputeNameAndTranslate(PredefinedIdentKind IK, const Decl *CurrentDecl,
+  TextEncodingConfig &TEC,
+  bool ForceElaboratedPrinting = false);
+
   static std::string ComputeName(PredefinedIdentKind IK,
  const Decl *CurrentDecl,
  bool ForceElaboratedPrinting = false);
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9f7d2a17a0f8a..ec7d4fcd4d8e3 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 09967a81beeed..f4ef578eb2991 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -26,7 +26,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef get

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-11 Thread Abhina Sree via llvm-branch-commits

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

>From 390277bb58ca168e88b81638b050fdf4244d984d Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH] Add format string handling

---
 clang/include/clang/AST/Expr.h   |  6 ++
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/Expr.cpp   | 14 +++
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 clang/lib/Sema/SemaExpr.cpp  |  5 +-
 clang/test/CodeGen/systemz-charset.c |  2 +
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 17 files changed, 257 insertions(+), 121 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 393fe275c6269..d01afcff4095d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SyncScope.h"
 #include "clang/Basic/TypeTraits.h"
+#include "clang/Lex/TextEncodingConfig.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -2066,6 +2067,11 @@ class PredefinedExpr final
 return getIdentKindName(getIdentKind());
   }
 
+  static std::string
+  ComputeNameAndTranslate(PredefinedIdentKind IK, const Decl *CurrentDecl,
+  TextEncodingConfig &TEC,
+  bool ForceElaboratedPrinting = false);
+
   static std::string ComputeName(PredefinedIdentKind IK,
  const Decl *CurrentDecl,
  bool ForceElaboratedPrinting = false);
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9f7d2a17a0f8a..ec7d4fcd4d8e3 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 09967a81beeed..f4ef578eb2991 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -26,7 +26,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef get

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-11 Thread Abhina Sree via llvm-branch-commits

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

>From 390277bb58ca168e88b81638b050fdf4244d984d Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH] Add format string handling

---
 clang/include/clang/AST/Expr.h   |  6 ++
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/lib/AST/Expr.cpp   | 14 +++
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 clang/lib/Sema/SemaExpr.cpp  |  5 +-
 clang/test/CodeGen/systemz-charset.c |  2 +
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 17 files changed, 257 insertions(+), 121 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 393fe275c6269..d01afcff4095d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SyncScope.h"
 #include "clang/Basic/TypeTraits.h"
+#include "clang/Lex/TextEncodingConfig.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -2066,6 +2067,11 @@ class PredefinedExpr final
 return getIdentKindName(getIdentKind());
   }
 
+  static std::string
+  ComputeNameAndTranslate(PredefinedIdentKind IK, const Decl *CurrentDecl,
+  TextEncodingConfig &TEC,
+  bool ForceElaboratedPrinting = false);
+
   static std::string ComputeName(PredefinedIdentKind IK,
  const Decl *CurrentDecl,
  bool ForceElaboratedPrinting = false);
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9f7d2a17a0f8a..ec7d4fcd4d8e3 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 09967a81beeed..f4ef578eb2991 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -26,7 +26,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef get

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-09 Thread Abhina Sree via llvm-branch-commits

abhina-sree wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.com/github/pr/llvm/llvm-project/196568?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#195890** https://app.graphite.com/github/pr/llvm/llvm-project/195890?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#196569** https://app.graphite.com/github/pr/llvm/llvm-project/196569?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#196568** https://app.graphite.com/github/pr/llvm/llvm-project/196568?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.com/github/pr/llvm/llvm-project/196568?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#169803** https://app.graphite.com/github/pr/llvm/llvm-project/169803?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#138895** https://app.graphite.com/github/pr/llvm/llvm-project/138895?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/196568
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-09 Thread Abhina Sree via llvm-branch-commits

https://github.com/abhina-sree created 
https://github.com/llvm/llvm-project/pull/196568

None

>From 5f9b389a8d09367107d54af8cb2e7ec94244bf6e Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH] Add format string handling

---
 clang/include/clang/AST/Expr.h   |  6 ++
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/include/clang/Sema/Sema.h  |  2 +-
 clang/lib/AST/Expr.cpp   | 14 +++
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 clang/lib/Sema/SemaExpr.cpp  |  5 +-
 clang/test/CodeGen/systemz-charset.c |  2 +
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 18 files changed, 258 insertions(+), 122 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 393fe275c6269..d01afcff4095d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SyncScope.h"
 #include "clang/Basic/TypeTraits.h"
+#include "clang/Lex/TextEncodingConfig.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -2066,6 +2067,11 @@ class PredefinedExpr final
 return getIdentKindName(getIdentKind());
   }
 
+  static std::string
+  ComputeNameAndTranslate(PredefinedIdentKind IK, const Decl *CurrentDecl,
+  TextEncodingConfig &TEC,
+  bool ForceElaboratedPrinting = false);
+
   static std::string ComputeName(PredefinedIdentKind IK,
  const Decl *CurrentDecl,
  bool ForceElaboratedPrinting = false);
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9f7d2a17a0f8a..ec7d4fcd4d8e3 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 09967a81beeed..f4ef578eb2991 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -26,7 +26,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+  

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-09 Thread Abhina Sree via llvm-branch-commits

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

>From 4db2f4ffa5cfade0f0538da5d11670cb814eb4c7 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH] Add format string handling

---
 clang/include/clang/AST/Expr.h   |  6 ++
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/include/clang/Sema/Sema.h  |  1 +
 clang/lib/AST/Expr.cpp   | 14 +++
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 clang/lib/Sema/SemaExpr.cpp  |  5 +-
 clang/test/CodeGen/systemz-charset.c |  2 +
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 18 files changed, 258 insertions(+), 121 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 393fe275c6269..d01afcff4095d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SyncScope.h"
 #include "clang/Basic/TypeTraits.h"
+#include "clang/Lex/TextEncodingConfig.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -2066,6 +2067,11 @@ class PredefinedExpr final
 return getIdentKindName(getIdentKind());
   }
 
+  static std::string
+  ComputeNameAndTranslate(PredefinedIdentKind IK, const Decl *CurrentDecl,
+  TextEncodingConfig &TEC,
+  bool ForceElaboratedPrinting = false);
+
   static std::string ComputeName(PredefinedIdentKind IK,
  const Decl *CurrentDecl,
  bool ForceElaboratedPrinting = false);
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9f7d2a17a0f8a..ec7d4fcd4d8e3 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 09967a81beeed..f4ef578eb2991 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -26,7 +26,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+ 

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-09 Thread via llvm-branch-commits

github-actions[bot] wrote:


# :penguin: Linux x64 Test Results

* 80065 tests passed
* 1507 tests skipped
* 1 test failed

## Failed Tests
(click on a test name to see its output)

### MLIR

MLIR.Pass/ir-printing-file-tree.mlir

```
Exit Code: -9
Timeout: Reached timeout of 1200 seconds

Command Output (stdout):
--
# RUN: at line 2
rm -rf 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp
 || true
# executed command: rm -rf 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp
# note: command had no output on stdout or stderr
# RUN: at line 3
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/mlir-opt 
/home/gha/actions-runner/_work/llvm-project/llvm-project/mlir/test/Pass/ir-printing-file-tree.mlir
 
-mlir-print-ir-tree-dir=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp

-pass-pipeline='builtin.module(builtin.module(func.func(cse,canonicalize)))'
-mlir-print-ir-before=cse
# executed command: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/mlir-opt 
/home/gha/actions-runner/_work/llvm-project/llvm-project/mlir/test/Pass/ir-printing-file-tree.mlir
 
-mlir-print-ir-tree-dir=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp
 '-pass-pipeline=builtin.module(builtin.module(func.func(cse,canonicalize)))' 
-mlir-print-ir-before=cse
# .---command stdout
# | module @outer {
# |   func.func @"sym/A"() {
# | return
# |   }
# |   func.func @"sym\\backslash"() {
# | return
# |   }
# |   module @inner {
# | func.func @symB() {
# |   return
# | }
# | func.func @symC() {
# |   return
# | }
# |   }
# | }
# | 
# `-
# RUN: at line 6
test -f 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp/builtin_module_outer/builtin_module_inner/func_func_symB/0_0_0_cse.mlir
# executed command: test -f 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp/builtin_module_outer/builtin_module_inner/func_func_symB/0_0_0_cse.mlir
# note: command had no output on stdout or stderr
# RUN: at line 7
test ! -f 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp/builtin_module_outer/builtin_module_inner/func_func_symB/0_0_1_canonicalize.mlir
# executed command: test '!' -f 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp/builtin_module_outer/builtin_module_inner/func_func_symB/0_0_1_canonicalize.mlir
# note: command had no output on stdout or stderr
# RUN: at line 8
test -f 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp/builtin_module_outer/builtin_module_inner/func_func_symC/0_0_0_cse.mlir
# executed command: test -f 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp/builtin_module_outer/builtin_module_inner/func_func_symC/0_0_0_cse.mlir
# note: command had no output on stdout or stderr
# RUN: at line 9
test ! -f 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp/builtin_module_outer/builtin_module_inner/func_func_symC/0_0_1_canonicalize.mlir
# executed command: test '!' -f 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp/builtin_module_outer/builtin_module_inner/func_func_symC/0_0_1_canonicalize.mlir
# note: command had no output on stdout or stderr
# RUN: at line 12
rm -rf 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp
 || true
# executed command: rm -rf 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp
# note: command had no output on stdout or stderr
# RUN: at line 13
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/mlir-opt 
/home/gha/actions-runner/_work/llvm-project/llvm-project/mlir/test/Pass/ir-printing-file-tree.mlir
 
-mlir-print-ir-tree-dir=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/test/Pass/Output/ir-printing-file-tree.mlir.tmp

-pass-pipeline='builtin.module(canonicalize,canonicalize,func.func(cse),builtin.module(canonicalize,func.func(cse,canonicalize),cse),cse)'
-mlir-print-ir-after-all
# executed command: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/mlir-opt 
/home/gha/actions-runner/_work/llvm-project/llvm-project/mlir/test/Pass/ir-printi

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-09 Thread via llvm-branch-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-llvm-support

Author: Abhina Sree (abhina-sree)


Changes



---

Patch is 42.41 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/196568.diff


18 Files Affected:

- (modified) clang/include/clang/AST/Expr.h (+6) 
- (modified) clang/include/clang/AST/FormatString.h (+7-5) 
- (modified) clang/include/clang/Basic/TargetInfo.h (+3) 
- (modified) clang/include/clang/Lex/TextEncodingConfig.h (+2-1) 
- (modified) clang/include/clang/Sema/Sema.h (+1-1) 
- (modified) clang/lib/AST/Expr.cpp (+14) 
- (modified) clang/lib/AST/FormatString.cpp (+46-40) 
- (modified) clang/lib/AST/FormatStringParsing.h (+25-11) 
- (modified) clang/lib/AST/PrintfFormatString.cpp (+58-31) 
- (modified) clang/lib/AST/ScanfFormatString.cpp (+15-8) 
- (modified) clang/lib/Basic/TargetInfo.cpp (+3) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+1-1) 
- (modified) clang/lib/Lex/TextEncodingConfig.cpp (+10-1) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+33-21) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+3-2) 
- (modified) clang/test/CodeGen/systemz-charset.c (+2) 
- (modified) llvm/include/llvm/Support/TextEncoding.h (+10) 
- (modified) llvm/lib/Support/TextEncoding.cpp (+19) 


``diff
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 393fe275c6269..d01afcff4095d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SyncScope.h"
 #include "clang/Basic/TypeTraits.h"
+#include "clang/Lex/TextEncodingConfig.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -2066,6 +2067,11 @@ class PredefinedExpr final
 return getIdentKindName(getIdentKind());
   }
 
+  static std::string
+  ComputeNameAndTranslate(PredefinedIdentKind IK, const Decl *CurrentDecl,
+  TextEncodingConfig &TEC,
+  bool ForceElaboratedPrinting = false);
+
   static std::string ComputeName(PredefinedIdentKind IK,
  const Decl *CurrentDecl,
  bool ForceElaboratedPrinting = false);
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9f7d2a17a0f8a..ec7d4fcd4d8e3 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 09967a81beeed..f4ef578eb2991 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -26,7 +26,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+   clang::TargetInfo &TInfo);
 
   llvm::StringRef getExecEncoding() { retu

[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-09 Thread via llvm-branch-commits

github-actions[bot] wrote:


# :window: Windows x64 Test Results

* 79467 tests passed
* 2054 tests skipped

All executed tests passed, but another part of the build **failed**. Click on a 
failure below to see the details.


[code=1] 
tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/TextEncodingConfig.cpp.obj

```
FAILED: [code=1] 
tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/TextEncodingConfig.cpp.obj
sccache C:\clang\clang-msvc\bin\clang-cl.exe  /nologo -TP -DCLANG_BUILD_STATIC 
-DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS 
-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS 
-D_HAS_EXCEPTIONS=0 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE 
-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-IC:\_work\llvm-project\llvm-project\build\tools\clang\lib\Lex 
-IC:\_work\llvm-project\llvm-project\clang\lib\Lex 
-IC:\_work\llvm-project\llvm-project\clang\include 
-IC:\_work\llvm-project\llvm-project\build\tools\clang\include 
-IC:\_work\llvm-project\llvm-project\build\include 
-IC:\_work\llvm-project\llvm-project\llvm\include /DWIN32 /D_WINDOWS   
/Zc:inline /Zc:__cplusplus /Oi /Brepro /bigobj /permissive- 
-Werror=unguarded-availability-new /W4  -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported /Gw /O2 /Ob2 
 -std:c++17 -MD -UNDEBUG /EHs-c- /GR- /showIncludes 
/Fotools\clang\lib\Lex\CMakeFiles\obj.clangLex.dir\TextEncodingConfig.cpp.obj 
/Fdtools\clang\lib\Lex\CMakeFiles\obj.clangLex.dir\ -c -- 
C:\_work\llvm-project\llvm-project\clang\lib\Lex\TextEncodingConfig.cpp
C:\_work\llvm-project\llvm-project\clang\lib\Lex\TextEncodingConfig.cpp(46,62): 
error: no member named 'SystemEncoding' in 'TextEncodingConfig'
46 |   ErrorOrConverter = 
llvm::TextEncodingConverter::create(TEC.SystemEncoding,
|  ~~~ ^
C:\_work\llvm-project\llvm-project\clang\lib\Lex\TextEncodingConfig.cpp(47,62): 
error: no member named 'InternalEncoding' in 'TextEncodingConfig'
47 |  
TEC.InternalEncoding);
|  ~~~ ^
2 errors generated.
```


If these failures are unrelated to your changes (for example tests are broken 
or flaky at HEAD), please open an issue at 
https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.

https://github.com/llvm/llvm-project/pull/196568
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] Add format string handling (PR #196568)

2026-05-09 Thread Abhina Sree via llvm-branch-commits

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

>From 4db2f4ffa5cfade0f0538da5d11670cb814eb4c7 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Fri, 8 May 2026 12:19:11 -0400
Subject: [PATCH] Add format string handling

---
 clang/include/clang/AST/Expr.h   |  6 ++
 clang/include/clang/AST/FormatString.h   | 12 +--
 clang/include/clang/Basic/TargetInfo.h   |  3 +
 clang/include/clang/Lex/TextEncodingConfig.h |  3 +-
 clang/include/clang/Sema/Sema.h  |  1 +
 clang/lib/AST/Expr.cpp   | 14 +++
 clang/lib/AST/FormatString.cpp   | 86 ++-
 clang/lib/AST/FormatStringParsing.h  | 36 +---
 clang/lib/AST/PrintfFormatString.cpp | 89 +---
 clang/lib/AST/ScanfFormatString.cpp  | 23 +++--
 clang/lib/Basic/TargetInfo.cpp   |  3 +
 clang/lib/Frontend/CompilerInstance.cpp  |  2 +-
 clang/lib/Lex/TextEncodingConfig.cpp | 11 ++-
 clang/lib/Sema/SemaChecking.cpp  | 54 +++-
 clang/lib/Sema/SemaExpr.cpp  |  5 +-
 clang/test/CodeGen/systemz-charset.c |  2 +
 llvm/include/llvm/Support/TextEncoding.h | 10 +++
 llvm/lib/Support/TextEncoding.cpp| 19 +
 18 files changed, 258 insertions(+), 121 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 393fe275c6269..d01afcff4095d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SyncScope.h"
 #include "clang/Basic/TypeTraits.h"
+#include "clang/Lex/TextEncodingConfig.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -2066,6 +2067,11 @@ class PredefinedExpr final
 return getIdentKindName(getIdentKind());
   }
 
+  static std::string
+  ComputeNameAndTranslate(PredefinedIdentKind IK, const Decl *CurrentDecl,
+  TextEncodingConfig &TEC,
+  bool ForceElaboratedPrinting = false);
+
   static std::string ComputeName(PredefinedIdentKind IK,
  const Decl *CurrentDecl,
  bool ForceElaboratedPrinting = false);
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a3382e1a1d007..a24ade2d71ee9 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_AST_FORMATSTRING_H
 
 #include "clang/AST/CanonicalType.h"
+#include "llvm/Support/TextEncoding.h"
 #include 
 
 namespace clang {
@@ -728,7 +729,8 @@ class FormatStringHandler {
 
   virtual bool HandleInvalidPrintfConversionSpecifier(
   const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
-  unsigned specifierLen) {
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
@@ -744,10 +746,10 @@ class FormatStringHandler {
 
   // Scanf-specific handlers.
 
-  virtual bool
-  HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier 
&FS,
-const char *startSpecifier,
-unsigned specifierLen) {
+  virtual bool HandleInvalidScanfConversionSpecifier(
+  const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
+  unsigned specifierLen,
+  const llvm::TextEncodingConverter &FormatStrConverter) {
 return true;
   }
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9f7d2a17a0f8a..ec7d4fcd4d8e3 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -38,6 +38,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TextEncoding.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -323,6 +324,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   virtual ~TargetInfo();
 
+  llvm::TextEncodingConverter *FormatStrConverter;
+
   /// Retrieve the target options.
   TargetOptions &getTargetOpts() const {
 assert(TargetOpts && "Missing target options");
diff --git a/clang/include/clang/Lex/TextEncodingConfig.h 
b/clang/include/clang/Lex/TextEncodingConfig.h
index 09967a81beeed..f4ef578eb2991 100644
--- a/clang/include/clang/Lex/TextEncodingConfig.h
+++ b/clang/include/clang/Lex/TextEncodingConfig.h
@@ -26,7 +26,8 @@ class TextEncodingConfig {
   llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
   static std::error_code
   setConvertersFromOptions(TextEncodingConfig &TEC,
-   const clang::LangOptions &Opts);
+   const clang::LangOptions &Opts,
+