[llvm-bugs] [Bug 36886] New: bool parameter is tested as a 32-bit value, should use only the low byte

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 23 15:40:36 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=36886

            Bug ID: 36886
           Summary: bool parameter is tested as a 32-bit value, should use
                    only the low byte
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: dmajor at mozilla.com
                CC: llvm-bugs at lists.llvm.org

__declspec(noinline) int fn(bool b) { return b ? 0x42 : 0; }

At -O1 and higher on 64-bit Windows, clang-cl generates code that goes like:

test!fn:
00000001`40001000 85c9            test    ecx,ecx
00000001`40001002 b842000000      mov     eax,42h
00000001`40001007 0f44c1          cmove   eax,ecx
00000001`4000100a c3              ret

where the function tests the full 32-bit value of ecx. This can end up taking
the wrong code path if the caller only filled in the low byte of the register
and the upper bytes are garbage. (For what it's worth, MSVC looks at only the
low byte in this case.)

clang version 7.0.0 (trunk 328367)

Reduced from
https://searchfox.org/mozilla-central/rev/de5c4376b89c3603341d226a65acea12f8851ec5/netwerk/base/nsUDPSocket.cpp#571

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180323/e44f96af/attachment.html>


More information about the llvm-bugs mailing list