[libc-commits] [libc] 5858f6c - [libc] Disable using __float128 on x86_64 Clang prior to 18.1. (#241999)
via libc-commits
libc-commits at lists.llvm.org
Fri Nov 13 07:48:19 PST 2026
Author: Alex Strelnikov
Date: 2026-11-13T15:48:12Z
New Revision: 5858f6c6890e8a594d8e1705edd54846b33bcad4
URL: https://github.com/llvm/llvm-project/commit/5858f6c6890e8a594d8e1705edd54846b33bcad4
DIFF: https://github.com/llvm/llvm-project/commit/5858f6c6890e8a594d8e1705edd54846b33bcad4.diff
LOG: [libc] Disable using __float128 on x86_64 Clang prior to 18.1. (#241999)
This fixes the root cause of the post-merge failures for #235008
implementing `swprintf`.
Prior to Clang 18.1, there is an x86_64 bug in `va_arg` for `__float128`
due to the type not being handled in `X86_64ABIInfo::classify` (fixed in
https://github.com/llvm/llvm-project/pull/75156).
https://godbolt.org/z/cWEej49jb compares Clang 17 and 18.1.
This should have been caught earlier by the same LLVM BuildBot running
sprintf_test, but `src/__support/printf_core/printf_config.h` which
configures `LIBC_INTERNAL_PRINTF_CONVERT_FLOAT128` was missing an
include of `include/llvm-libc-types/float128.h`. This meant the `%Q`
conversion cases in sprintf_test were getting compiled out, and it was
by luck that the header include order for swprintf_test triggered the
issue.
Assisted-by: Automated tooling, human reviewed.
Added:
Modified:
libc/include/llvm-libc-types/float128.h
libc/src/__support/printf_core/CMakeLists.txt
libc/src/__support/printf_core/printf_config.h
libc/test/src/stdio/sprintf_test.cpp
Removed:
################################################################################
diff --git a/libc/include/llvm-libc-types/float128.h b/libc/include/llvm-libc-types/float128.h
index 5bbb99109901b..1d42386d62684 100644
--- a/libc/include/llvm-libc-types/float128.h
+++ b/libc/include/llvm-libc-types/float128.h
@@ -26,8 +26,14 @@ typedef _Float128 float128;
// notify the availability of __float128.
// clang also uses __FLOAT128__ macro to notify the availability of __float128
// type: https://reviews.llvm.org/D15120
+// Disable on x86_64 Clang version less than 18.1 due to issue passing
+// __float128 via varargs prior to
+// https://github.com/llvm/llvm-project/pull/75156.
+#if !(defined(__clang__) && \
+ (__clang_major__ * 100 + __clang_minor__ < 1801) && defined(__x86_64__))
#define LIBC_TYPES_HAS_NATIVE_FLOAT128
typedef __float128 float128;
+#endif // !(Clang < 18.1 on x86_64)
#elif (LDBL_MANT_DIG == 113)
#define LIBC_TYPES_HAS_NATIVE_FLOAT128
typedef long double float128;
diff --git a/libc/src/__support/printf_core/CMakeLists.txt b/libc/src/__support/printf_core/CMakeLists.txt
index 961152fff2bba..07e79ef470fc8 100644
--- a/libc/src/__support/printf_core/CMakeLists.txt
+++ b/libc/src/__support/printf_core/CMakeLists.txt
@@ -79,6 +79,8 @@ add_header_library(
HDRS
printf_config.h
${printf_config_copts}
+ DEPENDS
+ libc.src.__support.macros.properties.types
)
add_header_library(
diff --git a/libc/src/__support/printf_core/printf_config.h b/libc/src/__support/printf_core/printf_config.h
index be6ab71958aaf..904d3d59ded3a 100644
--- a/libc/src/__support/printf_core/printf_config.h
+++ b/libc/src/__support/printf_core/printf_config.h
@@ -9,6 +9,8 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_PRINTF_CORE_PRINTF_CONFIG_H
#define LLVM_LIBC_SRC___SUPPORT_PRINTF_CORE_PRINTF_CONFIG_H
+#include "src/__support/macros/properties/types.h"
+
// The index array buffer is always initialized when printf is called. In cases
// where index mode is necessary but memory is limited, or when index mode
// performance is important and memory is available, this compile option
diff --git a/libc/test/src/stdio/sprintf_test.cpp b/libc/test/src/stdio/sprintf_test.cpp
index 8fe8091b6acfc..3378a8487242f 100644
--- a/libc/test/src/stdio/sprintf_test.cpp
+++ b/libc/test/src/stdio/sprintf_test.cpp
@@ -3367,10 +3367,10 @@ TEST(LlvmLibcSPrintfTest, FloatAutoFloat128Conv) {
ASSERT_STREQ_LEN(written, buff, "0.1");
written = LIBC_NAMESPACE::sprintf(buff, "%Qg", float128(1e1000L));
- ASSERT_STREQ_LEN(written, big_buff, "1e+1000");
+ ASSERT_STREQ_LEN(written, buff, "1e+1000");
written = LIBC_NAMESPACE::sprintf(buff, "%Qg", float128(1e4900L));
- ASSERT_STREQ_LEN(written, big_buff, "1e+4900");
+ ASSERT_STREQ_LEN(written, buff, "1e+4900");
}
#endif // LIBC_INTERNAL_PRINTF_CONVERT_FLOAT128
More information about the libc-commits
mailing list