Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Unified Diff: tests/toolchain/stackalign_test.c

Issue 508823007: Expose LLC's -force-align-stack flag to pnacl-translate (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: review Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/toolchain/nacl.scons ('k') | toolchain_build/toolchain_build_pnacl.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/toolchain/stackalign_test.c
diff --git a/tests/toolchain/stackalign_test.c b/tests/toolchain/stackalign_test.c
new file mode 100644
index 0000000000000000000000000000000000000000..c84226aa47c56ed527a6c1ccac43d94aae9e286c
--- /dev/null
+++ b/tests/toolchain/stackalign_test.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2014 The Native Client Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <stdio.h>
+
+#include "native_client/src/include/nacl_assert.h"
+
+void call_with_misaligned_stack(void (*func)(void));
+
+volatile uintptr_t addrf;
+
+/*
+ * Test that locals are properly aligned, even if functions are called with a
+ * misaligned stack. This tests the effect of LLC's -force-align-stack (and also
+ * the fact that doubles must be 8-byte aligned). This test should only pass
+ * when using a flag that forces stack realignment.
+*/
+void testfunc(void) {
+ double f;
+ /*
+ * Smart compiler will optimize away the test (it assumes the alignment is
+ * correct) unless we write it to a volatile.
+ */
+ addrf = (uintptr_t) &f;
+ ASSERT_EQ(addrf % 8, 0);
+}
+
+int main(void) {
+ printf("Calling testfunc with properly aligned stack\n");
+ testfunc();
+ printf("Calling testfunc with misaligned stack\n");
+ call_with_misaligned_stack(testfunc);
+ return 0;
+}
« no previous file with comments | « tests/toolchain/nacl.scons ('k') | toolchain_build/toolchain_build_pnacl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698