From: Aaron Puchert Date: Sun, 16 Dec 2018 16:19:11 +0000 (+0000) Subject: Thread safety analysis: Avoid intermediate copies [NFC] X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a6b9739069763243020f4ea6fe586bc135fde1f9;p=clang Thread safety analysis: Avoid intermediate copies [NFC] The main reason is to reduce the number of constructor arguments though, especially since many of them had the same type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349308 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ThreadSafety.cpp b/lib/Analysis/ThreadSafety.cpp index ca146a83c6..fe6d3a23a8 100644 --- a/lib/Analysis/ThreadSafety.cpp +++ b/lib/Analysis/ThreadSafety.cpp @@ -903,18 +903,23 @@ private: SmallVector UnderlyingMutexes; public: - ScopedLockableFactEntry(const CapabilityExpr &CE, SourceLocation Loc, - const CapExprSet &Excl, const CapExprSet &Shrd, - const CapExprSet &ExclRel, const CapExprSet &ShrdRel) - : FactEntry(CE, LK_Exclusive, Loc, false) { - for (const auto &M : Excl) - UnderlyingMutexes.emplace_back(M.sexpr(), UCK_Acquired); - for (const auto &M : Shrd) - UnderlyingMutexes.emplace_back(M.sexpr(), UCK_Acquired); - for (const auto &M : ExclRel) - UnderlyingMutexes.emplace_back(M.sexpr(), UCK_ReleasedExclusive); - for (const auto &M : ShrdRel) - UnderlyingMutexes.emplace_back(M.sexpr(), UCK_ReleasedShared); + ScopedLockableFactEntry(const CapabilityExpr &CE, SourceLocation Loc) + : FactEntry(CE, LK_Exclusive, Loc, false) {} + + void addExclusiveLock(const CapabilityExpr &M) { + UnderlyingMutexes.emplace_back(M.sexpr(), UCK_Acquired); + } + + void addSharedLock(const CapabilityExpr &M) { + UnderlyingMutexes.emplace_back(M.sexpr(), UCK_Acquired); + } + + void addExclusiveUnlock(const CapabilityExpr &M) { + UnderlyingMutexes.emplace_back(M.sexpr(), UCK_ReleasedExclusive); + } + + void addSharedUnlock(const CapabilityExpr &M) { + UnderlyingMutexes.emplace_back(M.sexpr(), UCK_ReleasedShared); } void @@ -1938,15 +1943,20 @@ void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D, // FIXME: does this store a pointer to DRE? CapabilityExpr Scp = Analyzer->SxBuilder.translateAttrExpr(&DRE, nullptr); - std::copy(ScopedExclusiveReqs.begin(), ScopedExclusiveReqs.end(), - std::back_inserter(ExclusiveLocksToAdd)); - std::copy(ScopedSharedReqs.begin(), ScopedSharedReqs.end(), - std::back_inserter(SharedLocksToAdd)); - Analyzer->addLock(FSet, - llvm::make_unique( - Scp, MLoc, ExclusiveLocksToAdd, SharedLocksToAdd, - ExclusiveLocksToRemove, SharedLocksToRemove), - CapDiagKind); + auto ScopedEntry = llvm::make_unique(Scp, MLoc); + for (const auto &M : ExclusiveLocksToAdd) + ScopedEntry->addExclusiveLock(M); + for (const auto &M : ScopedExclusiveReqs) + ScopedEntry->addExclusiveLock(M); + for (const auto &M : SharedLocksToAdd) + ScopedEntry->addSharedLock(M); + for (const auto &M : ScopedSharedReqs) + ScopedEntry->addSharedLock(M); + for (const auto &M : ExclusiveLocksToRemove) + ScopedEntry->addExclusiveUnlock(M); + for (const auto &M : SharedLocksToRemove) + ScopedEntry->addSharedUnlock(M); + Analyzer->addLock(FSet, std::move(ScopedEntry), CapDiagKind); } }