Page MenuHomePhabricator

[libc++] Add __pointer_int_pair
Needs RevisionPublic

Authored by philnik on Dec 18 2022, 6:58 PM.


Group Reviewers
Restricted Project

This is an implementation detail for move_only_function

Diff Detail

Unit TestsFailed

1,210 mslibcxx CI GCC 12 / C++latest > llvm-libc++-shared-gcc-cfg-in.libcxx/utilities/pointer_int_pair::constructor_assert.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/g++-12 /home/libcxx-builder/.buildkite-agent/builds/f62f96aca9d4-1/llvm-project/libcxx-ci/libcxx/test/libcxx/utilities/pointer_int_pair/constructor_assert.pass.cpp -nostdinc++ -I /home/libcxx-builder/.buildkite-agent/builds/f62f96aca9d4-1/llvm-project/libcxx-ci/build/generic-gcc/include/c++/v1 -I /home/libcxx-builder/.buildkite-agent/builds/f62f96aca9d4-1/llvm-project/libcxx-ci/build/generic-gcc/include/c++/v1 -I /home/libcxx-builder/.buildkite-agent/builds/f62f96aca9d4-1/llvm-project/libcxx-ci/libcxx/test/support -std=c++2b -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-noexcept-type -Wno-aligned-allocation-unavailable -Wno-atomic-alignment -Wno-sized-deallocation -Wno-literal-suffix -Wno-user-defined-literals -Wno-tautological-compare -Wno-stringop-overread -Wno-stringop-overflow -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_DISABLE_AVAILABILITY -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -Wno-placement-new -Wno-class-memaccess -D_LIBCPP_ENABLE_ASSERTIONS=1 -lc++experimental -L /home/libcxx-builder/.buildkite-agent/builds/f62f96aca9d4-1/llvm-project/libcxx-ci/build/generic-gcc/lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/f62f96aca9d4-1/llvm-project/libcxx-ci/build/generic-gcc/lib -nodefaultlibs -lc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc -latomic -o /home/libcxx-builder/.buildkite-agent/builds/f62f96aca9d4-1/llvm-project/libcxx-ci/build/generic-gcc/test/libcxx/utilities/pointer_int_pair/Output/constructor_assert.pass.cpp.dir/t.tmp.exe
100 mslibcxx CI Modular build > llvm-libc++-shared-cfg-in.libcxx/utilities/pointer_int_pair::pointer_int_pair.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/clang++-16 /home/libcxx-builder/.buildkite-agent/builds/a74f23cef547-1/llvm-project/libcxx-ci/libcxx/test/libcxx/utilities/pointer_int_pair/pointer_int_pair.pass.cpp --target=x86_64-unknown-linux-gnu -nostdinc++ -I /home/libcxx-builder/.buildkite-agent/builds/a74f23cef547-1/llvm-project/libcxx-ci/build/generic-modules/include/c++/v1 -I /home/libcxx-builder/.buildkite-agent/builds/a74f23cef547-1/llvm-project/libcxx-ci/build/generic-modules/include/c++/v1 -I /home/libcxx-builder/.buildkite-agent/builds/a74f23cef547-1/llvm-project/libcxx-ci/libcxx/test/support -std=c++2b -fmodules -fcxx-modules -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-noexcept-type -Wno-atomic-alignment -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -lc++experimental -nostdlib++ -L /home/libcxx-builder/.buildkite-agent/builds/a74f23cef547-1/llvm-project/libcxx-ci/build/generic-modules/lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/a74f23cef547-1/llvm-project/libcxx-ci/build/generic-modules/lib -lc++ -pthread -o /home/libcxx-builder/.buildkite-agent/builds/a74f23cef547-1/llvm-project/libcxx-ci/build/generic-modules/test/libcxx/utilities/pointer_int_pair/Output/pointer_int_pair.pass.cpp.dir/t.tmp.exe

Event Timeline

philnik created this revision.Dec 18 2022, 6:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 18 2022, 6:58 PM
philnik requested review of this revision.Dec 18 2022, 6:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 18 2022, 6:58 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
philnik updated this revision to Diff 483891.Dec 19 2022, 2:49 AM

Generate output

philnik updated this revision to Diff 483894.Dec 19 2022, 3:22 AM

Try to fix CI

philnik updated this revision to Diff 483915.Dec 19 2022, 4:51 AM

Try to fix CI

ldionne requested changes to this revision.Dec 19 2022, 12:04 PM
ldionne added inline comments.

Why is this not just under __math?


We might as well add a comment explaining what the function does (compute the base-2 log of an integral type)?


Here and elsewhere?


I really feel like the parameters should be the other way around here, because this is really a pair, and we always specify both types in a pair. I suggest we do this:

enum class __bitfield_width : size_t { };

template <class _Pointer, class _IntType, __bitfield_width __int_bit_count>
struct __pointer_int_pair;

This way, we can do this, which is more obvious than what we have right now IMO:

__pointer_int_pair<Overaligned*, size_t, __bitfield_width(2)>

In particular, I don't see why we have a default size_t type for the integral type. I don't think it makes sense, since this tries to be a general pointer-and-integral-type pair.


I think this can be defined as a typedef inside the class?




Please add a test that uses the implicit syntax here to lock in this behavior. I think it's useful to have this be non-explicit so you can do something like return {ptr, int} when you know that the return type is a __pointer_int_pair, but I think it should be locked with a test.


I would hold off creating this until you need it (which may be in the very next patch, but then we can see it in context and decide whether it pulls its weight).


I would just inline it like this. I missed the __pointer prefix when I first read it and I thought this was a bug -- I think it's a bit confusing and doesn't save a lot of typing.


Those could be constexpr, not that it wins us very much.


Let's name this assert.constructor.pass.cpp -- I've been trying to do this consistently.


You could use ADDITIONAL_COMPILE_FLAGS: -Wno-private-header instead.


Please test that you can constinit a pointer-int-pair.


Please test with an overaligned type and with more than 2 bits for the integer.


Please test with a non-std::size_t type, like bool and a few others.

This revision now requires changes to proceed.Dec 19 2022, 12:04 PM

Mainly curious, can you give an indication how much space this would save?


Actually I think this file should be removed. Instead we should make __bit_log2 in <bit> available in all language versions.

LLVM ships the same type: PointerIntPair.

LLVM ships the same type: PointerIntPair.

This is heavily inspired from it, but we're still tweaking the API as we think makes the most sense. Since this is a private type, we can always end up changing the API if we find the we like something closer to the original one better.

ldionne added inline comments.

Note for when we come back to this review: do we need to care about endianness? This was raised by @huixie90 during the live review of D142063.