Hi,
kernel/tests/generated.c currently shows one failure when the executable is compiled with MinGW. Investigation shows that MinGW and GCC differ when it comes to alignment of doubles (i.e. a 64 bit wide type).
I have constructed the test below that shows the difference between MinGW and GCC. My question is, could someone compile this with MSVC >= 6, run it, and report the outcome here?
Thanks,
-Hans
"Hans Leidekker" hans@it.vu.nl wrote:
kernel/tests/generated.c currently shows one failure when the executable is compiled with MinGW. Investigation shows that MinGW and GCC differ when it comes to alignment of doubles (i.e. a 64 bit wide type).
I have constructed the test below that shows the difference between MinGW and GCC. My question is, could someone compile this with MSVC >= 6, run it, and report the outcome here?
I had to add #include <windows.h> as the very first line to make it compile.
C:>cl Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
C:>align.exe Alignment of __int64: 8 Size of __int64: 8 Alignment of large_int: 8 Size of large_int: 8 Alignment of container1: 8 Size of container1: 16 Alignment of container2: 8 Size of container2: 16 Alignment of container3: 8 Size of container3: 8
Hi,
[Use a fixed width font to view this message]
MSVC MinGW GCC
Alignment of __int64: 8 8 8 Size of __int64: 8 8 8
Alignment of large_int: 8 8 4 Size of large_int: 8 8 8
Alignment of container1: 8 8 4 Size of container1: 16 16 12
Alignment of container2: 8 8 4 Size of container2: 16 16 12
Alignment of container3: 8 8 4 Size of container3: 8 8 8
Clearly GCC is the odd one out. When a double is embedded in a structure GCC does not adjust the alignment of the structure to the size of a double.
So, should we add -malign-double to the compiler flags?
-Hans
Hans Leidekker hans@it.vu.nl writes:
Clearly GCC is the odd one out. When a double is embedded in a structure GCC does not adjust the alignment of the structure to the size of a double.
So, should we add -malign-double to the compiler flags?
No, that would break Unix compatibility. We have to explicitly pad the structures that need it.
"Hans Leidekker" hans@it.vu.nl wrote:
[Use a fixed width font to view this message]
MSVC MinGW GCC
Alignment of __int64: 8 8 8 Size of __int64: 8 8 8
Alignment of large_int: 8 8 4 Size of large_int: 8 8 8
Alignment of container1: 8 8 4 Size of container1: 16 16 12
Alignment of container2: 8 8 4 Size of container2: 16 16 12
Alignment of container3: 8 8 4 Size of container3: 8 8 8
Clearly GCC is the odd one out. When a double is embedded in a structure GCC does not adjust the alignment of the structure to the size of a double.
So, should we add -malign-double to the compiler flags?
After another inspection of Wine's dlls/kernel/tests/generated.c I think that MSVC case was actually never tested!
Here is an example of the code:
#if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus) # define FIELD_ALIGNMENT(type, field) __alignof(((type*)0)->field) #elif defined(__GNUC__) # define FIELD_ALIGNMENT(type, field) __alignof__(((type*)0)->field) #else /* FIXME: Not sure if is possible to do without compiler extension */ #endif
I don't know what version of MS cl.exe has _MSC_VER >= 1300, but one that comes with Visual Studio 6.0 has _MSC_VER set to 1200. Moreover, since the test is a .c file __cplusplus is never defined, therefore FIELD_ALIGNMENT is not defined by the above code and later in that file we have:
#ifdef FIELD_ALIGNMENT # define TEST_FIELD_ALIGNMENT(type, field, align) \ ok(FIELD_ALIGNMENT(type, field) == align, \ "FIELD_ALIGNMENT(" #type ", " #field ") == %d (expected " #align ")\n", \ FIELD_ALIGNMENT(type, field)) #else # define TEST_FIELD_ALIGNMENT(type, field, align) do { } while (0) #endif
i.e. FIELD_ALIGNMENT gets an empty definition. Same for _TYPE_ALIGNMENT.
Patrik, did you actually got it working with MS cl.exe?