r252107 - Fix nullptr crash in -Wthread-safety-beta

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 16:24:01 PST 2015


Author: rnk
Date: Wed Nov  4 18:24:01 2015
New Revision: 252107

URL: http://llvm.org/viewvc/llvm-project?rev=252107&view=rev
Log:
Fix nullptr crash in -Wthread-safety-beta

Modified:
    cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
    cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyCommon.h?rev=252107&r1=252106&r2=252107&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyCommon.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyCommon.h Wed Nov  4 18:24:01 2015
@@ -287,7 +287,7 @@ public:
   }
 
   const ValueDecl* valueDecl() const {
-    if (Negated)
+    if (Negated || CapExpr == nullptr)
       return nullptr;
     if (auto *P = dyn_cast<til::Project>(CapExpr))
       return P->clangDecl();

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=252107&r1=252106&r2=252107&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Wed Nov  4 18:24:01 2015
@@ -5182,3 +5182,10 @@ void test() {
 
 }  // end namespace LockableUnions
 
+// This used to crash.
+class acquired_before_empty_str {
+  void WaitUntilSpaceAvailable() {
+    lock_.ReaderLock(); // expected-note {{acquired here}}
+  } // expected-warning {{mutex 'lock_' is still held at the end of function}}
+  Mutex lock_ ACQUIRED_BEFORE("");
+};




More information about the cfe-commits mailing list