[llvm] [libc] [libc][NFC] Fix "type qualifiers ignored on cast result type" GCC warning (PR #78509)

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 11:09:17 PST 2024


https://github.com/gchatelet updated https://github.com/llvm/llvm-project/pull/78509

>From c3b57887b9a3c04f61883aafd11cffdb301ea2c5 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Wed, 17 Jan 2024 22:07:11 +0000
Subject: [PATCH 1/4] [libc][NFC] Fix GCC volatile warning

GCC complains about "type qualifiers ignored on cast result type"
---
 libc/test/src/__support/FPUtil/dyadic_float_test.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/__support/FPUtil/dyadic_float_test.cpp b/libc/test/src/__support/FPUtil/dyadic_float_test.cpp
index 8fafa767ae38e34..4ab270c63628a30 100644
--- a/libc/test/src/__support/FPUtil/dyadic_float_test.cpp
+++ b/libc/test/src/__support/FPUtil/dyadic_float_test.cpp
@@ -48,7 +48,7 @@ TEST(LlvmLibcDyadicFloatTest, QuickAdd) {
 
   Float192 z = quick_add(x, y);
 
-  EXPECT_FP_EQ_ALL_ROUNDING(xd + yd, (volatile double)(z));
+  EXPECT_FP_EQ_ALL_ROUNDING(xd + yd, double(z));
 }
 
 TEST(LlvmLibcDyadicFloatTest, QuickMul) {

>From a4ab2cce6398c564c9a97c97595eb78c19d2cc7c Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Thu, 18 Jan 2024 15:25:48 +0000
Subject: [PATCH 2/4] Add "-frounding-math" to math tests

---
 libc/test/src/CMakeLists.txt                                | 6 +++++-
 .../llvm-project-overlay/libc/test/libc_test_rules.bzl      | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index 6bd8ace9ea71af0..dacd8664e512c3f 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -3,7 +3,7 @@ function(add_fp_unittest name)
     "MATH_UNITTEST"
     "NEED_MPFR;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments
     "" # Single value arguments
-    "LINK_LIBRARIES" # Multi-value arguments
+    "LINK_LIBRARIES;COMPILE_OPTIONS" # Multi-value arguments
     ${ARGN}
   )
 
@@ -28,10 +28,14 @@ function(add_fp_unittest name)
   endif()
   list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
 
+  if (NOT "-frounding-math" IN_LIST MATH_UNITTEST_COMPILE_OPTIONS)
+    list(APPEND MATH_UNITTEST_COMPILE_OPTIONS "-frounding-math")
+  endif()
   add_libc_test(
     ${name}
     ${test_type}
     LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"
+    COMPILE_OPTIONS "${MATH_UNITTEST_COMPILE_OPTIONS}"
     "${MATH_UNITTEST_UNPARSED_ARGUMENTS}"
   )
 endfunction(add_fp_unittest)
diff --git a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
index 18056bacfd50cea..4e819257e1c523c 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
@@ -26,6 +26,7 @@ def libc_test(name, srcs, libc_function_deps = [], copts = [], deps = [], **kwar
       **kwargs: Attributes relevant for a libc_test. For example, name, srcs.
     """
     all_function_deps = libc_function_deps + ["//libc:errno"]
+    copts = copts + ["-frounding-math"]
     native.cc_test(
         name = name,
         srcs = srcs,

>From 953b524cbce0b546a430de2a8b12c06665726bec Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Thu, 18 Jan 2024 16:26:24 +0000
Subject: [PATCH 3/4] Apply -frounding-math only on dyadic_float_test

---
 libc/test/src/CMakeLists.txt                                | 6 +-----
 libc/test/src/__support/FPUtil/CMakeLists.txt               | 2 ++
 .../llvm-project-overlay/libc/test/libc_test_rules.bzl      | 1 -
 .../libc/test/src/__support/FPUtil/BUILD.bazel              | 1 +
 4 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index dacd8664e512c3f..6bd8ace9ea71af0 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -3,7 +3,7 @@ function(add_fp_unittest name)
     "MATH_UNITTEST"
     "NEED_MPFR;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments
     "" # Single value arguments
-    "LINK_LIBRARIES;COMPILE_OPTIONS" # Multi-value arguments
+    "LINK_LIBRARIES" # Multi-value arguments
     ${ARGN}
   )
 
@@ -28,14 +28,10 @@ function(add_fp_unittest name)
   endif()
   list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
 
-  if (NOT "-frounding-math" IN_LIST MATH_UNITTEST_COMPILE_OPTIONS)
-    list(APPEND MATH_UNITTEST_COMPILE_OPTIONS "-frounding-math")
-  endif()
   add_libc_test(
     ${name}
     ${test_type}
     LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"
-    COMPILE_OPTIONS "${MATH_UNITTEST_COMPILE_OPTIONS}"
     "${MATH_UNITTEST_UNPARSED_ARGUMENTS}"
   )
 endfunction(add_fp_unittest)
diff --git a/libc/test/src/__support/FPUtil/CMakeLists.txt b/libc/test/src/__support/FPUtil/CMakeLists.txt
index 411b8281470cf17..9d807ec3068d412 100644
--- a/libc/test/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/test/src/__support/FPUtil/CMakeLists.txt
@@ -9,6 +9,8 @@ add_fp_unittest(
     dyadic_float_test.cpp
   DEPENDS
     libc.src.__support.FPUtil.dyadic_float
+  COMPILE_OPTIONS
+    "-frounding-math"
 )
 
 add_libc_test(
diff --git a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
index 4e819257e1c523c..18056bacfd50cea 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
@@ -26,7 +26,6 @@ def libc_test(name, srcs, libc_function_deps = [], copts = [], deps = [], **kwar
       **kwargs: Attributes relevant for a libc_test. For example, name, srcs.
     """
     all_function_deps = libc_function_deps + ["//libc:errno"]
-    copts = copts + ["-frounding-math"]
     native.cc_test(
         name = name,
         srcs = srcs,
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/__support/FPUtil/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/__support/FPUtil/BUILD.bazel
index 4f206b21e478b1a..461d5127a42a749 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/__support/FPUtil/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/__support/FPUtil/BUILD.bazel
@@ -22,6 +22,7 @@ libc_test(
 libc_test(
     name = "dyadic_float_test",
     srcs = ["dyadic_float_test.cpp"],
+    copts = ["-frounding-math"],
     deps = [
         "//libc:__support_fputil_dyadic_float",
         "//libc:__support_uint",

>From fe52404c7e55cf3931622f17b0d469abb75b0d49 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Thu, 18 Jan 2024 19:08:59 +0000
Subject: [PATCH 4/4] Remove `volatile` and simplify test

---
 .../__support/FPUtil/dyadic_float_test.cpp    | 34 +++++++------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/libc/test/src/__support/FPUtil/dyadic_float_test.cpp b/libc/test/src/__support/FPUtil/dyadic_float_test.cpp
index 4ab270c63628a30..4d0eae10d01a199 100644
--- a/libc/test/src/__support/FPUtil/dyadic_float_test.cpp
+++ b/libc/test/src/__support/FPUtil/dyadic_float_test.cpp
@@ -19,49 +19,39 @@ using Float256 = LIBC_NAMESPACE::fputil::DyadicFloat<256>;
 TEST(LlvmLibcDyadicFloatTest, BasicConversions) {
   Float128 x(/*sign*/ false, /*exponent*/ 0,
              /*mantissa*/ Float128::MantissaType(1));
-  volatile float xf = float(x);
-  volatile double xd = double(x);
-  ASSERT_FP_EQ(1.0f, xf);
-  ASSERT_FP_EQ(1.0, xd);
+  ASSERT_FP_EQ(1.0f, float(x));
+  ASSERT_FP_EQ(1.0, double(x));
 
   Float128 y(0x1.0p-53);
-  volatile float yf = float(y);
-  volatile double yd = double(y);
-  ASSERT_FP_EQ(0x1.0p-53f, yf);
-  ASSERT_FP_EQ(0x1.0p-53, yd);
+  ASSERT_FP_EQ(0x1.0p-53f, float(y));
+  ASSERT_FP_EQ(0x1.0p-53, double(y));
 
   Float128 z = quick_add(x, y);
 
-  EXPECT_FP_EQ_ALL_ROUNDING(xf + yf, float(z));
-  EXPECT_FP_EQ_ALL_ROUNDING(xd + yd, double(z));
+  EXPECT_FP_EQ_ALL_ROUNDING(float(x) + float(y), float(z));
+  EXPECT_FP_EQ_ALL_ROUNDING(double(x) + double(y), double(z));
 }
 
 TEST(LlvmLibcDyadicFloatTest, QuickAdd) {
   Float192 x(/*sign*/ false, /*exponent*/ 0,
              /*mantissa*/ Float192::MantissaType(0x123456));
-  volatile double xd = double(x);
-  ASSERT_FP_EQ(0x1.23456p20, xd);
+  ASSERT_FP_EQ(0x1.23456p20, double(x));
 
   Float192 y(0x1.abcdefp-20);
-  volatile double yd = double(y);
-  ASSERT_FP_EQ(0x1.abcdefp-20, yd);
+  ASSERT_FP_EQ(0x1.abcdefp-20, double(y));
 
   Float192 z = quick_add(x, y);
-
-  EXPECT_FP_EQ_ALL_ROUNDING(xd + yd, double(z));
+  EXPECT_FP_EQ_ALL_ROUNDING(double(x) + double(y), double(z));
 }
 
 TEST(LlvmLibcDyadicFloatTest, QuickMul) {
   Float256 x(/*sign*/ false, /*exponent*/ 0,
              /*mantissa*/ Float256::MantissaType(0x123456));
-  volatile double xd = double(x);
-  ASSERT_FP_EQ(0x1.23456p20, xd);
+  ASSERT_FP_EQ(0x1.23456p20, double(x));
 
   Float256 y(0x1.abcdefp-25);
-  volatile double yd = double(y);
-  ASSERT_FP_EQ(0x1.abcdefp-25, yd);
+  ASSERT_FP_EQ(0x1.abcdefp-25, double(y));
 
   Float256 z = quick_mul(x, y);
-
-  EXPECT_FP_EQ_ALL_ROUNDING(xd * yd, double(z));
+  EXPECT_FP_EQ_ALL_ROUNDING(double(x) * double(y), double(z));
 }



More information about the llvm-commits mailing list