[PATCH] D101202: Thread safety analysis: Fix false negative on break
Aaron Puchert via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 3 05:04:13 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdaca6edb31ef: Thread safety analysis: Fix false negative on break (authored by aaronpuchert).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101202/new/
https://reviews.llvm.org/D101202
Files:
clang/lib/Analysis/ThreadSafety.cpp
clang/test/PCH/thread-safety-attrs.cpp
clang/test/SemaCXX/warn-thread-safety-analysis.cpp
Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===================================================================
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -337,7 +337,8 @@
}
sls_mu.Lock();
}
- sls_mu.Unlock();
+ sls_mu.Unlock(); // \
+ // expected-warning{{releasing mutex 'sls_mu' that was not held}}
}
//-----------------------------------------//
@@ -2582,6 +2583,7 @@
void test3();
void test4();
void test5();
+ void test6();
};
@@ -2620,6 +2622,18 @@
rlock.Release(); // expected-warning {{releasing mutex 'mu_' that was not held}}
}
+void Foo::test6() {
+ ReleasableMutexLock rlock(&mu_);
+ do {
+ if (c) {
+ rlock.Release();
+ break;
+ }
+ } while (c);
+ // No warning on join point because the lock will be released by the scope object anyway
+ a = 1; // expected-warning {{writing variable 'a' requires holding mutex 'mu_' exclusively}}
+}
+
} // end namespace ReleasableScopedLock
Index: clang/test/PCH/thread-safety-attrs.cpp
===================================================================
--- clang/test/PCH/thread-safety-attrs.cpp
+++ clang/test/PCH/thread-safety-attrs.cpp
@@ -311,7 +311,8 @@
}
sls_mu.Lock();
}
- sls_mu.Unlock();
+ sls_mu.Unlock(); // \
+ // expected-warning{{releasing mutex 'sls_mu' that was not held}}
}
#endif
Index: clang/lib/Analysis/ThreadSafety.cpp
===================================================================
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2467,11 +2467,10 @@
PrevBlock, CurrBlock);
// Do not update EntrySet.
- intersectAndWarn(CurrBlockInfo->EntrySet, PrevLockset,
- PrevBlockInfo->ExitLoc,
- IsLoop ? LEK_LockedSomeLoopIterations
- : LEK_LockedSomePredecessors,
- false);
+ intersectAndWarn(
+ CurrBlockInfo->EntrySet, PrevLockset, PrevBlockInfo->ExitLoc,
+ IsLoop ? LEK_LockedSomeLoopIterations : LEK_LockedSomePredecessors,
+ !IsLoop);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101202.342363.patch
Type: text/x-patch
Size: 2225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210503/f7ecb7a4/attachment.bin>
More information about the cfe-commits
mailing list