[clang] [llvm] [clang] Fix encoding handling of asm strings (PR #169803)
Abhina Sree via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 13 12:16:37 PST 2026
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/169803
>From 428436d0c27c5108d4a9245c6a4f7ead1e676cd7 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 8 May 2026 12:17:22 -0400
Subject: [PATCH 01/22] add ParserConversionAction, do not translate
unevaluated strings
---
clang/include/clang/Parse/Parser.h | 1 +
clang/include/clang/Sema/Sema.h | 4 +++-
clang/lib/Parse/ParseDecl.cpp | 9 +++++++++
clang/lib/Parse/ParseExpr.cpp | 6 +++---
clang/lib/Parse/Parser.cpp | 4 ++++
clang/lib/Sema/SemaExpr.cpp | 8 ++++----
clang/test/CodeGen/systemz-charset-diag.cpp | 8 ++++++++
clang/test/CodeGen/systemz-charset.c | 5 +++++
8 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 5237d767affdd..24b012b050352 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -5762,6 +5762,7 @@ class Parser : public CodeCompletionHandler {
bool Finished;
};
ObjCImplParsingDataRAII *CurParsedObjCImpl;
+ ConversionAction ParserConversionAction;
/// StashAwayMethodOrFunctionBodyTokens - Consume the tokens and store them
/// for later parsing.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0d207679d1f4d..a15811c40f223 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -54,6 +54,7 @@
#include "clang/Basic/StackExhaustionHandler.h"
#include "clang/Basic/TemplateKinds.h"
#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/TextEncoding.h"
#include "clang/Sema/AnalysisBasedWarnings.h"
#include "clang/Sema/Attr.h"
#include "clang/Sema/CleanupInfo.h"
@@ -7439,7 +7440,8 @@ class Sema final : public SemaBase {
/// from multiple tokens. However, the common case is that StringToks points
/// to one string.
ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks,
- Scope *UDLScope = nullptr);
+ Scope *UDLScope = nullptr,
+ ConversionAction Action = CA_ToLiteralEncoding);
ExprResult ActOnUnevaluatedStringLiteral(ArrayRef<Token> StringToks);
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index ada54c85695c3..e5fee9f956d21 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -586,6 +586,9 @@ unsigned Parser::ParseAttributeArgsCommon(
nullptr,
Sema::ExpressionEvaluationContextRecord::EK_AttrArgument);
+ SaveAndRestore<ConversionAction> SavedTranslationState(
+ ParserConversionAction, CA_NoConversion);
+
ExprResult ArgExpr = ParseAssignmentExpression();
if (ArgExpr.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
@@ -666,6 +669,9 @@ void Parser::ParseGNUAttributeArgs(
ParsedAttr::Kind AttrKind =
ParsedAttr::getParsedKind(AttrName, ScopeName, Form.getSyntax());
+ SaveAndRestore<ConversionAction> SavedTranslationState(ParserConversionAction,
+ CA_NoConversion);
+
if (AttrKind == ParsedAttr::AT_Availability) {
ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
ScopeLoc, Form);
@@ -745,6 +751,9 @@ unsigned Parser::ParseClangAttributeArgs(
ParsedAttr::Kind AttrKind =
ParsedAttr::getParsedKind(AttrName, ScopeName, Form.getSyntax());
+ SaveAndRestore<ConversionAction> SavedTranslationState(ParserConversionAction,
+ CA_NoConversion);
+
switch (AttrKind) {
default:
return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index d42ffc2ccf0a6..68af97fad5c4a 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3044,9 +3044,9 @@ ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral,
}
// Pass the set of string tokens, ready for concatenation, to the actions.
- return Actions.ActOnStringLiteral(StringToks,
- AllowUserDefinedLiteral ? getCurScope()
- : nullptr);
+ return Actions.ActOnStringLiteral(
+ StringToks, AllowUserDefinedLiteral ? getCurScope() : nullptr,
+ ParserConversionAction);
}
ExprResult Parser::ParseGenericSelectionExpression() {
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index f0f4c7195381e..c334cd62ee256 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -82,6 +82,8 @@ Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies)
NumCachedScopes = 0;
CurParsedObjCImpl = nullptr;
+ ParserConversionAction = CA_ToLiteralEncoding;
+
// Add #pragma handlers. These are removed and destroyed in the
// destructor.
initializePragmaHandlers();
@@ -1564,6 +1566,8 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
}
ExprResult Parser::ParseAsmStringLiteral(bool ForAsmLabel) {
+ SaveAndRestore<ConversionAction> SavedTranslationState(ParserConversionAction,
+ CA_NoConversion);
ExprResult AsmString;
if (isTokenStringLiteral()) {
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 00dd8acf1f68d..cd1416a724e75 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2264,8 +2264,8 @@ Sema::ExpandFunctionLocalPredefinedMacros(ArrayRef<Token> Toks) {
return ExpandedToks;
}
-ExprResult
-Sema::ActOnStringLiteral(ArrayRef<Token> StringToks, Scope *UDLScope) {
+ExprResult Sema::ActOnStringLiteral(ArrayRef<Token> StringToks, Scope *UDLScope,
+ ConversionAction Action) {
assert(!StringToks.empty() && "Must have at least one string!");
// StringToks needs backing storage as it doesn't hold array elements itself
@@ -2273,8 +2273,8 @@ Sema::ActOnStringLiteral(ArrayRef<Token> StringToks, Scope *UDLScope) {
if (getLangOpts().MicrosoftExt)
StringToks = ExpandedToks = ExpandFunctionLocalPredefinedMacros(StringToks);
- StringLiteralParser Literal(
- StringToks, PP, StringLiteralEvalMethod::Evaluated, CA_ToLiteralEncoding);
+ StringLiteralParser Literal(StringToks, PP,
+ StringLiteralEvalMethod::Evaluated, Action);
if (Literal.hadError)
return ExprError();
diff --git a/clang/test/CodeGen/systemz-charset-diag.cpp b/clang/test/CodeGen/systemz-charset-diag.cpp
index 4ed94810150a3..ad08e1f391214 100644
--- a/clang/test/CodeGen/systemz-charset-diag.cpp
+++ b/clang/test/CodeGen/systemz-charset-diag.cpp
@@ -1,3 +1,11 @@
// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++17 -emit-llvm -o - -verify
const char* Computer = "🖥️"; // expected-error-re {{conversion to literal encoding failed: {{.*}}}}
+
+static_assert(false, "Error string"); // expected-error {{static assertion failed: Error string}}
+
+[[deprecated("message")]] void test_deprecated() {return;} // expected-note {{'test_deprecated' has been explicitly marked deprecated here}}
+
+int main() {
+ test_deprecated(); // expected-warning {{'test_deprecated' is deprecated: message}}
+}
diff --git a/clang/test/CodeGen/systemz-charset.c b/clang/test/CodeGen/systemz-charset.c
index e1dc1ec2dc23a..fd81110f5f6c7 100644
--- a/clang/test/CodeGen/systemz-charset.c
+++ b/clang/test/CodeGen/systemz-charset.c
@@ -66,3 +66,8 @@ const char* hello_macro = HELLO;
const char* preprocessor_concatenation = HELLO_WORLD;
//CHECK: c"\C8\85\93\93\96@\E6\96\99\93\84Z\00"
//CHECK-UTF8: c"Hello World!\00"
+
+void asm_labeled_fn(void) __asm__("asm_sym");
+void asm_labeled_fn(void) {}
+//CHECK: define{{.*}} void @asm_sym(
+//CHECK-UTF8: define{{.*}} void @asm_sym(
>From 275e5eb1aac06849962a6d43b73a5b7b0b86f4ff Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 3 Jul 2026 14:52:22 -0400
Subject: [PATCH 02/22] remove unnecessary changes
---
clang/lib/Parse/ParseDecl.cpp | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index e5fee9f956d21..ada54c85695c3 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -586,9 +586,6 @@ unsigned Parser::ParseAttributeArgsCommon(
nullptr,
Sema::ExpressionEvaluationContextRecord::EK_AttrArgument);
- SaveAndRestore<ConversionAction> SavedTranslationState(
- ParserConversionAction, CA_NoConversion);
-
ExprResult ArgExpr = ParseAssignmentExpression();
if (ArgExpr.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi);
@@ -669,9 +666,6 @@ void Parser::ParseGNUAttributeArgs(
ParsedAttr::Kind AttrKind =
ParsedAttr::getParsedKind(AttrName, ScopeName, Form.getSyntax());
- SaveAndRestore<ConversionAction> SavedTranslationState(ParserConversionAction,
- CA_NoConversion);
-
if (AttrKind == ParsedAttr::AT_Availability) {
ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
ScopeLoc, Form);
@@ -751,9 +745,6 @@ unsigned Parser::ParseClangAttributeArgs(
ParsedAttr::Kind AttrKind =
ParsedAttr::getParsedKind(AttrName, ScopeName, Form.getSyntax());
- SaveAndRestore<ConversionAction> SavedTranslationState(ParserConversionAction,
- CA_NoConversion);
-
switch (AttrKind) {
default:
return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
>From e2bc4da52621b79a237622f95f26aa319715a389 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Thu, 9 Jul 2026 13:25:39 -0400
Subject: [PATCH 03/22] remove ParserConversionAction, add paramter to
ParseStringLiteralExpression instead, add conversion to SystemCharset then
back to UTF8 to handle escape sequences in system encoding
---
clang/include/clang/Basic/TargetInfo.h | 3 ++
clang/include/clang/Lex/TextEncoding.h | 11 ++++++--
clang/include/clang/Parse/Parser.h | 6 ++--
clang/lib/Basic/TargetInfo.cpp | 2 ++
clang/lib/Frontend/CompilerInstance.cpp | 4 +--
clang/lib/Lex/TextEncoding.cpp | 37 +++++++++++++++++++++----
clang/lib/Parse/ParseExpr.cpp | 6 ++--
clang/lib/Parse/Parser.cpp | 8 ++----
clang/lib/Sema/SemaStmtAsm.cpp | 8 ++++++
clang/test/CodeGen/systemz-charset.c | 6 ++--
10 files changed, 67 insertions(+), 24 deletions(-)
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index a6523e8eaaa43..f073d98408b21 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -37,6 +37,7 @@
#include "llvm/Frontend/OpenMP/OMPGridValues.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 <cassert>
@@ -330,6 +331,8 @@ class TargetInfo : public TransferrableTargetInfo,
virtual ~TargetInfo();
+ std::unique_ptr<llvm::TextEncodingConverter> TargetStrConverter;
+
/// 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..02cb16cef9f1b 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -10,6 +10,7 @@
#define LLVM_CLANG_LEX_TEXTENCODING_H
#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/StringRef.h"
namespace llvm {
@@ -17,16 +18,22 @@ class TextEncodingConverter;
} // namespace llvm
namespace clang {
-enum ConversionAction { CA_NoConversion, CA_ToLiteralEncoding };
+enum ConversionAction {
+ CA_NoConversion,
+ CA_ToSystemEncoding,
+ CA_ToLiteralEncoding
+};
class TextEncoding {
llvm::StringRef LiteralEncoding;
std::unique_ptr<llvm::TextEncodingConverter> ToLiteralEncodingConverter;
+ std::unique_ptr<llvm::TextEncodingConverter> ToSystemEncodingConverter;
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/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 24b012b050352..5268a7eeb911e 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3893,8 +3893,9 @@ class Parser : public CodeCompletionHandler {
/// associated with the class's definition.
void PopParsingClass(Sema::ParsingClassState);
- ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral,
- bool Unevaluated);
+ ExprResult
+ ParseStringLiteralExpression(bool AllowUserDefinedLiteral, bool Unevaluated,
+ ConversionAction CA = CA_ToLiteralEncoding);
/// This routine is called when the '@' is seen and consumed.
/// Current token is an Identifier and is not a 'try'. This
@@ -5762,7 +5763,6 @@ class Parser : public CodeCompletionHandler {
bool Finished;
};
ObjCImplParsingDataRAII *CurParsedObjCImpl;
- ConversionAction ParserConversionAction;
/// StashAwayMethodOrFunctionBodyTokens - Consume the tokens and store them
/// for later parsing.
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 6e390226d2e4b..488c3c5c28a74 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -201,6 +201,8 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
MaxOpenCLWorkGroupSize = 1024;
MaxBitIntWidth.reset();
+
+ TargetStrConverter = nullptr;
}
// Out of line virtual dtor for TargetInfo.
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index f122208d6b4c8..8c255c317f0a1 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -568,8 +568,8 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
if (GetDependencyDirectives)
PP->setDependencyDirectivesGetter(*GetDependencyDirectives);
- if (auto EC = TextEncoding::setConvertersFromOptions(PP->getTextEncoding(),
- getLangOpts()))
+ if (auto EC = TextEncoding::setConvertersFromOptions(
+ PP->getTextEncoding(), getLangOpts(), getTarget()))
PP->getDiagnostics().Report(clang::diag::err_fe_text_encoding_config)
<< PP->getTextEncoding().getLiteralEncoding();
}
diff --git a/clang/lib/Lex/TextEncoding.cpp b/clang/lib/Lex/TextEncoding.cpp
index eb4fde8928a68..effd05185faf7 100644
--- a/clang/lib/Lex/TextEncoding.cpp
+++ b/clang/lib/Lex/TextEncoding.cpp
@@ -17,6 +17,8 @@ TextEncoding::getConverter(ConversionAction Action) const {
switch (Action) {
case CA_ToLiteralEncoding:
return ToLiteralEncodingConverter.get();
+ case CA_ToSystemEncoding:
+ return ToSystemEncodingConverter.get();
default:
return nullptr;
}
@@ -24,23 +26,46 @@ TextEncoding::getConverter(ConversionAction Action) const {
std::error_code
TextEncoding::setConvertersFromOptions(TextEncoding &TE,
- const clang::LangOptions &Opts) {
+ const clang::LangOptions &Opts,
+ clang::TargetInfo &TInfo) {
using namespace llvm;
const char *UTF8 = "UTF-8";
TE.LiteralEncoding =
Opts.LiteralEncoding.empty() ? UTF8 : Opts.LiteralEncoding.c_str();
- // Create converter between internal and literal encoding specified
- // in fexec-charset option.
- if (TE.LiteralEncoding == UTF8)
+ if (TE.LiteralEncoding != UTF8) {
+ ErrorOr<TextEncodingConverter> ErrorOrLiteralConverter =
+ llvm::TextEncodingConverter::create(UTF8, TE.LiteralEncoding);
+ if (ErrorOrLiteralConverter)
+ TE.ToLiteralEncodingConverter = std::make_unique<TextEncodingConverter>(
+ std::move(*ErrorOrLiteralConverter));
+ else
+ return ErrorOrLiteralConverter.getError();
+ }
+
+ if (TInfo.getDefaultOrdinaryLiteralEncoding() == UTF8)
return std::error_code();
+
+ // Create converter between internal and default ordinary encoding for the
+ // target
ErrorOr<TextEncodingConverter> ErrorOrConverter =
- llvm::TextEncodingConverter::create(UTF8, TE.LiteralEncoding);
+ llvm::TextEncodingConverter::create(
+ UTF8, TInfo.getDefaultOrdinaryLiteralEncoding());
+ if (ErrorOrConverter)
+ TE.ToSystemEncodingConverter =
+ std::make_unique<TextEncodingConverter>(std::move(*ErrorOrConverter));
+ else
+ return ErrorOrConverter.getError();
+
+ ErrorOrConverter = llvm::TextEncodingConverter::create(
+ TInfo.getDefaultOrdinaryLiteralEncoding(), UTF8);
+
if (ErrorOrConverter)
- TE.ToLiteralEncodingConverter =
+ TInfo.TargetStrConverter =
std::make_unique<TextEncodingConverter>(std::move(*ErrorOrConverter));
else
return ErrorOrConverter.getError();
+
return std::error_code();
}
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 68af97fad5c4a..45c4988f671df 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3024,7 +3024,8 @@ ExprResult Parser::ParseUnevaluatedStringLiteralExpression() {
}
ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral,
- bool Unevaluated) {
+ bool Unevaluated,
+ ConversionAction CA) {
assert(tokenIsLikeStringLiteral(Tok, getLangOpts()) &&
"Not a string-literal-like token!");
@@ -3045,8 +3046,7 @@ ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral,
// Pass the set of string tokens, ready for concatenation, to the actions.
return Actions.ActOnStringLiteral(
- StringToks, AllowUserDefinedLiteral ? getCurScope() : nullptr,
- ParserConversionAction);
+ StringToks, AllowUserDefinedLiteral ? getCurScope() : nullptr, CA);
}
ExprResult Parser::ParseGenericSelectionExpression() {
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index c334cd62ee256..0eb02a45d8906 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -82,8 +82,6 @@ Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies)
NumCachedScopes = 0;
CurParsedObjCImpl = nullptr;
- ParserConversionAction = CA_ToLiteralEncoding;
-
// Add #pragma handlers. These are removed and destroyed in the
// destructor.
initializePragmaHandlers();
@@ -1566,12 +1564,12 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
}
ExprResult Parser::ParseAsmStringLiteral(bool ForAsmLabel) {
- SaveAndRestore<ConversionAction> SavedTranslationState(ParserConversionAction,
- CA_NoConversion);
ExprResult AsmString;
if (isTokenStringLiteral()) {
- AsmString = ParseStringLiteralExpression();
+ AsmString = ParseStringLiteralExpression(/*AllowUserDefinedLiteral=*/false,
+ /*Unevaluated=*/false,
+ CA_ToSystemEncoding);
if (AsmString.isInvalid())
return AsmString;
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index bf460ebe75ef1..bf11f9f515109 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -245,6 +245,14 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel) {
Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string)
<< SL->getSourceRange();
}
+ if (Context.getTargetInfo().TargetStrConverter) {
+ SmallString<16> ConvertedAsm;
+ Context.getTargetInfo().TargetStrConverter->convert(SL->getString(),
+ ConvertedAsm);
+ return StringLiteral::Create(Context, ConvertedAsm,
+ StringLiteralKind::Ordinary,
+ /*Pascal*/ false, {}, SL->getBeginLoc());
+ }
return SL;
}
if (DiagnoseUnexpandedParameterPack(Expr))
diff --git a/clang/test/CodeGen/systemz-charset.c b/clang/test/CodeGen/systemz-charset.c
index fd81110f5f6c7..eaa2747d9ce5f 100644
--- a/clang/test/CodeGen/systemz-charset.c
+++ b/clang/test/CodeGen/systemz-charset.c
@@ -67,7 +67,7 @@ const char* preprocessor_concatenation = HELLO_WORLD;
//CHECK: c"\C8\85\93\93\96@\E6\96\99\93\84Z\00"
//CHECK-UTF8: c"Hello World!\00"
-void asm_labeled_fn(void) __asm__("asm_sym");
+void asm_labeled_fn(void) __asm__("\174asm_sym");
void asm_labeled_fn(void) {}
-//CHECK: define{{.*}} void @asm_sym(
-//CHECK-UTF8: define{{.*}} void @asm_sym(
+//CHECK: define{{.*}}void @"@asm_sym"(
+//CHECK-UTF8: define{{.*}}void @"@asm_sym"(
>From d664432d978c226dabbc470ebae76d7614139992 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 10 Jul 2026 15:07:07 -0400
Subject: [PATCH 04/22] address comments, attempt to fix CI
---
clang/include/clang/Basic/TargetInfo.h | 2 +-
clang/lib/Basic/TargetInfo.cpp | 2 +-
clang/lib/Lex/TextEncoding.cpp | 2 +-
clang/lib/Sema/SemaStmtAsm.cpp | 10 ++++++----
clang/test/CodeGen/systemz-charset.c | 4 ++++
5 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index f073d98408b21..3c906d870e576 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -331,7 +331,7 @@ class TargetInfo : public TransferrableTargetInfo,
virtual ~TargetInfo();
- std::unique_ptr<llvm::TextEncodingConverter> TargetStrConverter;
+ std::unique_ptr<llvm::TextEncodingConverter> FromSystemEncodingConverter;
/// Retrieve the target options.
TargetOptions &getTargetOpts() const {
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 488c3c5c28a74..09365d4f01b89 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -202,7 +202,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
MaxBitIntWidth.reset();
- TargetStrConverter = nullptr;
+ FromSystemEncodingConverter = nullptr;
}
// Out of line virtual dtor for TargetInfo.
diff --git a/clang/lib/Lex/TextEncoding.cpp b/clang/lib/Lex/TextEncoding.cpp
index effd05185faf7..fd59f3df59bdf 100644
--- a/clang/lib/Lex/TextEncoding.cpp
+++ b/clang/lib/Lex/TextEncoding.cpp
@@ -62,7 +62,7 @@ TextEncoding::setConvertersFromOptions(TextEncoding &TE,
TInfo.getDefaultOrdinaryLiteralEncoding(), UTF8);
if (ErrorOrConverter)
- TInfo.TargetStrConverter =
+ TInfo.FromSystemEncodingConverter =
std::make_unique<TextEncodingConverter>(std::move(*ErrorOrConverter));
else
return ErrorOrConverter.getError();
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index bf11f9f515109..1399191418fcd 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -245,13 +245,15 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel) {
Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string)
<< SL->getSourceRange();
}
- if (Context.getTargetInfo().TargetStrConverter) {
+ if (Context.getTargetInfo().FromSystemEncodingConverter) {
SmallString<16> ConvertedAsm;
- Context.getTargetInfo().TargetStrConverter->convert(SL->getString(),
- ConvertedAsm);
+ Context.getTargetInfo().FromSystemEncodingConverter->convert(
+ SL->getString(), ConvertedAsm);
+ QualType StrTy = Context.getStringLiteralArrayType(Context.CharTy,
+ ConvertedAsm.size());
return StringLiteral::Create(Context, ConvertedAsm,
StringLiteralKind::Ordinary,
- /*Pascal*/ false, {}, SL->getBeginLoc());
+ /*Pascal*/ false, StrTy, SL->getBeginLoc());
}
return SL;
}
diff --git a/clang/test/CodeGen/systemz-charset.c b/clang/test/CodeGen/systemz-charset.c
index eaa2747d9ce5f..db5a99b5eb3b7 100644
--- a/clang/test/CodeGen/systemz-charset.c
+++ b/clang/test/CodeGen/systemz-charset.c
@@ -71,3 +71,7 @@ void asm_labeled_fn(void) __asm__("\174asm_sym");
void asm_labeled_fn(void) {}
//CHECK: define{{.*}}void @"@asm_sym"(
//CHECK-UTF8: define{{.*}}void @"@asm_sym"(
+
+void asm_stmt_fn(void) { __asm__("\225\226\227nop"); }
+//CHECK: call void asm{{.*}}"nopnop"
+//CHECK-UTF8: call void asm{{.*}}"nopnop"
>From f03fd41cb059a525e846cec2f7dc7938daf5ec2f Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 17 Jul 2026 14:31:50 -0400
Subject: [PATCH 05/22] check for UTF-8 to avoid conversion codepath if no
conversion is needed
---
clang/lib/Sema/SemaStmtAsm.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 1399191418fcd..3ec75dab8d84e 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -245,7 +245,7 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel) {
Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string)
<< SL->getSourceRange();
}
- if (Context.getTargetInfo().FromSystemEncodingConverter) {
+ if (Context.getTargetInfo().FromSystemEncodingConverter != nullptr) {
SmallString<16> ConvertedAsm;
Context.getTargetInfo().FromSystemEncodingConverter->convert(
SL->getString(), ConvertedAsm);
>From 96837dfd7036f28fdf40eee09b3920f4567f272c Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Tue, 11 Aug 2026 09:02:17 -0400
Subject: [PATCH 06/22] Remove unrelated testcases
---
clang/test/CodeGen/systemz-charset-diag.cpp | 8 --------
1 file changed, 8 deletions(-)
diff --git a/clang/test/CodeGen/systemz-charset-diag.cpp b/clang/test/CodeGen/systemz-charset-diag.cpp
index ad08e1f391214..4ed94810150a3 100644
--- a/clang/test/CodeGen/systemz-charset-diag.cpp
+++ b/clang/test/CodeGen/systemz-charset-diag.cpp
@@ -1,11 +1,3 @@
// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++17 -emit-llvm -o - -verify
const char* Computer = "🖥️"; // expected-error-re {{conversion to literal encoding failed: {{.*}}}}
-
-static_assert(false, "Error string"); // expected-error {{static assertion failed: Error string}}
-
-[[deprecated("message")]] void test_deprecated() {return;} // expected-note {{'test_deprecated' has been explicitly marked deprecated here}}
-
-int main() {
- test_deprecated(); // expected-warning {{'test_deprecated' is deprecated: message}}
-}
>From 84b75379950aa969912714ee27e653c2e5dc8c04 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Thu, 13 Aug 2026 14:18:12 -0400
Subject: [PATCH 07/22] constexpr in asm strings will be in fexec-charset, do
not do backwards conversion for those strings
---
clang/include/clang/Sema/Sema.h | 3 ++-
clang/lib/Parse/Parser.cpp | 5 ++++-
clang/lib/Sema/SemaStmtAsm.cpp | 6 ++++--
clang/test/CodeGen/systemz-charset.cpp | 24 ++++++++++++++++++++++++
4 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a15811c40f223..778478f472323 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11489,7 +11489,8 @@ class Sema final : public SemaBase {
///@{
public:
- ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel);
+ ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel,
+ bool IsConstExpr = false);
StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
bool IsVolatile, unsigned NumOutputs,
unsigned NumInputs, IdentifierInfo **Names,
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 0eb02a45d8906..7fd9fe9dee0c7 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1566,6 +1566,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
ExprResult Parser::ParseAsmStringLiteral(bool ForAsmLabel) {
ExprResult AsmString;
+ bool IsConstExpr = false;
if (isTokenStringLiteral()) {
AsmString = ParseStringLiteralExpression(/*AllowUserDefinedLiteral=*/false,
/*Unevaluated=*/false,
@@ -1581,6 +1582,7 @@ ExprResult Parser::ParseAsmStringLiteral(bool ForAsmLabel) {
}
} else if (!ForAsmLabel && getLangOpts().CPlusPlus11 &&
Tok.is(tok::l_paren)) {
+ IsConstExpr = true;
ParenParseOption ExprType = ParenParseOption::SimpleExpr;
SourceLocation RParenLoc;
ParsedType CastTy;
@@ -1600,7 +1602,8 @@ ExprResult Parser::ParseAsmStringLiteral(bool ForAsmLabel) {
(getLangOpts().CPlusPlus11 && !ForAsmLabel) ? 0 : 1);
}
- return Actions.ActOnGCCAsmStmtString(AsmString.get(), ForAsmLabel);
+ return Actions.ActOnGCCAsmStmtString(AsmString.get(), ForAsmLabel,
+ IsConstExpr);
}
ExprResult Parser::ParseSimpleAsm(bool ForAsmLabel, SourceLocation *EndLoc) {
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 3ec75dab8d84e..5a376a21e8473 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -235,7 +235,8 @@ getClobberConflictLocation(MultiExprArg Exprs, Expr **Constraints,
return SourceLocation();
}
-ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel) {
+ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel,
+ bool IsConstExpr) {
if (!Expr)
return ExprError();
@@ -245,7 +246,8 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel) {
Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string)
<< SL->getSourceRange();
}
- if (Context.getTargetInfo().FromSystemEncodingConverter != nullptr) {
+ if (!IsConstExpr &&
+ Context.getTargetInfo().FromSystemEncodingConverter != nullptr) {
SmallString<16> ConvertedAsm;
Context.getTargetInfo().FromSystemEncodingConverter->convert(
SL->getString(), ConvertedAsm);
diff --git a/clang/test/CodeGen/systemz-charset.cpp b/clang/test/CodeGen/systemz-charset.cpp
index 41674e9c11a64..6348fb72dac9a 100644
--- a/clang/test/CodeGen/systemz-charset.cpp
+++ b/clang/test/CodeGen/systemz-charset.cpp
@@ -72,3 +72,27 @@ const char16_t *UnicodeUCNString16 = u"\u00E2\u00AC\U000000DF";
const char32_t *UnicodeUCNString32 = U"\u00E2\u00AC\U000000DF";
//CHECK: [4 x i32] [i32 226, i32 172, i32 223, i32 0]
//CHECK-UTF8: [4 x i32] [i32 226, i32 172, i32 223, i32 0]
+
+
+struct string_view {
+ int S;
+ const char* D;
+ constexpr string_view() : S(0), D(0){}
+ constexpr string_view(const char* Str) : S(__builtin_strlen(Str)), D(Str) {}
+ constexpr string_view(int Size, const char* Str) : S(Size), D(Str) {}
+ constexpr int size() const {
+ return S;
+ }
+ constexpr const char* data() const {
+ return D;
+ }
+};
+
+constexpr string_view getfoo() { return "\174foo"; }
+
+void function()
+{
+ asm((getfoo()));
+}
+// CHECK: asm{{.*}}|\86\96\96
+// CHECK-UTF8: asm{{.*}}|foo
>From 897d1978004be27dc60cb932fd2efa812a05717c Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Wed, 30 Sep 2026 11:52:59 -0400
Subject: [PATCH 08/22] rename FromSystemEncodingConverter and move out of
TargetInfo
---
clang/include/clang/Basic/TargetInfo.h | 3 ---
clang/include/clang/Lex/TextEncoding.h | 14 +++++++++++++-
clang/lib/Basic/TargetInfo.cpp | 2 --
clang/lib/Lex/TextEncoding.cpp | 19 +++++++++++++------
clang/lib/Sema/SemaStmtAsm.cpp | 8 +++++---
5 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 3c906d870e576..a6523e8eaaa43 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -37,7 +37,6 @@
#include "llvm/Frontend/OpenMP/OMPGridValues.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 <cassert>
@@ -331,8 +330,6 @@ class TargetInfo : public TransferrableTargetInfo,
virtual ~TargetInfo();
- std::unique_ptr<llvm::TextEncodingConverter> FromSystemEncodingConverter;
-
/// 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 02cb16cef9f1b..ec826ec661592 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -27,10 +27,22 @@ enum ConversionAction {
class TextEncoding {
llvm::StringRef LiteralEncoding;
std::unique_ptr<llvm::TextEncodingConverter> ToLiteralEncodingConverter;
- std::unique_ptr<llvm::TextEncodingConverter> ToSystemEncodingConverter;
+
+ // Only non-null on z/OS, where the system default encoding is IBM-1047.
+ // This converts UTF-8 to IBM-1047 for asm string literals so that
+ // octal/hex escape sequences are interpreted as IBM-1047 code points,
+ // regardless of -fexec-charset.
+ std::unique_ptr<llvm::TextEncodingConverter> ToIBM1047Converter;
+ std::unique_ptr<llvm::TextEncodingConverter> FromIBM1047Converter;
public:
llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
+
+ /// Returns the converter from IBM-1047 to UTF-8, or nullptr if not on z/OS.
+ llvm::TextEncodingConverter *getFromIBM1047Converter() const {
+ return FromIBM1047Converter.get();
+ }
+
static std::error_code
setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts,
clang::TargetInfo &TInfo);
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 09365d4f01b89..6e390226d2e4b 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -201,8 +201,6 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
MaxOpenCLWorkGroupSize = 1024;
MaxBitIntWidth.reset();
-
- FromSystemEncodingConverter = nullptr;
}
// Out of line virtual dtor for TargetInfo.
diff --git a/clang/lib/Lex/TextEncoding.cpp b/clang/lib/Lex/TextEncoding.cpp
index fd59f3df59bdf..6ee6f8a0ef266 100644
--- a/clang/lib/Lex/TextEncoding.cpp
+++ b/clang/lib/Lex/TextEncoding.cpp
@@ -18,7 +18,8 @@ TextEncoding::getConverter(ConversionAction Action) const {
case CA_ToLiteralEncoding:
return ToLiteralEncodingConverter.get();
case CA_ToSystemEncoding:
- return ToSystemEncodingConverter.get();
+ // return null for non-z/OS targets
+ return ToIBM1047Converter.get();
default:
return nullptr;
}
@@ -34,6 +35,8 @@ TextEncoding::setConvertersFromOptions(TextEncoding &TE,
TE.LiteralEncoding =
Opts.LiteralEncoding.empty() ? UTF8 : Opts.LiteralEncoding.c_str();
+ // Create converter between internal and literal encoding specified
+ // in fexec-charset option.
if (TE.LiteralEncoding != UTF8) {
ErrorOr<TextEncodingConverter> ErrorOrLiteralConverter =
llvm::TextEncodingConverter::create(UTF8, TE.LiteralEncoding);
@@ -47,22 +50,26 @@ TextEncoding::setConvertersFromOptions(TextEncoding &TE,
if (TInfo.getDefaultOrdinaryLiteralEncoding() == UTF8)
return std::error_code();
- // Create converter between internal and default ordinary encoding for the
- // target
+ // The IBM-1047 converters are only needed on z/OS, where the system
+ // (assembler/linker) default encoding is IBM-1047 rather than UTF-8.
+ assert((TInfo.getTriple().getOS() == llvm::Triple::ZOS) &&
+ "Non-UTF-8 system encoding is only expected on z/OS");
+
+ // Create a converter from UTF-8 to IBM-1047 for use when parsing asm string
+ // literals on z/OS, where escape sequences are IBM-1047 code points.
ErrorOr<TextEncodingConverter> ErrorOrConverter =
llvm::TextEncodingConverter::create(
UTF8, TInfo.getDefaultOrdinaryLiteralEncoding());
if (ErrorOrConverter)
- TE.ToSystemEncodingConverter =
+ TE.ToIBM1047Converter =
std::make_unique<TextEncodingConverter>(std::move(*ErrorOrConverter));
else
return ErrorOrConverter.getError();
ErrorOrConverter = llvm::TextEncodingConverter::create(
TInfo.getDefaultOrdinaryLiteralEncoding(), UTF8);
-
if (ErrorOrConverter)
- TInfo.FromSystemEncodingConverter =
+ TE.FromIBM1047Converter =
std::make_unique<TextEncodingConverter>(std::move(*ErrorOrConverter));
else
return ErrorOrConverter.getError();
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 5a376a21e8473..1746604f61378 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -15,6 +15,7 @@
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/TextEncoding.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Ownership.h"
@@ -24,6 +25,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/MC/MCParser/MCAsmParser.h"
+#include "llvm/Support/TextEncoding.h"
#include <optional>
using namespace clang;
using namespace sema;
@@ -247,10 +249,10 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel,
<< SL->getSourceRange();
}
if (!IsConstExpr &&
- Context.getTargetInfo().FromSystemEncodingConverter != nullptr) {
+ PP.getTextEncoding().getFromIBM1047Converter() != nullptr) {
SmallString<16> ConvertedAsm;
- Context.getTargetInfo().FromSystemEncodingConverter->convert(
- SL->getString(), ConvertedAsm);
+ PP.getTextEncoding().getFromIBM1047Converter()->convert(SL->getString(),
+ ConvertedAsm);
QualType StrTy = Context.getStringLiteralArrayType(Context.CharTy,
ConvertedAsm.size());
return StringLiteral::Create(Context, ConvertedAsm,
>From 16870c5a2529f0b39667bbda6cfb8a34f58e02c9 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Mon, 5 Oct 2026 10:13:37 -0400
Subject: [PATCH 09/22] rename CA_ToSystemEncoding to
CA_ToLiteralEncodingForAsm
---
clang/include/clang/Lex/TextEncoding.h | 2 +-
clang/lib/Lex/TextEncoding.cpp | 2 +-
clang/lib/Parse/Parser.cpp | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/include/clang/Lex/TextEncoding.h b/clang/include/clang/Lex/TextEncoding.h
index ec826ec661592..46903a5361059 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -20,7 +20,7 @@ class TextEncodingConverter;
namespace clang {
enum ConversionAction {
CA_NoConversion,
- CA_ToSystemEncoding,
+ CA_ToLiteralEncodingForAsm, // IBM-1047 on z/OS, UTF-8 on other platforms
CA_ToLiteralEncoding
};
diff --git a/clang/lib/Lex/TextEncoding.cpp b/clang/lib/Lex/TextEncoding.cpp
index 6ee6f8a0ef266..afb5130ece88e 100644
--- a/clang/lib/Lex/TextEncoding.cpp
+++ b/clang/lib/Lex/TextEncoding.cpp
@@ -17,7 +17,7 @@ TextEncoding::getConverter(ConversionAction Action) const {
switch (Action) {
case CA_ToLiteralEncoding:
return ToLiteralEncodingConverter.get();
- case CA_ToSystemEncoding:
+ case CA_ToLiteralEncodingForAsm:
// return null for non-z/OS targets
return ToIBM1047Converter.get();
default:
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 7fd9fe9dee0c7..3f6776d72d537 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1570,7 +1570,7 @@ ExprResult Parser::ParseAsmStringLiteral(bool ForAsmLabel) {
if (isTokenStringLiteral()) {
AsmString = ParseStringLiteralExpression(/*AllowUserDefinedLiteral=*/false,
/*Unevaluated=*/false,
- CA_ToSystemEncoding);
+ CA_ToLiteralEncodingForAsm);
if (AsmString.isInvalid())
return AsmString;
>From c6201b8bddf321d6d603dff89ad6372c56eb49b6 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Wed, 7 Oct 2026 10:56:26 -0400
Subject: [PATCH 10/22] add more testcases, make diagnostic message generic
---
clang/include/clang/Basic/DiagnosticLexKinds.td | 2 +-
clang/test/CodeGen/systemz-charset-diag.cpp | 2 +-
clang/test/CodeGen/systemz-charset.cpp | 8 ++++++--
clang/test/Sema/systemz-charset-asm.cpp | 11 +++++++++++
4 files changed, 19 insertions(+), 4 deletions(-)
create mode 100644 clang/test/Sema/systemz-charset-asm.cpp
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ee3fb0e74d220..d6d94005e57df 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -301,7 +301,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 literal encoding failed: '%0'">;
+ : Error<"encoding conversion failed: '%0'">;
def warn_c99_compat_unicode_literal : Warning<
"unicode literals are incompatible with C99">,
InGroup<C99Compat>, DefaultIgnore;
diff --git a/clang/test/CodeGen/systemz-charset-diag.cpp b/clang/test/CodeGen/systemz-charset-diag.cpp
index 4ed94810150a3..a59a5ef4f0604 100644
--- a/clang/test/CodeGen/systemz-charset-diag.cpp
+++ b/clang/test/CodeGen/systemz-charset-diag.cpp
@@ -1,3 +1,3 @@
// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++17 -emit-llvm -o - -verify
-const char* Computer = "🖥️"; // expected-error-re {{conversion to literal encoding failed: {{.*}}}}
+const char* Computer = "🖥️"; // expected-error-re {{encoding conversion failed: {{.*}}}}
diff --git a/clang/test/CodeGen/systemz-charset.cpp b/clang/test/CodeGen/systemz-charset.cpp
index 6348fb72dac9a..b6b79842468c1 100644
--- a/clang/test/CodeGen/systemz-charset.cpp
+++ b/clang/test/CodeGen/systemz-charset.cpp
@@ -92,7 +92,11 @@ constexpr string_view getfoo() { return "\174foo"; }
void function()
{
+ asm("\174foo");
+ // CHECK: asm{{.*}}@foo
+ // CHECK-UTF8: asm{{.*}}@foo
asm((getfoo()));
+ // CHECK: asm{{.*}}|\86\96\96
+ // CHECK-UTF8: asm{{.*}}|foo
}
-// CHECK: asm{{.*}}|\86\96\96
-// CHECK-UTF8: asm{{.*}}|foo
+
diff --git a/clang/test/Sema/systemz-charset-asm.cpp b/clang/test/Sema/systemz-charset-asm.cpp
new file mode 100644
index 0000000000000..b3c27cc53638e
--- /dev/null
+++ b/clang/test/Sema/systemz-charset-asm.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++23 -fsyntax-only -verify
+// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset UTF-8 %s -std=c++23 -fsyntax-only -verify
+
+long inline_asm_ucn_named_operand(long a, long b) {
+ // The \N{...} escape encodes to U+0130. IBM-1047 has no code point for
+ // U+0130, so the conversion reports an error.
+ asm("\tLGR %0, %[\N{LATIN CAPITAL LETTER I WITH DOT ABOVE}]\n" // expected-error-re {{encoding conversion failed: {{.*}}}}
+ : "=r"(a)
+ : [\N{LATIN CAPITAL LETTER I WITH DOT ABOVE}] "r"(b));
+ return a;
+}
>From 29f61ad886c78e05f4c4f11dff11603c60a3f0c0 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 9 Oct 2026 13:29:51 -0400
Subject: [PATCH 11/22] Add some documentation
---
clang/docs/LanguageExtensions.md | 47 ++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/clang/docs/LanguageExtensions.md b/clang/docs/LanguageExtensions.md
index 3db8d083c4075..4b0a39a37159e 100644
--- a/clang/docs/LanguageExtensions.md
+++ b/clang/docs/LanguageExtensions.md
@@ -2263,6 +2263,45 @@ int foo() {
}
```
+### String literal encoding in ASM statements
+
+On targets where the platform's default ordinary literal encoding differs from
+UTF-8 (such as z/OS, where the system default encoding is IBM-1047):
+
+* **Direct ASM string literals**: Direct string literals used in `asm` statements
+ or `asm` labels (such as `asm("...")` or `__asm__("...")`) are parsed and
+ interpreted using the target system's default encoding (such as IBM-1047 on
+ z/OS) rather than the literal encoding specified by `-fexec-charset`. This
+ ensures that escape sequences (such as octal or hexadecimal byte escapes)
+ are interpreted as system/assembler code points.
+
+* **Constexpr string expressions in ASM statements**: When a parenthesized
+ constant expression is provided in place of an `asm` string, string literals
+ within that constant expression are encoded according to the execution
+ character set specified by `-fexec-charset` (the literal encoding), as
+ constant expression evaluation expects `char` sequences to operate in the
+ literal encoding. The system encoding conversion applied to direct `asm`
+ string literals is restricted to the direct string literal case and does not
+ extend to string literals within constant expressions.
+
+For example, on z/OS compiled with `-fexec-charset UTF-8`:
+
+```c++
+constexpr std::string_view takeStringAndReturnEmptyStringView(const char *str) {
+ return std::string_view();
+}
+
+int main(void) {
+ // Direct string literals in asm statements are interpreted in the system encoding (IBM-1047).
+ asm("nop");
+
+ // String literals within the constexpr expression are encoded in the execution charset (UTF-8).
+ // Characters not representable in IBM-1047 (such as "\N{LATIN CAPITAL LETTER I WITH DOT ABOVE}")
+ // are valid here because constant evaluation evaluates the string literal in UTF-8.
+ asm((takeStringAndReturnEmptyStringView("\N{LATIN CAPITAL LETTER I WITH DOT ABOVE}")));
+}
+```
+
## Objective-C Features
### Related result types
@@ -5650,6 +5689,14 @@ The builtins return 0 if the values are equal, or 1 if they are unequal.
Generates a 16-byte compare-and-swap using the CDSG instruction.
+#### ASM string literal encoding
+
+On z/OS, the system default encoding is IBM-1047. Direct string literals in
+`asm` statements and `asm` labels are interpreted using IBM-1047 regardless of
+`-fexec-charset`. When using parenthesized constant expressions in `asm`
+statements, string literals within the constant expression are instead encoded
+using the execution character set specified by `-fexec-charset`.
+
## Extensions for Static Analysis
Clang supports additional attributes that are useful for documenting program
>From 864d56b11b9c0e2be9e156077e321e51ec25c936 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Tue, 13 Oct 2026 15:26:03 -0400
Subject: [PATCH 12/22] address comments on document
---
clang/docs/LanguageExtensions.md | 41 ++++++++++++++++----------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/clang/docs/LanguageExtensions.md b/clang/docs/LanguageExtensions.md
index 4b0a39a37159e..3c4fd93bdc45d 100644
--- a/clang/docs/LanguageExtensions.md
+++ b/clang/docs/LanguageExtensions.md
@@ -2268,23 +2268,21 @@ int foo() {
On targets where the platform's default ordinary literal encoding differs from
UTF-8 (such as z/OS, where the system default encoding is IBM-1047):
-* **Direct ASM string literals**: Direct string literals used in `asm` statements
- or `asm` labels (such as `asm("...")` or `__asm__("...")`) are parsed and
+* **ASM template strings**: Asm template strings used in `asm` statements or
+ `asm` labels (such as `asm("...")` or `__asm__("...")`) are parsed and
interpreted using the target system's default encoding (such as IBM-1047 on
- z/OS) rather than the literal encoding specified by `-fexec-charset`. This
- ensures that escape sequences (such as octal or hexadecimal byte escapes)
- are interpreted as system/assembler code points.
+ z/OS) rather than the literal encoding specified by `-fexec-charset=`. This
+ ensures that escape sequences (such as octal or hexadecimal byte escapes) are
+ interpreted as system/assembler code points.
* **Constexpr string expressions in ASM statements**: When a parenthesized
constant expression is provided in place of an `asm` string, string literals
within that constant expression are encoded according to the execution
- character set specified by `-fexec-charset` (the literal encoding), as
+ character set specified by `-fexec-charset=` (the literal encoding), as
constant expression evaluation expects `char` sequences to operate in the
- literal encoding. The system encoding conversion applied to direct `asm`
- string literals is restricted to the direct string literal case and does not
- extend to string literals within constant expressions.
+ literal encoding.
-For example, on z/OS compiled with `-fexec-charset UTF-8`:
+For example, on z/OS compiled with `-fexec-charset=UTF-8`:
```c++
constexpr std::string_view takeStringAndReturnEmptyStringView(const char *str) {
@@ -2292,12 +2290,15 @@ constexpr std::string_view takeStringAndReturnEmptyStringView(const char *str) {
}
int main(void) {
- // Direct string literals in asm statements are interpreted in the system encoding (IBM-1047).
- asm("nop");
-
- // String literals within the constexpr expression are encoded in the execution charset (UTF-8).
- // Characters not representable in IBM-1047 (such as "\N{LATIN CAPITAL LETTER I WITH DOT ABOVE}")
- // are valid here because constant evaluation evaluates the string literal in UTF-8.
+ // Template strings in asm statements are interpreted in the system encoding
+ // (IBM-1047).
+ asm("\t\x95\x96\x97");
+
+ // String literals within the constexpr expression are encoded in the
+ // execution character set specified by -fexec-charset=.
+ // With -fexec-charset=IBM-1047, the string below is diagnosed as invalid
+ // because U+0130 cannot be represented in IBM-1047.
+ // With -fexec-charset=UTF-8, the string below is valid.
asm((takeStringAndReturnEmptyStringView("\N{LATIN CAPITAL LETTER I WITH DOT ABOVE}")));
}
```
@@ -5691,11 +5692,11 @@ The builtins return 0 if the values are equal, or 1 if they are unequal.
#### ASM string literal encoding
-On z/OS, the system default encoding is IBM-1047. Direct string literals in
-`asm` statements and `asm` labels are interpreted using IBM-1047 regardless of
-`-fexec-charset`. When using parenthesized constant expressions in `asm`
+On z/OS, the system default encoding is IBM-1047. Template strings in `asm`
+statements and `asm` labels are interpreted using IBM-1047 regardless of
+`-fexec-charset=`. When using parenthesized constant expressions in `asm`
statements, string literals within the constant expression are instead encoded
-using the execution character set specified by `-fexec-charset`.
+using the execution character set specified by `-fexec-charset=`.
## Extensions for Static Analysis
>From 44385fbf7c329442d62eaca043680d3d3edac152 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Wed, 14 Oct 2026 09:04:23 -0400
Subject: [PATCH 13/22] address comments in LanguageExtensions.md
---
clang/docs/LanguageExtensions.md | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/clang/docs/LanguageExtensions.md b/clang/docs/LanguageExtensions.md
index 3c4fd93bdc45d..9e19cc8c34d3e 100644
--- a/clang/docs/LanguageExtensions.md
+++ b/clang/docs/LanguageExtensions.md
@@ -2268,12 +2268,15 @@ int foo() {
On targets where the platform's default ordinary literal encoding differs from
UTF-8 (such as z/OS, where the system default encoding is IBM-1047):
-* **ASM template strings**: Asm template strings used in `asm` statements or
- `asm` labels (such as `asm("...")` or `__asm__("...")`) are parsed and
- interpreted using the target system's default encoding (such as IBM-1047 on
- z/OS) rather than the literal encoding specified by `-fexec-charset=`. This
- ensures that escape sequences (such as octal or hexadecimal byte escapes) are
- interpreted as system/assembler code points.
+* **String literals**: A string literal used as the template string in an
+ extended asm statement, as the instruction string in a basic asm statement,
+ or as the string specifying the assembler name or register in an asm label or
+ a global/local register variable declaration (such as `asm("...")` or
+ `__asm__("...")`) is parsed and interpreted using the target system's default
+ encoding (such as IBM-1047 on z/OS) rather than the literal encoding
+ specified by `-fexec-charset=`. This ensures that escape sequences (such as
+ octal or hexadecimal byte escapes) are interpreted as system/assembler code
+ points.
* **Constexpr string expressions in ASM statements**: When a parenthesized
constant expression is provided in place of an `asm` string, string literals
@@ -2291,8 +2294,8 @@ constexpr std::string_view takeStringAndReturnEmptyStringView(const char *str) {
int main(void) {
// Template strings in asm statements are interpreted in the system encoding
- // (IBM-1047).
- asm("\t\x95\x96\x97");
+ // (IBM-1047 on z/OS).
+ asm("\t\x95\x96\x97"); // This generates a "nop" in IBM-1047
// String literals within the constexpr expression are encoded in the
// execution character set specified by -fexec-charset=.
@@ -5692,11 +5695,11 @@ The builtins return 0 if the values are equal, or 1 if they are unequal.
#### ASM string literal encoding
-On z/OS, the system default encoding is IBM-1047. Template strings in `asm`
-statements and `asm` labels are interpreted using IBM-1047 regardless of
-`-fexec-charset=`. When using parenthesized constant expressions in `asm`
-statements, string literals within the constant expression are instead encoded
-using the execution character set specified by `-fexec-charset=`.
+On z/OS, the system default encoding is IBM-1047, which has implications for
+ASM strings. See
+[String literal encoding in ASM statements](#string-literal-encoding-in-asm-statements)
+for details.
+
## Extensions for Static Analysis
>From 569d5680bb14511afa810854ebdb4b22a71da54b Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Mon, 19 Oct 2026 15:06:11 -0400
Subject: [PATCH 14/22] reverse conversion from literal encoding for assembler
template string
---
clang/include/clang/Lex/TextEncoding.h | 7 +++++++
clang/lib/Lex/TextEncoding.cpp | 8 ++++++++
clang/lib/Sema/SemaStmtAsm.cpp | 27 ++++++++++++++++++++++++++
clang/test/CodeGen/systemz-charset.cpp | 6 +++++-
4 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Lex/TextEncoding.h b/clang/include/clang/Lex/TextEncoding.h
index 46903a5361059..ebfd537488a1c 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -27,6 +27,7 @@ enum ConversionAction {
class TextEncoding {
llvm::StringRef LiteralEncoding;
std::unique_ptr<llvm::TextEncodingConverter> ToLiteralEncodingConverter;
+ std::unique_ptr<llvm::TextEncodingConverter> FromLiteralEncodingConverter;
// Only non-null on z/OS, where the system default encoding is IBM-1047.
// This converts UTF-8 to IBM-1047 for asm string literals so that
@@ -38,6 +39,12 @@ class TextEncoding {
public:
llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
+ /// Returns the converter from the literal encoding (-fexec-charset) to UTF-8,
+ /// or nullptr if the literal encoding is UTF-8.
+ llvm::TextEncodingConverter *getFromLiteralEncodingConverter() const {
+ return FromLiteralEncodingConverter.get();
+ }
+
/// Returns the converter from IBM-1047 to UTF-8, or nullptr if not on z/OS.
llvm::TextEncodingConverter *getFromIBM1047Converter() const {
return FromIBM1047Converter.get();
diff --git a/clang/lib/Lex/TextEncoding.cpp b/clang/lib/Lex/TextEncoding.cpp
index afb5130ece88e..3261319918710 100644
--- a/clang/lib/Lex/TextEncoding.cpp
+++ b/clang/lib/Lex/TextEncoding.cpp
@@ -45,6 +45,14 @@ TextEncoding::setConvertersFromOptions(TextEncoding &TE,
std::move(*ErrorOrLiteralConverter));
else
return ErrorOrLiteralConverter.getError();
+
+ ErrorOrLiteralConverter =
+ llvm::TextEncodingConverter::create(TE.LiteralEncoding, UTF8);
+ if (ErrorOrLiteralConverter)
+ TE.FromLiteralEncodingConverter = std::make_unique<TextEncodingConverter>(
+ std::move(*ErrorOrLiteralConverter));
+ else
+ return ErrorOrLiteralConverter.getError();
}
if (TInfo.getDefaultOrdinaryLiteralEncoding() == UTF8)
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 1746604f61378..b2d95a739c1c3 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -13,6 +13,7 @@
#include "clang/AST/ExprCXX.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/DiagnosticLex.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/TextEncoding.h"
@@ -248,6 +249,7 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel,
Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string)
<< SL->getSourceRange();
}
+
if (!IsConstExpr &&
PP.getTextEncoding().getFromIBM1047Converter() != nullptr) {
SmallString<16> ConvertedAsm;
@@ -274,6 +276,31 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel,
Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string);
}
+ // The evaluated string is in the literal encoding (-fexec-charset).
+ // Convert it back to UTF-8
+ if (llvm::TextEncodingConverter *FromLiteral =
+ PP.getTextEncoding().getFromLiteralEncodingConverter()) {
+ unsigned Size = V.getArraySize();
+ std::string Raw;
+ Raw.reserve(Size);
+ for (unsigned I = 0; I < Size; ++I)
+ Raw.push_back(static_cast<char>(
+ V.getArrayInitializedElt(I).getInt().getExtValue()));
+ SmallString<16> Converted;
+ if (std::error_code EC = FromLiteral->convert(Raw, Converted)) {
+ Diag(Expr->getBeginLoc(), diag::err_exec_charset_conversion_failed)
+ << EC.message();
+ return ExprError();
+ }
+ llvm::APSInt Proto(Context.getTypeSize(Context.CharTy),
+ Context.CharTy->isUnsignedIntegerType());
+ V = APValue(APValue::UninitArray{}, Converted.size(), Converted.size());
+ for (unsigned I = 0; I < Converted.size(); ++I) {
+ Proto = static_cast<unsigned char>(Converted[I]);
+ V.getArrayInitializedElt(I) = APValue(Proto);
+ }
+ }
+
return ConstantExpr::Create(getASTContext(), Expr, V);
}
diff --git a/clang/test/CodeGen/systemz-charset.cpp b/clang/test/CodeGen/systemz-charset.cpp
index b6b79842468c1..b1c58b3336bb3 100644
--- a/clang/test/CodeGen/systemz-charset.cpp
+++ b/clang/test/CodeGen/systemz-charset.cpp
@@ -96,7 +96,11 @@ void function()
// CHECK: asm{{.*}}@foo
// CHECK-UTF8: asm{{.*}}@foo
asm((getfoo()));
- // CHECK: asm{{.*}}|\86\96\96
+ // CHECK: asm{{.*}}@foo
// CHECK-UTF8: asm{{.*}}|foo
+
+ asm((string_view("\tnop\n")));
+ // CHECK: asm{{.*}}\09nop\0A
+ // CHECK-UTF8: asm{{.*}}\09nop\0A
}
>From 7eb4aec053c9efe538641995ec3bdaeda7c91f34 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Mon, 2 Nov 2026 13:57:43 -0500
Subject: [PATCH 15/22] address latest comments
---
clang/docs/LanguageExtensions.md | 18 +++----
clang/include/clang/AST/APValue.h | 4 ++
.../include/clang/Basic/DiagnosticLexKinds.td | 3 +-
clang/include/clang/Lex/LiteralSupport.h | 9 ++--
clang/include/clang/Sema/Sema.h | 2 +-
clang/lib/AST/APValue.cpp | 11 ++++
clang/lib/Lex/LiteralSupport.cpp | 51 +++++++++----------
clang/lib/Parse/Parser.cpp | 6 +--
clang/lib/Sema/SemaStmtAsm.cpp | 13 ++---
clang/test/CodeGen/systemz-charset-diag.cpp | 2 +-
clang/test/Sema/systemz-charset-asm.cpp | 2 +-
11 files changed, 64 insertions(+), 57 deletions(-)
diff --git a/clang/docs/LanguageExtensions.md b/clang/docs/LanguageExtensions.md
index 9e19cc8c34d3e..673cf45e13068 100644
--- a/clang/docs/LanguageExtensions.md
+++ b/clang/docs/LanguageExtensions.md
@@ -2265,10 +2265,9 @@ int foo() {
### String literal encoding in ASM statements
-On targets where the platform's default ordinary literal encoding differs from
-UTF-8 (such as z/OS, where the system default encoding is IBM-1047):
+On z/OS, where the system default encoding is IBM-1047 rather than UTF-8:
-* **String literals**: A string literal used as the template string in an
+* A string literal used as the template string in an
extended asm statement, as the instruction string in a basic asm statement,
or as the string specifying the assembler name or register in an asm label or
a global/local register variable declaration (such as `asm("...")` or
@@ -2276,14 +2275,11 @@ UTF-8 (such as z/OS, where the system default encoding is IBM-1047):
encoding (such as IBM-1047 on z/OS) rather than the literal encoding
specified by `-fexec-charset=`. This ensures that escape sequences (such as
octal or hexadecimal byte escapes) are interpreted as system/assembler code
- points.
-
-* **Constexpr string expressions in ASM statements**: When a parenthesized
- constant expression is provided in place of an `asm` string, string literals
- within that constant expression are encoded according to the execution
- character set specified by `-fexec-charset=` (the literal encoding), as
- constant expression evaluation expects `char` sequences to operate in the
- literal encoding.
+ points. This does **not** apply to parenthesized
+ constant expressions (see
+ [Constexpr strings in GNU ASM statements](#constexpr-strings-in-gnu-asm-statements)),
+ in which string literals are encoded according to the literal encoding
+ specified by `-fexec-charset=`.
For example, on z/OS compiled with `-fexec-charset=UTF-8`:
diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h
index 7a69a98702a8c..42e03c51533e8 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -570,6 +570,10 @@ class LLVM_ATTRIBUTE_WARN_UNUSED APValue {
std::string getAsString(const ASTContext &Ctx, QualType Ty) const;
+ /// Returns the contents of an array of integers (e.g. an evaluated character
+ /// array) as a string, with each element truncated to a char.
+ std::string getCharArrayAsString() const;
+
APSInt &getInt() {
assert(isInt() && "Invalid accessor");
return *(APSInt *)(char *)&Data;
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td
index d6d94005e57df..a75c7ddd66cb8 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -301,7 +301,8 @@ 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<"encoding conversion failed: '%0'">;
+ : Error<"conversion %select{to literal encoding|to asm string encoding|"
+ "from literal encoding to UTF-8}1 failed: '%0'">;
def warn_c99_compat_unicode_literal : Warning<
"unicode literals are incompatible with C99">,
InGroup<C99Compat>, DefaultIgnore;
diff --git a/clang/include/clang/Lex/LiteralSupport.h b/clang/include/clang/Lex/LiteralSupport.h
index 9270190e02480..ac52c76db0056 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -247,6 +247,7 @@ class StringLiteralParser {
unsigned UDSuffixToken;
unsigned UDSuffixOffset;
StringLiteralEvalMethod EvalMethod;
+ ConversionAction Action;
public:
StringLiteralParser(
@@ -259,9 +260,9 @@ class StringLiteralParser {
: SM(sm), Features(features), Target(target), Diags(diags), TE(nullptr),
MaxTokenLength(0), SizeBound(0), CharByteWidth(0), Kind(tok::unknown),
ResultPtr(ResultBuf.data()),
- EvalMethod(StringLiteralEvalMethod::Evaluated), hadError(false),
- Pascal(false) {
- init(StringToks, CA_NoConversion);
+ EvalMethod(StringLiteralEvalMethod::Evaluated), Action(CA_NoConversion),
+ hadError(false), Pascal(false) {
+ init(StringToks);
}
bool hadError;
@@ -309,7 +310,7 @@ class StringLiteralParser {
static bool isValidUDSuffix(const LangOptions &LangOpts, StringRef Suffix);
private:
- void init(ArrayRef<Token> StringToks, ConversionAction Action);
+ void init(ArrayRef<Token> StringToks);
bool CopyStringFragment(const Token &Tok, const char *TokBegin,
StringRef Fragment,
llvm::TextEncodingConverter *Converter);
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 778478f472323..a78e8bb94a1b9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11490,7 +11490,7 @@ class Sema final : public SemaBase {
public:
ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel,
- bool IsConstExpr = false);
+ bool IsConstexpr = false);
StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
bool IsVolatile, unsigned NumOutputs,
unsigned NumInputs, IdentifierInfo **Names,
diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 97023be49c715..51233d0a8fc41 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -1103,6 +1103,17 @@ std::string APValue::getAsString(const ASTContext &Ctx, QualType Ty) const {
return Result;
}
+std::string APValue::getCharArrayAsString() const {
+ assert(isArray() && "Invalid accessor");
+ unsigned Size = getArraySize();
+ std::string Result;
+ Result.reserve(Size);
+ for (unsigned I = 0; I < Size; ++I)
+ Result.push_back(
+ static_cast<char>(getArrayInitializedElt(I).getInt().getExtValue()));
+ return Result;
+}
+
bool APValue::toIntegralConstant(APSInt &Result, QualType SrcTy,
const ASTContext &Ctx) const {
if (isInt()) {
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index efb1138b46615..ca4c3574bd997 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -139,14 +139,12 @@ convertCharacter(StringRef Char, const llvm::TextEncodingConverter &Converter) {
/// ProcessCharEscape - Parse a standard C escape sequence, which can occur in
/// either a character or a string literal.
-static unsigned ProcessCharEscape(const char *ThisTokBegin,
- const char *&ThisTokBuf,
- const char *ThisTokEnd, bool &HadError,
- FullSourceLoc Loc, unsigned CharWidth,
- DiagnosticsEngine *Diags,
- const LangOptions &Features,
- StringLiteralEvalMethod EvalMethod,
- llvm::TextEncodingConverter *Converter) {
+static unsigned ProcessCharEscape(
+ const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd,
+ bool &HadError, FullSourceLoc Loc, unsigned CharWidth,
+ DiagnosticsEngine *Diags, const LangOptions &Features,
+ StringLiteralEvalMethod EvalMethod, llvm::TextEncodingConverter *Converter,
+ ConversionAction Action) {
const char *EscapeBegin = ThisTokBuf;
bool Delimited = false;
bool EndDelimiterFound = false;
@@ -397,7 +395,8 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin,
else {
Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
diag::err_exec_charset_conversion_failed)
- << ErrorOrChar.getError().message();
+ << ErrorOrChar.getError().message()
+ << (Action == CA_ToLiteralEncodingForAsm ? 1 : 0);
HadError = true;
}
}
@@ -807,7 +806,8 @@ static void EncodeUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf,
bool &HadError, FullSourceLoc Loc,
unsigned CharByteWidth, DiagnosticsEngine *Diags,
const LangOptions &Features,
- llvm::TextEncodingConverter *Converter) {
+ llvm::TextEncodingConverter *Converter,
+ ConversionAction Action) {
typedef uint32_t UTF32;
UTF32 UcnVal = 0;
unsigned short UcnLen = 0;
@@ -904,7 +904,7 @@ static void EncodeUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf,
ResultBuf = Cp + CpConv.size();
} else {
Diags->Report(Loc, diag::err_exec_charset_conversion_failed)
- << EC.message();
+ << EC.message() << (Action == CA_ToLiteralEncodingForAsm ? 1 : 0);
HadError = true;
}
}
@@ -1943,7 +1943,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
} else {
HadError = true;
PP.Diag(Loc, diag::err_exec_charset_conversion_failed)
- << ErrorOrChar.message();
+ << ErrorOrChar.message() << 0;
}
}
}
@@ -1968,7 +1968,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
EncodeUCNEscape(TokBegin, begin, end, ResultPtr, HadError,
FullSourceLoc(Loc, PP.getSourceManager()),
/*CharByteWidth=*/1u, &PP.getDiagnostics(),
- PP.getLangOpts(), Converter);
+ PP.getLangOpts(), Converter, CA_ToLiteralEncoding);
if (!HadError)
*buffer_begin = *Cp;
}
@@ -1976,11 +1976,11 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
continue;
}
unsigned CharWidth = getCharWidth(Kind, PP.getTargetInfo());
- uint64_t result =
- ProcessCharEscape(TokBegin, begin, end, HadError,
- FullSourceLoc(Loc, PP.getSourceManager()), CharWidth,
- &PP.getDiagnostics(), PP.getLangOpts(),
- StringLiteralEvalMethod::Evaluated, nullptr);
+ uint64_t result = ProcessCharEscape(
+ TokBegin, begin, end, HadError,
+ FullSourceLoc(Loc, PP.getSourceManager()), CharWidth,
+ &PP.getDiagnostics(), PP.getLangOpts(),
+ StringLiteralEvalMethod::Evaluated, nullptr, CA_NoConversion);
*buffer_begin++ = result;
}
@@ -2096,12 +2096,11 @@ StringLiteralParser::StringLiteralParser(ArrayRef<Token> StringToks,
Target(PP.getTargetInfo()), Diags(&PP.getDiagnostics()),
TE(&PP.getTextEncoding()), MaxTokenLength(0), SizeBound(0),
CharByteWidth(0), Kind(tok::unknown), ResultPtr(ResultBuf.data()),
- EvalMethod(EvalMethod), hadError(false), Pascal(false) {
- init(StringToks, Action);
+ EvalMethod(EvalMethod), Action(Action), hadError(false), Pascal(false) {
+ init(StringToks);
}
-void StringLiteralParser::init(ArrayRef<Token> StringToks,
- ConversionAction Action) {
+void StringLiteralParser::init(ArrayRef<Token> StringToks) {
// The literal token may have come from an invalid source location (e.g. due
// to a PCH error), in which case the token length will be 0.
if (StringToks.empty() || StringToks[0].getLength() < 2)
@@ -2358,14 +2357,14 @@ void StringLiteralParser::init(ArrayRef<Token> StringToks,
EncodeUCNEscape(ThisTokBegin, ThisTokBuf, ThisTokEnd, ResultPtr,
hadError,
FullSourceLoc(StringToks[i].getLocation(), SM),
- CharByteWidth, Diags, Features, Converter);
+ CharByteWidth, Diags, Features, Converter, Action);
continue;
}
// Otherwise, this is a non-UCN escape character. Process it.
unsigned ResultChar = ProcessCharEscape(
ThisTokBegin, ThisTokBuf, ThisTokEnd, hadError,
FullSourceLoc(StringToks[i].getLocation(), SM), CharByteWidth * 8,
- Diags, Features, EvalMethod, Converter);
+ Diags, Features, EvalMethod, Converter, Action);
if (CharByteWidth == 4) {
// FIXME: Make the type of the result buffer correct instead of
@@ -2459,7 +2458,7 @@ bool StringLiteralParser::CopyStringFragment(
if (Diags)
Diags->Report(Tok.getLocation(),
diag::err_exec_charset_conversion_failed)
- << EC.message();
+ << EC.message() << (Action == CA_ToLiteralEncodingForAsm ? 1 : 0);
return true;
}
}
@@ -2582,7 +2581,7 @@ unsigned StringLiteralParser::getOffsetOfStringByte(const Token &Tok,
ProcessCharEscape(SpellingStart, SpellingPtr, SpellingEnd, HadError,
FullSourceLoc(Tok.getLocation(), SM), CharByteWidth * 8,
Diags, Features, StringLiteralEvalMethod::Evaluated,
- /*TextEncoding=*/nullptr);
+ /*TextEncoding=*/nullptr, CA_NoConversion);
--ByteNo;
}
assert(!HadError && "This method isn't valid on erroneous strings");
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 3f6776d72d537..230363d98c985 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1566,7 +1566,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
ExprResult Parser::ParseAsmStringLiteral(bool ForAsmLabel) {
ExprResult AsmString;
- bool IsConstExpr = false;
+ bool IsConstexpr = false;
if (isTokenStringLiteral()) {
AsmString = ParseStringLiteralExpression(/*AllowUserDefinedLiteral=*/false,
/*Unevaluated=*/false,
@@ -1582,7 +1582,7 @@ ExprResult Parser::ParseAsmStringLiteral(bool ForAsmLabel) {
}
} else if (!ForAsmLabel && getLangOpts().CPlusPlus11 &&
Tok.is(tok::l_paren)) {
- IsConstExpr = true;
+ IsConstexpr = true;
ParenParseOption ExprType = ParenParseOption::SimpleExpr;
SourceLocation RParenLoc;
ParsedType CastTy;
@@ -1603,7 +1603,7 @@ ExprResult Parser::ParseAsmStringLiteral(bool ForAsmLabel) {
}
return Actions.ActOnGCCAsmStmtString(AsmString.get(), ForAsmLabel,
- IsConstExpr);
+ IsConstexpr);
}
ExprResult Parser::ParseSimpleAsm(bool ForAsmLabel, SourceLocation *EndLoc) {
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index b2d95a739c1c3..0f9b3e2fe1d07 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -239,7 +239,7 @@ getClobberConflictLocation(MultiExprArg Exprs, Expr **Constraints,
}
ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel,
- bool IsConstExpr) {
+ bool IsConstexpr) {
if (!Expr)
return ExprError();
@@ -250,7 +250,7 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel,
<< SL->getSourceRange();
}
- if (!IsConstExpr &&
+ if (!IsConstexpr &&
PP.getTextEncoding().getFromIBM1047Converter() != nullptr) {
SmallString<16> ConvertedAsm;
PP.getTextEncoding().getFromIBM1047Converter()->convert(SL->getString(),
@@ -280,16 +280,11 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel,
// Convert it back to UTF-8
if (llvm::TextEncodingConverter *FromLiteral =
PP.getTextEncoding().getFromLiteralEncodingConverter()) {
- unsigned Size = V.getArraySize();
- std::string Raw;
- Raw.reserve(Size);
- for (unsigned I = 0; I < Size; ++I)
- Raw.push_back(static_cast<char>(
- V.getArrayInitializedElt(I).getInt().getExtValue()));
+ std::string Raw = V.getCharArrayAsString();
SmallString<16> Converted;
if (std::error_code EC = FromLiteral->convert(Raw, Converted)) {
Diag(Expr->getBeginLoc(), diag::err_exec_charset_conversion_failed)
- << EC.message();
+ << EC.message() << /*from literal encoding to UTF-8*/ 2;
return ExprError();
}
llvm::APSInt Proto(Context.getTypeSize(Context.CharTy),
diff --git a/clang/test/CodeGen/systemz-charset-diag.cpp b/clang/test/CodeGen/systemz-charset-diag.cpp
index a59a5ef4f0604..4ed94810150a3 100644
--- a/clang/test/CodeGen/systemz-charset-diag.cpp
+++ b/clang/test/CodeGen/systemz-charset-diag.cpp
@@ -1,3 +1,3 @@
// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++17 -emit-llvm -o - -verify
-const char* Computer = "🖥️"; // expected-error-re {{encoding conversion failed: {{.*}}}}
+const char* Computer = "🖥️"; // expected-error-re {{conversion to literal encoding failed: {{.*}}}}
diff --git a/clang/test/Sema/systemz-charset-asm.cpp b/clang/test/Sema/systemz-charset-asm.cpp
index b3c27cc53638e..3b7067bde2bf9 100644
--- a/clang/test/Sema/systemz-charset-asm.cpp
+++ b/clang/test/Sema/systemz-charset-asm.cpp
@@ -4,7 +4,7 @@
long inline_asm_ucn_named_operand(long a, long b) {
// The \N{...} escape encodes to U+0130. IBM-1047 has no code point for
// U+0130, so the conversion reports an error.
- asm("\tLGR %0, %[\N{LATIN CAPITAL LETTER I WITH DOT ABOVE}]\n" // expected-error-re {{encoding conversion failed: {{.*}}}}
+ asm("\tLGR %0, %[\N{LATIN CAPITAL LETTER I WITH DOT ABOVE}]\n" // expected-error-re {{conversion to asm string encoding failed: {{.*}}}}
: "=r"(a)
: [\N{LATIN CAPITAL LETTER I WITH DOT ABOVE}] "r"(b));
return a;
>From 7e7b576702f2a260f39dd6e93b9dc66705282a3c Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 6 Nov 2026 11:54:41 -0500
Subject: [PATCH 16/22] Address latest comments
---
clang/lib/Lex/TextEncoding.cpp | 38 ++++++++++++++--------------------
1 file changed, 16 insertions(+), 22 deletions(-)
diff --git a/clang/lib/Lex/TextEncoding.cpp b/clang/lib/Lex/TextEncoding.cpp
index 3261319918710..3175f18cff523 100644
--- a/clang/lib/Lex/TextEncoding.cpp
+++ b/clang/lib/Lex/TextEncoding.cpp
@@ -35,7 +35,7 @@ TextEncoding::setConvertersFromOptions(TextEncoding &TE,
TE.LiteralEncoding =
Opts.LiteralEncoding.empty() ? UTF8 : Opts.LiteralEncoding.c_str();
- // Create converter between internal and literal encoding specified
+ // Create converters between internal and literal encoding specified
// in fexec-charset option.
if (TE.LiteralEncoding != UTF8) {
ErrorOr<TextEncodingConverter> ErrorOrLiteralConverter =
@@ -55,32 +55,26 @@ TextEncoding::setConvertersFromOptions(TextEncoding &TE,
return ErrorOrLiteralConverter.getError();
}
- if (TInfo.getDefaultOrdinaryLiteralEncoding() == UTF8)
- return std::error_code();
-
// The IBM-1047 converters are only needed on z/OS, where the system
// (assembler/linker) default encoding is IBM-1047 rather than UTF-8.
- assert((TInfo.getTriple().getOS() == llvm::Triple::ZOS) &&
- "Non-UTF-8 system encoding is only expected on z/OS");
+ if (TInfo.getTriple().getOS() != llvm::Triple::ZOS)
+ return std::error_code();
- // Create a converter from UTF-8 to IBM-1047 for use when parsing asm string
- // literals on z/OS, where escape sequences are IBM-1047 code points.
+ // Create converters between UTF-8 and IBM-1047 for use when processing asm
+ // string literals on z/OS, where escape sequences are IBM-1047 code points.
+ const char *IBM1047 = "IBM-1047";
ErrorOr<TextEncodingConverter> ErrorOrConverter =
- llvm::TextEncodingConverter::create(
- UTF8, TInfo.getDefaultOrdinaryLiteralEncoding());
- if (ErrorOrConverter)
- TE.ToIBM1047Converter =
- std::make_unique<TextEncodingConverter>(std::move(*ErrorOrConverter));
- else
- return ErrorOrConverter.getError();
+ llvm::TextEncodingConverter::create(UTF8, IBM1047);
+ assert(ErrorOrConverter &&
+ "Failed to create TextEncodingConverter from UTF-8 to IBM-1047");
+ TE.ToIBM1047Converter =
+ std::make_unique<TextEncodingConverter>(std::move(*ErrorOrConverter));
- ErrorOrConverter = llvm::TextEncodingConverter::create(
- TInfo.getDefaultOrdinaryLiteralEncoding(), UTF8);
- if (ErrorOrConverter)
- TE.FromIBM1047Converter =
- std::make_unique<TextEncodingConverter>(std::move(*ErrorOrConverter));
- else
- return ErrorOrConverter.getError();
+ ErrorOrConverter = llvm::TextEncodingConverter::create(IBM1047, UTF8);
+ assert(ErrorOrConverter &&
+ "Failed to create TextEncodingConverter from IBM-1047 to UTF-8");
+ TE.FromIBM1047Converter =
+ std::make_unique<TextEncodingConverter>(std::move(*ErrorOrConverter));
return std::error_code();
}
>From 7151fba000d3ff1a3cd2cef6dd04c7828c41fc2a Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Mon, 9 Nov 2026 09:54:14 -0500
Subject: [PATCH 17/22] address latest comments
---
clang/include/clang/Lex/TextEncoding.h | 2 +-
clang/lib/AST/Expr.cpp | 10 ++++++++--
clang/lib/Sema/SemaStmtAsm.cpp | 11 +++++++----
clang/test/CMakeLists.txt | 2 ++
.../test/Sema/systemz-charset-asm-diag-loc.cpp | 9 +++++++++
clang/test/Sema/systemz-charset-asm-diag.cpp | 17 +++++++++++++++++
clang/test/lit.site.cfg.py.in | 2 ++
llvm/utils/lit/lit/llvm/config.py | 6 ++++++
8 files changed, 52 insertions(+), 7 deletions(-)
create mode 100644 clang/test/Sema/systemz-charset-asm-diag-loc.cpp
create mode 100644 clang/test/Sema/systemz-charset-asm-diag.cpp
diff --git a/clang/include/clang/Lex/TextEncoding.h b/clang/include/clang/Lex/TextEncoding.h
index ebfd537488a1c..1d4ac51bb764f 100644
--- a/clang/include/clang/Lex/TextEncoding.h
+++ b/clang/include/clang/Lex/TextEncoding.h
@@ -46,7 +46,7 @@ class TextEncoding {
}
/// Returns the converter from IBM-1047 to UTF-8, or nullptr if not on z/OS.
- llvm::TextEncodingConverter *getFromIBM1047Converter() const {
+ llvm::TextEncodingConverter *getzOSFromAsmLiteralEncodingConverter() const {
return FromIBM1047Converter.get();
}
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 1ba2ccdf697f9..2ca8765c0cdb2 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1391,8 +1391,14 @@ StringLiteral::getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
unsigned TokNumBytes = SLP.GetStringLength();
// If the byte is in this token, return the location of the byte.
- if (ByteNo < TokNumBytes ||
- (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) {
+ //
+ // The string data may have been converted to a different encoding (e.g.
+ // -fexec-charset) than the one obtained by re-lexing the source token here,
+ // so ByteNo can lie beyond the end of the last token. In that case, clamp
+ // to the end of the last token rather than failing.
+ bool IsLastToken = TokNo == getNumConcatenated() - 1;
+ if (ByteNo < TokNumBytes || IsLastToken) {
+ ByteNo = std::min(ByteNo, TokNumBytes);
unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo);
// Now that we know the offset of the token in the spelling, use the
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0f9b3e2fe1d07..86794af7beda5 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -251,10 +251,13 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel,
}
if (!IsConstexpr &&
- PP.getTextEncoding().getFromIBM1047Converter() != nullptr) {
+ PP.getTextEncoding().getzOSFromAsmLiteralEncodingConverter() !=
+ nullptr) {
SmallString<16> ConvertedAsm;
- PP.getTextEncoding().getFromIBM1047Converter()->convert(SL->getString(),
- ConvertedAsm);
+ [[maybe_unused]] std::error_code EC =
+ PP.getTextEncoding().getzOSFromAsmLiteralEncodingConverter()->convert(
+ SL->getString(), ConvertedAsm);
+ assert(!EC && "This conversion should always succeed");
QualType StrTy = Context.getStringLiteralArrayType(Context.CharTy,
ConvertedAsm.size());
return StringLiteral::Create(Context, ConvertedAsm,
@@ -277,7 +280,7 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel,
}
// The evaluated string is in the literal encoding (-fexec-charset).
- // Convert it back to UTF-8
+ // Convert it back to UTF-8.
if (llvm::TextEncodingConverter *FromLiteral =
PP.getTextEncoding().getFromLiteralEncodingConverter()) {
std::string Raw = V.getCharArrayAsString();
diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 3cbc8354900fa..63802c183320a 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -14,6 +14,8 @@ llvm_canonicalize_cmake_booleans(
CLANG_LINK_CLANG_DYLIB
CLANG_USE_XCSELECT
ENABLE_BACKTRACES
+ HAVE_ICONV
+ HAVE_ICU
LLVM_BYE_LINK_INTO_TOOLS
LLVM_ENABLE_PLUGINS
LLVM_ENABLE_ZLIB
diff --git a/clang/test/Sema/systemz-charset-asm-diag-loc.cpp b/clang/test/Sema/systemz-charset-asm-diag-loc.cpp
new file mode 100644
index 0000000000000..9d7164aff87e2
--- /dev/null
+++ b/clang/test/Sema/systemz-charset-asm-diag-loc.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++23 -fsyntax-only -verify
+
+// In IBM-1047, \x68 is U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA), so the
+// asm string below is converted to UTF-8 with a different length than the
+// source token. Computing diagnostic locations within the string must not
+// assert.
+void f(unsigned x) {
+ __asm__("\tXR %[\x68\x68\x68],%[z]" : [\u{c7}\u{c7}\u{c7}] "=r"(x)); // expected-error {{unknown symbolic operand name in inline assembly string}}
+}
diff --git a/clang/test/Sema/systemz-charset-asm-diag.cpp b/clang/test/Sema/systemz-charset-asm-diag.cpp
new file mode 100644
index 0000000000000..4d6c233eba951
--- /dev/null
+++ b/clang/test/Sema/systemz-charset-asm-diag.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: icu || iconv
+// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset Shift_JIS %s -std=c++23 -fsyntax-only -verify
+
+struct string_view {
+ const char *D;
+ int S;
+ constexpr string_view(int Size, const char *Str) : D(Str), S(Size) {}
+ constexpr const char *data() const { return D; }
+ constexpr int size() const { return S; }
+};
+
+void asm_string_invalid_literal_encoding() {
+ // The numeric escape "\x81" is stored unconverted in the literal encoding.
+ // It is a Shift_JIS lead byte with no trail byte, so converting the evaluated
+ // string back to UTF-8 fails.
+ asm((string_view(1, "\x81"))); // expected-error-re {{conversion from literal encoding to UTF-8 failed: {{.*}}}}
+}
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index cb35118167d99..63b2e433914cb 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -18,6 +18,8 @@ config.clang_lib_dir = path(r"@CMAKE_LIBRARY_OUTPUT_DIRECTORY@")
config.host_triple = "@LLVM_HOST_TRIPLE@"
config.target_triple = "@LLVM_TARGET_TRIPLE@"
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
+config.have_icu = @HAVE_ICU@
+config.have_iconv = @HAVE_ICONV@
config.have_zlib = @LLVM_ENABLE_ZLIB@
config.have_zstd = @LLVM_ENABLE_ZSTD@
config.clang_objc_rewriter = @CLANG_ENABLE_OBJC_REWRITER@
diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py
index 138324d6ec83a..ed827b2b6f64b 100644
--- a/llvm/utils/lit/lit/llvm/config.py
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -150,6 +150,12 @@ def __init__(self, lit_config, config):
have_zstd = getattr(config, "have_zstd", None)
if have_zstd:
features.add("zstd")
+ have_icu = getattr(config, "have_icu", None)
+ if have_icu:
+ features.add("icu")
+ have_iconv = getattr(config, "have_iconv", None)
+ if have_iconv:
+ features.add("iconv")
have_lzma = getattr(config, "have_lzma", None)
if have_lzma:
features.add("lzma")
>From 0f9087ea68864b75a8e472cb05ea4b610a34542a Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Tue, 10 Nov 2026 11:15:46 -0500
Subject: [PATCH 18/22] address latest comments
---
clang/lib/AST/Expr.cpp | 8 ++++++++
...{systemz-charset-asm-diag.cpp => charset-asm-diag.cpp} | 4 ++--
2 files changed, 10 insertions(+), 2 deletions(-)
rename clang/test/Sema/{systemz-charset-asm-diag.cpp => charset-asm-diag.cpp} (81%)
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 2ca8765c0cdb2..5d1032fd62536 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1396,6 +1396,14 @@ StringLiteral::getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
// -fexec-charset) than the one obtained by re-lexing the source token here,
// so ByteNo can lie beyond the end of the last token. In that case, clamp
// to the end of the last token rather than failing.
+ //
+ // FIXME: When the conversion changes the number of bytes (e.g. a
+ // multi-byte UTF-8 sequence that maps to a single byte), ByteNo no longer
+ // corresponds to the byte offset in the source spelling, so the returned
+ // location can be wrong ("drift"), and diagnostics using it may point at
+ // the wrong place. Ideally, callers would fall back to the range of the
+ // entire string literal in that case, as is done for non-literal
+ // (constant-evaluated) asm strings.
bool IsLastToken = TokNo == getNumConcatenated() - 1;
if (ByteNo < TokNumBytes || IsLastToken) {
ByteNo = std::min(ByteNo, TokNumBytes);
diff --git a/clang/test/Sema/systemz-charset-asm-diag.cpp b/clang/test/Sema/charset-asm-diag.cpp
similarity index 81%
rename from clang/test/Sema/systemz-charset-asm-diag.cpp
rename to clang/test/Sema/charset-asm-diag.cpp
index 4d6c233eba951..cfe793e7b7ef2 100644
--- a/clang/test/Sema/systemz-charset-asm-diag.cpp
+++ b/clang/test/Sema/charset-asm-diag.cpp
@@ -1,5 +1,5 @@
-// REQUIRES: icu || iconv
-// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset Shift_JIS %s -std=c++23 -fsyntax-only -verify
+// REQUIRES: icu
+// RUN: %clang_cc1 -fexec-charset Shift_JIS %s -std=c++23 -fsyntax-only -verify
struct string_view {
const char *D;
>From 2ed0643f90c23b236339b92ed3097864873cd3f0 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Wed, 11 Nov 2026 16:01:50 -0500
Subject: [PATCH 19/22] remove clamping code and FIXME messages
---
clang/lib/AST/Expr.cpp | 18 ++----------------
clang/lib/Sema/SemaStmtAsm.cpp | 2 +-
clang/test/CMakeLists.txt | 2 --
clang/test/Sema/charset-asm-diag.cpp | 17 -----------------
.../test/Sema/systemz-charset-asm-diag-loc.cpp | 9 ---------
clang/test/lit.site.cfg.py.in | 2 --
llvm/utils/lit/lit/llvm/config.py | 6 ------
7 files changed, 3 insertions(+), 53 deletions(-)
delete mode 100644 clang/test/Sema/charset-asm-diag.cpp
delete mode 100644 clang/test/Sema/systemz-charset-asm-diag-loc.cpp
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 5d1032fd62536..1ba2ccdf697f9 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1391,22 +1391,8 @@ StringLiteral::getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
unsigned TokNumBytes = SLP.GetStringLength();
// If the byte is in this token, return the location of the byte.
- //
- // The string data may have been converted to a different encoding (e.g.
- // -fexec-charset) than the one obtained by re-lexing the source token here,
- // so ByteNo can lie beyond the end of the last token. In that case, clamp
- // to the end of the last token rather than failing.
- //
- // FIXME: When the conversion changes the number of bytes (e.g. a
- // multi-byte UTF-8 sequence that maps to a single byte), ByteNo no longer
- // corresponds to the byte offset in the source spelling, so the returned
- // location can be wrong ("drift"), and diagnostics using it may point at
- // the wrong place. Ideally, callers would fall back to the range of the
- // entire string literal in that case, as is done for non-literal
- // (constant-evaluated) asm strings.
- bool IsLastToken = TokNo == getNumConcatenated() - 1;
- if (ByteNo < TokNumBytes || IsLastToken) {
- ByteNo = std::min(ByteNo, TokNumBytes);
+ if (ByteNo < TokNumBytes ||
+ (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) {
unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo);
// Now that we know the offset of the token in the spelling, use the
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 86794af7beda5..f4490c940bf61 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -262,7 +262,7 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel,
ConvertedAsm.size());
return StringLiteral::Create(Context, ConvertedAsm,
StringLiteralKind::Ordinary,
- /*Pascal*/ false, StrTy, SL->getBeginLoc());
+ /*Pascal=*/false, StrTy, SL->getBeginLoc());
}
return SL;
}
diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 63802c183320a..3cbc8354900fa 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -14,8 +14,6 @@ llvm_canonicalize_cmake_booleans(
CLANG_LINK_CLANG_DYLIB
CLANG_USE_XCSELECT
ENABLE_BACKTRACES
- HAVE_ICONV
- HAVE_ICU
LLVM_BYE_LINK_INTO_TOOLS
LLVM_ENABLE_PLUGINS
LLVM_ENABLE_ZLIB
diff --git a/clang/test/Sema/charset-asm-diag.cpp b/clang/test/Sema/charset-asm-diag.cpp
deleted file mode 100644
index cfe793e7b7ef2..0000000000000
--- a/clang/test/Sema/charset-asm-diag.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-// REQUIRES: icu
-// RUN: %clang_cc1 -fexec-charset Shift_JIS %s -std=c++23 -fsyntax-only -verify
-
-struct string_view {
- const char *D;
- int S;
- constexpr string_view(int Size, const char *Str) : D(Str), S(Size) {}
- constexpr const char *data() const { return D; }
- constexpr int size() const { return S; }
-};
-
-void asm_string_invalid_literal_encoding() {
- // The numeric escape "\x81" is stored unconverted in the literal encoding.
- // It is a Shift_JIS lead byte with no trail byte, so converting the evaluated
- // string back to UTF-8 fails.
- asm((string_view(1, "\x81"))); // expected-error-re {{conversion from literal encoding to UTF-8 failed: {{.*}}}}
-}
diff --git a/clang/test/Sema/systemz-charset-asm-diag-loc.cpp b/clang/test/Sema/systemz-charset-asm-diag-loc.cpp
deleted file mode 100644
index 9d7164aff87e2..0000000000000
--- a/clang/test/Sema/systemz-charset-asm-diag-loc.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++23 -fsyntax-only -verify
-
-// In IBM-1047, \x68 is U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA), so the
-// asm string below is converted to UTF-8 with a different length than the
-// source token. Computing diagnostic locations within the string must not
-// assert.
-void f(unsigned x) {
- __asm__("\tXR %[\x68\x68\x68],%[z]" : [\u{c7}\u{c7}\u{c7}] "=r"(x)); // expected-error {{unknown symbolic operand name in inline assembly string}}
-}
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index 63b2e433914cb..cb35118167d99 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -18,8 +18,6 @@ config.clang_lib_dir = path(r"@CMAKE_LIBRARY_OUTPUT_DIRECTORY@")
config.host_triple = "@LLVM_HOST_TRIPLE@"
config.target_triple = "@LLVM_TARGET_TRIPLE@"
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
-config.have_icu = @HAVE_ICU@
-config.have_iconv = @HAVE_ICONV@
config.have_zlib = @LLVM_ENABLE_ZLIB@
config.have_zstd = @LLVM_ENABLE_ZSTD@
config.clang_objc_rewriter = @CLANG_ENABLE_OBJC_REWRITER@
diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py
index ed827b2b6f64b..138324d6ec83a 100644
--- a/llvm/utils/lit/lit/llvm/config.py
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -150,12 +150,6 @@ def __init__(self, lit_config, config):
have_zstd = getattr(config, "have_zstd", None)
if have_zstd:
features.add("zstd")
- have_icu = getattr(config, "have_icu", None)
- if have_icu:
- features.add("icu")
- have_iconv = getattr(config, "have_iconv", None)
- if have_iconv:
- features.add("iconv")
have_lzma = getattr(config, "have_lzma", None)
if have_lzma:
features.add("lzma")
>From f2dc30e727780f5def9d4f7e11b05bb148d2caf0 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 13 Nov 2026 10:00:03 -0500
Subject: [PATCH 20/22] add back two testcases, add back lit cfg for HAVE_ICU
and HAVE_ICONV
---
clang/test/CMakeLists.txt | 2 ++
clang/test/Sema/charset-asm-diag.cpp | 17 +++++++++++++++++
.../test/Sema/systemz-charset-asm-diag-loc.cpp | 11 +++++++++++
clang/test/lit.site.cfg.py.in | 2 ++
llvm/utils/lit/lit/llvm/config.py | 6 ++++++
5 files changed, 38 insertions(+)
create mode 100644 clang/test/Sema/charset-asm-diag.cpp
create mode 100644 clang/test/Sema/systemz-charset-asm-diag-loc.cpp
diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 3cbc8354900fa..63802c183320a 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -14,6 +14,8 @@ llvm_canonicalize_cmake_booleans(
CLANG_LINK_CLANG_DYLIB
CLANG_USE_XCSELECT
ENABLE_BACKTRACES
+ HAVE_ICONV
+ HAVE_ICU
LLVM_BYE_LINK_INTO_TOOLS
LLVM_ENABLE_PLUGINS
LLVM_ENABLE_ZLIB
diff --git a/clang/test/Sema/charset-asm-diag.cpp b/clang/test/Sema/charset-asm-diag.cpp
new file mode 100644
index 0000000000000..5850107479a3a
--- /dev/null
+++ b/clang/test/Sema/charset-asm-diag.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: icu
+// RUN: %clang_cc1 -fexec-charset Shift_JIS %s -std=c++23 -fsyntax-only -verify
+
+struct string_view {
+ const char *D;
+ int S;
+ constexpr string_view(const char *Str, int Size) : D(Str), S(Size) {}
+ constexpr const char *data() const { return D; }
+ constexpr int size() const { return S; }
+};
+
+void asm_string_invalid_literal_encoding() {
+ // The numeric escape "\x81" is stored unconverted in the literal encoding.
+ // It is a Shift_JIS lead byte with no trail byte, so converting the evaluated
+ // string back to UTF-8 fails.
+ asm((string_view("\x81", 1))); // expected-error-re {{conversion from literal encoding to UTF-8 failed: {{.*}}}}
+}
diff --git a/clang/test/Sema/systemz-charset-asm-diag-loc.cpp b/clang/test/Sema/systemz-charset-asm-diag-loc.cpp
new file mode 100644
index 0000000000000..54d698d67994e
--- /dev/null
+++ b/clang/test/Sema/systemz-charset-asm-diag-loc.cpp
@@ -0,0 +1,11 @@
+// FIXME: Tracked by Github Issue 241514
+// RUN: not --crash %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++23 -fsyntax-only -verify
+// REQUIRES: asserts
+
+// In IBM-1047, \x68 is U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA), so the
+// asm string below is converted to UTF-8 with a different length than the
+// source token. Computing diagnostic locations within the string must not
+// assert.
+void f(unsigned x) {
+ __asm__("\tXR %[\x68\x68\x68],%[z]" : [\u{c7}\u{c7}\u{c7}] "=r"(x)); // expected-error {{unknown symbolic operand name in inline assembly string}}
+}
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index cb35118167d99..63b2e433914cb 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -18,6 +18,8 @@ config.clang_lib_dir = path(r"@CMAKE_LIBRARY_OUTPUT_DIRECTORY@")
config.host_triple = "@LLVM_HOST_TRIPLE@"
config.target_triple = "@LLVM_TARGET_TRIPLE@"
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
+config.have_icu = @HAVE_ICU@
+config.have_iconv = @HAVE_ICONV@
config.have_zlib = @LLVM_ENABLE_ZLIB@
config.have_zstd = @LLVM_ENABLE_ZSTD@
config.clang_objc_rewriter = @CLANG_ENABLE_OBJC_REWRITER@
diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py
index 138324d6ec83a..43ec9529b1422 100644
--- a/llvm/utils/lit/lit/llvm/config.py
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -144,6 +144,12 @@ def __init__(self, lit_config, config):
if "thread" in sanitizers:
features.add("tsan")
+ have_icu = getattr(config, "have_icu", None)
+ if have_icu:
+ features.add("icu")
+ have_iconv = getattr(config, "have_iconv", None)
+ if have_iconv:
+ features.add("iconv")
have_zlib = getattr(config, "have_zlib", None)
if have_zlib:
features.add("zlib")
>From 48cfc9a33f4e552e18064f4743818651bd0aa10f Mon Sep 17 00:00:00 2001
From: Abhina Sree <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 13 Nov 2026 15:15:44 -0500
Subject: [PATCH 21/22] Use URL
Co-authored-by: Hubert Tong <hubert.reinterpretcast at gmail.com>
---
clang/test/Sema/systemz-charset-asm-diag-loc.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/Sema/systemz-charset-asm-diag-loc.cpp b/clang/test/Sema/systemz-charset-asm-diag-loc.cpp
index 54d698d67994e..1daccbcd5ba85 100644
--- a/clang/test/Sema/systemz-charset-asm-diag-loc.cpp
+++ b/clang/test/Sema/systemz-charset-asm-diag-loc.cpp
@@ -1,4 +1,4 @@
-// FIXME: Tracked by Github Issue 241514
+// FIXME: Tracked by https://github.com/llvm/llvm-project/issues/241514
// RUN: not --crash %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++23 -fsyntax-only -verify
// REQUIRES: asserts
>From 7c3489317837c407c06261648a95b9c650cf5eb2 Mon Sep 17 00:00:00 2001
From: Abhina Sree <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 13 Nov 2026 15:16:13 -0500
Subject: [PATCH 22/22] Update string_view class
Co-authored-by: Hubert Tong <hubert.reinterpretcast at gmail.com>
---
clang/test/CodeGen/systemz-charset.cpp | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/clang/test/CodeGen/systemz-charset.cpp b/clang/test/CodeGen/systemz-charset.cpp
index b1c58b3336bb3..9647b2e88af53 100644
--- a/clang/test/CodeGen/systemz-charset.cpp
+++ b/clang/test/CodeGen/systemz-charset.cpp
@@ -75,17 +75,15 @@ const char32_t *UnicodeUCNString32 = U"\u00E2\u00AC\U000000DF";
struct string_view {
- int S;
const char* D;
- constexpr string_view() : S(0), D(0){}
- constexpr string_view(const char* Str) : S(__builtin_strlen(Str)), D(Str) {}
- constexpr string_view(int Size, const char* Str) : S(Size), D(Str) {}
- constexpr int size() const {
- return S;
- }
+ int S;
+ constexpr string_view(const char* Str) : D(Str), S(__builtin_strlen(Str)) {}
constexpr const char* data() const {
return D;
}
+ constexpr int size() const {
+ return S;
+ }
};
constexpr string_view getfoo() { return "\174foo"; }
More information about the cfe-commits
mailing list