[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mes call encoding bug with struct return
From: |
Jan Nieuwenhuizen |
Subject: |
Re: mes call encoding bug with struct return |
Date: |
Mon, 08 Jun 2020 20:35:32 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
Danny Milosavljevic writes:
Hi!
> when encoding a function call, mescc assumes that a huge struct fits into a
> register directly. That is not actually possible.
Eh, struct by value...only if it's size pointer (int) or smaller... :-)
> Example:
>
> typedef struct
> {
> long quot;
> long rem;
> } ldiv_t;
>
> ldiv_t __mesabi_ldiv(long a, long b) {
> ldiv_t result = {2,3};
> return result;
> }
>
> long
> __aeabi_idiv (long a, long b)
> {
> ldiv_t result = __mesabi_ldiv(a, b); // actual result: Call is
> encoded as if RESULT can fit into r0, which is not possible.
> return result.quot; // actual result: not 2
> }
>
> That means at runtime we will get an erroneous result.
Yes.
> On the other hand, GCC automatically converts that into:
>
> void __mesabi_ldiv(long a, long b, ldiv_t* result);
>
> long
> __aeabi_idiv (long a, long b)
> {
> ldiv_t result;
> __mesabi_ldiv(a, b, &result);
> return result.quot;
> }
Hehe, I wrote a bug report with a patch for something very similar in
g++ once.
> Possible fixes in mescc:
>
> * Fail with an error message when someone tries to use that, or
> * Implement the same way as GCC does
(there's also the 0-option: do nothing and silently generate broken
code)
At the least, I'd like to see a test for this that fails; failing
with an error is an acceptable first improvement for now. WDYT?
Thanks,
Janneke
--
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.com