<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW " title="NEW --- - fabs of -0 returns -0 on Cortex-M4" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24091&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=CYd-YnDIhPiVZuBQQ1_DIH4fyCXR1HSWGVlBGcfj_Zw&s=T4v-2EEAsDimg6iP-42UguKy4lTqNsExPfNhrmPukTU&e=">24091</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>fabs of -0 returns -0 on Cortex-M4
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ambrop7@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=14574" name="attach_14574" title="test case, function that calls fabs">attachment 14574</a> <a href="attachment.cgi?id=14574&action=edit" title="test case, function that calls fabs">[details]</a></span>
test case, function that calls fabs

While trying to use Clang for a microcontroller project (Cortex-M4 with FPU), I
am seeing fabs(-0) returning -0. But the correct result is 0. Note, this is for
calculation with doubles not floats.

Attached is a simple test case that can be compiled to assembly, and the
resulting assembly, produced with the command below.

I cannot read ARM assembly well but I suspect the inlined implementation of
fabs really is incorrect with respect to -0. I have also attached the result of
compiling with GCC (same command line), which seems to be a much more optimized
implementation.

arm-none-eabi-clang -mcpu=cortex-m4 -mthumb -O2 -fno-math-errno
-fno-trapping-math -fshort-enums -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fno-rtti
-fno-exceptions abs.c -S -o abs.S

Clang was configured as follows:
../configure --enable-targets=arm --target=arm-none-eabi --enable-cxx11
--disable-docs \
            
--with-gcc-toolchain=${gcc-arm-embedded}/lib/gcc/arm-none-eabi/$gccVersion \
             --with-c-include-dirs=${gcc-arm-embedded}/arm-none-eabi/include</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>