[clang] [X86] Don't allow '+f' as an inline asm constraint. (PR #113871)

Craig Topper via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 27 23:46:40 PDT 2024


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/113871

f cannot be used as an output constraint. We already errored for '=f' but not '+f'.

Fixes #113692.

>From 48c30e1a7d82c7124abbe6980b0495f6e05a5753 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Sun, 27 Oct 2024 23:44:31 -0700
Subject: [PATCH] [X86] Don't allow '+f' as an inline asm constraint.

f cannot be used as an output constraint. We already errored for
'=f' but not '+f'.

Fixes #113692.
---
 clang/lib/Basic/Targets/X86.cpp | 2 +-
 clang/test/Sema/asm.c           | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index d067ec218b5270..700c2f9a5dbd18 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -1465,7 +1465,7 @@ bool X86TargetInfo::validateAsmConstraint(
     }
   case 'f': // Any x87 floating point stack register.
     // Constraint 'f' cannot be used for output operands.
-    if (Info.ConstraintStr[0] == '=')
+    if (Info.ConstraintStr[0] == '=' || Info.ConstraintStr[0] == '+')
       return false;
     Info.setAllowsRegister();
     return true;
diff --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c
index 6cd95c71604d44..28ef3ec6ce09c2 100644
--- a/clang/test/Sema/asm.c
+++ b/clang/test/Sema/asm.c
@@ -204,6 +204,12 @@ double f_output_constraint(void) {
   return result;
 }
 
+double f_output_constraint_2(void) {
+  double result;
+  __asm("foo1": "+f" (result)); // expected-error {{invalid output constraint '+f' in asm}}
+  return result;
+}
+
 void fn1(void) {
   int l;
   __asm__(""



More information about the cfe-commits mailing list