[libc-commits] [libc] [llvm] [libc] Temporary math macros fix (PR #87681)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Thu Apr 4 14:00:57 PDT 2024


https://github.com/michaelrj-google updated https://github.com/llvm/llvm-project/pull/87681

>From ac64d0656f423a5cd911fe0ebb02dbad195c30ce Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 4 Apr 2024 11:54:11 -0700
Subject: [PATCH 1/2] [libc] Temporary math macros fix

Downstream's having some issues due to math-macros.h issues. These will
be fixed properly soon.

See https://github.com/llvm/llvm-project/issues/87683 for tracking this tech debt.
---
 libc/include/llvm-libc-macros/math-macros.h       | 9 +++++++++
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 3 +--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h
index 1497e32044e975..99fb3dbf0a9b4e 100644
--- a/libc/include/llvm-libc-macros/math-macros.h
+++ b/libc/include/llvm-libc-macros/math-macros.h
@@ -9,6 +9,9 @@
 #ifndef LLVM_LIBC_MACROS_MATH_MACROS_H
 #define LLVM_LIBC_MACROS_MATH_MACROS_H
 
+// TODO: Remove this. This is a temporary fix for a downstream problem.
+#ifdef LLVM_LIBC_FULLBUILD
+
 #include "limits-macros.h"
 
 #define FP_NAN 0
@@ -79,4 +82,10 @@ template <typename T> inline constexpr bool isnan(T x) {
 
 #endif
 
+#else
+
+#include <math.h>
+
+#endif // LLVM_LIBC_FULLBUILD
+
 #endif // LLVM_LIBC_MACROS_MATH_MACROS_H
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 9dfe4c48184e3e..c06253b19558c8 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -68,7 +68,6 @@ libc_support_library(
     name = "llvm_libc_macros_math_macros",
     hdrs = ["include/llvm-libc-macros/math-macros.h"],
     deps = [":llvm_libc_macros_limits_macros"],
-    defines = ["__FP_LOGBNAN_MIN"],
 )
 
 libc_support_library(
@@ -1000,8 +999,8 @@ libc_support_library(
 
 libc_support_library(
     name = "__support_osutil_quick_exit",
-    hdrs = ["src/__support/OSUtil/quick_exit.h"],
     srcs = ["src/__support/OSUtil/linux/quick_exit.cpp"],
+    hdrs = ["src/__support/OSUtil/quick_exit.h"],
     deps = [
         ":__support_osutil_syscall",
     ],

>From d95569b714ffebd2ae14567256fc4ff020d5f543 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 4 Apr 2024 14:00:13 -0700
Subject: [PATCH 2/2] rename macro and set it for source/tests

---
 libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 7 +++++++
 libc/include/llvm-libc-macros/math-macros.h         | 8 +++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 40a1cfda060e6f..5b3a10d55fed35 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -43,6 +43,7 @@ function(_get_common_compile_options output_var flags)
     list(APPEND compile_options "-fpie")
 
     if(LLVM_LIBC_FULL_BUILD)
+      list(APPEND compile_options "-DLIBC_FULL_BUILD")
       # Only add -ffreestanding flag in full build mode.
       list(APPEND compile_options "-ffreestanding")
     endif()
@@ -126,6 +127,7 @@ function(_get_common_test_compile_options output_var c_test flags)
     list(APPEND compile_options "-fpie")
 
     if(LLVM_LIBC_FULL_BUILD)
+      list(APPEND compile_options "-DLIBC_FULL_BUILD")
       # Only add -ffreestanding flag in full build mode.
       list(APPEND compile_options "-ffreestanding")
       list(APPEND compile_options "-fno-exceptions")
@@ -178,5 +180,10 @@ function(_get_hermetic_test_compile_options output_var flags)
          -Wno-multi-gpu --cuda-path=${LIBC_CUDA_ROOT}
          -nogpulib -march=${LIBC_GPU_TARGET_ARCHITECTURE} -fno-use-cxa-atexit)
   endif()
+
+  if(LLVM_LIBC_FULL_BUILD)
+    list(APPEND compile_options "-DLIBC_FULL_BUILD")
+  endif()
+  
   set(${output_var} ${compile_options} PARENT_SCOPE)
 endfunction()
diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h
index 99fb3dbf0a9b4e..6046ea98cb8ac5 100644
--- a/libc/include/llvm-libc-macros/math-macros.h
+++ b/libc/include/llvm-libc-macros/math-macros.h
@@ -10,7 +10,9 @@
 #define LLVM_LIBC_MACROS_MATH_MACROS_H
 
 // TODO: Remove this. This is a temporary fix for a downstream problem.
-#ifdef LLVM_LIBC_FULLBUILD
+// This cannot be left permanently since it would require downstream users to
+// define this macro.
+#ifdef LIBC_FULL_BUILD
 
 #include "limits-macros.h"
 
@@ -82,10 +84,10 @@ template <typename T> inline constexpr bool isnan(T x) {
 
 #endif
 
-#else
+#else // LIBC_FULL_BUILD
 
 #include <math.h>
 
-#endif // LLVM_LIBC_FULLBUILD
+#endif // LIBC_FULL_BUILD
 
 #endif // LLVM_LIBC_MACROS_MATH_MACROS_H



More information about the libc-commits mailing list