[PATCH] D66486: [LifetimeAnalysis] Detect more cases when the address of a local variable escapes

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 23 12:10:53 PDT 2019


xazax.hun added a comment.

In D66486#1643374 <https://reviews.llvm.org/D66486#1643374>, @mgehre wrote:

> > Also it feels a bit weird to change the ownership semantics in a derived class, I bet that would violate the Liskov substitution principle.
>
> And then we see that llvm::OwningArrayRef inherits from llvm::ArrayRef ... But maybe this direction (strengthening a Pointer into an Owner)
>  is okay.


I am not sure. Consider the following code:

  ArrayRef f() {
    ArrayRef r = getRef();
    return r;
  }

According to the substitution principle I should be able to replace `r` with a derived class:

  ArrayRef f() {
    OwningArrayRef r = getOwningRef();
    return r;
  }

But this will introduce a lifetime issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66486





More information about the cfe-commits mailing list