================
@@ -2231,6 +2231,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}")));
----------------
hubert-reinterpretcast wrote:

The wording is fine for what it covers; however, I think we should have some 
agreement on how the result of the expression is interpreted before the PR 
lands.

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

Reply via email to