[libc-commits] [libc] [llvm] [libc] Add more functions in CPP/bit.h (PR #73814)
via libc-commits
libc-commits at lists.llvm.org
Wed Nov 29 09:47:53 PST 2023
================
@@ -1,57 +1,261 @@
-//===-- Freestanding version of bit_cast -----------------------*- C++ -*-===//
+//===-- Implementation of the C++20 bit header -----------------*- 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 is inspired from LLVM ADT/bit.h header.
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
+#include "src/__support/CPP/limits.h" // numeric_limits
#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 {
+#include <stdint.h>
-#if LIBC_HAS_BUILTIN(__builtin_bit_cast)
-#define LLVM_LIBC_HAS_BUILTIN_BIT_CAST
-#endif
+namespace LIBC_NAMESPACE::cpp {
#if LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
#define LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE
#endif
-// This function guarantees the bitcast to be optimized away by the compiler for
-// GCC >= 8 and Clang >= 6.
-template <class To, class From>
+// This implementation of bit_cast requires trivially-constructible To, to avoid
----------------
michaelrj-google wrote:
does this change cause any issues with existing bit_cast calls?
https://github.com/llvm/llvm-project/pull/73814
More information about the libc-commits
mailing list