[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-25 Thread Iris Shi via cfe-commits

el-ev wrote:

Closing this in favor of #196462

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-25 Thread Iris Shi via cfe-commits

https://github.com/el-ev closed https://github.com/llvm/llvm-project/pull/196223
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-09 Thread Corentin Jabot via cfe-commits

cor3ntin wrote:

Can we close this?

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-08 Thread Iris Shi via cfe-commits

el-ev wrote:

Fine, I'll submit a follow-up patch.

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-08 Thread Iris Shi via cfe-commits

el-ev wrote:

> Can we close this?

Do you mean discard this PR and merge 
https://github.com/llvm/llvm-project/pull/196462 directly into main instead?

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-07 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I would prefer to add a diagnostic to reject this; there's no existing code 
depending on this, and discarding bits of the constraint string is confusing.

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-07 Thread Iris Shi via cfe-commits


@@ -1072,6 +1072,9 @@ TargetInfo::simplifyConstraint(StringRef Constraint,
SmallVectorImpl *OutCons) const 
{
   std::string Result;
 
+  // Stop at '\0' to match the old behavior.

el-ev wrote:

Updated, thanks.

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-07 Thread Iris Shi via cfe-commits

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

>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 1/2] [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 *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 0..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.00e+00)
+void f(void) { __asm__("" : : "f\0001"(0.0)); }

>From 9dc3d00cc37af60a6db356eb13fc27c34cd86711 Mon Sep 17 00:00:00 2001
From: Iris Shi <[email protected]>
Date: Thu, 7 May 2026 16:42:42 +0800
Subject: [PATCH 2/2] Update clang/lib/Basic/TargetInfo.cpp

---
 clang/lib/Basic/TargetInfo.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index ea0e2671ef380..2acdfe339e2f6 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -1072,7 +1072,7 @@ TargetInfo::simplifyConstraint(StringRef Constraint,
SmallVectorImpl *OutCons) const 
{
   std::string Result;
 
-  // Stop at '\0' to match the old behavior.
+  // Ignore embedded nulls to match prior (clang-21 and earlier) behavior
   Constraint = Constraint.split('\0').first;
 
   for (const char *I = Constraint.begin(), *E = Constraint.end(); I < E; I++) {

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-07 Thread Iris Shi via cfe-commits


@@ -1072,6 +1072,9 @@ TargetInfo::simplifyConstraint(StringRef Constraint,
SmallVectorImpl *OutCons) const 
{
   std::string Result;
 
+  // Stop at '\0' to match the old behavior.

el-ev wrote:

```suggestion
  // Ignore embedded nulls to match prior (clang-21 and earlier) behavior
```

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-07 Thread Iris Shi via cfe-commits

el-ev wrote:

That's a malformed constraint string, in gcc and earlier versions of clang, it 
produces an error elsewhere. 

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-07 Thread Jeremy Morse via cfe-commits


@@ -1072,6 +1072,9 @@ TargetInfo::simplifyConstraint(StringRef Constraint,
SmallVectorImpl *OutCons) const 
{
   std::string Result;
 
+  // Stop at '\0' to match the old behavior.

jmorse wrote:

I'd suggest wording this to avoid the reader having to consider when "old" 
might be: something like "Ignore embedded nulls to match prior clang (clang-21 
and earlier) behaviours".

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-07 Thread Jeremy Morse via cfe-commits

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-07 Thread Jeremy Morse via cfe-commits

https://github.com/jmorse approved this pull request.

LGTM on the basis that not crashing is an improvement, as reproduced in 
#173900. There's a risk that there are other paths which will now see embedded 
nulls, which aren't easily discoverable -- what does gcc do for this input? It 
might be better to add an early diagnostic/error rejecting such embedded nulls, 
rather than try to handle nulls once they're inside clang.

(CC'd Eli as he was involved in the original patch #154905).

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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-06 Thread via cfe-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-clang

Author: Iris Shi (el-ev)


Changes

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 *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 0..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.00e+00)
+void f(void) { __asm__("" : : "f\0001"(0.0)); }

``




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


[clang] [clang] Stop simplifyConstraint at embedded NUL (PR #196223)

2026-05-06 Thread Iris Shi via cfe-commits

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 *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 0..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.00e+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