[PATCH] D99260: [analyzer] Fix false positives in inner pointer checker (PR49628)

Valeriy Savchenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 31 07:16:50 PDT 2021


vsavchenko added inline comments.


================
Comment at: clang/test/Analysis/inner-pointer.cpp:23
+
+char *data(std::string &c);
+
----------------
martong wrote:
> Seems like all test are exercising with std::string, this looks like a legacy in this Checker.
> Still, I miss a bit at least one test for the other overloads of `std::data`, maybe in a follow up patch?
I can add it here, but what other test you suggest to add?


================
Comment at: clang/test/Analysis/inner-pointer.cpp:378-392
+void func_addressof() {
+  const char *c;
+  std::string s;
+  c = s.c_str();
+  addressof(s);
+  consume(c); // no-warning
+}
----------------
martong wrote:
> So these are the FP cases that you are trying to solve?
> Would be nice to see more details about the bug report (rdar://73463300) if that is not proprietary.
```
std::optional<std::string> str = "example";
char* dup = strndup(str->c_str(), str->size());
```
`std::optional::operator->` uses `std::addressof` and the analyzer thinks that the pointer might get changed and raises the alarm.
I decided not to replicate `std::optional` in tests, and get straight to the point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99260



More information about the cfe-commits mailing list