[PATCH] D32378: Insert invariant.group.barrier for pointers comparisons

Hubert Tong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 30 20:38:27 PDT 2017


hubert.reinterpretcast added a comment.

Has it been discussed whether this is something to be addressed in the optimizer as opposed to the front-end?



================
Comment at: lib/CodeGen/CGExprScalar.cpp:3069
+          !isa<llvm::ConstantPointerNull>(RHS)) {
+        // Based on comparisons of pointers to dynamic objects, the optimizer
+        // can replace one pointer with another. This might result in
----------------
Consider:
```
extern "C" int printf(const char *, ...);
void *operator new(decltype(sizeof 0), void *);

struct A {
  virtual void foo() { printf("%s\n", __PRETTY_FUNCTION__); }
  int m;
  int *zip() { return &m; }
};

struct B : A {
  virtual void foo() { printf("%s\n", __PRETTY_FUNCTION__); }
};

int main(void) {
  A *ap = new A;
  ap->foo();
  int *const apz = ap->zip();
  B *bp = new (ap) B;
  if (apz == bp->zip()) {
    bp->foo();
  }
}
```


https://reviews.llvm.org/D32378





More information about the cfe-commits mailing list