Skip to content

Commit

Permalink
[vm] Fix the RISCV64 SDK build after 2f63ace.
Browse files Browse the repository at this point in the history
GCC (used in the RISCV64 build) and clang (used to build other
architectures) have different views of what's visible in the return type
position for an external template method definition. Thus, move the
use into the definition body via constexpr if, which works for both.

TEST=dart-sdk-linux-riscv64-try

Cq-Include-Trybots: luci.dart.try:dart-sdk-linux-riscv64-try
Change-Id: Id7adfd93764ff11d99d3ded4893739b90bb25676
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313123
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
  • Loading branch information
sstrickl authored and Commit Queue committed Jul 11, 2023
1 parent 453fce9 commit 03689db
Showing 1 changed file with 22 additions and 47 deletions.
69 changes: 22 additions & 47 deletions runtime/vm/raw_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,17 +523,7 @@ class UntaggedObject {
//
// Always returns an offset after the object header tags.
template <typename T>
static constexpr std::enable_if_t<!T::kContainsPointerFields, uword>
from_offset();

// The first offset in an allocated object of the given untagged type that
// contains a (possibly compressed) object pointer. Used to initialize object
// pointer fields to Object::null() instead of 0.
//
// Always returns an offset after the object header tags.
template <typename T>
DART_FORCE_INLINE static std::enable_if_t<T::kContainsPointerFields, uword>
from_offset();
DART_FORCE_INLINE static uword from_offset();

// The last offset in an allocated object of the given untagged type that
// contains a (possibly compressed) object pointer. Used to initialize object
Expand All @@ -545,21 +535,7 @@ class UntaggedObject {
// If there are no pointer fields in the object, then
// to_offset<T>() < from_offset<T>().
template <typename T>
static constexpr std::enable_if_t<!T::kContainsPointerFields, uword>
to_offset(intptr_t length = 0);

// The last offset in an allocated object of the given untagged type that
// contains a (possibly compressed) object pointer. Used to initialize object
// pointer fields to Object::null() instead of 0.
//
// Takes an optional argument that is the number of elements in the payload,
// which is ignored if the object never contains a payload.
//
// If there are no pointer fields in the object, then
// to_offset<T>() < from_offset<T>().
template <typename T>
DART_FORCE_INLINE static std::enable_if_t<T::kContainsPointerFields, uword>
to_offset(intptr_t length = 0);
DART_FORCE_INLINE static uword to_offset(intptr_t length = 0);

// All writes to heap objects should ultimately pass through one of the
// methods below or their counterparts in Object, to ensure that the
Expand Down Expand Up @@ -854,30 +830,29 @@ class UntaggedObject {
// in WeakArray/WeakProperty/WeakReference), then specialize the definitions.

template <typename T>
constexpr std::enable_if_t<!T::kContainsPointerFields, uword>
UntaggedObject::from_offset() {
// Non-zero to ensure to_offset() < from_offset() in this case, as
// to_offset() is the offset to the last pointer field, not past it.
return sizeof(UntaggedObject);
}
template <typename T>
DART_FORCE_INLINE std::enable_if_t<T::kContainsPointerFields, uword>
UntaggedObject::from_offset() {
return reinterpret_cast<uword>(reinterpret_cast<T*>(kOffsetOfPtr)->from()) -
kOffsetOfPtr;
DART_FORCE_INLINE uword UntaggedObject::from_offset() {
if constexpr (T::kContainsPointerFields) {
return reinterpret_cast<uword>(reinterpret_cast<T*>(kOffsetOfPtr)->from()) -
kOffsetOfPtr;
} else {
// Non-zero to ensure to_offset() < from_offset() in this case, as
// to_offset() is the offset to the last pointer field, not past it.
return sizeof(UntaggedObject);
}
}

template <typename T>
constexpr std::enable_if_t<!T::kContainsPointerFields, uword>
UntaggedObject::to_offset(intptr_t length) {
return 0;
}
template <typename T>
DART_FORCE_INLINE std::enable_if_t<T::kContainsPointerFields, uword>
UntaggedObject::to_offset(intptr_t length) {
return reinterpret_cast<uword>(
reinterpret_cast<T*>(kOffsetOfPtr)->to(length)) -
kOffsetOfPtr;
DART_FORCE_INLINE uword UntaggedObject::to_offset(intptr_t length) {
if constexpr (T::kContainsPointerFields) {
return reinterpret_cast<uword>(
reinterpret_cast<T*>(kOffsetOfPtr)->to(length)) -
kOffsetOfPtr;
} else {
USE(length);
// Zero to ensure to_offset() < from_offset() in this case, as
// from_offset() is guaranteed to return an offset after the header tags.
return 0;
}
}

inline intptr_t ObjectPtr::GetClassId() const {
Expand Down

0 comments on commit 03689db

Please sign in to comment.