Skip to content

Commit d8d3dd0

Browse files
committed
initial commit
1 parent e29bb9a commit d8d3dd0

File tree

172 files changed

+658
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+658
-621
lines changed

flang/include/flang/Parser/message.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ class Message : public common::ReferenceCounted<Message> {
292292
std::optional<ProvenanceRange> GetProvenanceRange(
293293
const AllCookedSources &) const;
294294
void Emit(llvm::raw_ostream &, const AllCookedSources &,
295-
bool echoSourceLine = true) const;
295+
bool echoSourceLine = true,
296+
const common::LanguageFeatureControl *hintFlags = nullptr) const;
296297

297298
// If this Message or any of its attachments locates itself via a CharBlock,
298299
// replace its location with the corresponding ProvenanceRange.
@@ -352,7 +353,8 @@ class Messages {
352353
void Copy(const Messages &);
353354
void ResolveProvenances(const AllCookedSources &);
354355
void Emit(llvm::raw_ostream &, const AllCookedSources &,
355-
bool echoSourceLines = true) const;
356+
bool echoSourceLines = true,
357+
const common::LanguageFeatureControl *hintFlags = nullptr) const;
356358
void AttachTo(Message &, std::optional<Severity> = std::nullopt);
357359
bool AnyFatalError() const;
358360

flang/include/flang/Support/Fortran-features.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ class LanguageFeatureControl {
149149
// These two arrays map the enum values to their cannonical Cli spellings.
150150
// Since each of the CanonicalSpelling is a string in the domain of the map
151151
// above we just use a view of the string instead of another copy.
152-
std::array<std::string_view, LanguageFeature_enumSize>
152+
std::array<std::string, LanguageFeature_enumSize>
153153
languageFeatureCliCanonicalSpelling_;
154-
std::array<std::string_view, UsageWarning_enumSize>
154+
std::array<std::string, UsageWarning_enumSize>
155155
usageWarningCliCanonicalSpelling_;
156156
LanguageFeatures disable_;
157157
LanguageFeatures warnLanguage_;

flang/lib/Frontend/FrontendAction.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ bool FrontendAction::runParse(bool emitMessages) {
171171
if (emitMessages) {
172172
// Report any non-fatal diagnostics from getParsing now rather than
173173
// combining them with messages from semantics.
174-
ci.getParsing().messages().Emit(llvm::errs(), ci.getAllCookedSources());
174+
bool echoSourceLine{true};
175+
auto &features {ci.getInvocation().getFortranOpts().features};
176+
ci.getParsing().messages().Emit(llvm::errs(), ci.getAllCookedSources(), echoSourceLine, &features);
175177
}
176178
return true;
177179
}
@@ -223,14 +225,16 @@ bool FrontendAction::generateRtTypeTables() {
223225

224226
template <unsigned N>
225227
bool FrontendAction::reportFatalErrors(const char (&message)[N]) {
228+
bool echoSourceLine{true};
229+
auto &features {instance->getInvocation().getFortranOpts().features};
226230
if (!instance->getParsing().messages().empty() &&
227231
(instance->getInvocation().getWarnAsErr() ||
228232
instance->getParsing().messages().AnyFatalError())) {
229233
const unsigned diagID = instance->getDiagnostics().getCustomDiagID(
230234
clang::DiagnosticsEngine::Error, message);
231235
instance->getDiagnostics().Report(diagID) << getCurrentFileOrBufferName();
232236
instance->getParsing().messages().Emit(llvm::errs(),
233-
instance->getAllCookedSources());
237+
instance->getAllCookedSources(), echoSourceLine, &features);
234238
return true;
235239
}
236240
if (instance->getParsing().parseTree().has_value() &&
@@ -240,7 +244,7 @@ bool FrontendAction::reportFatalErrors(const char (&message)[N]) {
240244
clang::DiagnosticsEngine::Error, message);
241245
instance->getDiagnostics().Report(diagID) << getCurrentFileOrBufferName();
242246
instance->getParsing().messages().Emit(llvm::errs(),
243-
instance->getAllCookedSources());
247+
instance->getAllCookedSources(), echoSourceLine, &features);
244248
instance->getParsing().EmitMessage(
245249
llvm::errs(), instance->getParsing().finalRestingPlace(),
246250
"parser FAIL (final position)", "error: ", llvm::raw_ostream::RED);

flang/lib/Parser/message.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,36 @@ static llvm::raw_ostream::Colors PrefixColor(Severity severity) {
273273
return llvm::raw_ostream::SAVEDCOLOR;
274274
}
275275

276+
static std::string hintLanguageControlFlag(
277+
const common::LanguageFeatureControl *hintFlagPtr,
278+
std::optional<common::LanguageFeature> feature,
279+
std::optional<common::UsageWarning> warning) {
280+
if (hintFlagPtr) {
281+
std::string_view flag{""};
282+
if (warning) {
283+
flag = hintFlagPtr->getDefaultCliSpelling(*warning);
284+
} else if (feature) {
285+
flag = hintFlagPtr->getDefaultCliSpelling(*feature);
286+
}
287+
if (!flag.empty()) {
288+
std::string s{" [-Wno-" + std::string(flag) + "]"};
289+
llvm::errs() << "hint: " << s << "\n";
290+
return s;
291+
}
292+
}
293+
return "";
294+
}
295+
276296
static constexpr int MAX_CONTEXTS_EMITTED{2};
277297
static constexpr bool OMIT_SHARED_CONTEXTS{true};
278298

279299
void Message::Emit(llvm::raw_ostream &o, const AllCookedSources &allCooked,
280-
bool echoSourceLine) const {
300+
bool echoSourceLine, const common::LanguageFeatureControl *hintFlagPtr) const {
281301
std::optional<ProvenanceRange> provenanceRange{GetProvenanceRange(allCooked)};
282302
const AllSources &sources{allCooked.allSources()};
283-
sources.EmitMessage(o, provenanceRange, ToString(), Prefix(severity()),
303+
std::string text{ToString()};
304+
std::string hint{hintLanguageControlFlag(hintFlagPtr, languageFeature_, usageWarning_)};
305+
sources.EmitMessage(o, provenanceRange, text + hint, Prefix(severity()),
284306
PrefixColor(severity()), echoSourceLine);
285307
// Refers to whether the attachment in the loop below is a context, but can't
286308
// be declared inside the loop because the previous iteration's
@@ -430,7 +452,7 @@ void Messages::ResolveProvenances(const AllCookedSources &allCooked) {
430452
}
431453

432454
void Messages::Emit(llvm::raw_ostream &o, const AllCookedSources &allCooked,
433-
bool echoSourceLines) const {
455+
bool echoSourceLines, const common::LanguageFeatureControl *hintFlagPtr) const {
434456
std::vector<const Message *> sorted;
435457
for (const auto &msg : messages_) {
436458
sorted.push_back(&msg);
@@ -443,7 +465,7 @@ void Messages::Emit(llvm::raw_ostream &o, const AllCookedSources &allCooked,
443465
// Don't emit two identical messages for the same location
444466
continue;
445467
}
446-
msg->Emit(o, allCooked, echoSourceLines);
468+
msg->Emit(o, allCooked, echoSourceLines, hintFlagPtr);
447469
lastMsg = msg;
448470
}
449471
}

flang/lib/Semantics/semantics.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,10 @@ bool Semantics::Perform() {
655655
void Semantics::EmitMessages(llvm::raw_ostream &os) {
656656
// Resolve the CharBlock locations of the Messages to ProvenanceRanges
657657
// so messages from parsing and semantics are intermixed in source order.
658+
bool echoSourceLine{true};
659+
auto &features {context_.languageFeatures()};
658660
context_.messages().ResolveProvenances(context_.allCookedSources());
659-
context_.messages().Emit(os, context_.allCookedSources());
661+
context_.messages().Emit(os, context_.allCookedSources(), echoSourceLine, &features);
660662
}
661663

662664
void SemanticsContext::DumpSymbols(llvm::raw_ostream &os) {

flang/lib/Support/Fortran-features.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,15 @@ LanguageFeatureControl::LanguageFeatureControl() {
5757
ForEachLanguageFeature([&](auto feature) {
5858
std::string_view name{Fortran::common::EnumToString(feature)};
5959
std::string cliOption{details::CamelCaseToLowerCaseHyphenated(name)};
60-
cliOptions_.insert({cliOption, {feature}});
61-
languageFeatureCliCanonicalSpelling_[EnumToInt(feature)] =
62-
std::string_view{cliOption};
60+
cliOptions_.insert({std::string{cliOption}, {feature}});
61+
languageFeatureCliCanonicalSpelling_[EnumToInt(feature)] = std::move(cliOption);
6362
});
6463

6564
ForEachUsageWarning([&](auto warning) {
6665
std::string_view name{Fortran::common::EnumToString(warning)};
6766
std::string cliOption{details::CamelCaseToLowerCaseHyphenated(name)};
68-
cliOptions_.insert({cliOption, {warning}});
69-
usageWarningCliCanonicalSpelling_[EnumToInt(warning)] =
70-
std::string_view{cliOption};
67+
cliOptions_.insert({std::string{cliOption}, {warning}});
68+
usageWarningCliCanonicalSpelling_[EnumToInt(warning)] = std::move(cliOption);
7169
});
7270

7371
// These features must be explicitly enabled by command line options.
@@ -171,20 +169,23 @@ bool LanguageFeatureControl::ApplyCliOption(std::string input) {
171169
return false;
172170
}
173171

172+
template <typename T, size_t ENUM_SIZE>
173+
static void replaceCliCanonicalSpelling(
174+
std::unordered_map<std::string, std::variant<LanguageFeature, UsageWarning>> &cliOptions,
175+
std::array<std::string, ENUM_SIZE> &canonicalSpelling, T t, std::string &input) {
176+
cliOptions.erase({canonicalSpelling[EnumToInt(t)]});
177+
canonicalSpelling[EnumToInt(t)] = std::string{input};
178+
cliOptions.insert({std::string{input}, {t}});
179+
}
180+
174181
void LanguageFeatureControl::ReplaceCliCanonicalSpelling(
175182
LanguageFeature f, std::string input) {
176-
std::string_view &old{languageFeatureCliCanonicalSpelling_[EnumToInt(f)]};
177-
cliOptions_.erase(std::string{old});
178-
languageFeatureCliCanonicalSpelling_[EnumToInt(f)] = input;
179-
cliOptions_.insert({input, {f}});
183+
replaceCliCanonicalSpelling(cliOptions_, languageFeatureCliCanonicalSpelling_, f, input);
180184
}
181185

182186
void LanguageFeatureControl::ReplaceCliCanonicalSpelling(
183187
UsageWarning w, std::string input) {
184-
std::string_view &old{usageWarningCliCanonicalSpelling_[EnumToInt(w)]};
185-
cliOptions_.erase(std::string{old});
186-
usageWarningCliCanonicalSpelling_[EnumToInt(w)] = input;
187-
cliOptions_.insert({input, {w}});
188+
replaceCliCanonicalSpelling(cliOptions_, usageWarningCliCanonicalSpelling_, w, input);
188189
}
189190

190191
std::vector<const char *> LanguageFeatureControl::GetNames(

flang/test/Evaluate/fold-dim.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module m
1111
logical, parameter :: test_a3 = dim(2., 1.) == 1.
1212
logical, parameter :: test_a4 = dim(2., -1.) == 3.
1313
logical, parameter :: test_a5 = dim(-1., 2.) == 0.
14-
!WARN: warning: invalid argument on division
14+
!WARN: warning: invalid argument on division [-Wno-folding-exception]
1515
real, parameter :: nan = 0./0.
1616
logical, parameter :: test_a6 = dim(nan, 1.) /= dim(nan, 1.)
1717
end module

flang/test/Evaluate/fold-nearest.f90

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ module m1
1919
real, parameter :: negZero = sign(0., -1.)
2020
logical, parameter :: test_12 = nearest(negZero, 1.) == minSubnormal
2121
logical, parameter :: test_13 = nearest(negZero, -1.) == -minSubnormal
22-
!WARN: warning: NEAREST: S argument is zero
22+
!WARN: warning: NEAREST: S argument is zero [-Wno-folding-value-checks]
2323
logical, parameter :: test_14 = nearest(0., negZero) == -minSubnormal
24-
!WARN: warning: NEAREST: S argument is zero
24+
!WARN: warning: NEAREST: S argument is zero [-Wno-folding-value-checks]
2525
logical, parameter :: test_15 = nearest(negZero, 0.) == minSubnormal
2626
logical, parameter :: test_16 = nearest(tiny(1.),-1.) == 1.1754942E-38
2727
logical, parameter :: test_17 = nearest(tiny(1.),1.) == 1.1754945E-38
2828
contains
2929
subroutine subr(a)
3030
real, intent(in) :: a
31-
!WARN: warning: NEAREST: S argument is zero
31+
!WARN: warning: NEAREST: S argument is zero [-Wno-folding-value-checks]
3232
print *, nearest(a, 0.)
3333
end
3434
end module
@@ -42,7 +42,7 @@ module m2
4242
logical, parameter :: test_2 = ieee_next_after(minSubnormal, -1.) == 0
4343
logical, parameter :: test_3 = ieee_next_after(1., 2.) == 1.0000001
4444
logical, parameter :: test_4 = ieee_next_after(1.0000001, -1.) == 1
45-
!WARN: warning: division by zero
45+
!WARN: warning: division by zero [-Wno-folding-exception]
4646
real, parameter :: inf = 1. / 0.
4747
logical, parameter :: test_5 = ieee_next_after(inf, inf) == inf
4848
logical, parameter :: test_6 = ieee_next_after(inf, -inf) == h
@@ -54,12 +54,12 @@ module m2
5454
logical, parameter :: test_11 = ieee_next_after(1.9999999999999999999_10, 3.) == 2._10
5555
#endif
5656
logical, parameter :: test_12 = ieee_next_after(1., 1.) == 1.
57-
!WARN: warning: invalid argument on division
57+
!WARN: warning: invalid argument on division [-Wno-folding-exception]
5858
real, parameter :: nan = 0. / 0.
59-
!WARN: warning: IEEE_NEXT_AFTER intrinsic folding: arguments are unordered
59+
!WARN: warning: IEEE_NEXT_AFTER intrinsic folding: arguments are unordered [-Wno-folding-value-checks]
6060
real, parameter :: x13 = ieee_next_after(nan, nan)
6161
logical, parameter :: test_13 = .not. (x13 == x13)
62-
!WARN: warning: IEEE_NEXT_AFTER intrinsic folding: arguments are unordered
62+
!WARN: warning: IEEE_NEXT_AFTER intrinsic folding: arguments are unordered [-Wno-folding-value-checks]
6363
real, parameter :: x14 = ieee_next_after(nan, 0.)
6464
logical, parameter :: test_14 = .not. (x14 == x14)
6565
end module
@@ -72,7 +72,7 @@ module m3
7272
logical, parameter :: test_2 = ieee_next_down(0.d0) == -minSubnormal
7373
logical, parameter :: test_3 = ieee_next_up(1.d0) == 1.0000000000000002d0
7474
logical, parameter :: test_4 = ieee_next_down(1.0000000000000002d0) == 1.d0
75-
!WARN: warning: division by zero
75+
!WARN: warning: division by zero [-Wno-folding-exception]
7676
real(kind(0.d0)), parameter :: inf = 1.d0 / 0.d0
7777
logical, parameter :: test_5 = ieee_next_up(huge(0.d0)) == inf
7878
logical, parameter :: test_6 = ieee_next_down(-huge(0.d0)) == -inf
@@ -82,12 +82,12 @@ module m3
8282
logical, parameter :: test_10 = ieee_next_down(-inf) == -inf
8383
logical, parameter :: test_11 = ieee_next_up(1.9999999999999997d0) == 2.d0
8484
logical, parameter :: test_12 = ieee_next_down(2.d0) == 1.9999999999999997d0
85-
!WARN: warning: invalid argument on division
85+
!WARN: warning: invalid argument on division [-Wno-folding-exception]
8686
real(kind(0.d0)), parameter :: nan = 0.d0 / 0.d0
87-
!WARN: warning: IEEE_NEXT_UP intrinsic folding: argument is NaN
87+
!WARN: warning: IEEE_NEXT_UP intrinsic folding: argument is NaN [-Wno-folding-exception]
8888
real(kind(0.d0)), parameter :: x13 = ieee_next_up(nan)
8989
logical, parameter :: test_13 = .not. (x13 == x13)
90-
!WARN: warning: IEEE_NEXT_DOWN intrinsic folding: argument is NaN
90+
!WARN: warning: IEEE_NEXT_DOWN intrinsic folding: argument is NaN [-Wno-folding-exception]
9191
real(kind(0.d0)), parameter :: x14 = ieee_next_down(nan)
9292
logical, parameter :: test_14 = .not. (x14 == x14)
9393
end module

flang/test/Evaluate/fold-unsigned.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module m
2424

2525
logical, parameter :: test_cus0 = int(0u,1) == 0
2626
logical, parameter :: test_cus0_k = kind(int(0u,1)) == 1
27-
!WARN: warning: conversion of 255_U1 to INTEGER(1) overflowed; result is -1
27+
!WARN: warning: conversion of 255_U1 to INTEGER(1) overflowed; result is -1 [-Wno-folding-exception]
2828
logical, parameter :: test_cus255 = int(255u_1,1) == -1
2929
logical, parameter :: test_cur255 = real(255u) == 255.
3030

0 commit comments

Comments
 (0)