[X86] When using Win64 ABI, exit with error if SSE is disabled for varargs
authorAmara Emerson <aemerson@apple.com>
Fri, 29 Mar 2019 21:30:51 +0000 (21:30 +0000)
committerAmara Emerson <aemerson@apple.com>
Fri, 29 Mar 2019 21:30:51 +0000 (21:30 +0000)
We need XMM registers to handle varargs with the Win64 ABI. Before we would
silently generate bad code resulting in an assertion failure elsewhere in the
backend.

llvm-svn: 357317

llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/win64-nosse-error.ll [new file with mode: 0644]

index a5691cd..6f9caf1 100644 (file)
@@ -3780,6 +3780,9 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
     } else if (VA.isRegLoc()) {
       RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
       if (isVarArg && IsWin64) {
+        if (!Subtarget.hasSSE1())
+          errorUnsupported(
+              DAG, dl, "Win64 ABI varargs functions require SSE to be enabled");
         // Win64 ABI requires argument XMM reg to be copied to the corresponding
         // shadow reg if callee is a varargs function.
         unsigned ShadowReg = 0;
diff --git a/llvm/test/CodeGen/X86/win64-nosse-error.ll b/llvm/test/CodeGen/X86/win64-nosse-error.ll
new file mode 100644 (file)
index 0000000..0d22adf
--- /dev/null
@@ -0,0 +1,17 @@
+; RUN: not --crash llc %s -mattr="-sse" 2>&1 | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-macho"
+
+; Function Attrs: noimplicitfloat noinline noredzone nounwind optnone
+define void @crash() #0 {
+  call void (i32*, ...) @func(i32* null, double undef)
+  ret void
+}
+; CHECK: in function crash void (): Win64 ABI varargs functions require SSE to be enabled
+; Function Attrs: noimplicitfloat noredzone
+declare void @func(i32*, ...)
+
+attributes #0 = { "target-cpu"="x86-64" "target-features"="-sse"}
+
+