summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-06-18 09:15:04 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-06-18 09:15:04 +0000
commit457dfbac8ac1e502f5ce2b86daa80b3c7db5bd08 (patch)
tree2835e5586f76749c379fce51c80969cc450ea23a /test
parent43369249e7c2be91535e3ef900673e6116a953de (diff)
downloadllvm-457dfbac8ac1e502f5ce2b86daa80b3c7db5bd08.tar.gz
llvm-457dfbac8ac1e502f5ce2b86daa80b3c7db5bd08.tar.bz2
llvm-457dfbac8ac1e502f5ce2b86daa80b3c7db5bd08.tar.xz
Add a regression test for the bug exposed by r158087, which has been
temporarily reverted. This test is annoyingly overspecified, but I don't know of another way to thoroughly test the saving and restoring of the registers. While this will have to be adjusted even with the issue fixed in order to re-apply r158087, those adjustments should very clearly indicate that it is still correct (%esp getting restored prior to pops), whereas without it, this case can easily slip under the radar. Still, any suggestions for improvements are very welcome. All credit to Matt Beaumont-Gay for reducing this out of an insane Address Sanitizer crash to a reasonably small seg-faulting C program when built with -mstackrealign. I just reduced it to IR, which was much simpler. =] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158656 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/CodeGen/X86/force-align-stack-alloca.ll63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/CodeGen/X86/force-align-stack-alloca.ll b/test/CodeGen/X86/force-align-stack-alloca.ll
new file mode 100644
index 0000000000..48f963f58e
--- /dev/null
+++ b/test/CodeGen/X86/force-align-stack-alloca.ll
@@ -0,0 +1,63 @@
+; This test is attempting to detect when we request forced re-alignment of the
+; stack to an alignment greater than would be available due to the ABI. We
+; arbitrarily force alignment up to 32-bytes for i386 hoping that this will
+; exceed any ABI provisions.
+;
+; RUN: llc < %s -force-align-stack -stack-alignment=32 | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
+target triple = "i386-unknown-linux-gnu"
+
+define i32 @f(i8* %p) nounwind {
+entry:
+ %0 = load i8* %p
+ %conv = sext i8 %0 to i32
+ ret i32 %conv
+}
+
+define i64 @g(i32 %i) nounwind {
+; CHECK: g:
+; CHECK: pushl
+; CHECK-NEXT: movl %esp, %ebp
+; CHECK-NEXT: pushl
+; CHECK-NEXT: subl $20, %esp
+; CHECK-NOT: {{[^ ,]*}}, %esp
+;
+; The next adjustment of the stack is due to the alloca.
+; CHECK: movl %{{...}}, %esp
+; CHECK-NOT: {{[^ ,]*}}, %esp
+;
+; Next we set up the memset call, and then undo it.
+; CHECK: subl $32, %esp
+; CHECK-NOT: {{[^ ,]*}}, %esp
+; CHECK: calll memset
+; CHECK-NEXT: addl $32, %esp
+; CHECK-NOT: {{[^ ,]*}}, %esp
+;
+; Next we set up the call to 'f'.
+; CHECK: subl $32, %esp
+; CHECK-NOT: {{[^ ,]*}}, %esp
+; CHECK: calll f
+; CHECK-NEXT: addl $32, %esp
+; CHECK-NOT: {{[^ ,]*}}, %esp
+;
+; Finally we nede to restore %esp from %ebp, the alloca prevents us from
+; restoring it directly.
+; CHECK-NOT: popl
+; CHECK: leal -4(%ebp), %esp
+; CHECK-NEXT: popl
+; CHECK-NEXT: popl
+; CHECK-NEXT: ret
+
+entry:
+ br label %if.then
+
+if.then:
+ %0 = alloca i8, i32 %i
+ call void @llvm.memset.p0i8.i32(i8* %0, i8 0, i32 %i, i32 1, i1 false)
+ %call = call i32 @f(i8* %0)
+ %conv = sext i32 %call to i64
+ ret i64 %conv
+}
+
+declare void @llvm.memset.p0i8.i32(i8*, i8, i32, i32, i1) nounwind