]> granicus.if.org Git - clang/commitdiff
Thread safety analysis: Avoid intermediate copies [NFC]
authorAaron Puchert <aaronpuchert@alice-dsl.net>
Sun, 16 Dec 2018 16:19:11 +0000 (16:19 +0000)
committerAaron Puchert <aaronpuchert@alice-dsl.net>
Sun, 16 Dec 2018 16:19:11 +0000 (16:19 +0000)
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

lib/Analysis/ThreadSafety.cpp

index ca146a83c6c2e7cea4051f1e26bd199afe15d7b7..fe6d3a23a8eda0c530a98f18be99a1dcf9677681 100644 (file)
@@ -903,18 +903,23 @@ private:
   SmallVector<UnderlyingCapability, 4> 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<ScopedLockableFactEntry>(
-                          Scp, MLoc, ExclusiveLocksToAdd, SharedLocksToAdd,
-                          ExclusiveLocksToRemove, SharedLocksToRemove),
-                      CapDiagKind);
+    auto ScopedEntry = llvm::make_unique<ScopedLockableFactEntry>(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);
   }
 }