summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Thread safety analysis: Peel away NoOp implicit casts in initializersAaron Puchert2019-10-301-0/+14
| | | | | | | | | | | | Summary: This happens when someone initializes a variable with guaranteed copy elision and an added const qualifier. Fixes PR43826. Reviewers: aaron.ballman, rsmith Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D69533
* Thread safety analysis: Add note for unlock kind mismatchAaron Puchert2019-03-181-4/+4
| | | | | | | | | | | | | | | | | | Summary: Similar to D56967, we add the existing diag::note_locked_here to tell the user where we saw the locking that isn't matched correctly. Reviewers: aaron.ballman, delesley Reviewed By: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59455 llvm-svn: 356427
* Thread safety analysis: Improve diagnostics for double lockingAaron Puchert2019-01-291-14/+14
| | | | | | | | | | | | | | | | Summary: We use the existing diag::note_locked_here to tell the user where we saw the first locking. Reviewers: aaron.ballman, delesley Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D56967 llvm-svn: 352549
* Thread safety analysis: Allow scoped releasing of capabilitiesAaron Puchert2018-12-161-0/+104
| | | | | | | | | | | | | | | | | | | | | | Summary: The pattern is problematic with C++ exceptions, and not as widespread as scoped locks, but it's still used by some, for example Chromium. We are a bit stricter here at join points, patterns that are allowed for scoped locks aren't allowed here. That could still be changed in the future, but I'd argue we should only relax this if people ask for it. Fixes PR36162. Reviewers: aaron.ballman, delesley, pwnall Reviewed By: delesley, pwnall Subscribers: pwnall, cfe-commits Differential Revision: https://reviews.llvm.org/D52578 llvm-svn: 349300
* Thread safety analysis: Handle conditional expression in getTrylockCallExprAaron Puchert2018-10-061-0/+17
| | | | | | | | | | | | | | | | | | | | | Summary: We unwrap conditional expressions containing try-lock functions. Additionally we don't acquire on conditional expression branches, since that is usually not helpful. When joining the branches we would almost certainly get a warning then. Hopefully fixes an issue that was raised in D52398. Reviewers: aaron.ballman, delesley, hokein Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52888 llvm-svn: 343902
* Thread safety analysis: Examine constructor argumentsAaron Puchert2018-10-041-0/+26
| | | | | | | | | | | | | | | | | | | | Summary: Instead of only examining call arguments, we also examine constructor arguments applying the same rules. That was an opportunity for refactoring the examination procedure to work with iterators instead of integer indices. For the case of CallExprs no functional change is intended. Reviewers: aaron.ballman, delesley Reviewed By: delesley Subscribers: JonasToth, cfe-commits Differential Revision: https://reviews.llvm.org/D52443 llvm-svn: 343831
* Thread safety analysis: Unwrap __builtin_expect in getTrylockCallExprAaron Puchert2018-10-031-0/+15
| | | | | | | | | | | | | | | | | | Summary: When people are really sure they'll get the lock they sometimes use __builtin_expect. It's also used by some assertion implementations. Asserting that try-lock succeeded is basically the same as asserting that the lock is not held by anyone else (and acquiring it). Reviewers: aaron.ballman, delesley Reviewed By: aaron.ballman Subscribers: kristina, cfe-commits Differential Revision: https://reviews.llvm.org/D52398 llvm-svn: 343681
* Update smart pointer detection for thread safety analysis.Richard Trieu2018-09-221-0/+95
| | | | | | | | | Objects are determined to be smart pointers if they have both a star and arrow operator. Some implementations of smart pointers have these overloaded operators in a base class, while the check only searched the derived class. This fix will also look for the operators in the base class. llvm-svn: 342794
* Thread safety analysis: Fix crash for function pointersAaron Puchert2018-09-191-0/+5
| | | | | | | | For function pointers, the FunctionDecl of the callee is unknown, so getDirectCallee will return nullptr. We have to catch that case to avoid crashing. We assume there is no attribute then. llvm-svn: 342519
* Thread safety analysis: Run more tests with capability attributes [NFC]Aaron Puchert2018-09-171-36/+1
| | | | | | | | | | | | | | | | | | | | | | Summary: We run the tests for -Wthread-safety-{negative,verbose} with the new attributes as well as the old ones. Also put the macros in a header so that we don't have to copy them all around. The warn-thread-safety-parsing.cpp test checks for warnings depending on the actual attribute name, so it can't undergo the same treatment. Together with D49275 this should fix PR33754. Reviewers: aaron.ballman, delesley, grooverdan Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52141 llvm-svn: 342418
* Thread safety analysis no longer hands when analyzing a self-referencing ↵Aaron Ballman2018-08-241-0/+8
| | | | | | | | initializer. This fixes PR38640. llvm-svn: 340636
* Thread safety analysis: Allow relockable scopesAaron Puchert2018-08-221-0/+164
| | | | | | | | | | | | | | | | | | | 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 llvm-svn: 340459
* Revert "Allow relockable scopes with thread safety attributes."Haojian Wu2018-08-131-148/+0
| | | | | | | | | | | | | | | | | | | | | | 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(); } llvm-svn: 339558
* Allow relockable scopes with thread safety attributes.Aaron Ballman2018-08-101-0/+148
| | | | | | Patch by Aaron Puchert llvm-svn: 339456
* Properly add shared locks to the initial list of locks being tracked, ↵Aaron Ballman2018-08-031-0/+8
| | | | | | | | instead of assuming unlock functions always use exclusive locks. Patch by Aaron Puchert. llvm-svn: 338912
* Allow thread safety annotation lock upgrading and downgrading.Aaron Ballman2018-07-261-4/+53
| | | | | | Patch thanks to Aaron Puchert! llvm-svn: 338024
* Run thread safety tests with both lock and capability attributes; NFC to the ↵Aaron Ballman2018-07-151-57/+59
| | | | | | | | analysis behavior. Patch thanks to Aaron Puchert. llvm-svn: 337125
* Fix the try_acquire_capability attribute to behave like the other try-lock ↵Aaron Ballman2018-04-121-2/+8
| | | | | | functions. Fixes PR32954. llvm-svn: 329930
* Fix typos in clangAlexander Kornienko2018-04-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found via codespell -q 3 -I ../clang-whitelist.txt Where whitelist consists of: archtype cas classs checkk compres definit frome iff inteval ith lod methode nd optin ot pres statics te thru Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few files that have dubious fixes reverted.) Differential revision: https://reviews.llvm.org/D44188 llvm-svn: 329399
* Fix some handling of AST nodes with diagnostics.Richard Trieu2018-03-281-6/+6
| | | | | | | | | The diagnostic system for Clang can already handle many AST nodes. Instead of converting them to strings first, just hand the AST node directly to the diagnostic system and let it handle the output. Minor changes in some diagnostic output. llvm-svn: 328688
* Handle scoped_lockable objects being returned by value in C++17.Richard Smith2018-01-111-0/+26
| | | | | | | | | | | 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. llvm-svn: 322316
* Determine the attribute subject for diagnostics based on declarative ↵Aaron Ballman2017-11-261-4/+4
| | | | | | | | | | information in DeclNodes.td. This greatly reduces the number of enumerated values used for more complex diagnostics; these are now only required when the "attribute only applies to" diagnostic needs to be generated manually as part of semantic processing. This also clarifies some terminology used by the diagnostic (methods -> Objective-C methods, fields -> non-static data members, etc). Many of the tests needed to be updated in multiple places for the diagnostic wording tweaks. The first instance of the diagnostic for that attribute is fully specified and subsequent instances cut off the complete list (to make it easier if additional subjects are added in the future for the attribute). llvm-svn: 319002
* Fix assertion failure in thread safety analysis (PR34800).Alexander Kornienko2017-10-041-0/+15
| | | | | | | | | | | | | | | | | Summary: Fix an assertion failure (http://llvm.org/PR34800) and clean up unused code relevant to the fixed logic. A bit of context: when `SExprBuilder::translateMemberExpr` is called on a member expression that involves a conversion operator, for example, `til::Project` constructor can't just call `getName()` on it, since the name is not a simple identifier. In order to handle this case I've introduced an optional string to print the member name to. I discovered that the other two `til::Project` constructors are not used, so it was better to delete them instead of ensuring they work correctly with the new logic. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D38458 llvm-svn: 314895
* Reland "Thread Safety Analysis: fix assert_capability."Josh Gao2017-08-081-6/+35
| | | | | | | | | | | 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 llvm-svn: 310402
* Revert "Thread Safety Analysis: fix assert_capability."Josh Gao2017-08-011-9/+1
| | | | | | | | This reverts commit rL309725. Broke test/Sema/attr-capabilities.c. llvm-svn: 309731
* Thread Safety Analysis: fix assert_capability.Josh Gao2017-08-011-1/+9
| | | | | | | | | | | | | | | | 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 llvm-svn: 309725
* [CFG] Fix crash finding destructor of lifetime-extended temporary.Devin Coughlin2016-08-021-0/+15
| | | | | | | | | | | Fix a crash under -Wthread-safety when finding the destructor for a lifetime-extending reference. A patch by Nandor Licker! Differential Revision: https://reviews.llvm.org/D22419 llvm-svn: 277522
* Fix nullptr crash in -Wthread-safety-betaReid Kleckner2015-11-051-0/+7
| | | | llvm-svn: 252107
* Thread Safety Analysis: allow capability attribute on unions.DeLesley Hutchins2015-09-291-0/+23
| | | | llvm-svn: 248805
* Thread Safety Analysis: fix before/after checks so that they work on globalDeLesley Hutchins2015-09-291-0/+13
| | | | | | variables as well member variables. llvm-svn: 248803
* Thread safety analysis: the NO_THREAD_SAFETY_ANALYSIS attribute will nowDeLesley Hutchins2015-09-031-0/+55
| | | | | | | disable checking of arguments to the function, which is done by -Wthread-safety-reference. llvm-svn: 246806
* Thread Safety Analysis: support adopting of locks, as implemented inDeLesley Hutchins2015-02-041-32/+65
| | | | | | | | 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. llvm-svn: 228194
* Thread Safety Analysis: add support for before/after annotations on mutexes.DeLesley Hutchins2015-02-031-1/+211
| | | | | | | | | | 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. llvm-svn: 228051
* Revert "Thread Safety Analysis: add support for before/after annotations on ↵Reid Kleckner2015-02-031-211/+1
| | | | | | | | | mutexes." This reverts r227997, as well as r228009. It does not pass check-clang for me locally on Linux. llvm-svn: 228020
* Thread Safety Analysis: add support for before/after annotations on mutexes.DeLesley Hutchins2015-02-031-1/+211
| | | | | | | These checks detect potential deadlocks caused by inconsistent lock ordering. The checks are implemented under the -Wthread-safety-beta flag. llvm-svn: 227997
* Thread Safety Analysis: add new warning flag, -Wthread-safety-reference, whichDeLesley Hutchins2014-09-181-0/+108
| | | | | | | | 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. llvm-svn: 218087
* Allow a scoped lockable object to acquire/release multiple locks.Ed Schouten2014-09-031-0/+12
| | | | | | | | | | | | | | | | | 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. llvm-svn: 217016
* Thread Safety Analysis: fix to improve handling of references to guardedDeLesley Hutchins2014-08-141-0/+83
| | | | | | data members and range based for loops. llvm-svn: 215671
* Thread Safety Analysis: add a -Wthread-safety-negative flag that warns wheneverDeLesley Hutchins2014-08-041-3/+26
| | | | | | | a mutex is acquired, but corresponding mutex is not provably not-held. This is based on the earlier negative requirements patch. llvm-svn: 214789
* Thread safety analysis: Add support for negative requirements, which areDeLesley Hutchins2014-08-041-0/+105
| | | | | | | capability expressions of the form !expr, and denote a capability that must not be held. llvm-svn: 214725
* Thread Safety Analysis: Replace the old and broken SExpr with the newDeLesley Hutchins2014-07-281-6/+145
| | | | | | | | 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. llvm-svn: 214089
* Updating the capability attribute diagnostics to be more capability-neutral. ↵Aaron Ballman2014-04-011-307/+307
| | | | | | Instead of using terminology such as "lock", "unlock" and "locked", the new terminology is "acquire", "release" and "held". Additionally, the capability attribute's name argument is now reported as part of the diagnostic, instead of hard coding as "mutex." llvm-svn: 205359
* Thread Safety Analysis: new test case for lambdasDeLesley Hutchins2014-03-121-2/+33
| | | | llvm-svn: 203720
* Thread safety analysis: handle duplicate assert_lock attributes.DeLesley Hutchins2014-01-231-0/+21
| | | | llvm-svn: 199949
* Removing some unneeded code, and a diagnostic that was obsoleted. The type ↵Aaron Ballman2013-12-261-0/+12
| | | | | | | | has already been determined to be a ValueDecl by virtue of the attribute subjects. Added some test case coverage as well. llvm-svn: 198046
* Thread safety analysis: fix ICE due to missing null check on dyn_cast.DeLesley Hutchins2013-11-261-0/+14
| | | | llvm-svn: 195777
* Thread-safety analysis: check guarded_by and pt_guarded_by on array access.DeLesley Hutchins2013-11-081-12/+56
| | | | | | Currently supported only with -Wthread-safety-beta. llvm-svn: 194275
* Thread safety analysis: minor bugfix to smart pointer handling, and expandedDeLesley Hutchins2013-11-061-6/+36
| | | | | | test case. llvm-svn: 194157
* Thread safety analysis: check pt_guarded_by attribute when calling -> and *DeLesley Hutchins2013-11-051-0/+84
| | | | | | on smart pointers. -Wthread-safety-beta only. llvm-svn: 194103
* Thread safety analysis: new test caseDeLesley Hutchins2013-08-161-0/+7
| | | | llvm-svn: 188571
OpenPOWER on IntegriCloud