Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Oct 28, 2024

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

Fixes #113692.

@topperc topperc requested review from RKSimon and phoebewang October 28, 2024 06:46
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 28, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 28, 2024

@llvm/pr-subscribers-clang

Author: Craig Topper (topperc)

Changes

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

Copy link
Contributor

@phoebewang phoebewang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

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

Fixes llvm#113692.
@topperc topperc merged commit 7bd8a16 into llvm:main Oct 28, 2024
8 checks passed
@topperc topperc deleted the pr/inline-asm-x86 branch October 28, 2024 20:20
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
f cannot be used as an output constraint. We already errored for '=f'
but not '+f'.

Fixes llvm#113692.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clang crashes on x86_64-linux-gnu: cannot pop empty stack
4 participants