https://github.com/nataliakokoromyti created
https://github.com/llvm/llvm-project/pull/177096
This input `asm("" ::: (u8""}))` made clang reach `ActOnGCCAsmStmtString` with
a `u8""` string literal.
That function had an `assert` that assumed the asm string is a plain `""`, so
it aborted instead of just throwing an error.
fixes #177056
>From 989b9b695193cf5e48f5676edbb262acc5b4378f Mon Sep 17 00:00:00 2001
From: Natalia Kokoromyti <[email protected]>
Date: Tue, 20 Jan 2026 19:38:52 -0800
Subject: [PATCH] fix crash on u8 string
---
clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 ++++
clang/lib/Sema/SemaStmtAsm.cpp | 5 ++++-
clang/test/Sema/asm-no-crash-non-ordinary-string.cpp | 7 +++++++
3 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Sema/asm-no-crash-non-ordinary-string.cpp
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44541a4c68197..935e896653fda 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9906,6 +9906,10 @@ let CategoryName = "Inline Assembly Issue" in {
def err_asm_operand_empty_string : Error<
"cannot use an empty string literal in 'asm'">;
+ def err_asm_string_literal_not_ordinary : Error<
+ "cannot use unicode string literal in 'asm'">;
+
+
def err_asm_pmf_through_constraint_not_permitted
: Error<"cannot pass a pointer-to-member through register-constrained "
"inline assembly parameter">;
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index f957bdf7156c7..8f39872fb5b3e 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -240,7 +240,10 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool
ForAsmLabel) {
return ExprError();
if (auto *SL = dyn_cast<StringLiteral>(Expr)) {
- assert(SL->isOrdinary());
+ if (!SL->isOrdinary()) {
+ Diag(SL->getBeginLoc(), diag::err_asm_string_literal_not_ordinary);
+ return ExprError();
+ }
if (ForAsmLabel && SL->getString().empty()) {
Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string)
<< SL->getSourceRange();
diff --git a/clang/test/Sema/asm-no-crash-non-ordinary-string.cpp
b/clang/test/Sema/asm-no-crash-non-ordinary-string.cpp
new file mode 100644
index 0000000000000..42a2f30db9138
--- /dev/null
+++ b/clang/test/Sema/asm-no-crash-non-ordinary-string.cpp
@@ -0,0 +1,7 @@
+// RUN: not %clang_cc1 -fsyntax-only -verify %s
+
+void foo() {
+ asm("" ::: (u8""}));
+ // expected-error@-1 {{cannot use unicode string literal in 'asm'}}
+ // expected-error@-2 {{expected ')'}}
+}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits