This is an archive of the discontinued LLVM Phabricator instance.

[libc][NFC] Add new is_trivially_destructible check to libc's type_traits
ClosedPublic

Authored by mikhail.ramalho on Aug 15 2023, 3:58 PM.

Details

Summary

This patch adds new code to check if a given object is trivially
destructible. The ifdefs where necessary to implement it in gcc, as it
doesn't have the __is_trivially_destructible builtin like clang.

In gcc, it's not enough to only call __has_trivial_destructor, see:
https://stackoverflow.com/questions/20181702/which-type-traits-cannot-be-implemented-without-compiler-hooks

This patch only adds the new check, it will be used in D150211.

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 15 2023, 3:58 PM
mikhail.ramalho requested review of this revision.Aug 15 2023, 3:58 PM
This revision is now accepted and ready to land.Aug 16 2023, 1:47 PM
sivachandra accepted this revision.Aug 16 2023, 2:13 PM
sivachandra added a subscriber: sivachandra.

Apart from the nit, rest LGTM.

libc/src/__support/CPP/type_traits.h
289

Internal types have been listed in nested namespace named details in this file. So, you should follow that convention.

This might be preventing me from building on one of my systems.

FAILED: projects/libc/utils/gpu/server/CMakeFiles/llvmlibc_rpc_server.dir/rpc_server.cpp.o
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/c++ -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LIBCPP_ENABLE_HARDENED_MODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/jhuber/llvm-project/build/projects/libc/utils/gpu/server -I/home/jhuber/llvm-project/libc/utils/gpu/server -I/home/jhuber/llvm-project/build/include -I/home/jhuber/llvm-project/llvm/include -I/home/jhuber/llvm-project/libc -I/home/jhuber/llvm-project/libc/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -UNDEBUG -Wno-attributes -MD -MT projects/libc/utils/gpu/server/CMakeFiles/llvmlibc_rpc_server.dir/rpc_server.cpp.o -MF projects/libc/utils/gpu/server/CMakeFiles/llvmlibc_rpc_server.dir/rpc_server.cpp.o.d -o projects/libc/utils/gpu/server/CMakeFiles/llvmlibc_rpc_server.dir/rpc_server.cpp.o -c /home/jhuber/llvm-project/libc/utils/gpu/server/rpc_server.cpp
In file included from /home/jhuber/llvm-project/libc/src/__support/RPC/rpc_util.h:12,
                 from /home/jhuber/llvm-project/libc/src/__support/RPC/rpc.h:21,
                 from /home/jhuber/llvm-project/libc/utils/gpu/server/rpc_server.cpp:11:
/home/jhuber/llvm-project/libc/src/__support/CPP/type_traits.h:223:18: error: missing binary operator before token "("
  223 | #if __has_builtin(__is_lvalue_reference) &&                                    \
      |                  ^
/home/jhuber/llvm-project/libc/src/__support/CPP/type_traits.h:246:18: error: missing binary operator before token "("
  246 | #if __has_builtin(__remove_all_extents)
      |                  ^
/home/jhuber/llvm-project/libc/src/__support/CPP/type_traits.h:263:18: error: missing binary operator before token "("
  263 | #if __has_builtin(__is_function)
      |                  ^
/home/jhuber/llvm-project/libc/src/__support/CPP/type_traits.h:277:18: error: missing binary operator before token "("
  277 | #if __has_builtin(__is_destructible)
      |                  ^
/home/jhuber/llvm-project/libc/src/__support/CPP/type_traits.h:331:18: error: missing binary operator before token "("
  331 | #if __has_builtin(__is_trivially_destructible)
      |                  ^
/home/jhuber/llvm-project/libc/src/__support/CPP/type_traits.h:337:20: error: missing binary operator before token "("
  337 | #elif __has_builtin(__has_trivial_destructor)
      |                    ^
In file included from /home/jhuber/llvm-project/libc/src/__support/RPC/rpc.h:25,
                 from /home/jhuber/llvm-project/libc/utils/gpu/server/rpc_server.cpp:11:
/home/jhuber/llvm-project/libc/src/__support/CPP/optional.h:39:33: error: ‘is_trivially_destructible’ was not declared in this scope; did you mean ‘is_trivially_constructible’?
   39 |   template <typename U, bool = !is_trivially_destructible<U>::value>
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                                 is_trivially_constructible
/home/jhuber/llvm-project/libc/src/__support/CPP/optional.h:39:60: error: expected primary-expression before ‘>’ token
   39 |   template <typename U, bool = !is_trivially_destructible<U>::value>
      |                                                            ^
/home/jhuber/llvm-project/libc/src/__support/CPP/optional.h:39:58: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
   39 |   template <typename U, bool = !is_trivially_destructible<U>::value>
      |                                                          ^
/home/jhuber/llvm-project/libc/src/__support/CPP/optional.h:39:63: error: ‘value’ in namespace ‘::’ does not name a type
   39 |   template <typename U, bool = !is_trivially_destructible<U>::value>
      |                                                               ^~~~~
/home/jhuber/llvm-project/libc/src/__support/CPP/optional.h:52:4: warning: extra ‘;’ [-Wpedantic]
   52 |   };
      |    ^
      |    -
/home/jhuber/llvm-project/libc/src/__support/CPP/optional.h:54:32: error: ‘OptionalStorage’ is not a class template
   54 |   template <typename U> struct OptionalStorage<U, false> {
      |                                ^~~~~~~~~~~~~~~
[74/4706] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenDAGPatterns.cpp.o
ninja: build stopped: subcommand failed.

This file is compiled with the system GCC which is version 9.4.

This file is compiled with the system GCC which is version 9.4.

The official supported minimum GCC version is 12.2: https://libc.llvm.org/compiler_support.html

This file is compiled with the system GCC which is version 9.4.

The official supported minimum GCC version is 12.2: https://libc.llvm.org/compiler_support.html

So this differs from the LLVM requirement? That's problematic for this particular file because it's expected to be compiled with the user's configuration since it implements the CPU side server to interface with the RPC server. The GPU portion is only compiled with just-built clang. So it'll end up that the files I'm including there need to at least be able to be compiled. Any way we could make these statically return false in this case? I'm assuming it won't negatively impact anything else considienrg they're already guarded by __has_builtin.