Skip to content

Commit

Permalink
[RR_GRAPH] Fixed Bug in LLVM17 Build
Browse files Browse the repository at this point in the history
The std::sort function requires operands to be "pointer-like", this
requires that de-referencing a const pointer should be allowed.

This was not an issue in the past, but in LLVM17 this property is
required. The edge_sort_iterator did not follow this property. This has
been fixed.
  • Loading branch information
AlexandreSinger committed Apr 1, 2024
1 parent 5cfbaa0 commit f4b6694
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions libs/librrgraph/src/base/rr_graph_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,25 @@ struct edge_swapper {

class edge_sort_iterator {
public:
edge_sort_iterator()
: swapper_(nullptr, 0) {}
edge_sort_iterator(t_rr_graph_storage* storage, size_t idx)
: swapper_(storage, idx) {}
edge_sort_iterator() {
swapper_ = new edge_swapper(nullptr, 0);
}

edge_sort_iterator(t_rr_graph_storage* storage, size_t idx) {
swapper_ = new edge_swapper(storage, idx);
}

edge_sort_iterator(const edge_sort_iterator& other)
: swapper_(
other.swapper_.storage_,
other.swapper_.idx_) {
edge_sort_iterator(const edge_sort_iterator& other) {
swapper_ = new edge_swapper(other.swapper_->storage_, other.swapper_->idx_);
}

~edge_sort_iterator() {
delete swapper_;
}

edge_sort_iterator& operator=(const edge_sort_iterator& other) {
swapper_.storage_ = other.swapper_.storage_;
swapper_.idx_ = other.swapper_.idx_;
swapper_->storage_ = other.swapper_->storage_;
swapper_->idx_ = other.swapper_->idx_;

return *this;
}
Expand All @@ -155,82 +160,82 @@ class edge_sort_iterator {
using pointer = edge_swapper*;
using difference_type = ssize_t;

edge_swapper& operator*() {
return this->swapper_;
edge_swapper& operator*() const {
return *this->swapper_;
}

edge_swapper* operator->() {
return &this->swapper_;
return this->swapper_;
}

edge_sort_iterator& operator+=(ssize_t n) {
swapper_.idx_ += n;
swapper_->idx_ += n;
return *this;
}

edge_sort_iterator& operator-=(ssize_t n) {
swapper_.idx_ -= n;
swapper_->idx_ -= n;
return *this;
}

edge_sort_iterator& operator++() {
++swapper_.idx_;
++swapper_->idx_;
return *this;
}

edge_sort_iterator& operator--() {
--swapper_.idx_;
--swapper_->idx_;
return *this;
}

friend edge_sort_iterator operator+(const edge_sort_iterator& lhs, ssize_t n) {
edge_sort_iterator ret = lhs;
ret.swapper_.idx_ += n;
ret.swapper_->idx_ += n;
return ret;
}

friend edge_sort_iterator operator-(const edge_sort_iterator& lhs, ssize_t n) {
edge_sort_iterator ret = lhs;
ret.swapper_.idx_ -= n;
ret.swapper_->idx_ -= n;
return ret;
}

friend ssize_t operator-(const edge_sort_iterator& lhs, const edge_sort_iterator& rhs) {
ssize_t diff = lhs.swapper_.idx_;
diff -= rhs.swapper_.idx_;
ssize_t diff = lhs.swapper_->idx_;
diff -= rhs.swapper_->idx_;
return diff;
}

friend bool operator==(const edge_sort_iterator& lhs, const edge_sort_iterator& rhs) {
return lhs.swapper_.idx_ == rhs.swapper_.idx_;
return lhs.swapper_->idx_ == rhs.swapper_->idx_;
}

friend bool operator!=(const edge_sort_iterator& lhs, const edge_sort_iterator& rhs) {
return lhs.swapper_.idx_ != rhs.swapper_.idx_;
return lhs.swapper_->idx_ != rhs.swapper_->idx_;
}

friend bool operator<(const edge_sort_iterator& lhs, const edge_sort_iterator& rhs) {
return lhs.swapper_.idx_ < rhs.swapper_.idx_;
return lhs.swapper_->idx_ < rhs.swapper_->idx_;
}

friend bool operator>(const edge_sort_iterator& lhs, const edge_sort_iterator& rhs) {
return lhs.swapper_.idx_ > rhs.swapper_.idx_;
return lhs.swapper_->idx_ > rhs.swapper_->idx_;
}

friend bool operator>=(const edge_sort_iterator& lhs, const edge_sort_iterator& rhs) {
return lhs.swapper_.idx_ >= rhs.swapper_.idx_;
return lhs.swapper_->idx_ >= rhs.swapper_->idx_;
}

friend bool operator<=(const edge_sort_iterator& lhs, const edge_sort_iterator& rhs) {
return lhs.swapper_.idx_ <= rhs.swapper_.idx_;
return lhs.swapper_->idx_ <= rhs.swapper_->idx_;
}

RREdgeId edge() const {
return RREdgeId(swapper_.idx_);
return RREdgeId(swapper_->idx_);
}

private:
edge_swapper swapper_;
edge_swapper *swapper_;
};

class edge_compare_src_node_and_configurable_first {
Expand Down

0 comments on commit f4b6694

Please sign in to comment.