[clang-tools-extra] [clang-tidy] Added bugprone-unsequenced-global-accesses check (PR #130421)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 10 13:03:52 PDT 2025
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 HEAD~1 HEAD --extensions cpp,h -- clang-tools-extra/clang-tidy/bugprone/UnsequencedGlobalAccessesCheck.cpp clang-tools-extra/clang-tidy/bugprone/UnsequencedGlobalAccessesCheck.h clang-tools-extra/clang-tidy/utils/ExecutionVisitor.h clang-tools-extra/test/clang-tidy/checkers/bugprone/unsequenced-global-accesses.cpp clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsequencedGlobalAccessesCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsequencedGlobalAccessesCheck.cpp
index e275df1c4..28bb43d5c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnsequencedGlobalAccessesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnsequencedGlobalAccessesCheck.cpp
@@ -19,11 +19,7 @@ namespace {
//
// The unchecked versions represent reads/writes that are not handled by
// -Wunsequenced. (e.g. accesses inside functions).
-enum AccessKind : uint8_t {
- AkRead = 0,
- AkWrite,
- AkLast
-};
+enum AccessKind : uint8_t { AkRead = 0, AkWrite, AkLast };
static constexpr uint8_t AkCount = AkLast;
@@ -307,7 +303,7 @@ void UnsequencedGlobalAccessesCheck::check(
const llvm::SmallVector<TraversalAggregation> &Globals =
Visitor.getGlobalsFound();
- for (const TraversalAggregation& Global : Globals)
+ for (const TraversalAggregation &Global : Globals)
if (Global.shouldBeReported())
diag(E->getBeginLoc(), "read/write conflict on global variable " +
Global.getDeclName().getAsString());
@@ -315,7 +311,7 @@ void UnsequencedGlobalAccessesCheck::check(
const llvm::SmallVector<ObjectTraversalAggregation> &ObjectGlobals =
Visitor.getObjectGlobalsFound();
- for (const ObjectTraversalAggregation& ObjectGlobal : ObjectGlobals)
+ for (const ObjectTraversalAggregation &ObjectGlobal : ObjectGlobals)
if (ObjectGlobal.shouldBeReported())
diag(E->getBeginLoc(), "read/write conflict on the field of the global "
"object " +
@@ -541,7 +537,7 @@ void GlobalRWVisitor::addGlobal(DeclarationName Name, SourceLocation Loc,
bool IsWrite) {
AccessKind Access = IsWrite ? AkWrite : AkRead;
- for (TraversalAggregation& Global : GlobalsFound) {
+ for (TraversalAggregation &Global : GlobalsFound) {
if (Global.getDeclName() == Name) {
Global.addGlobalRW(Loc, Access, TraversalIndex);
return;
@@ -556,7 +552,7 @@ void GlobalRWVisitor::addField(DeclarationName Name,
bool IsWrite) {
AccessKind Access = IsWrite ? AkWrite : AkRead;
- for (ObjectTraversalAggregation& ObjectGlobal : ObjectGlobalsFound) {
+ for (ObjectTraversalAggregation &ObjectGlobal : ObjectGlobalsFound) {
if (ObjectGlobal.getDeclName() == Name) {
ObjectGlobal.addFieldRW(Loc, FieldIndices, Access, TraversalIndex);
return;
@@ -607,8 +603,7 @@ void TraversalAggregation::addGlobalRW(SourceLocation Loc, AccessKind Access,
break;
}
case AkRead: {
- if (!(MainPart.Kind & TrWrite) &&
- (OtherPart.Kind & TrWrite))
+ if (!(MainPart.Kind & TrWrite) && (OtherPart.Kind & TrWrite))
MainPart = OtherPart;
OtherPart = TraversalResult(Index, Loc, Access);
break;
@@ -630,8 +625,7 @@ bool TraversalAggregation::hasTwoAccesses() const {
}
bool TraversalAggregation::hasConflictingOperations() const {
- return hasTwoAccesses() &&
- ((MainPart.Kind | OtherPart.Kind) & TrWrite);
+ return hasTwoAccesses() && ((MainPart.Kind | OtherPart.Kind) & TrWrite);
}
bool TraversalAggregation::shouldBeReported() const {
``````````
</details>
https://github.com/llvm/llvm-project/pull/130421
More information about the cfe-commits
mailing list