[libc-commits] [compiler-rt] [libc] [llvm] [Compiler-rt][builtins] introduce libc math routines (PR #197950)

via libc-commits libc-commits at lists.llvm.org
Fri May 22 11:04:19 PDT 2026


https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/197950

>From 78326c920eadd4d7a511cace2d645f2615422075 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Sun, 17 May 2026 02:12:46 +0300
Subject: [PATCH 1/6] [Compiler-rt][builtins] introduce libc math routines

---
 .github/workflows/libc-overlay-tests.yml      |  9 ++++-
 compiler-rt/lib/builtins/CMakeLists.txt       | 17 +++++++++-
 .../lib/builtins/{addtf3.c => addtf3.cpp}     | 20 ++++++++---
 compiler-rt/lib/builtins/fp_libc_config.h     | 12 +++++++
 compiler-rt/lib/builtins/int_lib.h            | 14 ++++++--
 libc/shared/builtins.h                        | 16 +++++++++
 libc/shared/builtins/addtf3.h                 | 29 ++++++++++++++++
 libc/src/__support/CMakeLists.txt             |  1 +
 libc/src/__support/FPUtil/dyadic_float.h      |  3 ++
 libc/src/__support/builtins/CMakeLists.txt    |  9 +++++
 libc/src/__support/builtins/addtf3.h          | 33 +++++++++++++++++++
 11 files changed, 154 insertions(+), 9 deletions(-)
 rename compiler-rt/lib/builtins/{addtf3.c => addtf3.cpp} (67%)
 create mode 100644 compiler-rt/lib/builtins/fp_libc_config.h
 create mode 100644 libc/shared/builtins.h
 create mode 100644 libc/shared/builtins/addtf3.h
 create mode 100644 libc/src/__support/builtins/CMakeLists.txt
 create mode 100644 libc/src/__support/builtins/addtf3.h

diff --git a/.github/workflows/libc-overlay-tests.yml b/.github/workflows/libc-overlay-tests.yml
index f63150983aa03..2974634cb6d3e 100644
--- a/.github/workflows/libc-overlay-tests.yml
+++ b/.github/workflows/libc-overlay-tests.yml
@@ -109,9 +109,16 @@ jobs:
         --parallel 
         --target libc
 
-    - name: Test
+    - name: Test libc
       run: >
         cmake 
         --build ${{ steps.strings.outputs.build-output-dir }} 
         --parallel 
         --target check-libc
+    
+    - name: Test Compiler-rt builtins
+      run: >
+        cmake
+        --build ${{ steps.strings.outputs.build-output-dir }}
+        --parallel
+        --target check-builtins
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index 3fa21578c86ad..2843d0870f39c 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -215,7 +215,7 @@ set(BF16_SOURCES
 )
 
 set(GENERIC_TF_SOURCES
-  addtf3.c
+  addtf3.cpp
   comparetf2.c
   divtc3.c
   divtf3.c
@@ -243,6 +243,21 @@ set(GENERIC_TF_SOURCES
   trunctfsf2.c
 )
 
+option(COMPILER_RT_USE_LIBC_MATH
+      "Use LLVM libc math routines for floating-point builtins" OFF)
+
+if(COMPILER_RT_USE_LIBC_MATH)
+  set(LLVM_LIBC_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../libc"
+      CACHE PATH "Path to LLVM libc source directory")
+
+  if(NOT EXISTS "${LLVM_LIBC_SRC_DIR}/src/__support/FPUtil/FPBits.h")
+    message(FATAL_ERROR "LLVM libc not found at ${LLVM_LIBC_SRC_DIR}")
+  endif()
+
+  include_directories(SYSTEM ${LLVM_LIBC_SRC_DIR})
+  add_definitions(-DCOMPILER_RT_USE_LIBC_MATH)
+endif()
+
 option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN
   "Skip the atomic builtin (these should normally be provided by a shared library)"
   On)
diff --git a/compiler-rt/lib/builtins/addtf3.c b/compiler-rt/lib/builtins/addtf3.cpp
similarity index 67%
rename from compiler-rt/lib/builtins/addtf3.c
rename to compiler-rt/lib/builtins/addtf3.cpp
index 2cb3a4d591917..f8d0f72a4357d 100644
--- a/compiler-rt/lib/builtins/addtf3.c
+++ b/compiler-rt/lib/builtins/addtf3.cpp
@@ -13,11 +13,23 @@
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#if defined(CRT_HAS_TF_MODE)
-#include "fp_add_impl.inc"
+#ifdef COMPILER_RT_USE_LIBC_MATH
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/addtf3.h"
 
 COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) {
-  return __addXf3__(a, b);
+  return LIBC_NAMESPACE::shared::addtf3(a, b);
 }
 
-#endif
+#else
+
+#include "fp_add_impl.inc"
+#if defined(CRT_HAS_TF_MODE)
+
+COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) { return __addXf3__(a, b); }
+
+#endif // defined(CRT_HAS_TF_MODE)
+
+#endif // COMPILER_RT_USE_LIBC_MATH
\ No newline at end of file
diff --git a/compiler-rt/lib/builtins/fp_libc_config.h b/compiler-rt/lib/builtins/fp_libc_config.h
new file mode 100644
index 0000000000000..1dc69a9f95167
--- /dev/null
+++ b/compiler-rt/lib/builtins/fp_libc_config.h
@@ -0,0 +1,12 @@
+#ifndef FP_LIBC_CONFIG_H
+#define FP_LIBC_CONFIG_H
+
+#ifndef LIBC_COPT_PUBLIC_PACKAGING
+#define LIBC_COPT_PUBLIC_PACKAGING
+#endif
+
+#ifndef LIBC_NAMESPACE
+#define LIBC_NAMESPACE __llvm_libc_rt
+#endif
+
+#endif
\ No newline at end of file
diff --git a/compiler-rt/lib/builtins/int_lib.h b/compiler-rt/lib/builtins/int_lib.h
index 629c3065da6a0..8e76985134d94 100644
--- a/compiler-rt/lib/builtins/int_lib.h
+++ b/compiler-rt/lib/builtins/int_lib.h
@@ -20,14 +20,22 @@
 
 // ABI macro definitions
 
+// In C++ translation units we must give compiler-rt entry points C linkage so
+// that their symbol names are not mangled.  C TUs are unaffected.
+#ifdef __cplusplus
+#define COMPILER_RT_C_LINKAGE extern "C"
+#else
+#define COMPILER_RT_C_LINKAGE
+#endif
+
 #if __ARM_EABI__
 #ifdef COMPILER_RT_ARMHF_TARGET
-#define COMPILER_RT_ABI
+#define COMPILER_RT_ABI COMPILER_RT_C_LINKAGE
 #else
-#define COMPILER_RT_ABI __attribute__((__pcs__("aapcs")))
+#define COMPILER_RT_ABI COMPILER_RT_C_LINKAGE __attribute__((__pcs__("aapcs")))
 #endif
 #else
-#define COMPILER_RT_ABI
+#define COMPILER_RT_ABI COMPILER_RT_C_LINKAGE
 #endif
 
 #define AEABI_RTABI __attribute__((__pcs__("aapcs")))
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
new file mode 100644
index 0000000000000..157b6622cbcff
--- /dev/null
+++ b/libc/shared/builtins.h
@@ -0,0 +1,16 @@
+//===-- Compiler-runtime builtin primitives ---------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_H
+#define LLVM_LIBC_SHARED_BUILTINS_H
+
+#include "libc_common.h"
+
+#include "builtins/addtf3.h"
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/shared/builtins/addtf3.h b/libc/shared/builtins/addtf3.h
new file mode 100644
index 0000000000000..5dfda22d929b7
--- /dev/null
+++ b/libc/shared/builtins/addtf3.h
@@ -0,0 +1,29 @@
+//===-- Shared __addtf3 function -------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/addtf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::addtf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index ada489046ef9e..0246bcd8f01b6 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -470,6 +470,7 @@ add_subdirectory(wchar)
 add_subdirectory(wctype)
 
 add_subdirectory(math)
+add_subdirectory(builtins)
 if(LIBC_COMPILER_HAS_EXT_VECTOR_TYPE)
   add_subdirectory(mathvec)
 endif()
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index 8ce041247716b..04e7c0c34859b 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -415,6 +415,9 @@ template <size_t Bits> struct DyadicFloat {
     if constexpr (cpp::is_same_v<T, bfloat16>
 #if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
                   || cpp::is_same_v<T, float16>
+#endif
+#if defined(LIBC_TYPES_HAS_FLOAT128)
+                  || cpp::is_same_v<T, float128>
 #endif
     )
       return generic_as<T, ShouldSignalExceptions>();
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
new file mode 100644
index 0000000000000..c4982887d0a7c
--- /dev/null
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -0,0 +1,9 @@
+add_header_library(
+  addtf3
+  HDRS
+    addtf3.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/addtf3.h b/libc/src/__support/builtins/addtf3.h
new file mode 100644
index 0000000000000..f2c5b5332e877
--- /dev/null
+++ b/libc/src/__support/builtins/addtf3.h
@@ -0,0 +1,33 @@
+//===-- Implementation header for __addtf3 ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDTF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDTF3_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Same-precision quad-precision addition.
+// Mirrors the compiler-rt __addtf3 ABI: a + b at float128 precision.
+LIBC_INLINE float128 addtf3(float128 x, float128 y) {
+  return fputil::generic::add<float128>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDTF3_H

>From c1fc00bcf16b05df96ff36214b9ea0f5887793ae Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Mon, 18 May 2026 20:58:47 +0300
Subject: [PATCH 2/6] fix the ci

---
 .../compiler-rt-libc-builtins-tests.yml       | 57 +++++++++++++++++++
 .github/workflows/libc-overlay-tests.yml      |  9 +--
 2 files changed, 58 insertions(+), 8 deletions(-)
 create mode 100644 .github/workflows/compiler-rt-libc-builtins-tests.yml

diff --git a/.github/workflows/compiler-rt-libc-builtins-tests.yml b/.github/workflows/compiler-rt-libc-builtins-tests.yml
new file mode 100644
index 0000000000000..613a932b9ce50
--- /dev/null
+++ b/.github/workflows/compiler-rt-libc-builtins-tests.yml
@@ -0,0 +1,57 @@
+# Pre-commit CI for the compiler-rt + LLVM-libc builtins integration.
+name: compiler-rt + libc Builtins Tests
+permissions:
+  contents: read
+on:
+  pull_request:
+    branches: ["main"]
+    paths:
+      - "compiler-rt/lib/builtins/**"
+      - "compiler-rt/test/builtins/**"
+      - "libc/shared/builtins.h"
+      - "libc/shared/builtins/**"
+      - "libc/src/__support/builtins/**"
+      - "libc/src/__support/FPUtil/**"
+      - ".github/workflows/compiler-rt-libc-builtins-tests.yml"
+
+jobs:
+  build:
+    name: builtins (${{ matrix.os }})
+    runs-on: ${{ matrix.os }}
+    container:
+      image: ${{ (startsWith(matrix.os, 'ubuntu-24.04-arm') && 'ghcr.io/llvm/arm64v8/libc-ubuntu-24.04') || 'ghcr.io/llvm/libc-ubuntu-24.04' }}
+      options: >-
+        --privileged
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-24.04, ubuntu-24.04-arm]
+
+    steps:
+      - uses: actions/checkout at de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+        with:
+          persist-credentials: false
+
+      - name: Configure CMake
+        shell: bash
+        run: |
+          cmake \
+            -B /__w/llvm-project/llvm-project/build \
+            -S /__w/llvm-project/llvm-project/llvm \
+            -G Ninja \
+            -DCMAKE_C_COMPILER=clang-23 \
+            -DCMAKE_CXX_COMPILER=clang++-23 \
+            -DCMAKE_BUILD_TYPE=Release \
+            -DLLVM_ENABLE_ASSERTIONS=ON \
+            -DLLVM_ENABLE_PROJECTS=clang \
+            -DLLVM_ENABLE_RUNTIMES="libc;compiler-rt" \
+            -DCOMPILER_RT_USE_LIBC_MATH=ON \
+            -DCOMPILER_RT_INCLUDE_TESTS=ON
+
+      - name: Test compiler-rt builtins
+        shell: bash
+        run: |
+          cmake \
+            --build /__w/llvm-project/llvm-project/build \
+            --parallel \
+            --target check-builtins
diff --git a/.github/workflows/libc-overlay-tests.yml b/.github/workflows/libc-overlay-tests.yml
index 2974634cb6d3e..f63150983aa03 100644
--- a/.github/workflows/libc-overlay-tests.yml
+++ b/.github/workflows/libc-overlay-tests.yml
@@ -109,16 +109,9 @@ jobs:
         --parallel 
         --target libc
 
-    - name: Test libc
+    - name: Test
       run: >
         cmake 
         --build ${{ steps.strings.outputs.build-output-dir }} 
         --parallel 
         --target check-libc
-    
-    - name: Test Compiler-rt builtins
-      run: >
-        cmake
-        --build ${{ steps.strings.outputs.build-output-dir }}
-        --parallel
-        --target check-builtins

>From ea0bb8cfb14d9e1567ac86f00f5d11f47b3e36b2 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Tue, 19 May 2026 23:17:19 +0300
Subject: [PATCH 3/6] keep c builtin file

---
 compiler-rt/lib/builtins/CMakeLists.txt | 19 ++++++++++++-------
 compiler-rt/lib/builtins/addtf3.c       | 23 +++++++++++++++++++++++
 compiler-rt/lib/builtins/addtf3.cpp     | 17 ++---------------
 3 files changed, 37 insertions(+), 22 deletions(-)
 create mode 100644 compiler-rt/lib/builtins/addtf3.c

diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index 2843d0870f39c..015b87e4061e6 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -215,7 +215,7 @@ set(BF16_SOURCES
 )
 
 set(GENERIC_TF_SOURCES
-  addtf3.cpp
+  addtf3.c
   comparetf2.c
   divtc3.c
   divtf3.c
@@ -247,15 +247,20 @@ option(COMPILER_RT_USE_LIBC_MATH
       "Use LLVM libc math routines for floating-point builtins" OFF)
 
 if(COMPILER_RT_USE_LIBC_MATH)
-  set(LLVM_LIBC_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../libc"
-      CACHE PATH "Path to LLVM libc source directory")
-
-  if(NOT EXISTS "${LLVM_LIBC_SRC_DIR}/src/__support/FPUtil/FPBits.h")
-    message(FATAL_ERROR "LLVM libc not found at ${LLVM_LIBC_SRC_DIR}")
+  include(FindLibcCommonUtils)
+  if(NOT TARGET llvm-libc-common-utilities)
+    message(FATAL_ERROR "LLVM libc is not found at ${libc_path}.")
   endif()
 
-  include_directories(SYSTEM ${LLVM_LIBC_SRC_DIR})
+  get_target_property(_libc_include_dirs llvm-libc-common-utilities
+                      INTERFACE_INCLUDE_DIRECTORIES)
+  include_directories(SYSTEM ${_libc_include_dirs})
   add_definitions(-DCOMPILER_RT_USE_LIBC_MATH)
+
+  # Swap the legacy soft-float .c builtins for the libc-backed .cpp
+  # implementations (which delegate to LIBC_NAMESPACE::shared::*).
+  list(REMOVE_ITEM GENERIC_TF_SOURCES addtf3.c)
+  list(APPEND GENERIC_TF_SOURCES addtf3.cpp)
 endif()
 
 option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN
diff --git a/compiler-rt/lib/builtins/addtf3.c b/compiler-rt/lib/builtins/addtf3.c
new file mode 100644
index 0000000000000..2cb3a4d591917
--- /dev/null
+++ b/compiler-rt/lib/builtins/addtf3.c
@@ -0,0 +1,23 @@
+//===-- lib/addtf3.c - Quad-precision addition --------------------*- C -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements quad-precision soft-float addition.
+//
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#if defined(CRT_HAS_TF_MODE)
+#include "fp_add_impl.inc"
+
+COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) {
+  return __addXf3__(a, b);
+}
+
+#endif
diff --git a/compiler-rt/lib/builtins/addtf3.cpp b/compiler-rt/lib/builtins/addtf3.cpp
index f8d0f72a4357d..ded906bac2ab0 100644
--- a/compiler-rt/lib/builtins/addtf3.cpp
+++ b/compiler-rt/lib/builtins/addtf3.cpp
@@ -1,4 +1,4 @@
-//===-- lib/addtf3.c - Quad-precision addition --------------------*- C -*-===//
+//===-- lib/addtf3.cpp - Quad-precision addition (libc-backed) --*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements quad-precision soft-float addition.
+// __addtf3 implemented on top of LLVM-libc's shared::addtf3 instruction.
 //
 //===----------------------------------------------------------------------===//
 
 #define QUAD_PRECISION
 #include "fp_lib.h"
 
-#ifdef COMPILER_RT_USE_LIBC_MATH
-
 #include "fp_libc_config.h"
 #include "int_lib.h"
 #include "shared/builtins/addtf3.h"
@@ -22,14 +20,3 @@
 COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) {
   return LIBC_NAMESPACE::shared::addtf3(a, b);
 }
-
-#else
-
-#include "fp_add_impl.inc"
-#if defined(CRT_HAS_TF_MODE)
-
-COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) { return __addXf3__(a, b); }
-
-#endif // defined(CRT_HAS_TF_MODE)
-
-#endif // COMPILER_RT_USE_LIBC_MATH
\ No newline at end of file

>From 820f4984e351d2609e4349a5b9ecafa8dd88d6c3 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 20 May 2026 01:32:08 +0300
Subject: [PATCH 4/6] nits

---
 .github/workflows/compiler-rt-libc-builtins-tests.yml | 8 ++++----
 compiler-rt/lib/builtins/fp_libc_config.h             | 4 ----
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/compiler-rt-libc-builtins-tests.yml b/.github/workflows/compiler-rt-libc-builtins-tests.yml
index 613a932b9ce50..a6436eab150f8 100644
--- a/.github/workflows/compiler-rt-libc-builtins-tests.yml
+++ b/.github/workflows/compiler-rt-libc-builtins-tests.yml
@@ -36,15 +36,15 @@ jobs:
         shell: bash
         run: |
           cmake \
-            -B /__w/llvm-project/llvm-project/build \
-            -S /__w/llvm-project/llvm-project/llvm \
+            -B build \
+            -S llvm \
             -G Ninja \
             -DCMAKE_C_COMPILER=clang-23 \
             -DCMAKE_CXX_COMPILER=clang++-23 \
             -DCMAKE_BUILD_TYPE=Release \
             -DLLVM_ENABLE_ASSERTIONS=ON \
             -DLLVM_ENABLE_PROJECTS=clang \
-            -DLLVM_ENABLE_RUNTIMES="libc;compiler-rt" \
+            -DLLVM_ENABLE_RUNTIMES="compiler-rt" \
             -DCOMPILER_RT_USE_LIBC_MATH=ON \
             -DCOMPILER_RT_INCLUDE_TESTS=ON
 
@@ -52,6 +52,6 @@ jobs:
         shell: bash
         run: |
           cmake \
-            --build /__w/llvm-project/llvm-project/build \
+            --build build \
             --parallel \
             --target check-builtins
diff --git a/compiler-rt/lib/builtins/fp_libc_config.h b/compiler-rt/lib/builtins/fp_libc_config.h
index 1dc69a9f95167..827bc7aed9f82 100644
--- a/compiler-rt/lib/builtins/fp_libc_config.h
+++ b/compiler-rt/lib/builtins/fp_libc_config.h
@@ -1,10 +1,6 @@
 #ifndef FP_LIBC_CONFIG_H
 #define FP_LIBC_CONFIG_H
 
-#ifndef LIBC_COPT_PUBLIC_PACKAGING
-#define LIBC_COPT_PUBLIC_PACKAGING
-#endif
-
 #ifndef LIBC_NAMESPACE
 #define LIBC_NAMESPACE __llvm_libc_rt
 #endif

>From 124431895832c45e0dd4c06151800aad5b530531 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Fri, 22 May 2026 19:00:06 +0300
Subject: [PATCH 5/6] some nits

---
 compiler-rt/lib/builtins/addtf3.cpp       |  2 +-
 compiler-rt/lib/builtins/fp_libc_config.h |  2 ++
 compiler-rt/lib/builtins/int_lib.h        | 14 +++-----------
 libc/shared/builtins/addtf3.h             |  6 ++++++
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/compiler-rt/lib/builtins/addtf3.cpp b/compiler-rt/lib/builtins/addtf3.cpp
index ded906bac2ab0..ae4dbd5772cfb 100644
--- a/compiler-rt/lib/builtins/addtf3.cpp
+++ b/compiler-rt/lib/builtins/addtf3.cpp
@@ -17,6 +17,6 @@
 #include "int_lib.h"
 #include "shared/builtins/addtf3.h"
 
-COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) {
+extern "C" COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) {
   return LIBC_NAMESPACE::shared::addtf3(a, b);
 }
diff --git a/compiler-rt/lib/builtins/fp_libc_config.h b/compiler-rt/lib/builtins/fp_libc_config.h
index 827bc7aed9f82..74d7bdbaa4a61 100644
--- a/compiler-rt/lib/builtins/fp_libc_config.h
+++ b/compiler-rt/lib/builtins/fp_libc_config.h
@@ -5,4 +5,6 @@
 #define LIBC_NAMESPACE __llvm_libc_rt
 #endif
 
+#define LIBC_MATH (LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)
+
 #endif
\ No newline at end of file
diff --git a/compiler-rt/lib/builtins/int_lib.h b/compiler-rt/lib/builtins/int_lib.h
index 8e76985134d94..629c3065da6a0 100644
--- a/compiler-rt/lib/builtins/int_lib.h
+++ b/compiler-rt/lib/builtins/int_lib.h
@@ -20,22 +20,14 @@
 
 // ABI macro definitions
 
-// In C++ translation units we must give compiler-rt entry points C linkage so
-// that their symbol names are not mangled.  C TUs are unaffected.
-#ifdef __cplusplus
-#define COMPILER_RT_C_LINKAGE extern "C"
-#else
-#define COMPILER_RT_C_LINKAGE
-#endif
-
 #if __ARM_EABI__
 #ifdef COMPILER_RT_ARMHF_TARGET
-#define COMPILER_RT_ABI COMPILER_RT_C_LINKAGE
+#define COMPILER_RT_ABI
 #else
-#define COMPILER_RT_ABI COMPILER_RT_C_LINKAGE __attribute__((__pcs__("aapcs")))
+#define COMPILER_RT_ABI __attribute__((__pcs__("aapcs")))
 #endif
 #else
-#define COMPILER_RT_ABI COMPILER_RT_C_LINKAGE
+#define COMPILER_RT_ABI
 #endif
 
 #define AEABI_RTABI __attribute__((__pcs__("aapcs")))
diff --git a/libc/shared/builtins/addtf3.h b/libc/shared/builtins/addtf3.h
index 5dfda22d929b7..9c39e6e9a8406 100644
--- a/libc/shared/builtins/addtf3.h
+++ b/libc/shared/builtins/addtf3.h
@@ -5,6 +5,12 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+//
+// This header exposes LLVM-libc's __addtf3 implementation as shared::addtf3
+// so that it can be reused by other LLVM projects, such as compiler-rt's
+// builtins library.
+//
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H
 #define LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H

>From 3fdc423850c126c0052e3e4f57a1af7fddc3b58e Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Fri, 22 May 2026 21:03:58 +0300
Subject: [PATCH 6/6] add adddf3

---
 compiler-rt/lib/builtins/CMakeLists.txt    | 14 ++++++++---
 compiler-rt/lib/builtins/adddf3.cpp        | 19 ++++++++++++++
 libc/shared/builtins.h                     |  1 +
 libc/shared/builtins/adddf3.h              | 29 ++++++++++++++++++++++
 libc/src/__support/builtins/CMakeLists.txt |  9 +++++++
 libc/src/__support/builtins/adddf3.h       | 27 ++++++++++++++++++++
 6 files changed, 95 insertions(+), 4 deletions(-)
 create mode 100644 compiler-rt/lib/builtins/adddf3.cpp
 create mode 100644 libc/shared/builtins/adddf3.h
 create mode 100644 libc/src/__support/builtins/adddf3.h

diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index 015b87e4061e6..ff46a515ce77b 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -246,6 +246,14 @@ set(GENERIC_TF_SOURCES
 option(COMPILER_RT_USE_LIBC_MATH
       "Use LLVM libc math routines for floating-point builtins" OFF)
 
+# Swap the legacy soft-float <name>.c builtin in <list> for the libc-backed
+# <name>.cpp implementation (which delegates to LIBC_NAMESPACE::shared::*).
+# A macro -- not a function -- so list() mutates the caller's variable.
+macro(use_libc_builtin list_var name)
+  list(REMOVE_ITEM ${list_var} ${name}.c)
+  list(APPEND ${list_var} ${name}.cpp)
+endmacro()
+
 if(COMPILER_RT_USE_LIBC_MATH)
   include(FindLibcCommonUtils)
   if(NOT TARGET llvm-libc-common-utilities)
@@ -257,10 +265,8 @@ if(COMPILER_RT_USE_LIBC_MATH)
   include_directories(SYSTEM ${_libc_include_dirs})
   add_definitions(-DCOMPILER_RT_USE_LIBC_MATH)
 
-  # Swap the legacy soft-float .c builtins for the libc-backed .cpp
-  # implementations (which delegate to LIBC_NAMESPACE::shared::*).
-  list(REMOVE_ITEM GENERIC_TF_SOURCES addtf3.c)
-  list(APPEND GENERIC_TF_SOURCES addtf3.cpp)
+  use_libc_builtin(GENERIC_TF_SOURCES addtf3)
+  use_libc_builtin(GENERIC_SOURCES adddf3)
 endif()
 
 option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN
diff --git a/compiler-rt/lib/builtins/adddf3.cpp b/compiler-rt/lib/builtins/adddf3.cpp
new file mode 100644
index 0000000000000..7fd6a722bfeab
--- /dev/null
+++ b/compiler-rt/lib/builtins/adddf3.cpp
@@ -0,0 +1,19 @@
+//===-- lib/adddf3.cpp - Double-precision addition (libc-backed) *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// __adddf3 implemented on top of LLVM-libc's shared::adddf3 instruction.
+//
+//===----------------------------------------------------------------------===//
+
+#include "fp_libc_config.h"
+#include "int_lib.h"
+#include "shared/builtins/adddf3.h"
+
+extern "C" COMPILER_RT_ABI double __adddf3(double a, double b) {
+  return LIBC_NAMESPACE::shared::adddf3(a, b);
+}
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 157b6622cbcff..d1812ae357bbc 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -11,6 +11,7 @@
 
 #include "libc_common.h"
 
+#include "builtins/adddf3.h"
 #include "builtins/addtf3.h"
 
 #endif // LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/shared/builtins/adddf3.h b/libc/shared/builtins/adddf3.h
new file mode 100644
index 0000000000000..ae27fd8bdd5f5
--- /dev/null
+++ b/libc/shared/builtins/adddf3.h
@@ -0,0 +1,29 @@
+//===-- Shared __adddf3 function -------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This header exposes LLVM-libc's __adddf3 implementation as shared::adddf3
+// so that it can be reused by other LLVM projects, such as compiler-rt's
+// builtins library.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_ADDDF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_ADDDF3_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/adddf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::adddf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_ADDDF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index c4982887d0a7c..384e1d079e54b 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -7,3 +7,12 @@ add_header_library(
     libc.src.__support.FPUtil.generic.add_sub
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  adddf3
+  HDRS
+    adddf3.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/adddf3.h b/libc/src/__support/builtins/adddf3.h
new file mode 100644
index 0000000000000..e3e907b3164ef
--- /dev/null
+++ b/libc/src/__support/builtins/adddf3.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for __adddf3 ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDDF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDDF3_H
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Same-precision double-precision addition.
+// Mirrors the compiler-rt __adddf3 ABI: a + b at double precision.
+LIBC_INLINE double adddf3(double x, double y) {
+  return fputil::generic::add<double>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDDF3_H



More information about the libc-commits mailing list