This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Fix allocator<void>::pointer in C++20 with removed members
ClosedPublic

Authored by ilya-biryukov on May 23 2022, 8:09 AM.

Details

Summary

When compiled with -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
uses of allocator<void>::pointer resulted in compiler errors after D104323.
If we instantiate the primary template, allocator<void>::reference produces
an error 'cannot form references to void'.

To workaround this, allow to bring back the allocator<void> specialization by defining the new _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION macro.

To make sure the code that uses allocator<void> and the removed members does not break,
both _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS and _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS have to be defined.

Diff Detail

Event Timeline

ilya-biryukov created this revision.May 23 2022, 8:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2022, 8:09 AM
ilya-biryukov requested review of this revision.May 23 2022, 8:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2022, 8:09 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
philnik requested changes to this revision.May 23 2022, 8:17 AM
philnik added a subscriber: philnik.
philnik added inline comments.
libcxx/include/__memory/allocator.h
30

I think using _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS is misleading. This doesn't just re-enable members, but an entire class specialization. Adding something like _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION would be the correct way IMO.

libcxx/test/std/utilities/memory/default.allocator/allocator_types.void.compile.cxx20_with_removed_members.pass.cpp
1 ↗(On Diff #431381)

This is a libc++ extension, so it should go in libcxx/test/libcxx and not libcxx/test/std.

18–23 ↗(On Diff #431381)

You can just make this a .compile.pass.cpp and remove the main().

This revision now requires changes to proceed.May 23 2022, 8:17 AM
ilya-biryukov added inline comments.May 23 2022, 8:23 AM
libcxx/include/__memory/allocator.h
30

That keeps allocator<void>::pointer broken with _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS defined and _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION not defined. Are we okay with that?

This specialization was there in the REMOVED_ALLOCATOR_MEMBERS mode before D104323 too, this change restores this behavior.

philnik added inline comments.May 23 2022, 8:31 AM
libcxx/include/__memory/allocator.h
30

I think it's Ok to have two flags for this, since the two changes are orthogonal IMO. But let's see what @ldionne thinks.

cjdb removed a subscriber: cjdb.May 23 2022, 9:19 AM
  • Move test to test/libcxx
  • Switch test to 'compile.pass' and remove 'main'
ilya-biryukov marked 2 inline comments as done.May 23 2022, 10:27 AM

@ldionne friendly ping. Just want to make sure this does not fall off your radar.
Let me know if you need more time, no rush here from our side.

@ldionne friendly ping. Just want to make sure this does not fall off your radar.
Let me know if you need more time, no rush here from our side.

Thanks for the ping.

Let's also add a release note and document the option in libcxx/docs/UsingLibcxx.rst.

libcxx/include/__memory/allocator.h
30

Yes, I agree with using _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION for this.

  • Add _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION
  • Document the new MACRO and add a release note
ilya-biryukov marked 2 inline comments as done.May 25 2022, 9:30 AM

Thanks for the quick response. I have addressed the comments, please take another look.

ldionne added inline comments.Jun 1 2022, 10:36 AM
libcxx/test/libcxx/utilities/memory/default.allocator/allocator_types.void.cxx20_allocator_void_no_members.fail.cpp
9–10

Can you explain what this test does? This sentence seems to be copy-pasted from the below test, but they are not checking the same thing.

ilya-biryukov added inline comments.Jun 2 2022, 12:01 AM
libcxx/test/libcxx/utilities/memory/default.allocator/allocator_types.void.cxx20_allocator_void_no_members.fail.cpp
9–10

It is copy-pasted indeed, thanks for catching that. I'll update the comment.
This test attempts to verify that the void specialization actually does not contain the removed members if the _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS is not specified.

ilya-biryukov edited the summary of this revision. (Show Details)Jun 2 2022, 12:06 AM
ilya-biryukov edited the summary of this revision. (Show Details)
  • Update test comment, only check in C++20 and beyond, add expected-errors

I've update change description and the added test. This should fix failures on buildbots and address the comments.
PTAL.

Side question: could you also point me to the docs that show how to run the test with clang in -verify mode?
I have tried passing --param=cxx_under_test=/usr/bin/clang++ to lit, but that did not even change the compiler that runs under tests.
I ended up running clang directly on the test with -Xclang -verify, but that's definitely not how other people do it :)

  • Fix test failure

Answering my own question here: I ended up pointing CC and CXX to Clang instead of GCC when running CMake. This makes lit add the -verify flag to tests.

@ldionne @philnik friendly ping, could you please take another look?

@ldionne @philnik another friendly ping, please take a look when you have a spare minute.

philnik accepted this revision as: philnik.Jun 14 2022, 8:08 AM

LGTM % nit.

libcxx/test/libcxx/utilities/memory/default.allocator/allocator_types.void.cxx20_allocator_void_no_members.fail.cpp
2

Could you make this a .verify.cpp?

ldionne accepted this revision.Jun 14 2022, 12:59 PM

LGTM with some comments. Please pay attention to the suggestions, some of them contain more than one fix per line and it's easy to miss!

Thanks!

libcxx/docs/ReleaseNotes.rst
112–116
libcxx/docs/UsingLibcxx.rst
328–330
libcxx/test/libcxx/utilities/memory/default.allocator/allocator_types.void.cxx20_allocator_void_no_members.fail.cpp
11
This revision is now accepted and ready to land.Jun 14 2022, 12:59 PM
  • Change test from .fail.cpp to .verify.cpp
  • Fix typos and apply suggestions in documentation and comments
This revision was landed with ongoing or failed builds.Jun 15 2022, 1:56 AM
This revision was automatically updated to reflect the committed changes.
ilya-biryukov marked an inline comment as done.