[clang] 4a2c827 - [X86][clang] Emit diagnostic for float and double when we have features -x87 and -sse on 64-bits

Phoebe Wang via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 7 17:50:35 PST 2021


Author: Phoebe Wang
Date: 2021-12-08T09:50:26+08:00
New Revision: 4a2c827b178f89d4cdeb56153d9440ad4ba786a3

URL: https://github.com/llvm/llvm-project/commit/4a2c827b178f89d4cdeb56153d9440ad4ba786a3
DIFF: https://github.com/llvm/llvm-project/commit/4a2c827b178f89d4cdeb56153d9440ad4ba786a3.diff

LOG: [X86][clang] Emit diagnostic for float and double when we have features -x87 and -sse on 64-bits

A follow up of D114162.

Reviewed By: asavonic

Differential Revision: https://reviews.llvm.org/D114782

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticSemaKinds.td
    clang/lib/Basic/Targets/X86.cpp
    clang/lib/Sema/Sema.cpp
    clang/test/CodeGen/X86/x86_64-mno-sse.c
    clang/test/Sema/x86_64-no-x87.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2ab99f5f4c9e2..a5312f9ba55ec 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10731,6 +10731,8 @@ def err_omp_wrong_dependency_iterator_type : Error<
 def err_target_unsupported_type
     : Error<"%0 requires %select{|%2 bit size}1 %3 %select{|return }4type support,"
             " but target '%5' does not support it">;
+def err_target_unsupported_type_without_sse : Error<
+  "SSE register return with SSE disabled">;
 def err_omp_lambda_capture_in_declare_target_not_to : Error<
   "variable captured in declare target region must appear in a to clause">;
 def err_omp_device_type_mismatch : Error<

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 5c4bd364b06a3..bf5481a1e03d7 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -387,6 +387,9 @@ bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
   if (!HasX87 && LongDoubleFormat == &llvm::APFloat::x87DoubleExtended())
     HasLongDouble = false;
 
+  if (SSELevel < SSE1 && getTriple().getArch() == llvm::Triple::x86_64)
+    HasFPReturn = false;
+
   return true;
 }
 

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 734ed0f62ec65..96f3d648dc7c7 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1957,15 +1957,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
     bool IsDouble = UnqualTy == Context.DoubleTy;
     bool IsFloat = UnqualTy == Context.FloatTy;
     if (IsRetTy && !TI.hasFPReturn() && (IsDouble || IsFloat)) {
-      PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
-      if (D)
-        PD << D;
-      else
-        PD << "expression";
-
-      if (Diag(Loc, PD, FD)
-          << false /*show bit size*/ << 0 << Ty << true /*return*/
-          << Context.getTargetInfo().getTriple().str()) {
+      if (Diag(Loc, diag::err_target_unsupported_type_without_sse)) {
         if (D)
           D->setInvalidDecl();
       }

diff  --git a/clang/test/CodeGen/X86/x86_64-mno-sse.c b/clang/test/CodeGen/X86/x86_64-mno-sse.c
index 43a695ae3cd3d..ec9995c929256 100644
--- a/clang/test/CodeGen/X86/x86_64-mno-sse.c
+++ b/clang/test/CodeGen/X86/x86_64-mno-sse.c
@@ -1,15 +1,16 @@
 // RUN: %clang_cc1 -triple x86_64-linux -target-feature -sse -target-feature -sse2 -S -o /dev/null -verify %s
 // REQUIRES: x86-registered-target
 
-double f1(void) { // expected-error {{SSE register return with SSE disabled}}
+// expected-error at +2{{SSE register return with SSE disabled}}
+// expected-note at +1{{'f1' defined here}}
+double f1(void) {
   return 1.4;
 }
 extern double g;
-void f2(void) { // expected-error {{SSE register return with SSE disabled}}
+void f2(void) {
   g = f1();
 }
 void take_double(double);
 void pass_double(void) {
-  // FIXME: Still asserts.
-  //take_double(1.5);
+  take_double(1.5);
 }

diff  --git a/clang/test/Sema/x86_64-no-x87.cpp b/clang/test/Sema/x86_64-no-x87.cpp
index b47e69e4b350c..a89c1ff7de93f 100644
--- a/clang/test/Sema/x86_64-no-x87.cpp
+++ b/clang/test/Sema/x86_64-no-x87.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-linux-gnu -target-feature -x87
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-linux-gnu -target-feature -x87 -target-feature -sse -DERROR_LONGDOUBLE -DERROR_NOSSE
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-linux-gnu -target-feature -x87 -DERROR_LONGDOUBLE
 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-linux-gnu -DNOERROR
 
 #ifdef NOERROR
@@ -18,45 +19,45 @@ long_double decl_ld_del(long_double) = delete;
 double decl_ld_del(double) = delete;
 float decl_ld_del(float) = delete;
 
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
 // expected-error at +4{{'def' requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
 // expected-note at +3{{'def' defined here}}
 // expected-note at +2{{'x' defined here}}
 #endif
 int def(long_double x) {
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
 // expected-error at +2{{'x' requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
 #endif
   return (int)x;
 }
 
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
 // expected-note at +3{{'ld_args' defined here}}
 // expected-note at +2{{'ld_args' defined here}}
 #endif
 int ld_args(long_double x, long_double y);
 
 int call1(float x, float y) {
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
   // expected-error at +2 2{{'ld_args' requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
 #endif
   return ld_args(x, y);
 }
 
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
 // expected-note at +2{{'ld_ret' defined here}}
 #endif
 long_double ld_ret(double x, double y);
 
 int call2(float x, float y) {
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
   // expected-error at +2{{'ld_ret' requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
 #endif
   return (int)ld_ret(x, y);
 }
 
 int binop(double x, double y) {
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
   // expected-error at +2 2{{expression requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
 #endif
   double z = (long_double)x * (long_double)y;
@@ -64,28 +65,28 @@ int binop(double x, double y) {
 }
 
 void assign1(long_double *ret, double x) {
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
   // expected-error at +2{{expression requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
 #endif
   *ret = x;
 }
 
 struct st_long_double1 {
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
   // expected-note at +2{{'ld' defined here}}
 #endif
   long_double ld;
 };
 
 struct st_long_double2 {
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
   // expected-note at +2{{'ld' defined here}}
 #endif
   long_double ld;
 };
 
 struct st_long_double3 {
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
   // expected-note at +2{{'ld' defined here}}
 #endif
   long_double ld;
@@ -93,7 +94,7 @@ struct st_long_double3 {
 
 void assign2() {
   struct st_long_double1 st;
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
   // expected-error at +3{{expression requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
   // expected-error at +2{{'ld' requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
 #endif
@@ -102,7 +103,7 @@ void assign2() {
 
 void assign3() {
   struct st_long_double2 st;
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
   // expected-error at +3{{expression requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
   // expected-error at +2{{'ld' requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
 #endif
@@ -111,7 +112,7 @@ void assign3() {
 
 void assign4(double d) {
   struct st_long_double3 st;
-#ifndef NOERROR
+#ifdef ERROR_LONGDOUBLE
   // expected-error at +3{{expression requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
   // expected-error at +2{{'ld' requires  'long_double' (aka 'long double') type support, but target 'x86_64-unknown-linux-gnu' does not support it}}
 #endif
@@ -124,22 +125,42 @@ void assign5() {
 }
 
 // Double and Float return type on x86_64 do not use x87 registers
+#ifdef ERROR_NOSSE
+  // expected-error at +3{{SSE register return with SSE disabled}}
+  // expected-note at +2{{'d_ret1' defined here}}
+#endif
 double d_ret1(float x) {
   return 0.0;
 }
 
+#ifdef ERROR_NOSSE
+  // expected-note at +2{{'d_ret2' defined here}}
+#endif
 double d_ret2(float x);
 
+#ifdef ERROR_NOSSE
+  // expected-error at +3{{SSE register return with SSE disabled}}
+#endif
 int d_ret3(float x) {
   return (int)d_ret2(x);
 }
 
+#ifdef ERROR_NOSSE
+  // expected-error at +3{{SSE register return with SSE disabled}}
+  // expected-note at +2{{'f_ret1' defined here}}
+#endif
 float f_ret1(float x) {
   return 0.0f;
 }
 
+#ifdef ERROR_NOSSE
+  // expected-note at +2{{'f_ret2' defined here}}
+#endif
 float f_ret2(float x);
 
+#ifdef ERROR_NOSSE
+  // expected-error at +3{{SSE register return with SSE disabled}}
+#endif
 int f_ret3(float x) {
   return (int)f_ret2(x);
 }


        


More information about the cfe-commits mailing list