[PATCH] D76943: [clang analysis] Make mutex guard detection more reliable.
Eli Friedman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 27 12:01:26 PDT 2020
efriedma created this revision.
efriedma added a reviewer: rsmith.
Herald added a project: clang.
-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 .
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D76943
Files:
clang/lib/Analysis/ThreadSafety.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
@@ -5648,6 +5648,14 @@
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();
+ }
}
namespace PR38640 {
Index: clang/lib/Analysis/ThreadSafety.cpp
===================================================================
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2139,12 +2139,13 @@
// 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)
+ 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());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76943.253186.patch
Type: text/x-patch
Size: 1581 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200327/8590ddd4/attachment-0001.bin>
More information about the cfe-commits
mailing list