[LLVMdev] endian independence

Jay Foad jay.foad at gmail.com
Mon Oct 27 03:14:48 PDT 2008


>> I'm already working on this myself. Would you be interested in having
>> this work contributed back to LLVM?
>
> If this were to better support target independent languages, it would
> be very useful.  If you're just trying to *reduce* the endianness
> assumptions that leak through, I don't think it's a good approach.
> There is just no way to solve this problem with C.

Yes, I can see that the llvm part of this is more straightforward and
less controversial than the llvm-gcc part. Maybe I should submit the
llvm part (since it applies to all source languages) and keep the
llvm-gcc part as a local hack.

> How do you propose to handle things like:
>
> struct foo {
> #ifdef __LITTLE_ENDIAN__
>   int x, y;
> #else
>   int y, x;
> #endif
> };

I can't make all C programs work regardless of target endianness. This
one will only work on little-endian:

  int x = 1;
  assert(*(char *)&x == 1);

You've just highlighted another restriction that I'll have to impose:
you shouldn't expect to be able to detect target endianness at compile
time.

All I want is that, if you write your source code so that it doesn't
make assumptions about endianness, then the compiler and its
optimisations won't introduce any new assumptions about endianness.

Thanks,
Jay.



More information about the llvm-dev mailing list