This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Fix bug in allocate_shared_for_overwrite
ClosedPublic

Authored by ldionne on Feb 10 2023, 3:44 PM.

Details

Reviewers
huixie90
tcanens
Group Reviewers
Restricted Project
Commits
rG580109025801: [libc++] Fix bug in allocate_shared_for_overwrite
Summary

Instead of destroying the object with allocator::destroy, we must
call its destructor directly. As a fly-by also mark LWG3008 as
fixed since it is handled by our implementation.

This was pointed out by Tim Song in https://reviews.llvm.org/D140913.

Diff Detail

Event Timeline

ldionne created this revision.Feb 10 2023, 3:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2023, 3:44 PM
ldionne requested review of this revision.Feb 10 2023, 3:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2023, 3:44 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript

The intent would be to cherry-pick to LLVM 16 since this is effectively a bugfix.

Thanks a lot @tcanens for bringing this to our attention.

libcxx/include/__memory/shared_ptr.h
266

@huixie90 I know this name is what you had started with and I asked to change it, but I think it now makes more sense since we do more than only default-constructing.

1013–1015

This is a fly-by refactoring.

Mordante added inline comments.
libcxx/include/__memory/construct_at.h
91
ldionne updated this revision to Diff 496691.Feb 11 2023, 8:45 AM
ldionne marked an inline comment as done.

Address comment and rebase.

huixie90 accepted this revision as: huixie90.Feb 11 2023, 1:04 PM

LGTM! thanks for the fix

ldionne accepted this revision as: Restricted Project.Feb 13 2023, 5:50 AM

Test failures are unrelated and have been fixed on main. @tcanens I'll ship this now because I think it is correct and I want to cherry-pick onto release/16.x ASAP, but I'll be happy to get your review even post-commit, as always.

This revision is now accepted and ready to land.Feb 13 2023, 5:50 AM
This revision was landed with ongoing or failed builds.Feb 13 2023, 5:51 AM
This revision was automatically updated to reflect the committed changes.
tcanens added inline comments.Feb 13 2023, 3:37 PM
libcxx/include/__memory/shared_ptr.h
299

Might want to make this consistent one way or the other instead of >= 20 in the ctor but > 17 here.

philnik added inline comments.
libcxx/include/__memory/shared_ptr.h
299

We decided to use >= for new code and didn't update the code base to reflect that change yet. Before it was just inconsistent.