Commit Graph

158 Commits

Author SHA1 Message Date
Aaron Ballman 8e7c1967e0 Thread safety analysis no longer hands when analyzing a self-referencing initializer.
This fixes PR38640.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340636 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-24 18:48:35 +00:00
Aaron Puchert 72f50eabcd Remove more const_casts by using ConstStmtVisitor [NFC]
Again, this required adding some const specifiers.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340580 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-23 21:53:04 +00:00
Aaron Puchert d2725d7944 Remove unnecessary const_cast [NFC]
This required adding a few const specifiers on functions.

Also a minor formatting fix suggested in D49885.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340575 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-23 21:13:32 +00:00
Aaron Puchert 4f97b44dc0 Thread safety analysis: Allow relockable scopes
Summary:
It's already allowed to prematurely release a scoped lock, now we also
allow relocking it again, possibly even in another mode.

This is the second attempt, the first had been merged as r339456 and
reverted in r339558 because it caused a crash.

Reviewers: delesley, aaron.ballman

Reviewed By: delesley, aaron.ballman

Subscribers: hokein, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340459 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-22 22:14:53 +00:00
Aaron Puchert 2c4b8ea78f [NFC] Test commit
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340452 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-22 21:06:04 +00:00
Haojian Wu f8f5148f03 Revert "Allow relockable scopes with thread safety attributes."
This reverts commit r339456.

The change introduces a new crash, see

class SCOPED_LOCKABLE FileLock {
 public:
  explicit FileLock()
      EXCLUSIVE_LOCK_FUNCTION(file_);
  ~FileLock() UNLOCK_FUNCTION(file_);
  void Lock() EXCLUSIVE_LOCK_FUNCTION(file_);
  Mutex file_;
};

void relockShared2() {
  FileLock file_lock;
  file_lock.Lock();
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339558 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-13 12:50:30 +00:00
Aaron Ballman 2cbc5aab72 Allow relockable scopes with thread safety attributes.
Patch by Aaron Puchert

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339456 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-10 17:33:47 +00:00
Stephen Kelly 2dfd8132cf Port getLocEnd -> getEndLoc
Reviewers: teemperor!

Subscribers: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339386 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-09 21:09:38 +00:00
Stephen Kelly d7b659b592 Port getLocStart -> getBeginLoc
Reviewers: teemperor!

Subscribers: jholewinski, whisperity, jfb, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339385 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-09 21:08:08 +00:00
Aaron Ballman 4418c5b56f Properly add shared locks to the initial list of locks being tracked, instead of assuming unlock functions always use exclusive locks.
Patch by Aaron Puchert.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338912 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-03 19:37:45 +00:00
Aaron Ballman 6e40d51988 Allow thread safety annotation lock upgrading and downgrading.
Patch thanks to Aaron Puchert!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338024 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-26 13:03:16 +00:00
Adrian Prantl 647be32c60 Remove \brief commands from doxygen comments.
This is similar to the LLVM change https://reviews.llvm.org/D46290.

We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331834 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-09 01:00:01 +00:00
Aaron Ballman 5febda6d2d Fix the try_acquire_capability attribute to behave like the other try-lock functions. Fixes PR32954.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329930 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-12 17:53:21 +00:00
Eugene Zelenko 681b846ef0 [Analysis] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327746 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-16 21:22:42 +00:00
Richard Smith 568cb88091 Handle scoped_lockable objects being returned by value in C++17.
In C++17, guaranteed copy elision means that there isn't necessarily a
constructor call when a local variable is initialized by a function call that
returns a scoped_lockable by value. In order to model the effects of
initializing a local variable with a function call returning a scoped_lockable,
pretend that the move constructor was invoked within the caller at the point of
return.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322316 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-11 22:13:57 +00:00
George Karpenkov 3e4f379cb6 [CSA] [NFC] Move AnalysisContext.h to AnalysisDeclContext.h
The implementation is in AnalysisDeclContext.cpp and the class is called
AnalysisDeclContext.

Making those match up has numerous benefits, including:

 - Easier jump from header to/from implementation.
 - Easily identify filename from class.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312671 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-06 21:45:03 +00:00
Josh Gao 56427e245e Reland "Thread Safety Analysis: fix assert_capability."
Delete the test that was broken by rL309725, and add it back in a
follow up commit. Also, improve the tests a bit.

Reviewers: delesley, aaron.ballman

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310402 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-08 19:44:34 +00:00
Josh Gao 64d9fef921 Revert "Thread Safety Analysis: fix assert_capability."
This reverts commit rL309725.

Broke test/Sema/attr-capabilities.c.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309731 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-01 19:53:31 +00:00
Josh Gao 1e94034bfc Thread Safety Analysis: fix assert_capability.
Summary:
Previously, the assert_capability attribute was completely ignored by
thread safety analysis.

Reviewers: delesley, rnk

Reviewed By: delesley

Subscribers: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309725 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-01 19:18:05 +00:00
Richard Smith ea344c8140 DR616, and part of P0135R1: member access (or pointer-to-member access) on a
temporary produces an xvalue, not a prvalue. Support this by materializing the
temporary prior to performing the member access.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288563 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-03 01:14:32 +00:00
Benjamin Kramer 2f23b38eed Remove move constructors that are identical to the generated default move ctor.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284856 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-21 18:55:07 +00:00
Mehdi Amini 2e23251d3e [NFC] Header cleanup
Summary: Removed unused headers, replaced some headers with forward class declarations

Patch by: Eugene <claprix@yandex.ru>

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275882 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-18 19:02:11 +00:00
Reid Kleckner 818f7069b8 Thread Safety Analysis: Fix DenseMap iterator invalidation UAF
Rather than storing BeforeInfo in the DenseMap by value, this stores a
unique_ptr to it, so that we can keep a pointer to it live across
subsequent DenseMap insertions.

This change also removes the unique_ptr wrapper around BeforeVect
because now we're indirecting at a higher level.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253694 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-20 19:08:30 +00:00
Angel Garcia Gomez d162035b9b Roll-back r250822.
Summary: It breaks the build for the ASTMatchers

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D13893

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250827 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-20 13:23:58 +00:00
Angel Garcia Gomez e83bf34da9 Apply modernize-use-default to clang.
Summary: Replace empty bodies of default constructors and destructors with '= default'.

Reviewers: bkramer, klimek

Subscribers: klimek, alexfh, cfe-commits

Differential Revision: http://reviews.llvm.org/D13890

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250822 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-20 12:52:55 +00:00
Yaron Keren facf2d2c3b Replace double-negated !SourceLocation.isInvalid() with SourceLocation.isValid().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249228 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-03 05:15:57 +00:00
DeLesley Hutchins d40851784c Thread safety analysis: the NO_THREAD_SAFETY_ANALYSIS attribute will now
disable checking of arguments to the function, which is done by
-Wthread-safety-reference.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246806 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-03 21:14:22 +00:00
Richard Trieu 58b5ea4288 Take the non-reference type when constructing a dummy expression.
Otherwise, Expr will assert during construction with a reference type.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232425 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-16 21:49:43 +00:00
Benjamin Kramer 2a332456ba Hide away implementation details of the ThreadSafetyAnalysis in anonymous namespaces
NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231653 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-09 14:19:54 +00:00
DeLesley Hutchins 2f7d29e066 Thread Safety Analysis: support adopting of locks, as implemented in
std::lock_guard.  If EXCLUSIVE_LOCKS_REQUIRED is placed on the constructor of
a SCOPED_LOCKABLE class, then that constructor is assumed to adopt the lock;
e.g. the lock must be held on construction, and will be released on destruction.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228194 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-04 21:16:17 +00:00
DeLesley Hutchins cd61356464 Thread Safety Analysis: remove minor piece of unused code. No change in
functionality.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228176 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-04 19:28:17 +00:00
DeLesley Hutchins bbe33819d4 Thread Safety Analysis: add support for before/after annotations on mutexes.
These checks detect potential deadlocks caused by inconsistent lock
ordering.  The checks are implemented under the -Wthread-safety-beta flag.

This patch also replaces calls to getAttrs() with calls to attrs() throughout
ThreadSafety.cpp, which fixes the earlier issue that cause assert failures.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228051 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-03 22:11:04 +00:00
Reid Kleckner 531e13fb3b Revert "Thread Safety Analysis: add support for before/after annotations on mutexes."
This reverts r227997, as well as r228009. It does not pass check-clang
for me locally on Linux.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228020 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-03 19:51:16 +00:00
Reid Kleckner dfed5475ba thread safety: Add move ctor to BeforeInfo to fix MSVC build
MSVC cannot infer move ctors yet.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228009 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-03 19:04:26 +00:00
DeLesley Hutchins 6818e0cc40 Thread Safety Analysis: add support for before/after annotations on mutexes.
These checks detect potential deadlocks caused by inconsistent lock
ordering.  The checks are implemented under the -Wthread-safety-beta flag.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227997 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-03 18:17:48 +00:00
Chandler Carruth 6c1b926674 [cleanup] Re-sort *all* #include lines with llvm/utils/sort_includes.py
Sorry for the noise, I managed to miss a bunch of recent regressions of
include orderings here. This should actually sort all the includes for
Clang. Again, no functionality changed, this is just a mechanical
cleanup that I try to run periodically to keep the #include lines as
regular as possible across the project.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225979 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-14 11:29:14 +00:00
DeLesley Hutchins 362e509a74 Thread Safety Analysis: move warnings on range-based for loops out of beta
and into -Wthread-safety.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221410 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-05 23:09:28 +00:00
DeLesley Hutchins 9308d1067c Thread Safety Analysis: add new warning flag, -Wthread-safety-reference, which
warns when a guarded variable is passed by reference as a function argument.
This is released as a separate warning flag, because it could potentially
break existing code that uses thread safety analysis.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218087 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-18 23:02:26 +00:00
Ed Schouten 8291bead63 Allow a scoped lockable object to acquire/release multiple locks.
Scoped lockable objects (mutex guards) are implemented as if it is a
lock itself that is acquired upon construction and unlocked upon
destruction. As it if course needs to be used to actually lock down
something else (a mutex), it keeps track of this knowledge through its
underlying mutex field in its FactEntry.

The problem with this approach is that this only allows us to lock down
a single mutex, so extend the code to use a vector of underlying
mutexes. This, however, makes the code a bit more complex than
necessary, so subclass FactEntry into LockableFactEntry and
ScopedLockableFactEntry and move all the logic that differs between
regular locks and scoped lockables into member functions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217016 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-03 06:00:11 +00:00
Aaron Ballman 547f9d8966 Adding const-qualifiers to auto declarations. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215704 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-15 12:29:39 +00:00
DeLesley Hutchins 2974801949 Thread safety analysis: add -Wthread-safety-verbose flag, which adds additional notes that are helpful when compiling statistics on thread safety warnings.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215677 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-14 21:40:15 +00:00
DeLesley Hutchins b95f6d560e Thread Safety Analysis: fix to improve handling of references to guarded
data members and range based for loops.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215671 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-14 19:17:06 +00:00
NAKAMURA Takumi ff0a7503ad ThreadSafety.cpp: Prune bogus \param(s). [-Wdocumentation]
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214796 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-04 22:48:46 +00:00
NAKAMURA Takumi e2558115f2 ThreadSafetyAnalysis: Fix annotations in class members. [-Wdocumentation]
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214795 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-04 22:48:36 +00:00
DeLesley Hutchins b951b142c7 Thread Safety Analysis: add a -Wthread-safety-negative flag that warns whenever
a mutex is acquired, but corresponding mutex is not provably not-held.  This
is based on the earlier negative requirements patch.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214789 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-04 22:13:06 +00:00
DeLesley Hutchins d8a1fd6e9c Thread safety analysis: Add support for negative requirements, which are
capability expressions of the form !expr, and denote a capability that must
not be held.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214725 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-04 16:10:59 +00:00
DeLesley Hutchins 61e498ab0a Thread Safety Analysis: Replace the old and broken SExpr with the new
til::SExpr.  This is a large patch, with many small changes to pretty printing
and expression lowering to make the new SExpr representation equivalent in
functionality to the old.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214089 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-28 15:57:27 +00:00
Craig Topper fa361696b1 [C++11] Use 'nullptr'. Analysis edition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209191 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-20 04:30:07 +00:00
Aaron Ballman e37df58b20 Converting some for loops to use range-based for loops. No functional changes intended.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208810 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-14 20:42:13 +00:00
Aaron Ballman 71d28c4f3c Amending r208783 based on a suggestion by David Blaikie.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208800 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-14 18:32:59 +00:00