[PATCH] D151325: [analyzer] Differentiate lifetime extended temporaries

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 4 08:15:25 PDT 2023


xazax.hun added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp:556
+  bool IsLocal =
+      isa_and_nonnull<VarRegion, CXXLifetimeExtendedObjectRegion>(MR) &&
+      isa<StackSpaceRegion>(MR->getMemorySpace());
----------------
I think strictly speaking this might be "unsound" resulting in false positives in scenarios like:
```
void f(bool reset) {
  static T&& extended = getTemp();
  if (reset) {
    extended = getTemp();
    return;
  }
  consume(std::move(extended));
  f(true);
  extended.use();
}
```

In case the call to `f(true)` is not inlined (or in other cases there is some aliasing the analyzer does not know about), we might not realize that the object is reset and might falsely report a use after move.

But I think this is probably sufficiently rare that we do not care about those. 


================
Comment at: clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:101
+    QualType Ty = LER->getValueType().getLocalUnqualifiedType();
+    os << "stack memory associated with temporary object of type '";
+    Ty.print(os, Ctx.getPrintingPolicy());
----------------
Is this a good wording for static lifetime extended temporaries?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151325



More information about the cfe-commits mailing list