[PATCH] D141188: [MergeICmps] Adapt to non-eq comparisons

Bogdan Graur via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 10:50:36 PDT 2023


bgraur added a comment.

@Allen this last patch is causing a miscompile again.

Here's a small artificial repro:

  namespace {
  struct Dt {
    Dt() = default;
  };
  
  class DtSet {
   public:
    DtSet() = default;
    ~DtSet() = default;
  
    class iterator {
     public:
      iterator(int a, int b, int idx)
          : a_(a), b_(b), idx_(idx) {}
      bool operator==(const iterator& other) const { return !(*this != other); }
      bool operator!=(const iterator& other) const;
     private:
      int a_, b_;
      int idx_;
    };
  
    iterator begin() const {
      if (0 == sz_) return end();
      int dt = 0;
      iterator iter(dt, dt+1, 0);
      return iter;
    }
    iterator end() const {
      return iterator(0, 0, sz_);
    }
  
   private:
    int sz_ = 0;
  
    DtSet(const DtSet&) = delete;
    DtSet& operator=(const DtSet&) = delete;
  };
  
  [[clang::noinline]]
  bool DtSet::iterator::operator!=(const iterator& other) const {
    return idx_ != other.idx_ || b_ != other.b_ || a_ != other.a_;
  }
  }  // namespace
  
  int main() {
    DtSet dt_set;
    if (dt_set.begin() == dt_set.end())
      return 0;
    else
      return 1;
  }

Compilation command:

  clang  -O3  -std=gnu++17  -pthread   \
     -o /tmp/out  \
     -x c++ /tmp/repro.cc

At this revision the program returns '1' (incorrect), at the previous revision the program returns '0' (as expected).

Could you please revert?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141188/new/

https://reviews.llvm.org/D141188



More information about the llvm-commits mailing list