[llvm] r230021 - Base isPodLike on is_trivially_copyable for GCC 5 and MSVC

Benjamin Kramer benny.kra at gmail.com
Fri Feb 20 08:57:24 PST 2015


On Fri, Feb 20, 2015 at 5:35 PM, Chandler Carruth <chandlerc at google.com> wrote:
> I think we end up relying on this for more than just copyable. We also skip
> destructor calls in some places etc.
>
> Would it be better to change the users of this to use the more precise
> names? We can provide wrappers with version checks and defaulr fallbacks
> based on explicit specializations of the old trait.
>
> Thoughts?

Right, isPodLike is really broad and the only thing we use in the
ADT's to pick a simpler code path for memcpyable types. The semantics
just happen to match std::is_trivially_copyable for historical
reasons, is_trivially_copyable is defined to return false for all
classes with non-trivial dtors so this also works for dtor skipping.

It would be better to have an 'is_memcpyable' trait that also returns
true for things like std::unique_ptr, where we can use memcpy to move
them around but can't skip dtors, and a separate 'can_skip_dtors'
trait. Both can use std::is_trivially_copyable as a baseline.

I've been meaning to do this for a while but couldn't find enough
motivation to refactor SmallVector's template heap to support all of
this ;)

- Ben

> On Feb 20, 2015 8:26 AM, "Benjamin Kramer" <benny.kra at googlemail.com> wrote:
>>
>> Author: d0k
>> Date: Fri Feb 20 10:19:28 2015
>> New Revision: 230021
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=230021&view=rev
>> Log:
>> Base isPodLike on is_trivially_copyable for GCC 5 and MSVC
>>
>> It would be nice to get rid of the version checks here, but that will
>> have to wait until libstdc++ is upgraded to 5.0 everywhere ...
>>
>> Modified:
>>     llvm/trunk/include/llvm/Support/type_traits.h
>>
>> Modified: llvm/trunk/include/llvm/Support/type_traits.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/type_traits.h?rev=230021&r1=230020&r2=230021&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Support/type_traits.h (original)
>> +++ llvm/trunk/include/llvm/Support/type_traits.h Fri Feb 20 10:19:28 2015
>> @@ -28,9 +28,17 @@ namespace llvm {
>>  /// type can be copied around with memcpy instead of running ctors etc.
>>  template <typename T>
>>  struct isPodLike {
>> -#if __has_feature(is_trivially_copyable)
>> +  // std::is_trivially copyable is available in libc++ with clang,
>> libstdc++
>> +  // that comes with GCC 5 and MSVC 2013.
>> +#if (__has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION)) ||
>> \
>> +    (defined(__GNUC__) && __GNUC__ >= 5) || defined(_MSC_VER)
>>    // If the compiler supports the is_trivially_copyable trait use it, as
>> it
>>    // matches the definition of isPodLike closely.
>> +  static const bool value = std::is_trivially_copyable<T>::value;
>> +#elif __has_feature(is_trivially_copyable)
>> +  // Use the internal name if the compiler supports is_trivially_copyable
>> but we
>> +  // don't know if the standard library does. This is the case for clang
>> in
>> +  // conjunction with libstdc++ from GCC 4.x.
>>    static const bool value = __is_trivially_copyable(T);
>>  #else
>>    // If we don't know anything else, we can (at least) assume that all
>> non-class
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list