WIP: fix for avr-rust issue 129 by carlos4242 · Pull Request #8 · avr-rust/llvm (original) (raw)

The bug is related to parameter ordering and endianness. (See avr-rust rust-lang#129.)

When a large type can't be legalised, it's broken into smaller types, those are passed as parameters in order based on the endianness of the platform, which is wrong in the case of AVR (at least).

I came up with the rather too radical idea of adding an extra variable to the data layout to reflect this so parameter order is done right. This seems too much because i) as far as I know only AVR is affected by this issue and ii) as far as I know, only one call is known to need this distinction, although we might find more later.

The problem is the legalising is in shared code, without any platform specific hooks that I can work out, but it might be possible to use another one that I don't know about?

To make this fail-safe, the ABI big endian flag defaults to false, just like the main endianness flag, plus by default, if an architecture is marked as big endian in the data layout string ('E'), it will set the ABI endianness flag to big endian too. Then for AVR (and any other platform that needs it), you can add 'K' to the data layout string to specify a big endian ABI.

One other serious problem with this patch is it doesn't work. :) The ABI endian flag is false when the expand node in the legaliser runs. I've tried to debug it and can't figure out why right now. Anyway, it's complete enough for discussion, which is the main thing right now.