LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 409 - ConstantFP::isValueValidForType Broken
Summary: ConstantFP::isValueValidForType Broken
Status: RESOLVED WONTFIX
Alias: None
Product: libraries
Classification: Unclassified
Component: Core LLVM classes (show other bugs)
Version: 1.0
Hardware: All All
: P normal
Assignee: Reid Spencer
URL:
Keywords: code-quality
Depends on:
Blocks:
 
Reported: 2004-07-26 00:22 PDT by Reid Spencer
Modified: 2010-02-22 12:44 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments
Test case for "float" range (339 bytes, text/plain)
2004-12-06 16:03 PST, Reid Spencer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Reid Spencer 2004-07-26 00:22:51 PDT
This method will happily accept double values for float constants that are
clearly out of range or have precision beyond the acceptable precision of a
float. The current implementation accepts all double values as valid for float.
It shouldn't do that.

Simply casting double -> float -> double and comparing the two doubles doesn't
work well as a test because of rounding errors and/or conversion errors from
decimal notation in AsmParser. Hex conversions work fine as long as the value is
a valid FP double.
Comment 1 Reid Spencer 2004-12-06 16:03:15 PST
Created attachment 189 [details]
Test case for "float" range

This test case just makes sure that double values can be assigned to double
constants, float values can be assigned to float constants, but double values
cannot be assigned to float constants.
Comment 2 Reid Spencer 2004-12-06 16:04:59 PST
Test case added here:

http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20041206/021805.html
Comment 4 Reid Spencer 2004-12-07 01:44:31 PST
Although the patch passed the nightly test and the regression test, it didn't
work on all platforms due to buggy std::numeric_limits<...> implementations. We
tried some math.h things too, but that didn't work. The patch was reverted so
this bug is open until we can find something that works on all platforms.
Comment 5 Reid Spencer 2004-12-08 22:39:42 PST
Its unclear to me how this should be implemented. What I want to do is make sure
that the range of double values accepted for a FloatTy is within range for the
float type. The cast thing doesn't work, neither does limits checking (because
std::numeric_limits<float> isn't portable or doesn't work everywhere). There are
things in math.h that could be used but they are also unreliable from platform
to plaform so .. what do we do?

I'm thinking along these lines:

float FV = float(V);
double DV = double(FV);

return isinf(V) || isnan(V) || V == DV

Any other ideas?
Comment 6 Chris Lattner 2004-12-08 23:10:05 PST
That seems reasonable to me.  I really have no idea what the right check is. 
Putting something in at the start of the 1.5 cycle that tests clean seems
reasonable though.

-Chris
Comment 8 Reid Spencer 2005-12-22 16:16:25 PST
This is a pernicious little bug. Reopened until a solution can be found that
doesn't cause tests to fail.
Comment 9 Chris Lattner 2006-04-11 23:31:55 PDT
Not happening for 1.7.

I don't think this bug really makes sense.  Should we just close it as wontfix?

-Chris 
Comment 10 Reid Spencer 2006-04-12 00:29:00 PDT
This bug has been around for a long time, we don't have a better solution than
the current one, and it isn't really affecting anything. So, its WONTFIX'd