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

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 28 13:20:50 PDT 2024


Author: Craig Topper
Date: 2024-10-28T13:20:46-07:00
New Revision: 7bd8a165f95123e390f9cbb0a6a5e60d835a4461

URL: https://github.com/llvm/llvm-project/commit/7bd8a165f95123e390f9cbb0a6a5e60d835a4461
DIFF: https://github.com/llvm/llvm-project/commit/7bd8a165f95123e390f9cbb0a6a5e60d835a4461.diff

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

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

Fixes #113692.

Added: 
    

Modified: 
    clang/lib/Basic/Targets/X86.cpp
    clang/test/Sema/asm.c

Removed: 
    


################################################################################
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