[all-commits] [llvm/llvm-project] 5250a0: Thread safety analysis: Consider global variables ...

Aaron Puchert via All-commits all-commits at lists.llvm.org
Sun Oct 25 11:35:52 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 5250a03a9959c2701a8338fe1a1ffa8bd93d6173
      https://github.com/llvm/llvm-project/commit/5250a03a9959c2701a8338fe1a1ffa8bd93d6173
  Author: Aaron Puchert <aaronpuchert at alice-dsl.net>
  Date:   2020-10-25 (Sun, 25 Oct 2020)

  Changed paths:
    M clang/lib/Analysis/ThreadSafety.cpp
    M clang/test/SemaCXX/warn-thread-safety-analysis.cpp
    M clang/test/SemaCXX/warn-thread-safety-negative.cpp

  Log Message:
  -----------
  Thread safety analysis: Consider global variables in scope

Instead of just mutex members we also consider mutex globals.
Unsurprisingly they are always in scope. Now the paper [1] says that

> The scope of a class member is assumed to be its enclosing class,
> while the scope of a global variable is the translation unit in
> which it is defined.

But I don't think we should limit this to TUs where a definition is
available - a declaration is enough to acquire the mutex, and if a mutex
is really limited in scope to a translation unit, it should probably be
only declared there.

The previous attempt in 9dcc82f34ea was causing false positives because
I wrongly assumed that LiteralPtrs were always globals, which they are
not. This should be fixed now.

[1] https://static.googleusercontent.com/media/research.google.com/en/us/pubs/archive/42958.pdf

Fixes PR46354.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D84604




More information about the All-commits mailing list