[llvm] Update the EBO static_assert to dheck against APFloat::Storage instead of IEEEFloat. (PR #112589)

Daniel Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 16 11:49:50 PDT 2024


https://github.com/DanielCChen updated https://github.com/llvm/llvm-project/pull/112589

>From e0d2620b9f88c52d302db262c09085c3329baf10 Mon Sep 17 00:00:00 2001
From: cdchen-ca <cdchen at ca.ibm.com>
Date: Wed, 16 Oct 2024 11:03:11 -0400
Subject: [PATCH 1/3] Update the EBO static_assert to dheck against
 APFloat::Storage instead of IEEEFloat.

---
 llvm/include/llvm/ADT/APFloat.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index 97547fb577e0ec..ef3ef51dabc35e 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -1474,10 +1474,14 @@ class APFloat : public APFloatBase {
   friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
   friend IEEEFloat;
   friend DoubleAPFloat;
+  friend class APFloatEBOChecker;
+};
+
+class APFloatEBOChecker {
+  static_assert(sizeof(APFloat) == sizeof(APFloat::U),
+                "Empty base class optimization is not performed.");
 };
 
-static_assert(sizeof(APFloat) == sizeof(detail::IEEEFloat),
-              "Empty base class optimization is not performed.");
 
 /// See friend declarations above.
 ///

>From 6952f51d4254e5f50ccf7bc46f7a4cb1a07fc4f8 Mon Sep 17 00:00:00 2001
From: cdchen-ca <cdchen at ca.ibm.com>
Date: Wed, 16 Oct 2024 13:53:18 -0400
Subject: [PATCH 2/3] Update EBO statich_assert.

---
 llvm/include/llvm/ADT/APFloat.h | 6 ------
 llvm/lib/Support/APFloat.cpp    | 5 +++++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index ef3ef51dabc35e..85e17efd1fba8e 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -1477,12 +1477,6 @@ class APFloat : public APFloatBase {
   friend class APFloatEBOChecker;
 };
 
-class APFloatEBOChecker {
-  static_assert(sizeof(APFloat) == sizeof(APFloat::U),
-                "Empty base class optimization is not performed.");
-};
-
-
 /// See friend declarations above.
 ///
 /// These additional declarations are required in order to compile LLVM with IBM
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index a33b6c4a6ddc63..f48c82b6afdd89 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -99,6 +99,11 @@ enum class fltNanEncoding {
   NegativeZero,
 };
 
+class APFloatEBOChecker {
+  static_assert(sizeof(APFloat) == sizeof(APFloat::U),
+                "Empty base class optimization is not performed.");
+};
+
 /* Represents floating point arithmetic semantics.  */
 struct fltSemantics {
   /* The largest E such that 2^E is representable; this matches the

>From ae31e73c581b1b2dbe6ec4c332dd4b7a44f261be Mon Sep 17 00:00:00 2001
From: cdchen-ca <cdchen at ca.ibm.com>
Date: Wed, 16 Oct 2024 14:49:33 -0400
Subject: [PATCH 3/3] Add a comment to explain the reason of needing friend
 class APFloatEBOChecker to address review comment.

---
 llvm/include/llvm/ADT/APFloat.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index 85e17efd1fba8e..436052d8aa2653 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -1474,6 +1474,8 @@ class APFloat : public APFloatBase {
   friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
   friend IEEEFloat;
   friend DoubleAPFloat;
+  // Since Storage is private, friend class APFloatEBOChecker is added to allow
+  // access to it in APFloat.cpp.
   friend class APFloatEBOChecker;
 };
 



More information about the llvm-commits mailing list