[clang] [clang] Fix handling of asm string literals (PR #169803)
Hubert Tong via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 18 22:38:58 PDT 2026
================
@@ -72,3 +72,31 @@ 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("\174foo");
+ // CHECK: asm{{.*}}@foo
+ // CHECK-UTF8: asm{{.*}}@foo
+ asm((getfoo()));
+ // CHECK: asm{{.*}}|\86\96\96
+ // CHECK-UTF8: asm{{.*}}|foo
----------------
hubert-reinterpretcast wrote:
@abhina-sree, I spoke with Corentin on Friday. The conversion from the execution charset first to UTF-8 (e.g., for parsing of an assembler template string by the compiler) is needed here. That conversion is also needed for the `static_assert` case (which can be covered an a later PR).
It is not clear to me where best to insert checking for any encoding restrictions tied to the assembler dialect/backend implementation. In any case, checking that the part of the string that survives converts to IBM-1047 is probably out of the scope of this PR (but may be something that is needed at some point).
https://github.com/llvm/llvm-project/pull/169803
More information about the cfe-commits
mailing list