[flang-commits] [flang] [flang][CLI] Have the CLI hint the flag to disable a warning (PR #144767)
via flang-commits
flang-commits at lists.llvm.org
Wed Jun 18 11:16:53 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 h,cpp -- flang/include/flang/Parser/message.h flang/include/flang/Support/Fortran-features.h flang/lib/Frontend/FrontendAction.cpp flang/lib/Parser/message.cpp flang/lib/Semantics/semantics.cpp flang/lib/Support/Fortran-features.cpp flang/unittests/Common/FortranFeaturesTest.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/flang/include/flang/Parser/message.h b/flang/include/flang/Parser/message.h
index 912870e73..7371a46ad 100644
--- a/flang/include/flang/Parser/message.h
+++ b/flang/include/flang/Parser/message.h
@@ -292,7 +292,7 @@ public:
std::optional<ProvenanceRange> GetProvenanceRange(
const AllCookedSources &) const;
void Emit(llvm::raw_ostream &, const AllCookedSources &,
- bool echoSourceLine = true,
+ bool echoSourceLine = true,
const common::LanguageFeatureControl *hintFlags = nullptr) const;
// If this Message or any of its attachments locates itself via a CharBlock,
diff --git a/flang/lib/Frontend/FrontendAction.cpp b/flang/lib/Frontend/FrontendAction.cpp
index 1233deed1..18112e97d 100644
--- a/flang/lib/Frontend/FrontendAction.cpp
+++ b/flang/lib/Frontend/FrontendAction.cpp
@@ -172,8 +172,9 @@ bool FrontendAction::runParse(bool emitMessages) {
// Report any non-fatal diagnostics from getParsing now rather than
// combining them with messages from semantics.
bool echoSourceLine{true};
- auto &features {ci.getInvocation().getFortranOpts().features};
- ci.getParsing().messages().Emit(llvm::errs(), ci.getAllCookedSources(), echoSourceLine, &features);
+ auto &features{ci.getInvocation().getFortranOpts().features};
+ ci.getParsing().messages().Emit(llvm::errs(), ci.getAllCookedSources(),
+ echoSourceLine, &features);
}
return true;
}
@@ -226,7 +227,7 @@ bool FrontendAction::generateRtTypeTables() {
template <unsigned N>
bool FrontendAction::reportFatalErrors(const char (&message)[N]) {
bool echoSourceLine{true};
- auto &features {instance->getInvocation().getFortranOpts().features};
+ auto &features{instance->getInvocation().getFortranOpts().features};
if (!instance->getParsing().messages().empty() &&
(instance->getInvocation().getWarnAsErr() ||
instance->getParsing().messages().AnyFatalError())) {
@@ -234,7 +235,8 @@ bool FrontendAction::reportFatalErrors(const char (&message)[N]) {
clang::DiagnosticsEngine::Error, message);
instance->getDiagnostics().Report(diagID) << getCurrentFileOrBufferName();
instance->getParsing().messages().Emit(llvm::errs(),
- instance->getAllCookedSources(), echoSourceLine, &features);
+ instance->getAllCookedSources(),
+ echoSourceLine, &features);
return true;
}
if (instance->getParsing().parseTree().has_value() &&
@@ -244,7 +246,8 @@ bool FrontendAction::reportFatalErrors(const char (&message)[N]) {
clang::DiagnosticsEngine::Error, message);
instance->getDiagnostics().Report(diagID) << getCurrentFileOrBufferName();
instance->getParsing().messages().Emit(llvm::errs(),
- instance->getAllCookedSources(), echoSourceLine, &features);
+ instance->getAllCookedSources(),
+ echoSourceLine, &features);
instance->getParsing().EmitMessage(
llvm::errs(), instance->getParsing().finalRestingPlace(),
"parser FAIL (final position)", "error: ", llvm::raw_ostream::RED);
diff --git a/flang/lib/Parser/message.cpp b/flang/lib/Parser/message.cpp
index 610fb3f9e..cbcb3f5ca 100644
--- a/flang/lib/Parser/message.cpp
+++ b/flang/lib/Parser/message.cpp
@@ -274,9 +274,9 @@ static llvm::raw_ostream::Colors PrefixColor(Severity severity) {
}
static std::string hintLanguageControlFlag(
- const common::LanguageFeatureControl *hintFlagPtr,
- std::optional<common::LanguageFeature> feature,
- std::optional<common::UsageWarning> warning) {
+ const common::LanguageFeatureControl *hintFlagPtr,
+ std::optional<common::LanguageFeature> feature,
+ std::optional<common::UsageWarning> warning) {
if (hintFlagPtr) {
std::string_view flag{""};
if (warning) {
@@ -297,11 +297,13 @@ static constexpr int MAX_CONTEXTS_EMITTED{2};
static constexpr bool OMIT_SHARED_CONTEXTS{true};
void Message::Emit(llvm::raw_ostream &o, const AllCookedSources &allCooked,
- bool echoSourceLine, const common::LanguageFeatureControl *hintFlagPtr) const {
+ bool echoSourceLine,
+ const common::LanguageFeatureControl *hintFlagPtr) const {
std::optional<ProvenanceRange> provenanceRange{GetProvenanceRange(allCooked)};
const AllSources &sources{allCooked.allSources()};
std::string text{ToString()};
- std::string hint{hintLanguageControlFlag(hintFlagPtr, languageFeature_, usageWarning_)};
+ std::string hint{
+ hintLanguageControlFlag(hintFlagPtr, languageFeature_, usageWarning_)};
sources.EmitMessage(o, provenanceRange, text + hint, Prefix(severity()),
PrefixColor(severity()), echoSourceLine);
// Refers to whether the attachment in the loop below is a context, but can't
@@ -452,7 +454,8 @@ void Messages::ResolveProvenances(const AllCookedSources &allCooked) {
}
void Messages::Emit(llvm::raw_ostream &o, const AllCookedSources &allCooked,
- bool echoSourceLines, const common::LanguageFeatureControl *hintFlagPtr) const {
+ bool echoSourceLines,
+ const common::LanguageFeatureControl *hintFlagPtr) const {
std::vector<const Message *> sorted;
for (const auto &msg : messages_) {
sorted.push_back(&msg);
diff --git a/flang/lib/Semantics/semantics.cpp b/flang/lib/Semantics/semantics.cpp
index c0160649e..1a7e1e599 100644
--- a/flang/lib/Semantics/semantics.cpp
+++ b/flang/lib/Semantics/semantics.cpp
@@ -656,9 +656,10 @@ void Semantics::EmitMessages(llvm::raw_ostream &os) {
// Resolve the CharBlock locations of the Messages to ProvenanceRanges
// so messages from parsing and semantics are intermixed in source order.
bool echoSourceLine{true};
- auto &features {context_.languageFeatures()};
+ auto &features{context_.languageFeatures()};
context_.messages().ResolveProvenances(context_.allCookedSources());
- context_.messages().Emit(os, context_.allCookedSources(), echoSourceLine, &features);
+ context_.messages().Emit(
+ os, context_.allCookedSources(), echoSourceLine, &features);
}
void SemanticsContext::DumpSymbols(llvm::raw_ostream &os) {
diff --git a/flang/lib/Support/Fortran-features.cpp b/flang/lib/Support/Fortran-features.cpp
index aeb0c0d3a..4959bd605 100644
--- a/flang/lib/Support/Fortran-features.cpp
+++ b/flang/lib/Support/Fortran-features.cpp
@@ -58,14 +58,16 @@ LanguageFeatureControl::LanguageFeatureControl() {
std::string_view name{Fortran::common::EnumToString(feature)};
std::string cliOption{details::CamelCaseToLowerCaseHyphenated(name)};
cliOptions_.insert({std::string{cliOption}, {feature}});
- languageFeatureCliCanonicalSpelling_[EnumToInt(feature)] = std::move(cliOption);
+ languageFeatureCliCanonicalSpelling_[EnumToInt(feature)] =
+ std::move(cliOption);
});
ForEachUsageWarning([&](auto warning) {
std::string_view name{Fortran::common::EnumToString(warning)};
std::string cliOption{details::CamelCaseToLowerCaseHyphenated(name)};
cliOptions_.insert({std::string{cliOption}, {warning}});
- usageWarningCliCanonicalSpelling_[EnumToInt(warning)] = std::move(cliOption);
+ usageWarningCliCanonicalSpelling_[EnumToInt(warning)] =
+ std::move(cliOption);
});
// These features must be explicitly enabled by command line options.
@@ -171,8 +173,10 @@ bool LanguageFeatureControl::ApplyCliOption(std::string input) {
template <typename T, size_t ENUM_SIZE>
static void replaceCliCanonicalSpelling(
- std::unordered_map<std::string, std::variant<LanguageFeature, UsageWarning>> &cliOptions,
- std::array<std::string, ENUM_SIZE> &canonicalSpelling, T t, std::string &input) {
+ std::unordered_map<std::string, std::variant<LanguageFeature, UsageWarning>>
+ &cliOptions,
+ std::array<std::string, ENUM_SIZE> &canonicalSpelling, T t,
+ std::string &input) {
cliOptions.erase({canonicalSpelling[EnumToInt(t)]});
canonicalSpelling[EnumToInt(t)] = std::string{input};
cliOptions.insert({std::string{input}, {t}});
@@ -180,12 +184,14 @@ static void replaceCliCanonicalSpelling(
void LanguageFeatureControl::ReplaceCliCanonicalSpelling(
LanguageFeature f, std::string input) {
- replaceCliCanonicalSpelling(cliOptions_, languageFeatureCliCanonicalSpelling_, f, input);
+ replaceCliCanonicalSpelling(
+ cliOptions_, languageFeatureCliCanonicalSpelling_, f, input);
}
void LanguageFeatureControl::ReplaceCliCanonicalSpelling(
UsageWarning w, std::string input) {
- replaceCliCanonicalSpelling(cliOptions_, usageWarningCliCanonicalSpelling_, w, input);
+ replaceCliCanonicalSpelling(
+ cliOptions_, usageWarningCliCanonicalSpelling_, w, input);
}
std::vector<const char *> LanguageFeatureControl::GetNames(
diff --git a/flang/unittests/Common/FortranFeaturesTest.cpp b/flang/unittests/Common/FortranFeaturesTest.cpp
index 9d8a7c7b1..9408da036 100644
--- a/flang/unittests/Common/FortranFeaturesTest.cpp
+++ b/flang/unittests/Common/FortranFeaturesTest.cpp
@@ -560,8 +560,10 @@ TEST(FortranFeaturesTest, CamelCaseToLowerCaseHyphenated) {
TEST(FortranFeaturesTest, HintLanguageControlFlag) {
LanguageFeatureControl control{};
- EXPECT_EQ(control.getDefaultCliSpelling(LanguageFeature::BenignNameClash), "benign-name-clash");
- EXPECT_EQ(control.getDefaultCliSpelling(UsageWarning::Portability), "portability");
+ EXPECT_EQ(control.getDefaultCliSpelling(LanguageFeature::BenignNameClash),
+ "benign-name-clash");
+ EXPECT_EQ(
+ control.getDefaultCliSpelling(UsageWarning::Portability), "portability");
}
} // namespace Fortran::common::details
``````````
</details>
https://github.com/llvm/llvm-project/pull/144767
More information about the flang-commits
mailing list