diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt index a2d3bd7df9e90..6853bfa3b304a 100644 --- a/libc/src/__support/CPP/CMakeLists.txt +++ b/libc/src/__support/CPP/CMakeLists.txt @@ -15,7 +15,10 @@ add_header_library( HDRS bit.h DEPENDS - libc.src.__support.macros.properties.compiler + .type_traits + libc.src.__support.macros.attributes + libc.src.__support.macros.config + libc.src.__support.macros.sanitizer ) add_header_library( diff --git a/libc/src/__support/CPP/bit.h b/libc/src/__support/CPP/bit.h index 456266626ae9b..f6f3131c1ccfd 100644 --- a/libc/src/__support/CPP/bit.h +++ b/libc/src/__support/CPP/bit.h @@ -12,6 +12,7 @@ #include "src/__support/CPP/type_traits.h" #include "src/__support/macros/attributes.h" #include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN +#include "src/__support/macros/sanitizer.h" namespace LIBC_NAMESPACE::cpp { @@ -31,6 +32,7 @@ LIBC_INLINE constexpr To bit_cast(const From &from) { static_assert(cpp::is_trivially_copyable::value && cpp::is_trivially_copyable::value, "Cannot bit-cast instances of non-trivially copyable classes."); + MSAN_UNPOISON(&from, sizeof(From)); #if defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST) return __builtin_bit_cast(To, from); #else diff --git a/libc/src/stdio/printf_core/float_inf_nan_converter.h b/libc/src/stdio/printf_core/float_inf_nan_converter.h index 3c24c393b3548..27a034cdcab1b 100644 --- a/libc/src/stdio/printf_core/float_inf_nan_converter.h +++ b/libc/src/stdio/printf_core/float_inf_nan_converter.h @@ -34,13 +34,13 @@ LIBC_INLINE int convert_inf_nan(Writer *writer, const FormatSection &to_conv) { fputil::FPBits::UIntType float_raw = to_conv.conv_val_raw; fputil::FPBits float_bits(float_raw); is_negative = float_bits.get_sign(); - mantissa = float_bits.get_explicit_mantissa(); + mantissa = float_bits.get_mantissa(); } else { fputil::FPBits::UIntType float_raw = static_cast::UIntType>(to_conv.conv_val_raw); fputil::FPBits float_bits(float_raw); is_negative = float_bits.get_sign(); - mantissa = float_bits.get_explicit_mantissa(); + mantissa = float_bits.get_mantissa(); } char sign_char = 0; diff --git a/libc/test/src/stdio/sprintf_test.cpp b/libc/test/src/stdio/sprintf_test.cpp index f3d5dd698cbea..5aa346c414b1f 100644 --- a/libc/test/src/stdio/sprintf_test.cpp +++ b/libc/test/src/stdio/sprintf_test.cpp @@ -572,7 +572,6 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) { ForceRoundingMode r(RoundingMode::Nearest); double inf = LIBC_NAMESPACE::fputil::FPBits::inf().get_val(); double nan = LIBC_NAMESPACE::fputil::FPBits::build_nan(1); - written = LIBC_NAMESPACE::sprintf(buff, "%a", 1.0); ASSERT_STREQ_LEN(written, buff, "0x1p+0"); @@ -937,6 +936,10 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) { ForceRoundingMode r(RoundingMode::Nearest); double inf = LIBC_NAMESPACE::fputil::FPBits::inf().get_val(); double nan = LIBC_NAMESPACE::fputil::FPBits::build_nan(1); + long double ld_inf = + LIBC_NAMESPACE::fputil::FPBits::inf().get_val(); + long double ld_nan = + LIBC_NAMESPACE::fputil::FPBits::build_nan(1); char big_buff[10000]; // Used for long doubles and other extremely wide // numbers. @@ -996,6 +999,18 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) { written = LIBC_NAMESPACE::sprintf(buff, "%F", -nan); ASSERT_STREQ_LEN(written, buff, "-NAN"); + written = LIBC_NAMESPACE::sprintf(buff, "%Lf", ld_inf); + ASSERT_STREQ_LEN(written, buff, "inf"); + + written = LIBC_NAMESPACE::sprintf(buff, "%LF", -ld_inf); + ASSERT_STREQ_LEN(written, buff, "-INF"); + + written = LIBC_NAMESPACE::sprintf(buff, "%Lf", ld_nan); + ASSERT_STREQ_LEN(written, buff, "nan"); + + written = LIBC_NAMESPACE::sprintf(buff, "%LF", -ld_nan); + ASSERT_STREQ_LEN(written, buff, "-NAN"); + // Length Modifier Tests. // TODO(michaelrj): Add tests for LONG_DOUBLE_IS_DOUBLE and 128 bit long diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index fdf60cd0df89c..3ae68193dccd2 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -170,6 +170,7 @@ libc_support_library( ":__support_cpp_type_traits", ":__support_macros_attributes", ":__support_macros_config", + ":__support_macros_sanitizer", ":libc_root", ], )