mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 13:47:50 +00:00
[build] Move from the C++11 to the C++17 standard.
Also includes some example changes using C++14/C++17 features. TEST=vm/cc/BitField_Assert Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-win-release-x64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-kernel-precomp-linux-release-x64-try,dart-sdk-win-try,vm-kernel-win-release-x64-try,vm-kernel-win-release-ia32-try,dart-sdk-mac-try,vm-kernel-mac-release-x64-try Change-Id: Icf5c5267431daf9cea2e61b67131021557675f3c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192183 Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Commit-Queue: Tess Strickland <sstrickl@google.com>
This commit is contained in:
parent
caa31f55be
commit
6d1ea68cc9
|
@ -271,15 +271,12 @@ config("compiler") {
|
|||
cflags += [ "-fcolor-diagnostics" ]
|
||||
}
|
||||
|
||||
# C++11 compiler flags setup.
|
||||
# C++ standard compiler flags setup.
|
||||
# ---------------------------
|
||||
if (is_win) {
|
||||
# Up-to-date toolchain MSVC doesn't support c++11 flag any longer.
|
||||
cc_std = [ "/std:c++14" ]
|
||||
} else if (is_fuchsia) {
|
||||
cc_std = [ "-std=c++17" ]
|
||||
cc_std = [ "/std:c++17" ]
|
||||
} else {
|
||||
cc_std = [ "-std=c++11" ]
|
||||
cc_std = [ "-std=c++17" ]
|
||||
}
|
||||
cflags_cc += cc_std
|
||||
cflags_objcc += cc_std
|
||||
|
|
|
@ -20,7 +20,13 @@
|
|||
// from the way the Dart project expects it: DEBUG indicating a debug build.
|
||||
#if !defined(NDEBUG) && !defined(DEBUG)
|
||||
#define DEBUG
|
||||
#endif // !NDEBUG && !DEBUG
|
||||
#endif // !NDEBUG && !DEBUG \
|
||||
#else
|
||||
// Since <cassert> uses NDEBUG to signify that assert() macros should be turned
|
||||
// off, we'll define it when DEBUG is _not_ set.
|
||||
#if !defined(DEBUG)
|
||||
#define NDEBUG
|
||||
#endif
|
||||
#endif // GOOGLE3
|
||||
|
||||
// __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to
|
||||
|
@ -85,6 +91,8 @@
|
|||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cassert> // For assert() in constant expressions.
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include "platform/floating_point_win.h"
|
||||
#endif // defined(_WIN32)
|
||||
|
@ -136,12 +144,6 @@
|
|||
#define DEBUG_ONLY(code)
|
||||
#endif // defined(DEBUG)
|
||||
|
||||
#if defined(DEBUG)
|
||||
#define UNLESS_DEBUG(code)
|
||||
#else // defined(DEBUG)
|
||||
#define UNLESS_DEBUG(code) code
|
||||
#endif // defined(DEBUG)
|
||||
|
||||
namespace dart {
|
||||
|
||||
struct simd128_value_t {
|
||||
|
|
|
@ -57,7 +57,7 @@ class Utils {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static inline bool IsPowerOfTwo(T x) {
|
||||
static constexpr bool IsPowerOfTwo(T x) {
|
||||
return ((x & (x - 1)) == 0) && (x != 0);
|
||||
}
|
||||
|
||||
|
@ -73,13 +73,13 @@ class Utils {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static inline bool IsAligned(T x, intptr_t n) {
|
||||
ASSERT(IsPowerOfTwo(n));
|
||||
static constexpr bool IsAligned(T x, intptr_t n) {
|
||||
assert(IsPowerOfTwo(n));
|
||||
return (x & (n - 1)) == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline bool IsAligned(T* x, intptr_t n) {
|
||||
static constexpr bool IsAligned(T* x, intptr_t n) {
|
||||
return IsAligned(reinterpret_cast<uword>(x), n);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
|
||||
#include "platform/assert.h"
|
||||
#include "platform/globals.h"
|
||||
|
||||
namespace dart {
|
||||
|
@ -52,8 +51,8 @@ class BitField {
|
|||
static constexpr int bitsize() { return size; }
|
||||
|
||||
// Returns an S with the bit field value encoded.
|
||||
static UNLESS_DEBUG(constexpr) S encode(T value) {
|
||||
DEBUG_ASSERT(is_valid(value));
|
||||
static constexpr S encode(T value) {
|
||||
assert(is_valid(value));
|
||||
return encode_unchecked(value);
|
||||
}
|
||||
|
||||
|
@ -62,29 +61,28 @@ class BitField {
|
|||
// Ensure we slide down the sign bit if the value in the bit field is signed
|
||||
// and negative. We use 64-bit ints inside the expression since we can have
|
||||
// both cases: sizeof(S) > sizeof(T) or sizeof(S) < sizeof(T).
|
||||
return static_cast<T>(
|
||||
(sign_extend
|
||||
? (static_cast<int64_t>(static_cast<uint64_t>(value)
|
||||
<< (64 - (size + position))) >>
|
||||
(64 - size))
|
||||
: ((static_cast<typename std::make_unsigned<S>::type>(value) >>
|
||||
position) &
|
||||
mask())));
|
||||
if constexpr (sign_extend) {
|
||||
auto const u = static_cast<uint64_t>(value);
|
||||
return static_cast<T>((static_cast<int64_t>(u << (64 - kNextBit))) >>
|
||||
(64 - size));
|
||||
} else {
|
||||
auto const u = static_cast<typename std::make_unsigned<S>::type>(value);
|
||||
return static_cast<T>((u >> position) & mask());
|
||||
}
|
||||
}
|
||||
|
||||
// Returns an S with the bit field value encoded based on the
|
||||
// original value. Only the bits corresponding to this bit field
|
||||
// will be changed.
|
||||
static UNLESS_DEBUG(constexpr) S update(T value, S original) {
|
||||
DEBUG_ASSERT(is_valid(value));
|
||||
return encode_unchecked(value) | (~mask_in_place() & original);
|
||||
static constexpr S update(T value, S original) {
|
||||
return encode(value) | (~mask_in_place() & original);
|
||||
}
|
||||
|
||||
private:
|
||||
// Returns an S with the bit field value encoded.
|
||||
static constexpr S encode_unchecked(T value) {
|
||||
return (static_cast<typename std::make_unsigned<S>::type>(value) & mask())
|
||||
<< position;
|
||||
auto const u = static_cast<typename std::make_unsigned<S>::type>(value);
|
||||
return (u & mask()) << position;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -70,4 +70,16 @@ VM_UNIT_TEST_CASE(BitFields_SignedField) {
|
|||
TestSignExtendedBitField<int32_t>();
|
||||
}
|
||||
|
||||
#if defined(DEBUG)
|
||||
#define DEBUG_CRASH "Crash"
|
||||
#else
|
||||
#define DEBUG_CRASH "Pass"
|
||||
#endif
|
||||
|
||||
VM_UNIT_TEST_CASE_WITH_EXPECTATION(BitFields_Assert, DEBUG_CRASH) {
|
||||
class F : public BitField<uint32_t, uint32_t, 0, 8, /*sign_extend=*/false> {};
|
||||
const uint32_t value = F::encode(kMaxUint32);
|
||||
EXPECT_EQ(kMaxUint8, value);
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
|
|
@ -557,7 +557,7 @@ void ImageWriter::WriteROData(NonStreamingWriteStream* stream, bool vm) {
|
|||
}
|
||||
}
|
||||
|
||||
static UNLESS_DEBUG(constexpr) const uword kReadOnlyGCBits =
|
||||
static constexpr uword kReadOnlyGCBits =
|
||||
UntaggedObject::OldBit::encode(true) |
|
||||
UntaggedObject::OldAndNotMarkedBit::encode(false) |
|
||||
UntaggedObject::OldAndNotRememberedBit::encode(true) |
|
||||
|
|
|
@ -153,7 +153,7 @@ class UntaggedObject {
|
|||
static constexpr intptr_t kMaxSizeTag =
|
||||
kMaxSizeTagInUnitsOfAlignment * kObjectAlignment;
|
||||
|
||||
static UNLESS_DEBUG(constexpr) uword encode(intptr_t size) {
|
||||
static constexpr uword encode(intptr_t size) {
|
||||
return SizeBits::encode(SizeToTagValue(size));
|
||||
}
|
||||
|
||||
|
@ -161,11 +161,11 @@ class UntaggedObject {
|
|||
return TagValueToSize(SizeBits::decode(tag));
|
||||
}
|
||||
|
||||
static UNLESS_DEBUG(constexpr) uword update(intptr_t size, uword tag) {
|
||||
static constexpr uword update(intptr_t size, uword tag) {
|
||||
return SizeBits::update(SizeToTagValue(size), tag);
|
||||
}
|
||||
|
||||
static UNLESS_DEBUG(constexpr) bool SizeFits(intptr_t size) {
|
||||
static constexpr bool SizeFits(intptr_t size) {
|
||||
DEBUG_ASSERT(Utils::IsAligned(size, kObjectAlignment));
|
||||
return (size <= kMaxSizeTag);
|
||||
}
|
||||
|
@ -175,8 +175,8 @@ class UntaggedObject {
|
|||
class SizeBits
|
||||
: public BitField<uword, intptr_t, kSizeTagPos, kSizeTagSize> {};
|
||||
|
||||
static UNLESS_DEBUG(constexpr) intptr_t SizeToTagValue(intptr_t size) {
|
||||
DEBUG_ASSERT(Utils::IsAligned(size, kObjectAlignment));
|
||||
static constexpr intptr_t SizeToTagValue(intptr_t size) {
|
||||
assert(Utils::IsAligned(size, kObjectAlignment));
|
||||
return !SizeFits(size) ? 0 : (size >> kObjectAlignmentLog2);
|
||||
}
|
||||
static constexpr intptr_t TagValueToSize(intptr_t value) {
|
||||
|
|
Loading…
Reference in a new issue