[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 08:26:41 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/3] [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 8fafa767ae38e3..4ab270c63628a3 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/3] 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 6bd8ace9ea71af..dacd8664e512c3 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 18056bacfd50ce..4e819257e1c523 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/3] 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 dacd8664e512c3..6bd8ace9ea71af 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 411b8281470cf1..9d807ec3068d41 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 4e819257e1c523..18056bacfd50ce 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 4f206b21e478b1..461d5127a42a74 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",



More information about the llvm-commits mailing list