Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

trunc() is now returning incorrect results, not even an integer #13228

Closed Quuxplusone closed 12 years ago

Quuxplusone commented 12 years ago
Bugzilla Link PR13609
Status RESOLVED FIXED
Importance P normal
Reported by Patrick Pelletier (ppelletier@oblong.net)
Reported on 2012-08-14 21:29:54 -0700
Last modified on 2012-08-15 00:40:28 -0700
Version unspecified
Hardware PC Linux
CC efriedma@quicinc.com, llvm-bugs@lists.llvm.org, nlewycky@google.com, resistor@mac.com
Fixed by commit(s)
Attachments a.out (8504 bytes, application/octet-stream)
Blocks
Blocked by
See also
This seems to be a recently introduced problem, because I don't believe it
happened with the clang I built last week, but it happens with the clang I
built today.

Here is my test program:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (int argc, char **argv)
{
  printf ("compiled with: " __VERSION__ "\n");
  printf ("trunc (-0.5) = %f\n", trunc (-0.5));
  printf ("trunc (-3.14) = %f\n", trunc (-3.14));
  printf ("trunc (-2.71) = %f\n", trunc (-2.71));
  printf ("trunc (-0.1) = %f\n", trunc (-0.1));
  return EXIT_SUCCESS;
}

And here is what happens when I run it with today's clang, and when I run it
with gcc:

ppelletier@chives:~/misc$ /home/ppelletier/clang/bin/clang trunc-test.c
ppelletier@chives:~/misc$ ./a.out
compiled with: 4.2.1 Compatible Clang 3.2 (trunk 161724) (llvm/trunk 161918)
trunc (-0.5) = -0.500000
trunc (-3.14) = -3.500000
trunc (-2.71) = -3.000000
trunc (-0.1) = -0.500000
ppelletier@chives:~/misc$ gcc trunc-test.c
ppelletier@chives:~/misc$ ./a.out
compiled with: 4.4.3
trunc (-0.5) = -0.000000
trunc (-3.14) = -3.000000
trunc (-2.71) = -2.000000
trunc (-0.1) = -0.000000

The gcc results are what I would expect, but the clang results seem obviously
wrong by inspection, in addition to disagreeing with the gcc results.

This is on Ubuntu 10.04, on an x86_64 machine.
Quuxplusone commented 12 years ago

This is probably my fault.

Quuxplusone commented 12 years ago
Can you confirm that you built this against latest ToT?  I fixed a bug that was
almost certainly the cause of this in r161885, and I get the correct result now:

resistor$ ./Debug+Asserts/bin/clang foo.c -o foo
resistor$ ./foo
compiled with: 4.2.1 Compatible Clang 3.2 (trunk 161758) (llvm/trunk 161926)
trunc (-0.5) = -0.000000
trunc (-3.14) = -3.000000
trunc (-2.71) = -2.000000
trunc (-0.1) = -0.000000
Quuxplusone commented 12 years ago

Try explicitly declaring "double trunc(double) __attribute((const));"...

Quuxplusone commented 12 years ago

Attached a.out (8504 bytes, application/octet-stream): a.out built with clang 161927 on x86_64 Ubuntu 10.04

Quuxplusone commented 12 years ago
(In reply to comment #3)
> Try explicitly declaring "double trunc(double) __attribute((const));"...

I tried replacing "#include <math.h>" with that explicit declaration, but I'm
still getting the same result.
Quuxplusone commented 12 years ago

Fixed in r161929.