Skip to content

Commit c72ebee

Browse files
authored
ADT: Switch to a raw pointer for DoubleAPFloat::Floats.
In order for the union APFloat::Storage to permit access to the semantics field when another union member is stored there, all members of Storage must be standard layout. This is not necessarily the case for DoubleAPFloat which may be non-standard layout because there is no requirement that its std::unique_ptr member is standard layout. Fix this by converting Floats to a raw pointer. Reviewers: arsenm Reviewed By: arsenm Pull Request: #129981
1 parent f905bf3 commit c72ebee

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/include/llvm/ADT/APFloat.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM);
805805
class DoubleAPFloat final {
806806
// Note: this must be the first data member.
807807
const fltSemantics *Semantics;
808-
std::unique_ptr<APFloat[]> Floats;
808+
APFloat *Floats;
809809

810810
opStatus addImpl(const APFloat &a, const APFloat &aa, const APFloat &c,
811811
const APFloat &cc, roundingMode RM);
@@ -821,6 +821,7 @@ class DoubleAPFloat final {
821821
DoubleAPFloat(const fltSemantics &S, APFloat &&First, APFloat &&Second);
822822
DoubleAPFloat(const DoubleAPFloat &RHS);
823823
DoubleAPFloat(DoubleAPFloat &&RHS);
824+
~DoubleAPFloat();
824825

825826
DoubleAPFloat &operator=(const DoubleAPFloat &RHS);
826827
inline DoubleAPFloat &operator=(DoubleAPFloat &&RHS);
@@ -1659,6 +1660,8 @@ const APFloat &DoubleAPFloat::getFirst() const { return Floats[0]; }
16591660
APFloat &DoubleAPFloat::getSecond() { return Floats[1]; }
16601661
const APFloat &DoubleAPFloat::getSecond() const { return Floats[1]; }
16611662

1663+
inline DoubleAPFloat::~DoubleAPFloat() { delete[] Floats; }
1664+
16621665
} // namespace detail
16631666

16641667
} // namespace llvm

llvm/lib/Support/APFloat.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -4876,8 +4876,9 @@ DoubleAPFloat::DoubleAPFloat(const DoubleAPFloat &RHS)
48764876
}
48774877

48784878
DoubleAPFloat::DoubleAPFloat(DoubleAPFloat &&RHS)
4879-
: Semantics(RHS.Semantics), Floats(std::move(RHS.Floats)) {
4879+
: Semantics(RHS.Semantics), Floats(RHS.Floats) {
48804880
RHS.Semantics = &semBogus;
4881+
RHS.Floats = nullptr;
48814882
assert(Semantics == &semPPCDoubleDouble);
48824883
}
48834884

0 commit comments

Comments
 (0)