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

2016-12-01 Thread Visoiu Mistrih Francis via Phabricator via cfe-commits
thegameg added a comment.

In https://reviews.llvm.org/D27304#610697, @joerg wrote:

> I think this is the absolutely wrong place to put such logic. It really can 
> not be anywhere but the backend.


I am aware of this. But the way the backend informs the Diagnostics looks like 
a crash, and asks for a bug report.

Are there any proper ways to inform the frontend about backend errors?


https://reviews.llvm.org/D27304



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-12-01 Thread Visoiu Mistrih Francis via Phabricator via cfe-commits
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">;


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">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits