[PATCH] D69533: Thread safety analysis: Peel away NoOp implicit casts in initializers

Aaron Puchert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 28 14:29:46 PDT 2019


aaronpuchert created this revision.
aaronpuchert added reviewers: aaron.ballman, rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This happens when someone initializes a variable with guaranteed copy
elision and an added const qualifier. Fixes PR43826.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69533

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
@@ -3051,6 +3051,20 @@
   int b = a;  // expected-warning {{reading variable 'a' requires holding mutex 'getMutexPtr()'}}
 }
 
+#ifdef __cpp_guaranteed_copy_elision
+
+void guaranteed_copy_elision() {
+  MutexLock lock = MutexLock{&sls_mu};
+  sls_guard_var = 0;
+}
+
+void guaranteed_copy_elision_const() {
+  const MutexLock lock = MutexLock{&sls_mu};
+  sls_guard_var = 0;
+}
+
+#endif
+
 } // end namespace TemporaryCleanupExpr
 
 
Index: clang/lib/Analysis/ThreadSafety.cpp
===================================================================
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2142,6 +2142,9 @@
       // 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();
       if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(E))
         E = BTE->getSubExpr();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69533.226750.patch
Type: text/x-patch
Size: 1250 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191028/a1ebe3af/attachment.bin>


More information about the cfe-commits mailing list