
(This is a big patch, but it's nearly an NFC. No test results have changed and all Fortran tests in the LLVM test suites work as expected.) Allow a parser::Message for a warning to be marked with the common::LanguageFeature or common::UsageWarning that controls it. This will allow a later patch to add hooks whereby a driver will be able to decorate warning messages with the names of its options that enable each particular warning, and to add hooks whereby a driver can map those enumerators by name to command-line options that enable/disable the language feature and enable/disable the messages. The default settings in the constructor for LanguageFeatureControl were moved from its header file into its C++ source file. Hooks for a driver to use to map the name of a feature or warning to its enumerator were also added. To simplify the tagging of warnings with their corresponding language feature or usage warning, to ensure that they are properly controlled by ShouldWarn(), and to ensure that warnings never issue at code sites in module files, two new Warn() member function templates were added to SemanticsContext and other contextual frameworks. Warn() can't be used before source locations can be mapped to scopes, but the bulk of existing code blocks testing ShouldWarn() and FindModuleFile() before calling Say() were convertible into calls to Warn(). The ones that were not convertible were extended with explicit calls to Message::set_languageFeature() and set_usageWarning().
64 lines
2.1 KiB
C++
64 lines
2.1 KiB
C++
//===-- lib/Evaluate/common.cpp -------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "flang/Evaluate/common.h"
|
|
#include "flang/Common/idioms.h"
|
|
|
|
using namespace Fortran::parser::literals;
|
|
|
|
namespace Fortran::evaluate {
|
|
|
|
void RealFlagWarnings(
|
|
FoldingContext &context, const RealFlags &flags, const char *operation) {
|
|
static constexpr auto warning{common::UsageWarning::FoldingException};
|
|
if (context.languageFeatures().ShouldWarn(warning)) {
|
|
if (flags.test(RealFlag::Overflow)) {
|
|
context.messages().Say(warning, "overflow on %s"_warn_en_US, operation);
|
|
}
|
|
if (flags.test(RealFlag::DivideByZero)) {
|
|
if (std::strcmp(operation, "division") == 0) {
|
|
context.messages().Say(warning, "division by zero"_warn_en_US);
|
|
} else {
|
|
context.messages().Say(
|
|
warning, "division by zero on %s"_warn_en_US, operation);
|
|
}
|
|
}
|
|
if (flags.test(RealFlag::InvalidArgument)) {
|
|
context.messages().Say(
|
|
warning, "invalid argument on %s"_warn_en_US, operation);
|
|
}
|
|
if (flags.test(RealFlag::Underflow)) {
|
|
context.messages().Say(warning, "underflow on %s"_warn_en_US, operation);
|
|
}
|
|
}
|
|
}
|
|
|
|
ConstantSubscript &FoldingContext::StartImpliedDo(
|
|
parser::CharBlock name, ConstantSubscript n) {
|
|
auto pair{impliedDos_.insert(std::make_pair(name, n))};
|
|
CHECK(pair.second);
|
|
return pair.first->second;
|
|
}
|
|
|
|
std::optional<ConstantSubscript> FoldingContext::GetImpliedDo(
|
|
parser::CharBlock name) const {
|
|
if (auto iter{impliedDos_.find(name)}; iter != impliedDos_.cend()) {
|
|
return {iter->second};
|
|
} else {
|
|
return std::nullopt;
|
|
}
|
|
}
|
|
|
|
void FoldingContext::EndImpliedDo(parser::CharBlock name) {
|
|
auto iter{impliedDos_.find(name)};
|
|
if (iter != impliedDos_.end()) {
|
|
impliedDos_.erase(iter);
|
|
}
|
|
}
|
|
} // namespace Fortran::evaluate
|