[LLVMbugs] [Bug 7130] New: Clang++ fails to calculate const double for global variables

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu May 13 08:43:21 PDT 2010


           Summary: Clang++ fails to calculate const double for global
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: nbigaouette at gmail.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com

Created an attachment (id=4886)
 --> (http://llvm.org/bugs/attachment.cgi?id=4886)
Simple source file showing the problem.

In my project I put const doubles in a header file for global variables. But I
just realized that clang++ failed to calculate them correctly.

I've created an example program which shows the problem. I'll be attaching it
next. The file only contains variables with the factors to convert bytes,
kibibyte, mebibytes and gibibyte. The values are then outputed.

If the variables are declared/defined globally, their values are wrong. If they
are declared/defined locally, they are good.

g++ correctly calculates them.

$ clang++ const_double.cpp -o const_double && ./const_double
B_to_KiB   =0.000976562
B_to_MiB   =9.53674e-07
B_to_GiB   =0
KiB_to_B   =1024
KiB_to_MiB =0
KiB_to_GiB =0
MiB_to_B   =inf
MiB_to_KiB =inf
MiB_to_GiB =0.000976562
GiB_to_B   =inf
GiB_to_KiB =inf
GiB_to_MiB =1024

compared to:
$ g++ const_double.cpp -o const_double && ./const_double
B_to_KiB   = 0.000976562
B_to_MiB   = 9.53674e-07
B_to_GiB   = 9.31323e-10
KiB_to_B   = 1024
KiB_to_MiB = 1
KiB_to_GiB = 0.000976562
MiB_to_B   = 1.04858e+06
MiB_to_KiB = 1
MiB_to_GiB = 0.000976562
GiB_to_B   = 1.07374e+09
GiB_to_KiB = 1024
GiB_to_MiB = 1024

Using clang built from svn revision 103172 on ArchLinux.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list