From: Eddie Elizondo Date: Mon, 15 Nov 2021 15:34:43 +0000 (-0500) Subject: Add comment to sorting function X-Git-Tag: v0.23.0~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ffec628c64faa4d15dc006240b17c0a7213c2b2a;p=platform%2Fupstream%2Fbcc.git Add comment to sorting function --- diff --git a/src/cc/usdt/usdt.cc b/src/cc/usdt/usdt.cc index bd3f2651..e3d0c441 100644 --- a/src/cc/usdt/usdt.cc +++ b/src/cc/usdt/usdt.cc @@ -220,6 +220,10 @@ void Probe::add_location(uint64_t addr, const std::string &bin_path, const char } void Probe::finalize_locations() { + // The following comparator needs to establish a strict weak ordering relation. Such + // that when x < y == true, y < x == false. Otherwise it leads to undefined behavior. + // To guarantee this, it uses std::tie which allows the lambda to have a lexicographical + // comparison and hence, guarantee the strict weak ordering. std::sort(locations_.begin(), locations_.end(), [](const Location &a, const Location &b) { return std::tie(a.bin_path_, a.address_) < std::tie(b.bin_path_, b.address_);