[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-09 Thread via llvm-branch-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-clang

Author: Iris Shi (el-ev)


Changes

As suggested by @jmorse and @efriedma-quic in #196223.



---
Full diff: https://github.com/llvm/llvm-project/pull/196462.diff


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3) 
- (modified) clang/lib/Sema/SemaStmtAsm.cpp (+18) 
- (removed) clang/test/CodeGen/inline-asm-constraint-embedded-null.c (-8) 
- (added) clang/test/Sema/inline-asm-constraint-embedded-null.c (+16) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb19b80b7e994..51e98aef4d251 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -479,6 +479,9 @@ Improvements to Clang's diagnostics
 
 - Removed the body of lambdas from some diagnostic messages.
 
+- Clang now rejects inline asm constraints and clobbers that contain an
+  embedded null character, instead of silently truncating them. (#GH173900)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c69b2ce3648f8..c30ddf445ed65 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10074,6 +10074,9 @@ let CategoryName = "Inline Assembly Issue" in {
 "invalid lvalue in asm input for constraint '%0'">;
   def err_asm_invalid_input_constraint : Error<
 "invalid input constraint '%0' in asm">;
+  def err_asm_constraint_embedded_null : Error<
+"%select{output constraint|input constraint|clobber}0 contains "
+"embedded null character">;
   def err_asm_tying_incompatible_types : Error<
 "unsupported inline asm: input with type "
 "%diff{$ matching output with type $|}0,1">;
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index f957bdf7156c7..f80c1a5b65f93 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -306,6 +306,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*output*/0;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, OutputName);
 if (!Context.getTargetInfo().validateOutputConstraint(Info) &&
 !(LangOpts.HIPStdPar && LangOpts.CUDAIsDevice)) {
@@ -396,6 +402,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*input*/1;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, InputName);
 if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
  Info)) {
@@ -503,6 +515,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string Clobber =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(ClobberExpr);
 
+if (Clobber.find('\0') != std::string::npos) {
+  Diag(ClobberExpr->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*clobber*/2;
+  return CreateGCCAsmStmt();
+}
+
 if (!Context.getTargetInfo().isValidClobber(Clobber)) {
   targetDiag(ClobberExpr->getBeginLoc(),
  diag::err_asm_unknown_register_name)
diff --git a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c 
b/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
deleted file mode 100644
index c2cd3ace0ddd3..0
--- a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// 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)); }
diff --git a/clang/test/Sema/inline-asm-constraint-embedded-null.c 
b/clang/test/Sema/inline-asm-constraint-embedded-null.c
new file mode 100644
index 0..e8587e469ba85
--- /dev/null
+++ b/clang/test/Sema/inline-asm-constraint-embedded-null.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+
+// Regression test for issue173900.
+
+void test_input(void) {
+  __asm__("" : : "f\0001"(0.0)); // expected-error {{input constraint contains 
embedded null character}}
+}
+

[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread Corentin Jabot via llvm-branch-commits


@@ -10074,6 +10074,9 @@ let CategoryName = "Inline Assembly Issue" in {
 "invalid lvalue in asm input for constraint '%0'">;
   def err_asm_invalid_input_constraint : Error<
 "invalid input constraint '%0' in asm">;
+  def err_asm_constraint_embedded_null : Error<
+"%select{output constraint|input constraint|clobber}0 contains "
+"embedded null character">;

cor3ntin wrote:

```suggestion
"an embedded null character">;
```

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


[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread Jeremy Morse via llvm-branch-commits

https://github.com/jmorse commented:

Thanks for refining this into a diagnostic, I feel it's a much more complete 
solution. In principle this looks good to me, but it's a lot further into clang 
than I usually venture, so I'd much prefer someone else tick the approve button.

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


[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread Iris Shi via llvm-branch-commits

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

As suggested by @jmorse and @efriedma-quic in #196223.



>From bdf2a67e1040548b95393bac50aed1578a072fbd Mon Sep 17 00:00:00 2001
From: Iris Shi <[email protected]>
Date: Fri, 8 May 2026 10:45:03 +0800
Subject: [PATCH] [clang][diagnostics] Reject embedded NUL characters in inline
 asm constraints and clobbers

---
 clang/docs/ReleaseNotes.rst|  3 +++
 .../include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaStmtAsm.cpp | 18 ++
 .../inline-asm-constraint-embedded-null.c  |  8 
 .../Sema/inline-asm-constraint-embedded-null.c | 16 
 5 files changed, 40 insertions(+), 8 deletions(-)
 delete mode 100644 clang/test/CodeGen/inline-asm-constraint-embedded-null.c
 create mode 100644 clang/test/Sema/inline-asm-constraint-embedded-null.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb19b80b7e994..51e98aef4d251 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -479,6 +479,9 @@ Improvements to Clang's diagnostics
 
 - Removed the body of lambdas from some diagnostic messages.
 
+- Clang now rejects inline asm constraints and clobbers that contain an
+  embedded null character, instead of silently truncating them. (#GH173900)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c69b2ce3648f8..c30ddf445ed65 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10074,6 +10074,9 @@ let CategoryName = "Inline Assembly Issue" in {
 "invalid lvalue in asm input for constraint '%0'">;
   def err_asm_invalid_input_constraint : Error<
 "invalid input constraint '%0' in asm">;
+  def err_asm_constraint_embedded_null : Error<
+"%select{output constraint|input constraint|clobber}0 contains "
+"embedded null character">;
   def err_asm_tying_incompatible_types : Error<
 "unsupported inline asm: input with type "
 "%diff{$ matching output with type $|}0,1">;
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index f957bdf7156c7..f80c1a5b65f93 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -306,6 +306,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*output*/0;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, OutputName);
 if (!Context.getTargetInfo().validateOutputConstraint(Info) &&
 !(LangOpts.HIPStdPar && LangOpts.CUDAIsDevice)) {
@@ -396,6 +402,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*input*/1;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, InputName);
 if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
  Info)) {
@@ -503,6 +515,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string Clobber =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(ClobberExpr);
 
+if (Clobber.find('\0') != std::string::npos) {
+  Diag(ClobberExpr->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*clobber*/2;
+  return CreateGCCAsmStmt();
+}
+
 if (!Context.getTargetInfo().isValidClobber(Clobber)) {
   targetDiag(ClobberExpr->getBeginLoc(),
  diag::err_asm_unknown_register_name)
diff --git a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c 
b/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
deleted file mode 100644
index c2cd3ace0ddd3..0
--- a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// 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)); }
diff --git a/clang/test/Sema/inline-asm-constraint-embedded-null.c 
b/clang/test/Sema/inline-asm-constraint-embedded-null.c
new file mode 100644
index 0..e8587e469ba85
--- /dev/

[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread Corentin Jabot via llvm-branch-commits

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

LGTM, thanks!

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


[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread via llvm-branch-commits

github-actions[bot] wrote:


# :window: Windows x64 Test Results

* 53856 tests passed
* 1186 tests skipped
* 1 test failed

## Failed Tests
(click on a test name to see its output)

### Clang

Clang.Sema/inline-asm-constraint-embedded-null.c

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -cc1 -internal-isystem 
C:\_work\llvm-project\llvm-project\build\lib\clang\23\include -nostdsysteminc 
-triple x86_64-unknown-unknown -fsyntax-only -verify 
C:\_work\llvm-project\llvm-project\clang\test\Sema\inline-asm-constraint-embedded-null.c
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' 
-cc1 -internal-isystem 
'C:\_work\llvm-project\llvm-project\build\lib\clang\23\include' -nostdsysteminc 
-triple x86_64-unknown-unknown -fsyntax-only -verify 
'C:\_work\llvm-project\llvm-project\clang\test\Sema\inline-asm-constraint-embedded-null.c'
# .---command stderr
# | error: 'expected-error' diagnostics expected but not seen: 
# |   File 
C:\_work\llvm-project\llvm-project\clang\test\Sema\inline-asm-constraint-embedded-null.c
 Line 6: input constraint contains embedded an null character
# |   File 
C:\_work\llvm-project\llvm-project\clang\test\Sema\inline-asm-constraint-embedded-null.c
 Line 11: output constraint contains embedded an null character
# |   File 
C:\_work\llvm-project\llvm-project\clang\test\Sema\inline-asm-constraint-embedded-null.c
 Line 15: clobber contains embedded an null character
# | error: 'expected-error' diagnostics seen but not expected: 
# |   File 
C:\_work\llvm-project\llvm-project\clang\test\Sema\inline-asm-constraint-embedded-null.c
 Line 6: input constraint contains an embedded null character
# |   File 
C:\_work\llvm-project\llvm-project\clang\test\Sema\inline-asm-constraint-embedded-null.c
 Line 11: output constraint contains an embedded null character
# |   File 
C:\_work\llvm-project\llvm-project\clang\test\Sema\inline-asm-constraint-embedded-null.c
 Line 15: clobber contains an embedded null character
# | 6 errors generated.
# `-
# error: command failed with exit status: 1

--

```


If these failures are unrelated to your changes (for example tests are broken 
or flaky at HEAD), please open an issue at 
https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.

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


[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread Iris Shi via llvm-branch-commits

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

>From fd83d89b6ef8648d765938b3eaaa7b2b3b6922b8 Mon Sep 17 00:00:00 2001
From: Iris Shi <[email protected]>
Date: Fri, 8 May 2026 10:45:03 +0800
Subject: [PATCH 1/4] [clang][diagnostics] Reject embedded NUL characters in
 inline asm constraints and clobbers

---
 clang/docs/ReleaseNotes.rst|  3 +++
 .../include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaStmtAsm.cpp | 18 ++
 .../inline-asm-constraint-embedded-null.c  |  8 
 .../Sema/inline-asm-constraint-embedded-null.c | 16 
 5 files changed, 40 insertions(+), 8 deletions(-)
 delete mode 100644 clang/test/CodeGen/inline-asm-constraint-embedded-null.c
 create mode 100644 clang/test/Sema/inline-asm-constraint-embedded-null.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb19b80b7e994..51e98aef4d251 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -479,6 +479,9 @@ Improvements to Clang's diagnostics
 
 - Removed the body of lambdas from some diagnostic messages.
 
+- Clang now rejects inline asm constraints and clobbers that contain an
+  embedded null character, instead of silently truncating them. (#GH173900)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c69b2ce3648f8..c30ddf445ed65 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10074,6 +10074,9 @@ let CategoryName = "Inline Assembly Issue" in {
 "invalid lvalue in asm input for constraint '%0'">;
   def err_asm_invalid_input_constraint : Error<
 "invalid input constraint '%0' in asm">;
+  def err_asm_constraint_embedded_null : Error<
+"%select{output constraint|input constraint|clobber}0 contains "
+"embedded null character">;
   def err_asm_tying_incompatible_types : Error<
 "unsupported inline asm: input with type "
 "%diff{$ matching output with type $|}0,1">;
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index f957bdf7156c7..96d372c89d2b1 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -306,6 +306,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*output*/ 0;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, OutputName);
 if (!Context.getTargetInfo().validateOutputConstraint(Info) &&
 !(LangOpts.HIPStdPar && LangOpts.CUDAIsDevice)) {
@@ -396,6 +402,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*input*/ 1;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, InputName);
 if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
  Info)) {
@@ -503,6 +515,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string Clobber =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(ClobberExpr);
 
+if (Clobber.find('\0') != std::string::npos) {
+  Diag(ClobberExpr->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*clobber*/ 2;
+  return CreateGCCAsmStmt();
+}
+
 if (!Context.getTargetInfo().isValidClobber(Clobber)) {
   targetDiag(ClobberExpr->getBeginLoc(),
  diag::err_asm_unknown_register_name)
diff --git a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c 
b/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
deleted file mode 100644
index c2cd3ace0ddd3..0
--- a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// 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)); }
diff --git a/clang/test/Sema/inline-asm-constraint-embedded-null.c 
b/clang/test/Sema/inline-asm-constraint-embedded-null.c
new file mode 100644
index 0..e8587e469ba85
--- /dev/null
+++ b/clang/test/Sema/inline-asm-constraint-em

[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread Iris Shi via llvm-branch-commits

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

>From fd83d89b6ef8648d765938b3eaaa7b2b3b6922b8 Mon Sep 17 00:00:00 2001
From: Iris Shi <[email protected]>
Date: Fri, 8 May 2026 10:45:03 +0800
Subject: [PATCH 1/2] [clang][diagnostics] Reject embedded NUL characters in
 inline asm constraints and clobbers

---
 clang/docs/ReleaseNotes.rst|  3 +++
 .../include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaStmtAsm.cpp | 18 ++
 .../inline-asm-constraint-embedded-null.c  |  8 
 .../Sema/inline-asm-constraint-embedded-null.c | 16 
 5 files changed, 40 insertions(+), 8 deletions(-)
 delete mode 100644 clang/test/CodeGen/inline-asm-constraint-embedded-null.c
 create mode 100644 clang/test/Sema/inline-asm-constraint-embedded-null.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb19b80b7e994..51e98aef4d251 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -479,6 +479,9 @@ Improvements to Clang's diagnostics
 
 - Removed the body of lambdas from some diagnostic messages.
 
+- Clang now rejects inline asm constraints and clobbers that contain an
+  embedded null character, instead of silently truncating them. (#GH173900)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c69b2ce3648f8..c30ddf445ed65 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10074,6 +10074,9 @@ let CategoryName = "Inline Assembly Issue" in {
 "invalid lvalue in asm input for constraint '%0'">;
   def err_asm_invalid_input_constraint : Error<
 "invalid input constraint '%0' in asm">;
+  def err_asm_constraint_embedded_null : Error<
+"%select{output constraint|input constraint|clobber}0 contains "
+"embedded null character">;
   def err_asm_tying_incompatible_types : Error<
 "unsupported inline asm: input with type "
 "%diff{$ matching output with type $|}0,1">;
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index f957bdf7156c7..96d372c89d2b1 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -306,6 +306,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*output*/ 0;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, OutputName);
 if (!Context.getTargetInfo().validateOutputConstraint(Info) &&
 !(LangOpts.HIPStdPar && LangOpts.CUDAIsDevice)) {
@@ -396,6 +402,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*input*/ 1;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, InputName);
 if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
  Info)) {
@@ -503,6 +515,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string Clobber =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(ClobberExpr);
 
+if (Clobber.find('\0') != std::string::npos) {
+  Diag(ClobberExpr->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*clobber*/ 2;
+  return CreateGCCAsmStmt();
+}
+
 if (!Context.getTargetInfo().isValidClobber(Clobber)) {
   targetDiag(ClobberExpr->getBeginLoc(),
  diag::err_asm_unknown_register_name)
diff --git a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c 
b/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
deleted file mode 100644
index c2cd3ace0ddd3..0
--- a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// 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)); }
diff --git a/clang/test/Sema/inline-asm-constraint-embedded-null.c 
b/clang/test/Sema/inline-asm-constraint-embedded-null.c
new file mode 100644
index 0..e8587e469ba85
--- /dev/null
+++ b/clang/test/Sema/inline-asm-constraint-em

[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread via llvm-branch-commits

github-actions[bot] wrote:


# :penguin: Linux x64 Test Results

* 87830 tests passed
* 1533 tests skipped
* 1 test failed

## Failed Tests
(click on a test name to see its output)

### Clang

Clang.Sema/inline-asm-constraint-embedded-null.c

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 
-internal-isystem 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/23/include
 -nostdsysteminc -triple x86_64-unknown-unknown -fsyntax-only -verify 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Sema/inline-asm-constraint-embedded-null.c
# executed command: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 
-internal-isystem 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/23/include
 -nostdsysteminc -triple x86_64-unknown-unknown -fsyntax-only -verify 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Sema/inline-asm-constraint-embedded-null.c
# .---command stderr
# | error: 'expected-error' diagnostics expected but not seen: 
# |   File 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Sema/inline-asm-constraint-embedded-null.c
 Line 6: input constraint contains embedded an null character
# |   File 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Sema/inline-asm-constraint-embedded-null.c
 Line 11: output constraint contains embedded an null character
# |   File 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Sema/inline-asm-constraint-embedded-null.c
 Line 15: clobber contains embedded an null character
# | error: 'expected-error' diagnostics seen but not expected: 
# |   File 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Sema/inline-asm-constraint-embedded-null.c
 Line 6: input constraint contains an embedded null character
# |   File 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Sema/inline-asm-constraint-embedded-null.c
 Line 11: output constraint contains an embedded null character
# |   File 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Sema/inline-asm-constraint-embedded-null.c
 Line 15: clobber contains an embedded null character
# | 6 errors generated.
# `-
# error: command failed with exit status: 1

--

```


If these failures are unrelated to your changes (for example tests are broken 
or flaky at HEAD), please open an issue at 
https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.

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


[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread Iris Shi via llvm-branch-commits

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

>From fd83d89b6ef8648d765938b3eaaa7b2b3b6922b8 Mon Sep 17 00:00:00 2001
From: Iris Shi <[email protected]>
Date: Fri, 8 May 2026 10:45:03 +0800
Subject: [PATCH] [clang][diagnostics] Reject embedded NUL characters in inline
 asm constraints and clobbers

---
 clang/docs/ReleaseNotes.rst|  3 +++
 .../include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaStmtAsm.cpp | 18 ++
 .../inline-asm-constraint-embedded-null.c  |  8 
 .../Sema/inline-asm-constraint-embedded-null.c | 16 
 5 files changed, 40 insertions(+), 8 deletions(-)
 delete mode 100644 clang/test/CodeGen/inline-asm-constraint-embedded-null.c
 create mode 100644 clang/test/Sema/inline-asm-constraint-embedded-null.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb19b80b7e994..51e98aef4d251 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -479,6 +479,9 @@ Improvements to Clang's diagnostics
 
 - Removed the body of lambdas from some diagnostic messages.
 
+- Clang now rejects inline asm constraints and clobbers that contain an
+  embedded null character, instead of silently truncating them. (#GH173900)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c69b2ce3648f8..c30ddf445ed65 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10074,6 +10074,9 @@ let CategoryName = "Inline Assembly Issue" in {
 "invalid lvalue in asm input for constraint '%0'">;
   def err_asm_invalid_input_constraint : Error<
 "invalid input constraint '%0' in asm">;
+  def err_asm_constraint_embedded_null : Error<
+"%select{output constraint|input constraint|clobber}0 contains "
+"embedded null character">;
   def err_asm_tying_incompatible_types : Error<
 "unsupported inline asm: input with type "
 "%diff{$ matching output with type $|}0,1">;
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index f957bdf7156c7..96d372c89d2b1 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -306,6 +306,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*output*/ 0;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, OutputName);
 if (!Context.getTargetInfo().validateOutputConstraint(Info) &&
 !(LangOpts.HIPStdPar && LangOpts.CUDAIsDevice)) {
@@ -396,6 +402,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*input*/ 1;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, InputName);
 if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
  Info)) {
@@ -503,6 +515,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string Clobber =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(ClobberExpr);
 
+if (Clobber.find('\0') != std::string::npos) {
+  Diag(ClobberExpr->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*clobber*/ 2;
+  return CreateGCCAsmStmt();
+}
+
 if (!Context.getTargetInfo().isValidClobber(Clobber)) {
   targetDiag(ClobberExpr->getBeginLoc(),
  diag::err_asm_unknown_register_name)
diff --git a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c 
b/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
deleted file mode 100644
index c2cd3ace0ddd3..0
--- a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// 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)); }
diff --git a/clang/test/Sema/inline-asm-constraint-embedded-null.c 
b/clang/test/Sema/inline-asm-constraint-embedded-null.c
new file mode 100644
index 0..e8587e469ba85
--- /dev/null
+++ b/clang/test/Sema/inline-asm-constraint-embedd

[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff origin/main HEAD --extensions cpp,c -- 
clang/test/Sema/inline-asm-constraint-embedded-null.c 
clang/lib/Sema/SemaStmtAsm.cpp --diff_from_common_commit
``

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index f80c1a5b6..96d372c89 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -308,7 +308,7 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 
 if (ConstraintStr.find('\0') != std::string::npos) {
   Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
-  << /*output*/0;
+  << /*output*/ 0;
   return CreateGCCAsmStmt();
 }
 
@@ -404,7 +404,7 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 
 if (ConstraintStr.find('\0') != std::string::npos) {
   Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
-  << /*input*/1;
+  << /*input*/ 1;
   return CreateGCCAsmStmt();
 }
 
@@ -517,7 +517,7 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 
 if (Clobber.find('\0') != std::string::npos) {
   Diag(ClobberExpr->getBeginLoc(), diag::err_asm_constraint_embedded_null)
-  << /*clobber*/2;
+  << /*clobber*/ 2;
   return CreateGCCAsmStmt();
 }
 

``




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


[llvm-branch-commits] [clang] [clang][diagnostics] Reject embedded NUL characters in inline asm (PR #196462)

2026-05-08 Thread Iris Shi via llvm-branch-commits

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

>From fd83d89b6ef8648d765938b3eaaa7b2b3b6922b8 Mon Sep 17 00:00:00 2001
From: Iris Shi <[email protected]>
Date: Fri, 8 May 2026 10:45:03 +0800
Subject: [PATCH 1/3] [clang][diagnostics] Reject embedded NUL characters in
 inline asm constraints and clobbers

---
 clang/docs/ReleaseNotes.rst|  3 +++
 .../include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaStmtAsm.cpp | 18 ++
 .../inline-asm-constraint-embedded-null.c  |  8 
 .../Sema/inline-asm-constraint-embedded-null.c | 16 
 5 files changed, 40 insertions(+), 8 deletions(-)
 delete mode 100644 clang/test/CodeGen/inline-asm-constraint-embedded-null.c
 create mode 100644 clang/test/Sema/inline-asm-constraint-embedded-null.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb19b80b7e994..51e98aef4d251 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -479,6 +479,9 @@ Improvements to Clang's diagnostics
 
 - Removed the body of lambdas from some diagnostic messages.
 
+- Clang now rejects inline asm constraints and clobbers that contain an
+  embedded null character, instead of silently truncating them. (#GH173900)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c69b2ce3648f8..c30ddf445ed65 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10074,6 +10074,9 @@ let CategoryName = "Inline Assembly Issue" in {
 "invalid lvalue in asm input for constraint '%0'">;
   def err_asm_invalid_input_constraint : Error<
 "invalid input constraint '%0' in asm">;
+  def err_asm_constraint_embedded_null : Error<
+"%select{output constraint|input constraint|clobber}0 contains "
+"embedded null character">;
   def err_asm_tying_incompatible_types : Error<
 "unsupported inline asm: input with type "
 "%diff{$ matching output with type $|}0,1">;
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index f957bdf7156c7..96d372c89d2b1 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -306,6 +306,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*output*/ 0;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, OutputName);
 if (!Context.getTargetInfo().validateOutputConstraint(Info) &&
 !(LangOpts.HIPStdPar && LangOpts.CUDAIsDevice)) {
@@ -396,6 +402,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string ConstraintStr =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint);
 
+if (ConstraintStr.find('\0') != std::string::npos) {
+  Diag(Constraint->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*input*/ 1;
+  return CreateGCCAsmStmt();
+}
+
 TargetInfo::ConstraintInfo Info(ConstraintStr, InputName);
 if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
  Info)) {
@@ -503,6 +515,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 std::string Clobber =
 GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(ClobberExpr);
 
+if (Clobber.find('\0') != std::string::npos) {
+  Diag(ClobberExpr->getBeginLoc(), diag::err_asm_constraint_embedded_null)
+  << /*clobber*/ 2;
+  return CreateGCCAsmStmt();
+}
+
 if (!Context.getTargetInfo().isValidClobber(Clobber)) {
   targetDiag(ClobberExpr->getBeginLoc(),
  diag::err_asm_unknown_register_name)
diff --git a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c 
b/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
deleted file mode 100644
index c2cd3ace0ddd3..0
--- a/clang/test/CodeGen/inline-asm-constraint-embedded-null.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// 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)); }
diff --git a/clang/test/Sema/inline-asm-constraint-embedded-null.c 
b/clang/test/Sema/inline-asm-constraint-embedded-null.c
new file mode 100644
index 0..e8587e469ba85
--- /dev/null
+++ b/clang/test/Sema/inline-asm-constraint-em