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

            Bug ID: 95121
           Summary: Wrong code generated: low-byte registers are silently
                    used in place of their corresponding high-byte
                    registers (ah, bh, ch, dh)
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: josephcsible at gmail dot com
  Target Milestone: ---

Consider this function:

char f(void) {
    register char x __asm__("dh");
    __asm__("movb $42, %%dh" : "=r"(x));
    return x;
}

It's supposed to return 42, but it actually returns whatever happened to be in
dl. In general, any time you use a high-byte register for input or output to
inline assembly, GCC will instead erroneously use the corresponding low-byte
register in its place. I tested this with -m32 and -m64, with -O0 through -O3,
and with "=d" and "=Q" as constraints in place of "=r", and it occurred in
every combination I tried. I can reproduce it locally with the gcc:10.1.0
Docker image as well as on Godbolt.

Reply via email to