[PATCH] D48027: [analyzer] Improve `CallDescription` to handle c++ method.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 22 13:16:33 PDT 2018


NoQ added a comment.

In https://reviews.llvm.org/D48027#1207721, @rnkovacs wrote:

> I guess it is highly unlikely for someone to write namespaces like that, and if they do, I think they deserve to have them treated as a `std::string`.


Yup. On the other hand, if we specify our method as `{"basic_string", "c_str"}` and they make a `namespace basic_string { const char *c_str(); }`, we are pretty likely to //crash// when we try to obtain this-value for the call that isn't a method. This is still not a big deal because it's still highly unlikely, but we've seen crash reports of this sort, and the easier our spec is, the more likely it becomes that somebody has a different thing with the same name. For example, if we want to model iterators and we specify `{"begin"}` without specifying the base class (so that all sorts of containers were covered), we still want to specify that we're looking for a method call and not for a global function call.

So i believe that one of the important remaining problems with `CallDescription` is to teach it to discriminate between global functions and methods. We can do it in a number of ways:

1. Make a special sub-class for CallDescription depending on the sort of the function (too verbose),
2. Tag all items in the list as "record" vs. "namespace" (too many tags),
3. Dunno, tons of other boring and verbose approaches,
4. Change our PreCall/PostCall callbacks to callback templates that let allow the user subscribe to specific sub-classes of `CallEvent` similarly to how he can subscribe to different kinds of statements in PreStmt<Class>/PostStmt<Class>, and then the user doesn't need to write any code to check it dynamically.


Repository:
  rC Clang

https://reviews.llvm.org/D48027





More information about the cfe-commits mailing list