32-bit LLVM C compiler reports incorrect value for __alignof__(int64_t)

Originator:miguel.de.icaza
Number:rdar://10932851 Date Originated:25-Feb-2012
Status:Open Resolved:
Product:Xcode Product Version:4.3
Classification:Regression Reproducible:yes
 
25-Feb-2012 11:58 AM Miguel De Icaza:
Summary:
The 32-bit LLVM C compiler shipped with Xcode 4.3 (build 4E109) returns the wrong value for __alignof__(int64_t), it returns the value 8, but actually uses 4 to align data in structures

Steps to Reproduce:
Compile the attached program using:

cc -m32 demo.c

=== demo.c ===
#include <stdio.h>
#include <stdint.h>

struct {
	int32_t first;
	int64_t second;
} a;


int main ()
{
	void *pfirst = (void *) &a.first;
	void *psecond = (void *) &a.second;

	printf ("The 64 bit value is aligned at %d\n", (int) (psecond-pfirst));
	printf ("The compiler reports: %d\n", (int) __alignof__(long long));
	return 1;
}
============

Expected Results:
The 64 bit value is aligned at 4
The compiler reports: 8

Actual Results:
The 64 bit value is aligned at 4
The compiler reports: 4

Regression:

Before Xcode 4.2, __alignof__ of a 64-bit integer on 32-bit environments returned 4, now it returns 8.

This is at odds with the actual convention implemented by the compiler.   As the sample shows, the first field in the structure is a 32-bit value and the second is a 64-bit value.   The compiler aligns the second value at a 4-byte boundary, instead of the reported 8.

Notes:

This regresses code that marshalls structures and depends on __alignof__ reporting the actual platform sizes.   

25-Feb-2012 11:58 AM Miguel De Icaza:
'demo.c' was successfully uploaded

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!