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

Deep Majumder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 4 09:20:31 PST 2021


RedDocMD added a comment.

@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?


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