[PATCH] D27304: [PATCH] [Sema][X86] Don't allow floating-point return types when SSE is disabled

Visoiu Mistrih Francis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 1 08:53:21 PST 2016


thegameg created this revision.
thegameg added reviewers: craig.topper, majnemer.
thegameg added a subscriber: cfe-commits.

The following program hits a fatal_error in the X86 backend, when the
program is compiled with -mno-sse or -mno-sse2, which is understandable
due to the calling convention:

> float f() { return 0.5f; };

since the error occurs in the backend, there are stack traces and bug
report messages that are generated.

This patch allows the compiler to avoid crashing and check in advance if
the code can be generated properly.

- include/clang/Basic/DiagnosticSemaKinds.td: Add the error.
- lib/Sema/SemaChecking.cpp: Check if the function returns a floating-point type.


https://reviews.llvm.org/D27304

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp


Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -2474,6 +2474,17 @@
         CheckArgumentWithTypeTag(I, Args.data());
     }
   }
+
+  // Don't allow calls returning floating point scalars when
+  // target == x86_64 && SSE disabled.
+  if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86_64 &&
+      (!Context.getTargetInfo().hasFeature("sse") ||
+       !Context.getTargetInfo().hasFeature("sse2"))) {
+    if (auto *ResultType = Proto->getReturnType().getTypePtrOrNull()) {
+      if (ResultType->isRealFloatingType())
+        Diag(Loc, diag::err_x86_sse_register);
+    }
+  }
 }
 
 /// CheckConstructorCall - Check a constructor call for correctness and safety
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7840,6 +7840,8 @@
   "this builtin is only available on x86-64 targets">;
 def err_x86_builtin_invalid_rounding : Error<
   "invalid rounding argument">;
+def err_x86_sse_register : Error<
+  "SSE register return with SSE disabled">;
 
 def err_builtin_longjmp_unsupported : Error<
   "__builtin_longjmp is not supported for the current target">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27304.79914.patch
Type: text/x-patch
Size: 1367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161201/56de058f/attachment.bin>


More information about the cfe-commits mailing list