Skip to content

Commit

Permalink
[APFloat] Fix memory bugs revealed by MSan
Browse files Browse the repository at this point in the history
Reviewers: eugenis, hfinkel, kbarton, iteratee, echristo

Subscribers: mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D26102

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285468 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
timshen91 committed Oct 28, 2016
1 parent 342cdd8 commit 88ccb3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/llvm/ADT/APFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ class APFloat : public APFloatBase {
APFloat(const fltSemantics &Semantics) : U(Semantics) {}
APFloat(const fltSemantics &Semantics, StringRef S);
APFloat(const fltSemantics &Semantics, integerPart I) : U(Semantics, I) {}
// TODO: Remove this constructor. This isn't faster than the first one.
APFloat(const fltSemantics &Semantics, uninitializedTag)
: U(Semantics, uninitialized) {}
APFloat(const fltSemantics &Semantics, const APInt &I) : U(Semantics, I) {}
Expand Down
11 changes: 8 additions & 3 deletions lib/Support/APFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,10 @@ IEEEFloat::IEEEFloat(const fltSemantics &ourSemantics) {
sign = false;
}

IEEEFloat::IEEEFloat(const fltSemantics &ourSemantics, uninitializedTag tag) {
// Delegate to the previous constructor, because later copy constructor may
// actually inspects category, which can't be garbage.
IEEEFloat::IEEEFloat(const fltSemantics &ourSemantics, uninitializedTag tag)
: IEEEFloat(ourSemantics) {
// Allocates storage if necessary but does not initialize it.
initialize(&ourSemantics);
}
Expand Down Expand Up @@ -3877,7 +3880,9 @@ DoubleAPFloat::DoubleAPFloat(const fltSemantics &S, APFloat &&First,

DoubleAPFloat::DoubleAPFloat(const DoubleAPFloat &RHS)
: Semantics(RHS.Semantics),
Floats(new APFloat[2]{APFloat(RHS.Floats[0]), APFloat(RHS.Floats[1])}) {
Floats(RHS.Floats ? new APFloat[2]{APFloat(RHS.Floats[0]),
APFloat(RHS.Floats[1])}
: nullptr) {
assert(Semantics == &PPCDoubleDouble);
}

Expand All @@ -3888,7 +3893,7 @@ DoubleAPFloat::DoubleAPFloat(DoubleAPFloat &&RHS)
}

DoubleAPFloat &DoubleAPFloat::operator=(const DoubleAPFloat &RHS) {
if (Semantics == RHS.Semantics) {
if (Semantics == RHS.Semantics && RHS.Floats) {
Floats[0] = RHS.Floats[0];
Floats[1] = RHS.Floats[1];
} else if (this != &RHS) {
Expand Down

0 comments on commit 88ccb3e

Please sign in to comment.