Expression evaluation order

Iain Buclaw ibuclaw at ubuntu.com
Sat Jun 15 10:46:57 PDT 2013


On 15 June 2013 18:16, David Nadlinger <code at klickverbot.at> wrote:
> On Friday, 14 June 2013 at 09:59:07 UTC, Iain Buclaw wrote:
>>
>> Interesting, that certainly doesn't flag up as a regression in the
>> 2.063 merge in GDC... :o)
>>
>> However yes, the behaviour relies on the order the sucky X86 ABI
>> pushes arguments onto the stack (which for this array op is from right
>> to left).  Whereas on *all* other architectures it will execute the
>> parameters in left to right order, which would be a, c, b in this
>> case.
>
>
> In LDC, the actual evaluation order is completely separate from the target
> ABI (you simply pass the SSA vales to a function call in LLVM, and you can
> decide the order in which to create them yourself).
>
> Turns out that for array operations, we actually need to reverse the order
> compared to our normal one (left to right), as their signatures have
> specifically been chosen for the evaluation order in DMD that is intertwined
> with the backend ABI/function call implementation details.
>


We don't have that luxury, but as I said in the last thread brought up
on this some time ago, for extern(D) we just make temporaries and
compound them all together  (_a = a(), _b = b(), _c = c(),
_arrayop(_a, _b, _c));   There's no reason why this can't be done for
extern (C) - other than it will break a load of code that relies on
X86 ABI behaviour  (such as what array operations apparently do...)

--
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';


More information about the Digitalmars-d mailing list