[PATCH] D86029: [analyzer] Add modeling for unque_ptr::get()

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 15 18:33:12 PDT 2020


NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Excellent, thanks!



================
Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:362-363
+  const auto *InnerPointVal = State->get<TrackedRegionMap>(ThisRegion);
+  if (!InnerPointVal)
+    return;
+
----------------
You'll have to actively handle this case, sooner or later. Consider the following test cases that won't work until you do:
```lang=c++
void foo(std::unique_ptr<A> p) {
  A *x = p.get();
  A *y = p.get();
  clang_analyzer_eval(x == y); // expected-warning{{TRUE}}
  if (!x) {
    y->foo(); // expected-warning{{Called C++ object pointer is null}}
  }
}

```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86029



More information about the cfe-commits mailing list