[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 17:05:48 PDT 2020
efriedma updated this revision to Diff 253253.
efriedma added a comment.
Add support for conversion operators.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76943/new/
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,19 @@
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 {
Index: clang/lib/Analysis/ThreadSafety.cpp
===================================================================
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2139,12 +2139,14 @@
// 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());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76943.253253.patch
Type: text/x-patch
Size: 1814 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200328/fb75fd04/attachment-0001.bin>
More information about the cfe-commits
mailing list