Skip to content

Commit e553150

Browse files
committed
rt: Align when comparing the insides of boxes
1 parent 0459e38 commit e553150

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/rt/rust_shape.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,9 @@ class copy : public data<copy,uint8_t *> {
910910
class cmp : public data<cmp,ptr_pair> {
911911
private:
912912
template<typename T>
913-
int cmp_number(ptr_pair &ptrs);
913+
void cmp_number(const data_pair<T> &nums) {
914+
result = (nums.fst < nums.snd) ? -1 : (nums.fst == nums.snd) ? 0 : 1;
915+
}
914916

915917
public:
916918
int result;
@@ -933,20 +935,20 @@ class cmp : public data<cmp,ptr_pair> {
933935
void walk_box(bool align);
934936
void walk_struct(bool align, const uint8_t *end_sp);
935937
void walk_tag(bool align, tag_info &tinfo,
936-
data_pair<uint32_t> &tag_variants);
938+
const data_pair<uint32_t> &tag_variants);
937939
void walk_res(bool align, const rust_fn *dtor, uint16_t n_ty_params,
938940
const uint8_t *ty_params_sp);
939941

940942
template<typename T>
941-
void walk_number() { result = cmp_number<T>(dp); }
943+
void walk_number() { cmp_number(bump_dp<T>(dp)); }
942944
};
943945

944946
void
945947
cmp::walk_box(bool align) {
946948
data_pair<uint8_t *> subdp = bump_dp<uint8_t *>(dp);
947949
cmp subcx(*this, ptr_pair::make(subdp));
948950
subcx.dp += sizeof(uint32_t); // Skip over the reference count.
949-
subcx.walk(false);
951+
subcx.walk(true);
950952
result = subcx.result;
951953
}
952954

@@ -960,7 +962,10 @@ cmp::walk_struct(bool align, const uint8_t *end_sp) {
960962

961963
void
962964
cmp::walk_tag(bool align, tag_info &tinfo,
963-
data_pair<uint32_t> &tag_variants) {
965+
const data_pair<uint32_t> &tag_variants) {
966+
cmp_number(tag_variants);
967+
if (result != 0)
968+
return;
964969
abort(); // TODO
965970
}
966971

@@ -970,14 +975,6 @@ cmp::walk_res(bool align, const rust_fn *dtor, uint16_t n_ty_params,
970975
abort(); // TODO
971976
}
972977

973-
template<typename T>
974-
int
975-
cmp::cmp_number(ptr_pair &ptrs) {
976-
T a = *(reinterpret_cast<T *>(dp.fst));
977-
T b = *(reinterpret_cast<T *>(dp.snd));
978-
return (a < b) ? -1 : (a == b) ? 0 : 1;
979-
}
980-
981978
} // end namespace shape
982979

983980
extern "C" void

0 commit comments

Comments
 (0)