[PATCH] D84604: Thread safety analysis: Consider global variables in scope

Jordan Rupprecht via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 29 14:21:56 PDT 2020


rupprecht added a comment.

I'm seeing failures which I think are due to this patch -- I don't have a nice godbolt repro yet, but it's something like:

  foo.h: 
  class Foo {
   public:
    static void DoStuff();  // Grabs mu_
  
  private:
    static std::vector<int> blah_ GUARDED_BY(mu_);
    static Mutex mu_;
  };
  
  bar.h:
  class Bar {
    static void DoThings(); // calls Foo::DoStuff()
  };

Because `DoStuff()` grabs `mu_`, it needs the lock, and this patch gives an error like `requires negative capability 'mu_'`. That's fine, and in fact better analysis is welcome.

However, I'm also seeing the same error for `DoThings()`, which doesn't make sense. When I add it, I then get errors that `mu_` is private, and therefore needs to be made public or friended for the thread analysis -- which is not at all a good change (the mutex should be encapsulated in the class). Even though it's "global" in the linkage sense, it's not visible outside of the class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84604



More information about the cfe-commits mailing list