[clang] Thread Safety Analysis: Support passing scoped locks between functions with appropriate annotations (PR #110523)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 30 08:53:00 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff f4042077e2e3946ee35c1df8cab8237de6086480 f669df245c2661ad502c8f4eca2bc446ebc06606 --extensions cpp,h -- clang/include/clang/Analysis/Analyses/ThreadSafety.h clang/lib/Analysis/ThreadSafety.cpp clang/lib/Sema/AnalysisBasedWarnings.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/SemaCXX/warn-thread-safety-analysis.cpp clang/test/SemaCXX/warn-thread-safety-parsing.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
index 591891b07c..0fcf5bed12 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
@@ -256,7 +256,8 @@ public:
virtual void handleExpectFewerUnderlyingMutexes(SourceLocation Loc,
SourceLocation DLoc,
Name ScopeName,
- StringRef Kind, Name Actual) {}
+ StringRef Kind, Name Actual) {
+ }
/// Warn that L1 cannot be acquired before L2.
virtual void handleLockAcquiredBefore(StringRef Kind, Name L1Name,
diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp
index f40a4f5f39..9736e1d7bd 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -126,8 +126,8 @@ private:
SourceLocation AcquireLoc;
public:
- FactEntry(FactEntryKind FK, const CapabilityExpr &CE, LockKind LK, SourceLocation Loc,
- SourceKind Src)
+ FactEntry(FactEntryKind FK, const CapabilityExpr &CE, LockKind LK,
+ SourceLocation Loc, SourceKind Src)
: CapabilityExpr(CE), Kind(FK), LKind(LK), Source(Src), AcquireLoc(Loc) {}
virtual ~FactEntry() = default;
@@ -2010,8 +2010,7 @@ void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D,
Exp->getExprLoc());
continue;
}
- const auto *Scope =
- cast<ScopedLockableFactEntry>(Fact);
+ const auto *Scope = cast<ScopedLockableFactEntry>(Fact);
for (const auto &[a, b] :
zip_longest(DeclaredLocks, Scope->getUnderlyingMutexes())) {
if (!a.has_value()) {
@@ -2510,7 +2509,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
}
if (UnderlyingLocks.empty())
continue;
- CapabilityExpr Cp (SxBuilder.createVariable(Param), StringRef(), false);
+ CapabilityExpr Cp(SxBuilder.createVariable(Param), StringRef(), false);
auto ScopedEntry = std::make_unique<ScopedLockableFactEntry>(
Cp, Param->getLocation(), FactEntry::Declared);
for (const CapabilityExpr &M : UnderlyingLocks)
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index d20cf553b6..d131072aea 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1854,7 +1854,8 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler {
OptionalNotes makeManagedMismatchNoteForParam(SourceLocation DeclLoc) {
return DeclLoc.isValid()
? getNotes(PartialDiagnosticAt(
- DeclLoc, S.PDiag(diag::note_managed_mismatch_here_for_param)))
+ DeclLoc,
+ S.PDiag(diag::note_managed_mismatch_here_for_param)))
: getNotes();
}
@@ -1890,7 +1891,7 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler {
void handleExpectMoreUnderlyingMutexes(SourceLocation Loc,
SourceLocation DLoc, Name scopeName,
- StringRef Kind,
+ StringRef Kind,
Name expected) override {
PartialDiagnosticAt Warning(
Loc, S.PDiag(diag::warn_expect_more_underlying_mutexes)
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 2248354e17..e28f8b0e70 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -431,7 +431,8 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
}
}
-static bool checkFunParamsAreScopedLockable(Sema &S, const ParmVarDecl *ParamDecl,
+static bool checkFunParamsAreScopedLockable(Sema &S,
+ const ParmVarDecl *ParamDecl,
const ParsedAttr &AL) {
QualType ParamType = ParamDecl->getType();
if (const auto *RefType = ParamType->getAs<ReferenceType>())
``````````
</details>
https://github.com/llvm/llvm-project/pull/110523
More information about the cfe-commits
mailing list