[flang-commits] [flang] [flang][Semantics] Introduce `-Wpass-global-variable` warning (PR #160324)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 23 08:21:38 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 origin/main HEAD --extensions h,cpp -- flang/include/flang/Support/Fortran-features.h flang/lib/Semantics/check-call.cpp flang/lib/Support/Fortran-features.cpp flang/unittests/Common/FortranFeaturesTest.cpp
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 1b8f914fc..6d8e27b8b 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -56,7 +56,7 @@ static void CheckImplicitInterfaceArg(evaluate::ActualArgument &arg,
"%VAL argument must be a scalar numeric or logical expression"_err_en_US);
}
if (const auto *expr{arg.UnwrapExpr()}) {
- if (const Symbol * base{GetFirstSymbol(*expr)}) {
+ if (const Symbol *base{GetFirstSymbol(*expr)}) {
if (IsFunctionResult(*base)) {
context.NoteDefinedSymbol(*base);
} else {
@@ -74,7 +74,8 @@ static void CheckImplicitInterfaceArg(evaluate::ActualArgument &arg,
} else if (base->Rank() == 1) {
if (const ArraySpec *dims{base->GetShape()};
dims && dims->IsExplicitShape()) {
- if (!((*dims)[0].lbound().GetExplicit() == (*dims)[0].ubound().GetExplicit())) {
+ if (!((*dims)[0].lbound().GetExplicit() ==
+ (*dims)[0].ubound().GetExplicit())) {
warn |= true;
}
}
@@ -83,7 +84,7 @@ static void CheckImplicitInterfaceArg(evaluate::ActualArgument &arg,
}
}
} else if (const auto &owner{base->GetUltimate().owner()};
- owner.IsModule() || owner.IsSubmodule()) {
+ owner.IsModule() || owner.IsSubmodule()) {
const Scope *module{FindModuleContaining(owner)};
ownerType = "MODULE";
ownerName = module->GetName()->ToString();
@@ -92,26 +93,27 @@ static void CheckImplicitInterfaceArg(evaluate::ActualArgument &arg,
} else if (base->Rank() != 1) {
warn |= true;
} else if (!base->attrs().test(Attr::ALLOCATABLE) &&
- !base->attrs().test(Attr::POINTER) &&
- !base->attrs().test(Attr::VOLATILE)) {
- // by some reason, dims is not constructed here. For common blocks' variables, it works
- // it leads to three skipped tests
+ !base->attrs().test(Attr::POINTER) &&
+ !base->attrs().test(Attr::VOLATILE)) {
+ // by some reason, dims is not constructed here. For common blocks'
+ // variables, it works it leads to three skipped tests
/*
if (const ArraySpec *dims{base->GetShape()};
dims && dims->IsExplicitShape()) {
- if (!((*dims)[0].lbound().GetExplicit() == (*dims)[0].ubound().GetExplicit())) {
- warn |= true;
+ if (!((*dims)[0].lbound().GetExplicit() ==
+ (*dims)[0].ubound().GetExplicit())) { warn |= true;
}
}
*/
- // just give some warnings in code where modules and implicit interfaces are mixed
+ // just give some warnings in code where modules and implicit
+ // interfaces are mixed
warn |= true;
}
}
if (warn) {
context.Warn(common::UsageWarning::PassGlobalVariable, messages.at(),
- "Passing global variable '%s' from %s '%s' as function argument"_warn_en_US,
- base->name(), ownerType, ownerName);
+ "Passing global variable '%s' from %s '%s' as function argument"_warn_en_US,
+ base->name(), ownerType, ownerName);
}
}
}
@@ -144,8 +146,8 @@ static void CheckImplicitInterfaceArg(evaluate::ActualArgument &arg,
ownerType = "COMMON";
ownerName = common->name().ToString();
warn |= true;
- } else if (const auto& owner{symbol.GetUltimate().owner()};
- owner.IsModule() || owner.IsSubmodule()) {
+ } else if (const auto &owner{symbol.GetUltimate().owner()};
+ owner.IsModule() || owner.IsSubmodule()) {
const Scope *module{FindModuleContaining(owner)};
ownerType = "MODULE";
ownerName = module->GetName()->ToString();
@@ -154,15 +156,15 @@ static void CheckImplicitInterfaceArg(evaluate::ActualArgument &arg,
} else if (symbol.Rank() != 1) {
warn |= true;
} else if (!symbol.attrs().test(Attr::ALLOCATABLE) &&
- !symbol.attrs().test(Attr::POINTER) &&
- !symbol.attrs().test(Attr::VOLATILE)) {
+ !symbol.attrs().test(Attr::POINTER) &&
+ !symbol.attrs().test(Attr::VOLATILE)) {
warn |= true;
}
}
if (warn) {
context.Warn(common::UsageWarning::PassGlobalVariable, messages.at(),
- "Passing global variable '%s' from %s '%s' as function argument"_warn_en_US,
- symbol.name(), ownerType, ownerName);
+ "Passing global variable '%s' from %s '%s' as function argument"_warn_en_US,
+ symbol.name(), ownerType, ownerName);
}
} else if (auto argChars{characteristics::DummyArgument::FromActual(
"actual argument", *expr, context.foldingContext(),
@@ -1232,7 +1234,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
const Symbol *common{FindCommonBlockContaining(*actualFirstSymbol)};
ownerType = "COMMON";
ownerName = common->name().ToString();
- if (!(actualFirstSymbol->Rank() == 1 && actualFirstSymbol->offset() == 0)) {
+ if (!(actualFirstSymbol->Rank() == 1 &&
+ actualFirstSymbol->offset() == 0)) {
warn |= true;
} else if (actualFirstSymbol->Rank() == 1) {
bool actualIsArrayElement{IsArrayElement(actual) != nullptr};
@@ -1241,7 +1244,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
}
if (const ArraySpec *dims{actualFirstSymbol->GetShape()};
dims && dims->IsExplicitShape()) {
- if (!((*dims)[0].lbound().GetExplicit() == (*dims)[0].ubound().GetExplicit())) {
+ if (!((*dims)[0].lbound().GetExplicit() ==
+ (*dims)[0].ubound().GetExplicit())) {
warn |= true;
}
}
@@ -1250,7 +1254,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
}
}
} else if (const auto &owner{actualFirstSymbol->GetUltimate().owner()};
- owner.IsModule() || owner.IsSubmodule()) {
+ owner.IsModule() || owner.IsSubmodule()) {
const Scope *module{FindModuleContaining(owner)};
ownerType = "MODULE";
ownerName = module->GetName()->ToString();
@@ -1259,15 +1263,16 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
} else if (actualFirstSymbol->Rank() != 1) {
warn |= true;
} else if (!actualFirstSymbol->attrs().test(Attr::ALLOCATABLE) &&
- !actualFirstSymbol->attrs().test(Attr::POINTER) &&
- !actualFirstSymbol->attrs().test(Attr::VOLATILE)) {
+ !actualFirstSymbol->attrs().test(Attr::POINTER) &&
+ !actualFirstSymbol->attrs().test(Attr::VOLATILE)) {
bool actualIsArrayElement{IsArrayElement(actual) != nullptr};
if (!actualIsArrayElement) {
warn |= true;
}
if (const ArraySpec *dims{actualFirstSymbol->GetShape()};
dims && dims->IsExplicitShape()) {
- if (!((*dims)[0].lbound().GetExplicit() == (*dims)[0].ubound().GetExplicit())) {
+ if (!((*dims)[0].lbound().GetExplicit() ==
+ (*dims)[0].ubound().GetExplicit())) {
warn |= true;
}
}
@@ -1275,8 +1280,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
}
if (warn) {
context.Warn(common::UsageWarning::PassGlobalVariable, messages.at(),
- "Passing global variable '%s' from %s '%s' as function argument"_warn_en_US,
- actualFirstSymbol->name(), ownerType, ownerName);
+ "Passing global variable '%s' from %s '%s' as function argument"_warn_en_US,
+ actualFirstSymbol->name(), ownerType, ownerName);
}
}
}
diff --git a/flang/unittests/Common/FortranFeaturesTest.cpp b/flang/unittests/Common/FortranFeaturesTest.cpp
index 80417cfae..72946f5cb 100644
--- a/flang/unittests/Common/FortranFeaturesTest.cpp
+++ b/flang/unittests/Common/FortranFeaturesTest.cpp
@@ -556,8 +556,8 @@ TEST(FortranFeaturesTest, CamelCaseToLowerCaseHyphenated) {
EXPECT_EQ(CamelCaseToLowerCaseHyphenated(
EnumToString(UsageWarning::NonVolatilePointerToVolatile)),
"non-volatile-pointer-to-volatile");
- EXPECT_EQ(
- CamelCaseToLowerCaseHyphenated(EnumToString(UsageWarning::PassGlobalVariable)),
+ EXPECT_EQ(CamelCaseToLowerCaseHyphenated(
+ EnumToString(UsageWarning::PassGlobalVariable)),
"pass-global-variable");
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/160324
More information about the flang-commits
mailing list