[PATCH] D95877: [analyzer] Fix static_cast on pointer-to-member handling

Valeriy Savchenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 5 00:13:22 PST 2021


vsavchenko added a comment.

In D95877#2542578 <https://reviews.llvm.org/D95877#2542578>, @RedDocMD wrote:

> @vsavchenko, after some experimentation, I found out that handling reinterpret_cast will be a real pain. Consider the following:
>
>   struct Base {
>   	int field;
>   };
>   
>   struct Derived : public Base {};
>   
>   struct DoubleDerived : public Derived {};
>   
>   struct Some {};
>   
>   void f() {
>   	int DoubleDerived::* ddf = &Base::field;
>   	int Base::* bf = reinterpret_cast<int Base::*>(reinterpret_cast<int Derived::*>(reinterpret_cast<int Base::*>(ddf)));
>   	int Some::* sf = reinterpret_cast<int Some::*>(ddf);
>   	Base base;
>   	base.*bf;
>   }
>
> The definition of `bf` can be handled I guess by manually discovering when to insert a sub-class or when to remove. It will require a bit of code but I guess is doable.
> As for the next one, also it has to be manually worked out whether it makes sense to process this statement further and add a node to the Exploded Graph. For the example I gave I don't think it makes a lot of sense. Multiple inheritance will make the task a lot worse as far as I can tell.
> Should I try to achieve this in another commit? What are your thoughts on this?

Yes, another commit is fine.  However, I'd say that it is still good to add test cases with TODOs with this commit.



================
Comment at: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:27
 #include <cstdint>
+#include <list>
 #include <utility>
----------------
We don't need this anymore :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95877



More information about the cfe-commits mailing list