//===- ThreadSafety.h -------------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // // A intra-procedural analysis for thread safety (e.g. deadlocks and race // conditions), based off of an annotation system. // // See http://clang.llvm.org/docs/LanguageExtensions.html#thread-safety-annotation-checking // for more information. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETY_H #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETY_H #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/StringRef.h" namespace clang { class AnalysisDeclContext; class FunctionDecl; class NamedDecl; namespace threadSafety { class BeforeSet; /// This enum distinguishes between different kinds of operations that may /// need to be protected by locks. We use this enum in error handling. enum ProtectedOperationKind { … }; /// This enum distinguishes between different kinds of lock actions. For /// example, it is an error to write a variable protected by shared version of a /// mutex. enum LockKind { … }; /// This enum distinguishes between different ways to access (read or write) a /// variable. enum AccessKind { … }; /// This enum distinguishes between different situations where we warn due to /// inconsistent locking. /// \enum SK_LockedSomeLoopIterations -- a mutex is locked for some but not all /// loop iterations. /// \enum SK_LockedSomePredecessors -- a mutex is locked in some but not all /// predecessors of a CFGBlock. /// \enum SK_LockedAtEndOfFunction -- a mutex is still locked at the end of a /// function. enum LockErrorKind { … }; /// Handler class for thread safety warnings. class ThreadSafetyHandler { … }; /// Check a function's CFG for thread-safety violations. /// /// We traverse the blocks in the CFG, compute the set of mutexes that are held /// at the end of each block, and issue warnings for thread safety violations. /// Each block in the CFG is traversed exactly once. void runThreadSafetyAnalysis(AnalysisDeclContext &AC, ThreadSafetyHandler &Handler, BeforeSet **Bset); void threadSafetyCleanup(BeforeSet *Cache); /// Helper function that returns a LockKind required for the given level /// of access. LockKind getLockKindFromAccessKind(AccessKind AK); } // namespace threadSafety } // namespace clang #endif // LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETY_H