[llvm-bugs] [Bug 44680] New: Optimizer breaks compare for the negation of the signed integer -0x80000000

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 27 08:48:34 PST 2020


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

            Bug ID: 44680
           Summary: Optimizer breaks compare for the negation of the
                    signed integer -0x80000000
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: info at artsoft.nl
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 23065
  --> https://bugs.llvm.org/attachment.cgi?id=23065&action=edit
simple program to reproduce the bug

The following 2 lines of code:

int NaN = -0x80000000;
printf ( "%d < 0 : %s\n", -NaN, (-NaN) < 0 ? "true" : "false" );

Correctly prints when build without optimizations:
-2147483648 < 0 : true

But incorrectly prints when build with -O1 or higher:
-2147483648 < 0 : false

_______________________________________________

-0x80000000 has no positive counterpart  as 0x7FFFFFFF is the max positive
value of an int32. So when you negate -0x80000000 it remains -0x80000000.

I think the optimizer rewrites the statement "( -Nan ) < 0" to  "Nan  > 0", but
this changes the result.

-- 
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/20200127/7004b46e/attachment-0001.html>


More information about the llvm-bugs mailing list