public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/95121] New: Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh)
@ 2020-05-14  1:32 josephcsible at gmail dot com
  2020-05-14  1:42 ` [Bug inline-asm/95121] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: josephcsible at gmail dot com @ 2020-05-14  1:32 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug inline-asm/95121] Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh)
  2020-05-14  1:32 [Bug inline-asm/95121] New: Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh) josephcsible at gmail dot com
@ 2020-05-14  1:42 ` pinskia at gcc dot gnu.org
  2020-05-14  1:53 ` josephcsible at gmail dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-05-14  1:42 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
    register char x __asm__("dh");

Is the same as:
    register char x __asm__("di");

dh and dl are the same register really but the high are low parts can be
modified seperately via some of the 8bit instructions.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug inline-asm/95121] Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh)
  2020-05-14  1:32 [Bug inline-asm/95121] New: Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh) josephcsible at gmail dot com
  2020-05-14  1:42 ` [Bug inline-asm/95121] " pinskia at gcc dot gnu.org
@ 2020-05-14  1:53 ` josephcsible at gmail dot com
  2020-05-14  1:54 ` josephcsible at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: josephcsible at gmail dot com @ 2020-05-14  1:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Joseph C. Sible <josephcsible at gmail dot com> ---
Does this mean that Clang is wrong, then? Because it works the way I
wanted/expected.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug inline-asm/95121] Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh)
  2020-05-14  1:32 [Bug inline-asm/95121] New: Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh) josephcsible at gmail dot com
  2020-05-14  1:42 ` [Bug inline-asm/95121] " pinskia at gcc dot gnu.org
  2020-05-14  1:53 ` josephcsible at gmail dot com
@ 2020-05-14  1:54 ` josephcsible at gmail dot com
  2020-05-14  2:07 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: josephcsible at gmail dot com @ 2020-05-14  1:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Joseph C. Sible <josephcsible at gmail dot com> ---
Also, is that documented to work that way anywhere? I didn't notice anything in
the manual to that effect.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug inline-asm/95121] Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh)
  2020-05-14  1:32 [Bug inline-asm/95121] New: Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh) josephcsible at gmail dot com
                   ` (2 preceding siblings ...)
  2020-05-14  1:54 ` josephcsible at gmail dot com
@ 2020-05-14  2:07 ` pinskia at gcc dot gnu.org
  2020-05-14  2:08 ` pinskia at gcc dot gnu.org
  2020-05-14 17:55 ` craig.topper at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-05-14  2:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Joseph C. Sible from comment #2)
> Does this mean that Clang is wrong, then? Because it works the way I
> wanted/expected.

Depends, this is a GNU extension.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug inline-asm/95121] Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh)
  2020-05-14  1:32 [Bug inline-asm/95121] New: Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh) josephcsible at gmail dot com
                   ` (3 preceding siblings ...)
  2020-05-14  2:07 ` pinskia at gcc dot gnu.org
@ 2020-05-14  2:08 ` pinskia at gcc dot gnu.org
  2020-05-14 17:55 ` craig.topper at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-05-14  2:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Joseph C. Sible from comment #3)
> Also, is that documented to work that way anywhere? I didn't notice anything
> in the manual to that effect.

Register names seems not to be documented, correct.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug inline-asm/95121] Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh)
  2020-05-14  1:32 [Bug inline-asm/95121] New: Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh) josephcsible at gmail dot com
                   ` (4 preceding siblings ...)
  2020-05-14  2:08 ` pinskia at gcc dot gnu.org
@ 2020-05-14 17:55 ` craig.topper at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: craig.topper at gmail dot com @ 2020-05-14 17:55 UTC (permalink / raw)
  To: gcc-bugs

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

Craig Topper <craig.topper at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |craig.topper at gmail dot com

--- Comment #6 from Craig Topper <craig.topper at gmail dot com> ---
Could gcc at least emit an error?

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-14 17:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14  1:32 [Bug inline-asm/95121] New: Wrong code generated: low-byte registers are silently used in place of their corresponding high-byte registers (ah, bh, ch, dh) josephcsible at gmail dot com
2020-05-14  1:42 ` [Bug inline-asm/95121] " pinskia at gcc dot gnu.org
2020-05-14  1:53 ` josephcsible at gmail dot com
2020-05-14  1:54 ` josephcsible at gmail dot com
2020-05-14  2:07 ` pinskia at gcc dot gnu.org
2020-05-14  2:08 ` pinskia at gcc dot gnu.org
2020-05-14 17:55 ` craig.topper at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).