From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 807093851C2E; Thu, 14 May 2020 01:32:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 807093851C2E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589419965; bh=A0kZixcs4L4fhttFBvmaYve2EM+RnlVtxBPe6DQJ83I=; h=From:To:Subject:Date:From; b=A9DNp5ViiRvgnlph8kz6x50TgtRPU45MNLM/Bf9lB777yyg7D8xYEFDDMitpu+l3R 2ll4na4ZgvT1SHbKKuKxmvbBRGxUtHI5PpOhwDAruSy9e+b3Oyh6QjBGNCcPGuFxca Fg3N04CBviu+Lq0lq7x+lVgGmei64EjcMHraNiRQ= From: "josephcsible at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [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) Date: Thu, 14 May 2020 01:32:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: inline-asm X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: josephcsible at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 May 2020 01:32:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95121 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" : "=3Dr"(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 "=3Dd" and "=3DQ" as constraints in place of "=3Dr", and it occurr= ed in every combination I tried. I can reproduce it locally with the gcc:10.1.0 Docker image as well as on Godbolt.=