1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00
Commit Graph

56 Commits

Author SHA1 Message Date
Duncan P. N. Exon Smith
a126d2972b ADT: Add SFINAE to the generic IntrusiveRefCntPtr constructors
Add an `enable_if` to the generic `IntrusiveRefCntPtr` constructors so
that std::is_convertible gives an honest answer when the underlying
pointers cannot be converted. Added `static_assert`s to the test suite
to verify.

Also combine generic constructors from `IntrusiveRefCntPtr<X>&&` and
`const IntrusiveRefCntPtr<X>&`. At first glance this appears to be an
infinite loop, but the real copy/move constructors are spelled out
separately above. Added a unit test to verify.

Differential Revision: https://reviews.llvm.org/D95498
2021-01-28 15:07:27 -08:00
Nathan James
5ed102c708 [ADT] Add makeIntrusiveRefCnt helper function
Works like std::make_unique but for IntrusiveRefCntPtr objects.
See https://lists.llvm.org/pipermail/llvm-dev/2021-January/147729.html

Reviewed By: dblaikie, MaskRay

Differential Revision: https://reviews.llvm.org/D94440
2021-01-11 20:12:53 +00:00
Duncan P. N. Exon Smith
7308ff63ab ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC
Allow a `std::unique_ptr` to be moved into the an `IntrusiveRefCntPtr`,
and remove a couple of now-unnecessary `release()` calls.

Differential Revision: https://reviews.llvm.org/D92888
2020-12-08 17:33:19 -08:00
Nathan James
28b9fcb9d6 [llvm][NFC] Made RefCountBase constructors protected
Matches ThreadSafeRefCountBase and forces the class to be inherited.
2020-12-07 20:23:11 +00:00
Nathan James
d6790a9df8 [llvm] Add asserts in (ThreadSafe)?RefCountedBase destructors
Added a trivial destructor in release mode and in debug mode a destructor that asserts RefCount is indeed zero.
This ensure people aren't manually (maybe accidentally) destroying these objects like in this contrived example.
```lang=c++
{
  std::unique_ptr<SomethingRefCounted> Object;
  holdIntrusiveOwnership(Object.get());
  // Object Destructor called here will assert.
}
```

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D92480
2020-12-07 20:20:08 +00:00
David Blaikie
4518389307 IntrusiveRefCntPtr: Ensure RefCount is initialized during ThreadSafeRefCountedBase copy construction
Post commit feedback on 2e83ccc2ee33 from Nathan James!
2020-12-03 18:43:01 -08:00
David Blaikie
88c4002891 ADT: Support copying of IntrusiveRefCntPtr objects
This was partially supported but untested for RefCountedBase (the
implicit copy assignment would've been problematic - so delete that) and
unsupported (would not have compiled, because std::atomic is
non-copyable) for ThreadSafeRefCountedBase (implement similar support
to RefCountedBase)

Fix the test that had a copy ctor for the derived object but called
RefCountBase's default ctor from that copy ctor - which meant it wasn't
actually testing RefCountBase's copy semantics.
2020-12-03 17:42:32 -08:00
Chandler Carruth
ae65e281f3 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Eugene Zelenko
c35b5b5fe7 [ADT] Partial re-commit of r303383. Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 305419
2017-06-14 21:42:24 +00:00
Adam Nemet
ee90d5e61d Revert "[ADT] Fix some Clang-tidy modernize-use-using warnings; other minor fixes (NFC)."
This reverts commit r303383.

This breaks the modules-enabled macOS build with:

lib/Support/LockFileManager.cpp:86:7: error: declaration of 'gethostuuid' must be imported from module 'Darwin.POSIX.unistd' before it is required

llvm-svn: 303402
2017-05-19 02:56:37 +00:00
Eugene Zelenko
7351729728 [ADT] Fix some Clang-tidy modernize-use-using warnings; other minor fixes (NFC).
llvm-svn: 303383
2017-05-18 21:27:11 +00:00
David Blaikie
4e010264d6 ADT: IntrusiveRefCntPtr: Broaden the definition of correct usage of RefCountedBase
This roughly matches the semantics of std::enable_shared_from_this - that it
does not dictate the ownership model of all users, but constrains those users
taking advantage of the intrusive nature to do so only when there's a guarantee
that that's the ownership model being used for the object being passed.

Reviewers: jlebar

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

llvm-svn: 290987
2017-01-04 18:57:31 +00:00
Justin Lebar
9746bebf2f [ADT] Rewrite IntrusiveRefCntPtr's comments. NFC
Edit for voice, and also add examples.  In particular, add an
explanation for why you might want to specialize IntrusiveRefCntPtrInfo,
which is not obvious.

llvm-svn: 290720
2016-12-29 19:59:38 +00:00
Justin Lebar
61e5b34b7e [ADT] Rename RefCountedBase::ref_cnt to RefCount. NFC
This makes it comply with the LLVM style guide, and also makes it
consistent with ThreadSafeRefCountedBase below.

llvm-svn: 290719
2016-12-29 19:59:34 +00:00
Justin Lebar
c54ca36396 [ADT] clang-format IntrusiveRefCntrPtr.h. NFC
This file had some strange indentation.

Also remove some unnecessary whitespace between one-line member
functions.

llvm-svn: 290718
2016-12-29 19:59:30 +00:00
Justin Lebar
71e5133921 [ADT] Delete RefCountedBaseVPTR.
Summary:
This class is unnecessary.

Its comment indicated that it was a compile error to allocate an
instance of a class that inherits from RefCountedBaseVPTR on the stack.
This may have been true at one point, but it's not today.

Moreover you really do not want to allocate *any* refcounted object on
the stack, vptrs or not, so if we did have a way to prevent these
objects from being stack-allocated, we'd want to apply it to regular
RefCountedBase too, obviating the need for a separate RefCountedBaseVPTR
class.

It seems that the main way RefCountedBaseVPTR provides safety is by
making its subclass's destructor virtual.  This may have been helpful at
one point, but these days clang will emit an error if you define a class
with virtual functions that inherits from RefCountedBase but doesn't
have a virtual destructor.

Reviewers: compnerd, dblaikie

Subscribers: cfe-commits, klimek, llvm-commits, mgorny

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

llvm-svn: 290717
2016-12-29 19:59:26 +00:00
Eugene Zelenko
becb428e09 [ADT] Fix some Clang-tidy modernize-use-default and Include What You Use warnings; other minor fixes.
Differential revision: https://reviews.llvm.org/D27001

llvm-svn: 287725
2016-11-23 00:30:24 +00:00
Benjamin Kramer
6d65c1193c Weaken ThreadSafeRefCountedBase atomics.
Doesn't make a difference on x86, but avoids memory barriers on
weakly-ordered archs like PowerPC and ARM.

llvm-svn: 276291
2016-07-21 15:06:50 +00:00
Hans Wennborg
00bac51e3e Fix Clang-tidy modernize-use-nullptr warnings in examples and include directories; other minor cleanups.
Patch by Eugene Zelenko!

Differential Revision: http://reviews.llvm.org/D13172

llvm-svn: 248811
2015-09-29 18:02:48 +00:00
Benjamin Kramer
45a545b9c6 Purge unused includes throughout libSupport.
NFC.

llvm-svn: 232976
2015-03-23 18:07:13 +00:00
Aaron Ballman
0e19b5d670 Removing LLVM_EXPLICIT, as MSVC 2012 was the last reason for requiring the macro. NFC; LLVM edition.
llvm-svn: 229335
2015-02-15 22:00:20 +00:00
Argyrios Kyrtzidis
1f6a53d959 [ADT/IntrusiveRefCntPtr] Give friend access to IntrusiveRefCntPtr<X> so the relevant move constructor can access 'Obj'.
llvm-svn: 218295
2014-09-23 06:06:43 +00:00
Alp Toker
3cfd773515 Remove IntrusiveRefCntPtr::getPtr() function
It was deprecated in r212366 and all uses have been switched to get().

llvm-svn: 212382
2014-07-05 22:20:59 +00:00
Alp Toker
aa479ec6e9 Deprecate IntrusiveRefCntPtr::getPtr() in favour of get()
This better aligns with other LLVM-specific and C++ standard library smart
pointer types.

In particular there are at least a few uses of intrusive refcounting in the
frontend where it's worth investigating std::shared_ptr as a more appropriate
alternative.

llvm-svn: 212366
2014-07-05 03:03:21 +00:00
Rafael Espindola
051278b46c Implement one operator== with another.
Thanks for David Blaikie for the suggestion.

llvm-svn: 210107
2014-06-03 15:06:22 +00:00
Rafael Espindola
863c5719fd Add operator== and operator!= to compare with nullptr.
llvm-svn: 210100
2014-06-03 13:26:18 +00:00
Rafael Espindola
47aa1edc02 Remove the last unspecified_bool_type from llvm.
llvm-svn: 210076
2014-06-03 05:05:15 +00:00
Craig Topper
52173239da [C++11] Replace some comparisons with 'nullptr' with simple boolean checks to reduce verbosity.
llvm-svn: 205829
2014-04-09 04:20:00 +00:00
Craig Topper
ee78063a54 [C++11] Make use of 'nullptr' in the Support library.
llvm-svn: 205697
2014-04-07 04:17:22 +00:00
Dmitri Gribenko
7ec0214e19 Remove unused private typedef
llvm-svn: 205190
2014-03-31 14:14:13 +00:00
Chandler Carruth
b3a97d3fa0 [cleanup] Re-sort the standard library include lines.
llvm-svn: 203066
2014-03-06 03:43:04 +00:00
Hans Wennborg
2cf252b12d Work around MSVC bug in IntrusiveRefCntPtr.h
The build was failing with:

  error C2664: 'std::atomic_int::atomic_int(const std::atomic_int &)' : cannot convert argument 1 from 'int' to 'const std::atomic_int &'

Apparently "std::atomic_int x(0)" doesn't work, but "std::atomic<int> x(0)"
does.

llvm-svn: 202988
2014-03-05 16:26:04 +00:00
Ben Langmuir
9d2ef01bfd Add a ThreadSafeRefCountedBase
A version of RefCountedBase that uses std::atomic_int to store its
reference count.

llvm-svn: 202984
2014-03-05 15:24:33 +00:00
Chandler Carruth
df9f7f4aec [C++11] Remove the R-value reference #if usage from the ADT and Support
libraries. It is now always 1 in LLVM builds.

llvm-svn: 202580
2014-03-01 09:27:28 +00:00
Rafael Espindola
8a0ed6dcd6 Cleanup the simplify_type implementation.
As far as simplify_type is concerned, there are 3 kinds of smart pointers:

* const correct: A 'const MyPtr<int> &' produces a 'const int*'. A
'MyPtr<int> &' produces a 'int *'.
* always const: Even a 'MyPtr<int> &' produces a 'const int*'.
* no const: Even a 'const MyPtr<int> &' produces a 'int*'.

This patch then does the following:

* Removes the unused specializations. Since they are unused, it is hard
to know which kind should be implemented.
* Make sure we don't drop const.
* Fix the default forwarding so that const correct pointer only need
one specialization.
* Simplifies the existing specializations.

llvm-svn: 178147
2013-03-27 16:43:11 +00:00
Jakub Staszak
f1ea1a7f37 Fix include guards so they exactly match file names.
llvm-svn: 172025
2013-01-10 00:45:19 +00:00
Chandler Carruth
5286042938 Switch LLVM_USE_RVALUE_REFERENCES to LLVM_HAS_RVALUE_REFERENCES.
Rationale:
1) This was the name in the comment block. ;]
2) It matches Clang's __has_feature naming convention.
3) It matches other compiler-feature-test conventions.

Sorry for the noise. =]

I've also switch the comment block to use a \brief tag and not duplicate
the name.

llvm-svn: 168996
2012-11-30 11:45:22 +00:00
Axel Naumann
e7f1c18fe7 Reference IntrusiveRefCntPtr in doxygen doc of RefCountedBase to get a link to the pointer class documentation.
llvm-svn: 161112
2012-08-01 14:53:13 +00:00
Benjamin Kramer
2f57459340 IntrusiveRefCntPtr: Simplify operator= as suggested by Richard Smith.
This way the constructors do all the hard work. No intended functionality change.

llvm-svn: 157773
2012-05-31 22:25:25 +00:00
Benjamin Kramer
5144cce317 IntrusiveRefCntPtr: Use the same pattern as the other operator= overloads when using rvalue refs.
llvm-svn: 157546
2012-05-27 20:46:04 +00:00
Benjamin Kramer
c529ae7728 Move-enable IntrusiveRefCntPtr.
These tend to be copied around a lot, moving it instead saves a ton of memory
accesses.

llvm-svn: 157535
2012-05-27 16:22:08 +00:00
Manuel Klimek
bd5c3cbb68 RefCountedBaseVPTR needs the IntrusiveRefCntPtrInfo as friend,
now that this handles the release / retain calls.

Adds a regression test for that bug (which is a compile-time
regression) and for the last two changes to the IntrusiveRefCntPtr,
especially tests for the memory leak due to copy construction of the
ref-counted object and ensuring that the traits are used for release /
retain calls.

llvm-svn: 149411
2012-01-31 19:58:34 +00:00
Ted Kremenek
add0641097 Relax constructor for IntrusiveRefCntPtr to not be explicit.
llvm-svn: 149309
2012-01-31 00:57:08 +00:00
Ted Kremenek
0022d6619e Use traits for IntrusiveRefCntPtr to determine how to increment/decrement a reference count.
llvm-svn: 149308
2012-01-31 00:57:04 +00:00
David Blaikie
576aba04f1 Unweaken vtables as per http://llvm.org/docs/CodingStandards.html#ll_virtual_anch
llvm-svn: 146960
2011-12-20 02:50:00 +00:00
Michael J. Spencer
d85f1f84f3 Support/FileSystem: Implement recursive_directory_iterator and make
directory_iterator preserve InputIterator semantics on copy.

llvm-svn: 146200
2011-12-08 22:50:09 +00:00
Ted Kremenek
5b61764405 Fix bug in RefCountedBase/RefCountedBaseVPTR where the reference count was accidentally copied as part of the copy constructor. This could result in objects getting leaked because there reference count was too high.
llvm-svn: 144931
2011-11-17 23:02:14 +00:00
Peter Collingbourne
44b69879c2 IntrusiveRefCntPtr: in RefCountedBase and RefCountedBaseVPTR, make
ref_cnt mutable and Retain/Release const to enable reference counted
pointers to const objects

llvm-svn: 128804
2011-04-04 00:57:03 +00:00
Ted Kremenek
a686187713 Relax access control on 'Release' method of RefCountedBase.
llvm-svn: 128054
2011-03-22 01:15:07 +00:00
Ted Kremenek
58a4560569 Allow a client to clear an IntrustiveRefCntPtr (deliberately leaking the referenced object).
llvm-svn: 128007
2011-03-21 18:37:59 +00:00