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..2c52ad4fdc8c4fca3503d1936be7993dd783ddd8 |
--- /dev/null |
+++ b/tests/toolchain/stackalign_test.c |
@@ -0,0 +1,33 @@ |
+/* |
+ * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
Mark Seaborn
2014/08/28 19:13:14
Nit: 2014
Derek Schuff
2014/08/28 22:07:24
Done.
|
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include <stdio.h> |
+#include <stdlib.h> |
+ |
+void call_with_misaligned_stack(void (*func)()); |
Mark Seaborn
2014/08/28 19:13:13
"()" -> "(void)"
This is supposed to be getting c
Derek Schuff
2014/08/28 22:07:24
Done.
Nico
2014/08/29 04:34:09
If you find warnings that don't work right in clan
|
+ |
+volatile uintptr_t addrf; |
+ |
+/* |
+ Test that locals are properly aligned, even if functions are called with a |
Mark Seaborn
2014/08/28 19:13:13
Use NaCl comment style
Derek Schuff
2014/08/28 22:07:24
Done.
|
+ 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() { |
Mark Seaborn
2014/08/28 19:13:13
"(void)"
Derek Schuff
2014/08/28 22:07:24
Done.
|
+ double f; |
+ /* Smart compiler will optimize away the test (it assumes the alignment is |
Mark Seaborn
2014/08/28 19:13:14
Nit: Use the NaCl style for multiline comments, wi
Derek Schuff
2014/08/28 22:07:24
Done.
|
+ correct) unless we write it to a volatile. */ |
+ addrf = (uintptr_t) &f; |
+ if(addrf % 8 != 0) abort(); |
Mark Seaborn
2014/08/28 19:13:13
Add space after "if", or better, use ASSERT_EQ(add
Derek Schuff
2014/08/28 22:07:24
Done.
|
+} |
+ |
+int main() { |
Mark Seaborn
2014/08/28 19:13:13
"(void)"
Derek Schuff
2014/08/28 22:07:24
Done.
|
+ printf("Calling testfunc with properly aligned stack\n"); |
+ testfunc(); |
+ printf("Calling testfunc with misaligned stack\n"); |
+ call_with_misaligned_stack(testfunc); |
+} |
Mark Seaborn
2014/08/28 19:13:13
Add "return 0", otherwise the return value in unde
Derek Schuff
2014/08/28 22:07:24
Done.
|