Non-native endianness support in Clang

Hello,
I'd like to implement the gnu attribute "scalar_storage_order" to mark structs with non-native endianness. My rational is working on network protocols over little endian architecture (for instance: RiscV).

An old bug is open on this issue here:
https://bugs.llvm.org/show_bug.cgi?id=35293

I'd like to discuss the possible ways to implement this.

The GCC implementation is pretty complicated, touching almost everything, modifying optimizations, etc...:
https://github.com/gcc-mirror/gcc/commit/292237f3c109f2e0d2752ad1e73181689f7d0d53

I think, it would be better, to implement this attribute in the frontend only, adding the required byte-swaps early.

Any thoughts, ideas, objections?

Thanks
          Guy Benyei

Hello,
I'd like to implement the gnu attribute "scalar_storage_order" to mark structs with non-native endianness. My rational is working on network protocols over little endian architecture (for instance: RiscV).

An old bug is open on this issue here:
https://bugs.llvm.org/show_bug.cgi?id=35293

I'd like to discuss the possible ways to implement this.

The GCC implementation is pretty complicated, touching almost everything, modifying optimizations, etc...:
https://github.com/gcc-mirror/gcc/commit/292237f3c109f2e0d2752ad1e73181689f7d0d53

I think, it would be better, to implement this attribute in the frontend only, adding the required byte-swaps early.

I agree. Adding the swaps in the frontend seems relatively
straightforward. As I understand it, for non-packed structs, you also
need to adjust the relative position of the padding?

-Hal

AFAIK, the padding of non-packed structs shouldn't be affected, but bitfield offsets must be adjusted.
I'll test the solution thoroughly to make sure different structs with this attribute are interpreted the same on BE and LE targets.

Thanks
        Guy Benyei