[clang] 24485ae - [clang analysis] Make mutex guard detection more reliable.
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 30 11:46:30 PDT 2020
Author: Eli Friedman
Date: 2020-03-30T11:46:02-07:00
New Revision: 24485aec4750255574a9a8211b3aef1ce00e83b6
URL: https://github.com/llvm/llvm-project/commit/24485aec4750255574a9a8211b3aef1ce00e83b6
DIFF: https://github.com/llvm/llvm-project/commit/24485aec4750255574a9a8211b3aef1ce00e83b6.diff
LOG: [clang analysis] Make mutex guard detection more reliable.
-Wthread-safety was failing to detect certain AST patterns it should
detect. Make the pattern detection a bit more comprehensive.
Due to an unrelated bug involving template instantiation, this showed up
as a regression in 10.0 vs. 9.0 in the original bug report. The included
testcase fails on older versions of clang, though.
Fixes https://bugs.llvm.org/show_bug.cgi?id=45323 .
Differential Revision: https://reviews.llvm.org/D76943
Added:
Modified:
clang/lib/Analysis/ThreadSafety.cpp
clang/test/SemaCXX/warn-thread-safety-analysis.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp
index 252083f377d9..e0ff23df5ab4 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -2139,12 +2139,14 @@ void BuildLockset::VisitDeclStmt(const DeclStmt *S) {
// handle constructors that involve temporaries
if (auto *EWC = dyn_cast<ExprWithCleanups>(E))
- E = EWC->getSubExpr();
- if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
- if (ICE->getCastKind() == CK_NoOp)
- E = ICE->getSubExpr();
+ E = EWC->getSubExpr()->IgnoreParens();
+ if (auto *CE = dyn_cast<CastExpr>(E))
+ if (CE->getCastKind() == CK_NoOp ||
+ CE->getCastKind() == CK_ConstructorConversion ||
+ CE->getCastKind() == CK_UserDefinedConversion)
+ E = CE->getSubExpr()->IgnoreParens();
if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(E))
- E = BTE->getSubExpr();
+ E = BTE->getSubExpr()->IgnoreParens();
if (const auto *CE = dyn_cast<CXXConstructExpr>(E)) {
const auto *CtorD = dyn_cast_or_null<NamedDecl>(CE->getConstructor());
diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index 23255a53eae7..cdb22cd22a99 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5648,6 +5648,22 @@ namespace ReturnScopedLockable {
auto ptr = get();
return ptr->f();
}
+ void use_constructor() {
+ auto ptr = ReadLockedPtr<Object>(nullptr);
+ ptr->f();
+ auto ptr2 = ReadLockedPtr<Object>{nullptr};
+ ptr2->f();
+ auto ptr3 = (ReadLockedPtr<Object>{nullptr});
+ ptr3->f();
+ }
+ struct Convertible {
+ Convertible();
+ operator ReadLockedPtr<Object>();
+ };
+ void use_conversion() {
+ ReadLockedPtr<Object> ptr = Convertible();
+ ptr->f();
+ }
}
namespace PR38640 {
More information about the cfe-commits
mailing list