Ignore stack adjustment for ebp-based variables.

The TargetX8632 class maintains a "current stack adjustment" during a push sequence, so that pushing or otherwise accessing stack locations during a function arg push sequence can use the right esp offset.

This adjustment should only be used for esp-based frames, but it was being used for ebp-based frames as well, causing the wrong stack-based arguments to be pushed.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=3878
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/331743002
diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp
index 81973d0..46a587f 100644
--- a/src/IceTargetLoweringX8632.cpp
+++ b/src/IceTargetLoweringX8632.cpp
@@ -390,7 +390,9 @@
   }
   Str << InstX8632::getWidthString(Var->getType());
   Str << " [" << getRegName(getFrameOrStackReg(), IceType_i32);
-  int32_t Offset = Var->getStackOffset() + getStackAdjustment();
+  int32_t Offset = Var->getStackOffset();
+  if (!hasFramePointer())
+    Offset += getStackAdjustment();
   if (Offset) {
     if (Offset > 0)
       Str << "+";
diff --git a/tests_lit/llvm2ice_tests/ebp_args.ll b/tests_lit/llvm2ice_tests/ebp_args.ll
new file mode 100644
index 0000000..e7acd50
--- /dev/null
+++ b/tests_lit/llvm2ice_tests/ebp_args.ll
@@ -0,0 +1,39 @@
+; This test originally exhibited a bug in ebp-based stack slots.  The
+; problem was that during a function call push sequence, the esp
+; adjustment was incorrectly added to the stack/frame offset for
+; ebp-based frames.
+
+; RUN: %llvm2ice -Om1 --target=x8632 --verbose none %s | FileCheck %s
+
+declare i32 @memcpy_helper2(i32 %buf, i32 %buf2, i32 %n);
+
+define i32 @memcpy_helper(i32 %buf, i32 %n) {
+entry:
+  %n.arg_trunc = trunc i32 %n to i8
+  %buf2 = alloca i8, i32 128, align 4
+  %buf2.asint = ptrtoint i8* %buf2 to i32
+  %arg_ext = zext i8 %n.arg_trunc to i32
+  %call = call i32 @memcpy_helper2(i32 %buf, i32 %buf2.asint, i32 %arg_ext)
+  ret i32 %call
+}
+
+; This check sequence is highly specific to the current Om1 lowering
+; and stack slot assignment code, and may need to be relaxed if the
+; lowering code changes.
+
+; CHECK: memcpy_helper:
+; CHECK: push     ebp
+; CHECK: mov      ebp, esp
+; CHECK: sub      esp, 20
+; CHECK: mov      eax, dword ptr [ebp+12]
+; CHECK: mov      dword ptr [ebp-4], eax
+; CHECK: sub      esp, 128
+; CHECK: mov      dword ptr [ebp-8], esp
+; CHECK: mov      eax, dword ptr [ebp-8]
+; CHECK: mov      dword ptr [ebp-12], eax
+; CHECK: movzx    eax, byte ptr [ebp-4]
+; CHECK: mov      dword ptr [ebp-16], eax
+; CHECK: push     dword ptr [ebp-16]
+; CHECK: push     dword ptr [ebp-12]
+; CHECK: push     dword ptr [ebp+8]
+; CHECK: call     memcpy_helper2