This is an archive of the discontinued LLVM Phabricator instance.

[APFloat] Fix uninitialized variable in IEEEFloat constructors
ClosedPublic

Authored by nullptr.cpp on Sep 1 2020, 6:46 PM.

Details

Summary

Some constructors of IEEEFloat do not initialize member variable exponent.
Fix it by initializing exponent with the following values:

For NaNs, the `exponent` is `maxExponent+1`.
For Infinities, the `exponent` is `maxExponent+1`.
For Zeroes, the `exponent` is `maxExponent-1`.

Diff Detail

Event Timeline

nullptr.cpp created this revision.Sep 1 2020, 6:46 PM
nullptr.cpp requested review of this revision.Sep 1 2020, 6:46 PM

What problem does this cause? IEEEFloat::initFromFloatAPInt which is called for IEEEFloat::IEEEFloat(float f) also doesn't assign exponent from what I can see.

What problem does this cause? IEEEFloat::initFromFloatAPInt which is called for IEEEFloat::IEEEFloat(float f) also doesn't assign exponent from what I can see.

I found this by a static analyzer checker, I’m just worried if an uninitialized variable is used somewhere before initialization.
Should we initialize it or just leave it as it is?

RKSimon added a subscriber: RKSimon.

https://llvm.org/reports/scan-build/ lists a large number of APFloat warnings - it may be possible to create test cases from one of those analysis paths.

lattner accepted this revision.Sep 2 2020, 11:49 AM

This patch LGTM. I think that conservatively init the members is a good idea.

This revision is now accepted and ready to land.Sep 2 2020, 11:49 AM

Also fix other constructors.

nullptr.cpp retitled this revision from [APFloat] Fix uninitialized variable in IEEEFloat constructor to [APFloat] Fix uninitialized variable in IEEEFloat constructors.Sep 3 2020, 2:46 AM
nullptr.cpp edited the summary of this revision. (Show Details)
nullptr.cpp added a reviewer: gottesmm.

LGTM, thanks for doing this.

I don't have commit access, can anyone help commit this?
Yang Fan <nullptr.cpp@gmail.com>
Thanks!

I don't have commit access, can anyone help commit this?
Yang Fan <nullptr.cpp@gmail.com>
Thanks!

Thanks for looking at this @nullptr.cpp - I'll merge this later today