https://github.com/el-ev created 
https://github.com/llvm/llvm-project/pull/196223

Resolves #173900.

#154905 switched simplifyConstraint from a C-style string to a StringRef, which 
silently changed behavior when encountering embedded NUL bytes. Truncate at the 
first '\0' to restore the old behavior.

>From abba0bb55ff41295326c1a2ce9f981098d76da32 Mon Sep 17 00:00:00 2001
From: Iris Shi <[email protected]>
Date: Thu, 7 May 2026 10:47:25 +0800
Subject: [PATCH] [clang] Stop simplifyConstraint at embedded NUL

---
 clang/lib/Basic/TargetInfo.cpp                           | 3 +++
 clang/test/CodeGen/inline-asm-constraint-embedded-null.c | 8 ++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 clang/test/CodeGen/inline-asm-constraint-embedded-null.c

diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index e6ae89e0948c5..ea0e2671ef380 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -1072,6 +1072,9 @@ TargetInfo::simplifyConstraint(StringRef Constraint,
                                SmallVectorImpl<ConstraintInfo> *OutCons) const 
{
   std::string Result;
 
+  // Stop at '\0' to match the old behavior.
+  Constraint = Constraint.split('\0').first;
+
   for (const char *I = Constraint.begin(), *E = Constraint.end(); I < E; I++) {
     switch (*I) {
     default:
diff --git a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c 
b/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
new file mode 100644
index 0000000000000..c2cd3ace0ddd3
--- /dev/null
+++ b/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
@@ -0,0 +1,8 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | 
FileCheck %s
+
+// Regression test for issue173900.
+
+// CHECK-LABEL: define {{.*}}void @f(
+// CHECK: call void asm sideeffect "", "f,{{[^"]*}}"(double 0.000000e+00)
+void f(void) { __asm__("" : : "f\0001"(0.0)); }

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

Reply via email to