[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 21 01:14:44 PDT 2017


xazax.hun added a comment.

In https://reviews.llvm.org/D34275#785294, @wangxindsb wrote:

> > What about:
> > 
> >   struct A {
> >     A() {
> >       X x;
> >       x.virtualMethod(); // this virtual call is ok
> >       foo(); // should warn here
> >     }
> >     virtual foo();
> >   }
> >   int main() {
> >     A a;
> >   }
> > 
> > 
> > Does the checker warn on the second call?
>
> Yes, the checker warn on the second call.


Oh, I think I see how it works now. How about:

  struct A;
  struct X {
     void callFooOfA(A*);
  };
  struct A {
    A() {
      X x;
      x.virtualMethod(); // this virtual call is ok
      x.callFooOfA(this)
    }
    virtual foo();
  };
  void X::callFooOfA(A* a) {
     a->foo(); // Would be good to warn here. 
  }
  int main() {
    A a;
  }



================
Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:1
-//=======- VirtualCallChecker.cpp --------------------------------*- C++ -*-==//
-//
----------------
Please add the license back. 


https://reviews.llvm.org/D34275





More information about the cfe-commits mailing list