This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Teach is_integral, is_[un]signed and make_[un]signed about __[u]int128_t
ClosedPublic

Authored by stephant on Mar 2 2014, 11:16 AM.

Details

Reviewers
mclow.lists
Summary

This patch adds support for [u]int128_t to std::is_integral, std::is_[un]signed and std::make_[un]signed in <type_traits>. It also adds tests for std::numeric_limits<[u]int128_t>.

Currently, clang, GCC and compatible compilers support these 128-bit integer types. These compilers also define the SIZEOF_INT128 macro, which we use to detect the compiler support.

Diff Detail

Event Timeline

Per the cxx_status documentation:

"__int128 is not treated as an extended integer type, because changing
intmax_t would be an ABI-incompatible change."

With this in mind, I don't think it makes sense for these intrinsics to
accept __int128.

IMHO, having support for int128 in the type traits can be useful irrespective of whether int128 is recognized as an extended integer type. libstdc++ does support __int128 too (except in strict ansi mode).

Wouldn't that make strict ANSI mode abi incompatible when not in strict
ANSI mode?

Having talked to @rsmith about this issue, I'm compelled to withdraw my concerns regarding allowing types which aren't either standard or extended integer types.

This behavior would be consistent with clang's __is_integral intrinsic.

This all looks fine to me, EXCEPT for the types as macros.
Let's give those types real names.

Lets either just use __int128_t, or bikeshed a name and have a typedef.

stephant updated this revision to Unknown Object (????).Mar 12 2014, 3:53 PM

Thanks for the review!

I've added a feature check macro called _LIBCPP_HAS_NO_INT128 to config and replaced the type macros with int128_t and __uint128_t.

I've also updated the 33(!) separate test files for numeric limits with tests for std::numeric_limit<__[u]int128_t>, as discussed on IRC.

The HugeEnum test fails when compiled with -std=c++03.

It needs to be wrapped in a "#if _LIBCPP_STD_VER > 11" block (see test/utilities/function.objects/unord.hash/enum.pass.cpp for an example)

stephant updated this revision to Unknown Object (????).Mar 12 2014, 4:59 PM

Thanks for finding this!

I've surrounded the uses of typed enums with ifndef _LIBCPP_HAS_NO_STRONG_ENUMS checks.

stephant updated this revision to Unknown Object (????).Mar 26 2014, 11:11 AM

I've rebased the patch.

With a formatting change to type_traits (discussed on IRC), this looks good to me.

mclow.lists accepted this revision.Mar 26 2014, 12:29 PM
stephant closed this revision.Mar 26 2014, 12:54 PM

Thanks a lot for the review!

Commited as r204849.