3 #include <unordered_set> 4 #include <unordered_map> 45 template <
typename T,
typename U>
46 bool mayAlias(
const T& a,
const U& b)
const {
47 if (a.empty() || b.empty()) {
52 std::unordered_set<const Element*> memoryLocations;
53 for (
auto it = a.cbegin(); it != a.cend();) {
54 const auto element = *it;
56 for (
const auto loc : element->getMemoryLocations()) {
57 memoryLocations.insert(loc);
60 const auto cnt = a.count(*it);
61 std::advance(it, cnt);
65 for (
auto it = b.cbegin(); it != b.cend();) {
66 const auto element = *it;
68 for (
const auto loc : element->getMemoryLocations()) {
69 if (memoryLocations.count(loc)) {
74 const auto cnt = b.count(*it);
75 std::advance(it, cnt);
85 std::unordered_map<Element*, std::unique_ptr<Element>> elements_;
88 enum class BfsDirection {
99 const Value* value =
nullptr;
103 std::unordered_set<Element*> pointsTo;
105 std::unordered_set<Element*> pointedFrom;
108 std::unordered_set<const Element*> getMemoryLocations()
const;
112 mutable std::unordered_set<const Element*> cachedMemoryLocations_;
116 template <
typename Fn>
117 bool bfs(Fn fn, BfsDirection dir)
const;