[llvm] ADT: Switch to a raw pointer for DoubleAPFloat::Floats. (PR #129981)

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 5 21:15:08 PST 2025


https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/129981

>From d45e3881e15ec032e431d5f9414ee91c15802616 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Wed, 5 Mar 2025 19:39:22 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6-beta.1
---
 llvm/include/llvm/ADT/APFloat.h | 7 ++++++-
 llvm/lib/Support/APFloat.cpp    | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)

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);
 }
 

>From 74def902832b8cdc7a5d98ff96a5bdc1129aa604 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Wed, 5 Mar 2025 21:14:54 -0800
Subject: [PATCH 2/2] clang-format

Created using spr 1.3.6-beta.1
---
 llvm/include/llvm/ADT/APFloat.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index 9962c878cfbfc..00d92740259eb 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -1660,9 +1660,7 @@ 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;
-}
+inline DoubleAPFloat::~DoubleAPFloat() { delete[] Floats; }
 
 } // namespace detail
 



More information about the llvm-commits mailing list