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



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to