-
Notifications
You must be signed in to change notification settings - Fork 13.5k
ADT: Switch to a raw pointer for DoubleAPFloat::Floats. #129981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ADT: Switch to a raw pointer for DoubleAPFloat::Floats. #129981
Conversation
Created using spr 1.3.6-beta.1
@llvm/pr-subscribers-llvm-adt Author: Peter Collingbourne (pcc) ChangesIn order for the union APFloat::Storage to permit access to the Full diff: https://github.com/llvm/llvm-project/pull/129981.diff 2 Files Affected:
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index 70fbf2059841e..9962c878cfbfc 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -805,7 +805,7 @@ IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM);
class DoubleAPFloat final {
// Note: this must be the first data member.
const fltSemantics *Semantics;
- std::unique_ptr<APFloat[]> Floats;
+ APFloat *Floats;
opStatus addImpl(const APFloat &a, const APFloat &aa, const APFloat &c,
const APFloat &cc, roundingMode RM);
@@ -821,6 +821,7 @@ class DoubleAPFloat final {
DoubleAPFloat(const fltSemantics &S, APFloat &&First, APFloat &&Second);
DoubleAPFloat(const DoubleAPFloat &RHS);
DoubleAPFloat(DoubleAPFloat &&RHS);
+ ~DoubleAPFloat();
DoubleAPFloat &operator=(const DoubleAPFloat &RHS);
inline DoubleAPFloat &operator=(DoubleAPFloat &&RHS);
@@ -1659,6 +1660,10 @@ const APFloat &DoubleAPFloat::getFirst() const { return Floats[0]; }
APFloat &DoubleAPFloat::getSecond() { return Floats[1]; }
const APFloat &DoubleAPFloat::getSecond() const { return Floats[1]; }
+inline DoubleAPFloat::~DoubleAPFloat() {
+ delete[] Floats;
+}
+
} // namespace detail
} // namespace llvm
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index cbee7f48b8773..cfc3c3b4974c5 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -4876,8 +4876,9 @@ DoubleAPFloat::DoubleAPFloat(const DoubleAPFloat &RHS)
}
DoubleAPFloat::DoubleAPFloat(DoubleAPFloat &&RHS)
- : Semantics(RHS.Semantics), Floats(std::move(RHS.Floats)) {
+ : Semantics(RHS.Semantics), Floats(RHS.Floats) {
RHS.Semantics = &semBogus;
+ RHS.Floats = nullptr;
assert(Semantics == &semPPCDoubleDouble);
}
|
@llvm/pr-subscribers-llvm-support Author: Peter Collingbourne (pcc) ChangesIn order for the union APFloat::Storage to permit access to the Full diff: https://github.com/llvm/llvm-project/pull/129981.diff 2 Files Affected:
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index 70fbf2059841e..9962c878cfbfc 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -805,7 +805,7 @@ IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM);
class DoubleAPFloat final {
// Note: this must be the first data member.
const fltSemantics *Semantics;
- std::unique_ptr<APFloat[]> Floats;
+ APFloat *Floats;
opStatus addImpl(const APFloat &a, const APFloat &aa, const APFloat &c,
const APFloat &cc, roundingMode RM);
@@ -821,6 +821,7 @@ class DoubleAPFloat final {
DoubleAPFloat(const fltSemantics &S, APFloat &&First, APFloat &&Second);
DoubleAPFloat(const DoubleAPFloat &RHS);
DoubleAPFloat(DoubleAPFloat &&RHS);
+ ~DoubleAPFloat();
DoubleAPFloat &operator=(const DoubleAPFloat &RHS);
inline DoubleAPFloat &operator=(DoubleAPFloat &&RHS);
@@ -1659,6 +1660,10 @@ const APFloat &DoubleAPFloat::getFirst() const { return Floats[0]; }
APFloat &DoubleAPFloat::getSecond() { return Floats[1]; }
const APFloat &DoubleAPFloat::getSecond() const { return Floats[1]; }
+inline DoubleAPFloat::~DoubleAPFloat() {
+ delete[] Floats;
+}
+
} // namespace detail
} // namespace llvm
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index cbee7f48b8773..cfc3c3b4974c5 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -4876,8 +4876,9 @@ DoubleAPFloat::DoubleAPFloat(const DoubleAPFloat &RHS)
}
DoubleAPFloat::DoubleAPFloat(DoubleAPFloat &&RHS)
- : Semantics(RHS.Semantics), Floats(std::move(RHS.Floats)) {
+ : Semantics(RHS.Semantics), Floats(RHS.Floats) {
RHS.Semantics = &semBogus;
+ RHS.Floats = nullptr;
assert(Semantics == &semPPCDoubleDouble);
}
|
Created using spr 1.3.6-beta.1
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: llvm/llvm-project#129981
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: llvm#129981
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.