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

via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 27 23:47:20 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Craig Topper (topperc)

<details>
<summary>Changes</summary>

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

Fixes #<!-- -->113692.

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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/X86.cpp (+1-1) 
- (modified) clang/test/Sema/asm.c (+6) 


``````````diff
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__(""

``````````

</details>


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


More information about the cfe-commits mailing list