summaryrefslogtreecommitdiff
path: root/test/CodeGen
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2014-01-31 17:41:22 +0000
committerReid Kleckner <reid@kleckner.net>2014-01-31 17:41:22 +0000
commit65c98b9da474d0562f883d6001f31ba5b2b95183 (patch)
tree18a2b8a062180aa9b4f289b5caa8db5e1d7aa061 /test/CodeGen
parent0cb94d9adc631eafa88218a5e972d45e0cf35f61 (diff)
downloadllvm-65c98b9da474d0562f883d6001f31ba5b2b95183.tar.gz
llvm-65c98b9da474d0562f883d6001f31ba5b2b95183.tar.bz2
llvm-65c98b9da474d0562f883d6001f31ba5b2b95183.tar.xz
[ms-cxxabi] Add a new calling convention that swaps 'this' and 'sret'
MSVC always places the 'this' parameter for a method first. The implicit 'sret' pointer for methods always comes second. We already implement this for __thiscall by putting sret parameters on the stack, but __cdecl methods require putting both parameters on the stack in opposite order. Using a special calling convention allows frontends to keep the sret parameter first, which avoids breaking lots of assumptions in LLVM and Clang. Fixes PR15768 with the corresponding change in Clang. Reviewers: ributzka, majnemer Differential Revision: http://llvm-reviews.chandlerc.com/D2663 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200561 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen')
-rw-r--r--test/CodeGen/X86/cdecl-method-return.ll69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/CodeGen/X86/cdecl-method-return.ll b/test/CodeGen/X86/cdecl-method-return.ll
new file mode 100644
index 0000000000..e7af59737e
--- /dev/null
+++ b/test/CodeGen/X86/cdecl-method-return.ll
@@ -0,0 +1,69 @@
+; RUN: llc < %s -mtriple=i686-pc-win32 | FileCheck %s
+
+; The sret flag causes the first two parameters to be reordered on the stack.
+
+define x86_cdeclmethodcc void @foo(i32* sret %dst, i32* %src) {
+ %v = load i32* %src
+ store i32 %v, i32* %dst
+ ret void
+}
+
+; CHECK-LABEL: _foo:
+; CHECK: movl 8(%esp), %[[dst:[^ ]*]]
+; CHECK: movl 4(%esp), %[[src:[^ ]*]]
+; CHECK: movl (%[[src]]), %[[v:[^ ]*]]
+; CHECK: movl %[[v]], (%[[dst]])
+; CHECK: retl
+
+define i32 @bar() {
+ %src = alloca i32
+ %dst = alloca i32
+ store i32 42, i32* %src
+ call x86_cdeclmethodcc void @foo(i32* sret %dst, i32* %src)
+ %v = load i32* %dst
+ ret i32 %v
+}
+
+; CHECK-LABEL: _bar:
+; CHECK: movl $42, [[src:[^,]*]]
+; CHECK: leal [[src]], %[[reg:[^ ]*]]
+; CHECK: movl %[[reg]], (%esp)
+; CHECK: leal [[dst:[^,]*]], %[[reg:[^ ]*]]
+; CHECK: movl %[[reg]], 4(%esp)
+; CHECK: calll _foo
+; CHECK: movl [[dst]], %eax
+; CHECK: retl
+
+; If we don't have the sret flag, parameters are not reordered.
+
+define x86_cdeclmethodcc void @baz(i32* %dst, i32* %src) {
+ %v = load i32* %src
+ store i32 %v, i32* %dst
+ ret void
+}
+
+; CHECK-LABEL: _baz:
+; CHECK: movl 4(%esp), %[[dst:[^ ]*]]
+; CHECK: movl 8(%esp), %[[src:[^ ]*]]
+; CHECK: movl (%[[src]]), %[[v:[^ ]*]]
+; CHECK: movl %[[v]], (%[[dst]])
+; CHECK: retl
+
+define i32 @qux() {
+ %src = alloca i32
+ %dst = alloca i32
+ store i32 42, i32* %src
+ call x86_cdeclmethodcc void @baz(i32* %dst, i32* %src)
+ %v = load i32* %dst
+ ret i32 %v
+}
+
+; CHECK-LABEL: _qux:
+; CHECK: movl $42, [[src:[^,]*]]
+; CHECK: leal [[src]], %[[reg:[^ ]*]]
+; CHECK: movl %[[reg]], 4(%esp)
+; CHECK: leal [[dst:[^,]*]], %[[reg:[^ ]*]]
+; CHECK: movl %[[reg]], (%esp)
+; CHECK: calll _baz
+; CHECK: movl [[dst]], %eax
+; CHECK: retl