[clang] ae3159e - Thread safety analysis: Peel away NoOp implicit casts in initializers

Aaron Puchert via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 29 16:44:48 PDT 2019


Author: Aaron Puchert
Date: 2019-10-30T00:37:32+01:00
New Revision: ae3159e497934ed1320d20aab8b32e3bf00a8f10

URL: https://github.com/llvm/llvm-project/commit/ae3159e497934ed1320d20aab8b32e3bf00a8f10
DIFF: https://github.com/llvm/llvm-project/commit/ae3159e497934ed1320d20aab8b32e3bf00a8f10.diff

LOG: Thread safety analysis: Peel away NoOp implicit casts in initializers

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

Reviewers: aaron.ballman, rsmith

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D69533

Added: 
    

Modified: 
    clang/lib/Analysis/ThreadSafety.cpp
    clang/test/SemaCXX/warn-thread-safety-analysis.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp
index c60954374ce3..48f4106b6bae 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -2142,6 +2142,9 @@ void BuildLockset::VisitDeclStmt(const DeclStmt *S) {
       // 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();
 

diff  --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index ac89ea86f085..23255a53eae7 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -3051,6 +3051,20 @@ void Foo::test() {
   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
 
 


        


More information about the cfe-commits mailing list