[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 6 19:54:08 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Iris Shi (el-ev)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/196223.diff
2 Files Affected:
- (modified) clang/lib/Basic/TargetInfo.cpp (+3)
- (added) clang/test/CodeGen/inline-asm-constraint-embedded-null.c (+8)
``````````diff
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)); }
``````````
</details>
https://github.com/llvm/llvm-project/pull/196223
More information about the cfe-commits
mailing list