1
#line 1 "test-alignment.c"
2
/*===========================================================================
3
* Filename : test-alignment.c
4
* About : unit test for alignment on stack
6
* Copyright (C) 2006 YAMAMOTO Kengo <yamaken AT bp.iij4u.or.jp>
7
* Copyright (c) 2007 SigScheme Project <uim AT freedesktop.org>
11
* Redistribution and use in source and binary forms, with or without
12
* modification, are permitted provided that the following conditions
15
* 1. Redistributions of source code must retain the above copyright
16
* notice, this list of conditions and the following disclaimer.
17
* 2. Redistributions in binary form must reproduce the above copyright
18
* notice, this list of conditions and the following disclaimer in the
19
* documentation and/or other materials provided with the distribution.
20
* 3. Neither the name of authors nor the names of its contributors
21
* may be used to endorse or promote products derived from this software
22
* without specific prior written permission.
24
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
25
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
28
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
===========================================================================*/
37
#include "sscm-test.h"
39
#define MSG(offs, exp) ("offset " #offs ": " #exp)
41
#define TEST_ALIGNMENT(od, offs) \
42
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.i % ALIGNOF_INT, \
44
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.l % ALIGNOF_LONG, \
46
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.p % ALIGNOF_VOID_P, \
48
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.cp.p % ALIGNOF_VOID_P, \
49
MSG(offs, {char; void *p;}.p)); \
50
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.sp.p % ALIGNOF_VOID_P, \
51
MSG(offs, {short; void *p;}.p)); \
52
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.c3p.p % ALIGNOF_VOID_P, \
53
MSG(offs, {char[3]; void *p;}.p)); \
54
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.ip.p % ALIGNOF_VOID_P, \
55
MSG(offs, {int; void *p;}.p)); \
56
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.c5p.p % ALIGNOF_VOID_P, \
57
MSG(offs, {char[5]; void *p;}.p)); \
58
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.lp.p % ALIGNOF_VOID_P, \
59
MSG(offs, {long; void *p;}.p)); \
60
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.qp.p % ALIGNOF_VOID_P, \
61
MSG(offs, {int64_t; void *p;}.p)); \
62
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.i32p.p % ALIGNOF_VOID_P, \
63
MSG(offs, {int32_t; void *p;}.p)); \
64
TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.c9p.p % ALIGNOF_VOID_P, \
65
MSG(offs, {char[9]; void *p;}.p))
105
/* for LLP64 pointer alignment check */
111
/* for LP64 pointer alignment check */
123
union offsettable_data {
169
TST_CASE(tst_1, "stack alignment all")
171
union offsettable_data od;
173
TEST_ALIGNMENT(od, 0);
174
TEST_ALIGNMENT(od, 1);
175
TEST_ALIGNMENT(od, 2);
176
TEST_ALIGNMENT(od, 3);
177
TEST_ALIGNMENT(od, 4);
178
TEST_ALIGNMENT(od, 5);
179
TEST_ALIGNMENT(od, 6);
180
TEST_ALIGNMENT(od, 7);
181
TEST_ALIGNMENT(od, 8);