[all-commits] [llvm/llvm-project] 7e7ece: [libc] Replace type punning with bit_cast

Guillaume Chatelet via All-commits all-commits at lists.llvm.org
Tue Feb 8 12:46:19 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7e7ecef98080500ad12766695a86d687170d3639
      https://github.com/llvm/llvm-project/commit/7e7ecef98080500ad12766695a86d687170d3639
  Author: Guillaume Chatelet <gchatelet at google.com>
  Date:   2022-02-08 (Tue, 08 Feb 2022)

  Changed paths:
    A libc/src/__support/CPP/Bit.h
    M libc/src/__support/CPP/CMakeLists.txt
    M libc/src/__support/FPUtil/FPBits.h
    M libc/src/__support/FPUtil/Hypot.h
    M libc/src/__support/FPUtil/ManipulationFunctions.h
    M libc/src/__support/FPUtil/generic/sqrt.h
    M libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
    M libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
    M libc/src/__support/FPUtil/x86_64/sqrt.h
    M libc/src/math/generic/log10f.cpp
    M libc/src/math/generic/log1pf.cpp
    M libc/src/math/generic/log2f.cpp
    M libc/src/math/generic/logf.cpp
    M libc/src/math/generic/math_utils.h
    M libc/src/string/memory_utils/CMakeLists.txt
    M libc/src/string/memory_utils/elements_x86.h
    M libc/test/src/math/NextAfterTest.h
    M libc/test/src/math/SqrtTest.h
    M utils/bazel/llvm-project-overlay/libc/BUILD.bazel

  Log Message:
  -----------
  [libc] Replace type punning with bit_cast

Although type punning is defined for union in C, it is UB in C++.
This patch introduces a bit_cast function to convert between types in a safe way.

This is necessary to get llvm-libc compile with GCC.
This patch is extracted from D119002.

Differential Revision: https://reviews.llvm.org/D119145




More information about the All-commits mailing list