https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103882

Jose Silva <krystalgamer at protonmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |---

--- Comment #2 from Jose Silva <krystalgamer at protonmail dot com> ---
Marking as noinline does not help.

See the generated code:

```
0040014c <example>:
  40014c:       27bdffe0        addiu   sp,sp,-32
  400150:       afbf001c        sw      ra,28(sp)
  400154:       0c100050        jal     400140 <fail>
  400158:       00000000        nop
  40015c:       80820000        lb      v0,0(a0)
  400160:       8fbf001c        lw      ra,28(sp)
  400164:       27bd0020        addiu   sp,sp,32
  400168:       38420061        xori    v0,v0,0x61
  40016c:       03e00008        jr      ra
  400170:       2c420001        sltiu   v0,v0,1

```

The marking as a clobbered does work, but it doesn't fix the underlying issue.
On my original code I had a `syscall`, which passes the code execution to the
kernel that I have no control over or know the full implementation.


The specific syscall was overwriting the $a0 register which I simplified in my
example.

GCC when -O2 is enabled is making too strong assumptions about the code. To
better illustrate the issue, let me give another example. If I call a function
via a function pointer regardless of the optimization level, GCC will save all
caller-saved registers in use. But when it encounters an ASM statement it
treats it like it doesn't exist. In my opinion, the same assumptions made when
calling from a function pointer should apply when calling a function with
inline-asm*.

* Manually indicating the clobbered registers could override this behaviour

Reply via email to