[llvm-commits] [llvm-gcc-4.2] r46726 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Devang Patel dpatel at apple.com
Thu Feb 7 09:54:23 PST 2008


It is possible that I'm not solving the real problem here.

struct {
	char a;
	char b;
	int c:8;
	int d:20;
} S;

When this struct is packed and S is aligned at 4 byte, what alignment  
should be specified on load instruction to load 'd' ?

-
Devang
On Feb 7, 2008, at 9:35 AM, Duncan Sands wrote:

> Hi Devang,
>
>> Use appropriate alignment while handling  packed struct member.
>
> the reason I asked for a testcase is that I thought all objects
> created by the IR we generate (whether locals, globals or on the
> heap) were supposed to be aligned at least as much as the gcc
> alignment.  If so, the fact that we create a packed struct type
> (alignment 1) shouldn't make the gcc object alignment info in
> expr_align wrong, in fact it should be irrelevant.  My fear is
> that your change might only be papering over the problem.
>
>>    bool isVolatile = TREE_THIS_VOLATILE(exp);
>>    const Type *Ty = ConvertType(TREE_TYPE(exp));
>>    unsigned Alignment = expr_align(exp) / 8;
>> +  if (TREE_CODE(exp) == COMPONENT_REF)
>> +    if (const StructType *STy =
>> +        dyn_cast<StructType>(ConvertType(TREE_TYPE(TREE_OPERAND(exp,
>> 0))))) +      if (STy->isPacked())
>> +        // Packed struct members use 1 byte alignment
>> +        Alignment = 1;
>> +
>>
>
> Best wishes,
>
> Duncan.






More information about the llvm-commits mailing list