[clang] [analyzer] Fix StackAddrEscapeChecker crash on temporary object fields (PR #66493)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 15 06:27:30 PDT 2023


================
@@ -398,7 +400,7 @@ void StackAddrEscapeChecker::checkEndFunction(const ReturnStmt *RS,
     }(Referrer->getMemorySpace());
 
     // This cast supposed to succeed.
----------------
steakhal wrote:

> I think the best would be either a comment that explains _why_ we expect a `VarRegion` here (e.g. it's already checked in function `fooBar()` etc.) or if possible, then a crash-less logic (converting an earlier `isa`-like check + this `cast` into a single `getAs`).

There is nothing that would directly imply this.
It's like, ATM I don't know of any other situations where it could be not a `VarRegion`, and so far it didn't appear in practice that would disprove this.

I'm not exactly sure if a comment like that would suffice. Would you accept it? And do you think it's necessary?

Another alternative could be a combination:

```c++
if (!isa<VarRegion>(Referrer)) {
  assert(false && "We should really only have VarRegions here");
  continue;
}
// ...
cast<VarRegion>(Referrer)...
```

https://github.com/llvm/llvm-project/pull/66493


More information about the cfe-commits mailing list