summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/bf-ms-layout-2.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/bf-ms-layout-2.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/bf-ms-layout-2.c')
-rw-r--r--gcc/testsuite/gcc.dg/bf-ms-layout-2.c236
1 files changed, 236 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/bf-ms-layout-2.c b/gcc/testsuite/gcc.dg/bf-ms-layout-2.c
new file mode 100644
index 000000000..0bd472bc1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bf-ms-layout-2.c
@@ -0,0 +1,236 @@
+/* bf-ms-layout.c */
+
+/* Test for MS bitfield layout */
+/* Adapted from Donn Terry <donnte@microsoft.com> testcase
+ posted to GCC-patches
+ http://gcc.gnu.org/ml/gcc-patches/2000-08/msg00577.html */
+
+/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* i?86-*-darwin* } } */
+/* { dg-options "-D_TEST_MS_LAYOUT" } */
+/* This test uses the attribute instead of the command line option. */
+
+#include <stddef.h>
+#include <string.h>
+
+extern void abort();
+
+#pragma pack(8)
+
+#ifdef __GNUC__
+#define ATTR __attribute__ ((ms_struct))
+#endif
+
+struct one {
+ int d;
+ unsigned char a;
+ unsigned short b:7;
+ char c;
+} ATTR;
+
+struct two {
+ int d;
+ unsigned char a;
+ unsigned int b:7;
+ char c;
+} ATTR;
+
+struct three {
+ short d;
+ unsigned short a:3;
+ unsigned short b:9;
+ unsigned char c:7;
+} ATTR;
+
+
+/* Bitfields of size 0 have some truly odd behaviors. */
+
+struct four {
+ unsigned short a:3;
+ unsigned short b:9;
+ unsigned int :0; /* forces struct alignment to int */
+ unsigned char c:7;
+} ATTR;
+
+struct five {
+ char a;
+ int :0; /* ignored; prior field is not a bitfield. */
+ char b;
+ char c;
+} ATTR;
+
+struct six {
+ char a :8;
+ int :0; /* not ignored; prior field IS a bitfield, causes
+ struct alignment as well. */
+ char b;
+ char c;
+} ATTR;
+
+struct seven {
+ char a:8;
+ char :0;
+ int :0; /* Ignored; prior field is zero size bitfield. */
+ char b;
+ char c;
+} ATTR;
+
+struct eight { /* ms size 4 */
+ short b:3;
+ char c;
+} ATTR;
+
+#ifdef _MSC_VER
+#define LONGLONG __int64
+#else
+#define LONGLONG long long
+#endif
+
+union nine { /* ms size 8 */
+ LONGLONG a:3;
+ char c;
+} ATTR;
+
+struct ten { /* ms size 16 */
+ LONGLONG a:3;
+ LONGLONG b:3;
+ char c;
+} ATTR;
+
+
+#define val(s,f) (s.f)
+
+#define check_struct(_X) \
+{ \
+ if (sizeof (struct _X) != exp_sizeof_##_X ) \
+ abort(); \
+ memcpy(&test_##_X, filler, sizeof(test_##_X));\
+ if (val(test_##_X,c) != exp_##_X##_c) \
+ abort(); \
+}
+
+#define check_union(_X) \
+{ \
+ if (sizeof (union _X) != exp_sizeof_##_X ) \
+ abort(); \
+ memcpy(&test_##_X, filler, sizeof(test_##_X));\
+ if (val(test_##_X,c) != exp_##_X##_c) \
+ abort(); \
+}
+
+#define check_struct_size(_X) \
+{ \
+ if (sizeof (struct _X) != exp_sizeof_##_X ) \
+ abort(); \
+}
+
+#define check_struct_off(_X) \
+{ \
+ memcpy(&test_##_X, filler, sizeof(test_##_X));\
+ if (val(test_##_X,c) != exp_##_X##_c) \
+ abort(); \
+}
+
+#define check_union_size(_X) \
+{ \
+ if (sizeof (union _X) != exp_sizeof_##_X ) \
+ abort(); \
+}
+
+#define check_union_off(_X) \
+{ \
+ memcpy(&test_##_X, filler, sizeof(test_##_X));\
+ if (val(test_##_X,c) != exp_##_X##_c) \
+ abort(); \
+}
+
+int main(){
+
+ unsigned char filler[16];
+ struct one test_one;
+ struct two test_two;
+ struct three test_three;
+ struct four test_four;
+ struct five test_five;
+ struct six test_six;
+ struct seven test_seven;
+ struct eight test_eight;
+ union nine test_nine;
+ struct ten test_ten;
+
+#if defined (_TEST_MS_LAYOUT) || defined (_MSC_VER)
+ size_t exp_sizeof_one = 12;
+ size_t exp_sizeof_two = 16;
+ size_t exp_sizeof_three =6;
+ size_t exp_sizeof_four = 8;
+ size_t exp_sizeof_five = 3;
+ size_t exp_sizeof_six = 8;
+ size_t exp_sizeof_seven = 3;
+ size_t exp_sizeof_eight = 4;
+ size_t exp_sizeof_nine = 8;
+ size_t exp_sizeof_ten = 16;
+
+ unsigned char exp_one_c = 8;
+ unsigned char exp_two_c = 12;
+ unsigned char exp_three_c = 4;
+ unsigned char exp_four_c = 4;
+ char exp_five_c = 2;
+ char exp_six_c = 5;
+ char exp_seven_c = 2;
+ char exp_eight_c = 2;
+ char exp_nine_c = 0;
+ char exp_ten_c = 8;
+
+#else /* testing -mno-ms-bitfields */
+
+ size_t exp_sizeof_one = 8;
+ size_t exp_sizeof_two = 8;
+ size_t exp_sizeof_three = 6;
+ size_t exp_sizeof_four = 6;
+ size_t exp_sizeof_five = 6;
+ size_t exp_sizeof_six = 6;
+ size_t exp_sizeof_seven = 6;
+ size_t exp_sizeof_eight = 2;
+ size_t exp_sizeof_nine = 8;
+ size_t exp_sizeof_ten = 8;
+
+ unsigned short exp_one_c = 6;
+ unsigned int exp_two_c = 6;
+ unsigned char exp_three_c = 64;
+ unsigned char exp_four_c = 4;
+ char exp_five_c = 5;
+ char exp_six_c = 5;
+ char exp_seven_c = 5;
+ char exp_eight_c = 1;
+ char exp_nine_c = 0;
+ char exp_ten_c = 1;
+
+#endif
+
+ unsigned char i;
+ for ( i = 0; i < 16; i++ )
+ filler[i] = i;
+
+ check_struct_off (one);
+ check_struct_off (two);
+ check_struct_off (three);
+ check_struct_off (four);
+ check_struct_off (five);
+ check_struct_off (six);
+ check_struct_off (seven);
+ check_struct_off (eight);
+ check_union_off (nine);
+ check_struct_off (ten);
+
+ check_struct_size (one);
+ check_struct_size (two);
+ check_struct_size (three);
+ check_struct_size (four);
+ check_struct_size (five);
+ check_struct_size (six);
+ check_struct_size (seven);
+ check_struct_size (eight);
+ check_union_size (nine);
+ check_struct_size (ten);
+
+ return 0;
+};