Skip to content

Commit a53967c

Browse files
committed
[flang] Distinguish usage and portability warning messages
Using recently established message severity codes, upgrade non-fatal messages to usage and portability warnings as appropriate. Differential Revision: https://reviews.llvm.org/D121246
1 parent 0605724 commit a53967c

37 files changed

+200
-188
lines changed

flang/lib/Evaluate/check-expression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ std::optional<Expr<SomeType>> NonPointerInitializationExpr(const Symbol &symbol,
410410
symbol.owner().context().ShouldWarn(
411411
common::LanguageFeature::LogicalIntegerAssignment)) {
412412
context.messages().Say(
413-
"nonstandard usage: initialization of %s with %s"_en_US,
413+
"nonstandard usage: initialization of %s with %s"_port_en_US,
414414
symTS->type().AsFortran(), x.GetType().value().AsFortran());
415415
}
416416
}

flang/lib/Evaluate/common.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ namespace Fortran::evaluate {
1616
void RealFlagWarnings(
1717
FoldingContext &context, const RealFlags &flags, const char *operation) {
1818
if (flags.test(RealFlag::Overflow)) {
19-
context.messages().Say("overflow on %s"_en_US, operation);
19+
context.messages().Say("overflow on %s"_warn_en_US, operation);
2020
}
2121
if (flags.test(RealFlag::DivideByZero)) {
2222
if (std::strcmp(operation, "division") == 0) {
23-
context.messages().Say("division by zero"_en_US);
23+
context.messages().Say("division by zero"_warn_en_US);
2424
} else {
25-
context.messages().Say("division on %s"_en_US);
25+
context.messages().Say("division on %s"_warn_en_US);
2626
}
2727
}
2828
if (flags.test(RealFlag::InvalidArgument)) {
29-
context.messages().Say("invalid argument on %s"_en_US, operation);
29+
context.messages().Say("invalid argument on %s"_warn_en_US, operation);
3030
}
3131
if (flags.test(RealFlag::Underflow)) {
32-
context.messages().Say("underflow on %s"_en_US, operation);
32+
context.messages().Say("underflow on %s"_warn_en_US, operation);
3333
}
3434
}
3535

flang/lib/Evaluate/fold-complex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Expr<Type<TypeCategory::Complex, KIND>> FoldIntrinsicFunction(
3030
context, std::move(funcRef), *callable);
3131
} else {
3232
context.messages().Say(
33-
"%s(complex(kind=%d)) cannot be folded on host"_en_US, name, KIND);
33+
"%s(complex(kind=%d)) cannot be folded on host"_warn_en_US, name,
34+
KIND);
3435
}
3536
} else if (name == "conjg") {
3637
return FoldElementalIntrinsic<T, T>(

flang/lib/Evaluate/fold-implementation.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,19 +1534,19 @@ Expr<TO> FoldOperation(
15341534
auto converted{Scalar<TO>::ConvertSigned(*value)};
15351535
if (converted.overflow) {
15361536
ctx.messages().Say(
1537-
"INTEGER(%d) to INTEGER(%d) conversion overflowed"_en_US,
1537+
"INTEGER(%d) to INTEGER(%d) conversion overflowed"_warn_en_US,
15381538
Operand::kind, TO::kind);
15391539
}
15401540
return ScalarConstantToExpr(std::move(converted.value));
15411541
} else if constexpr (FromCat == TypeCategory::Real) {
15421542
auto converted{value->template ToInteger<Scalar<TO>>()};
15431543
if (converted.flags.test(RealFlag::InvalidArgument)) {
15441544
ctx.messages().Say(
1545-
"REAL(%d) to INTEGER(%d) conversion: invalid argument"_en_US,
1545+
"REAL(%d) to INTEGER(%d) conversion: invalid argument"_warn_en_US,
15461546
Operand::kind, TO::kind);
15471547
} else if (converted.flags.test(RealFlag::Overflow)) {
15481548
ctx.messages().Say(
1549-
"REAL(%d) to INTEGER(%d) conversion overflowed"_en_US,
1549+
"REAL(%d) to INTEGER(%d) conversion overflowed"_warn_en_US,
15501550
Operand::kind, TO::kind);
15511551
}
15521552
return ScalarConstantToExpr(std::move(converted.value));
@@ -1651,7 +1651,7 @@ Expr<T> FoldOperation(FoldingContext &context, Negate<T> &&x) {
16511651
auto negated{value->Negate()};
16521652
if (negated.overflow) {
16531653
context.messages().Say(
1654-
"INTEGER(%d) negation overflowed"_en_US, T::kind);
1654+
"INTEGER(%d) negation overflowed"_warn_en_US, T::kind);
16551655
}
16561656
return Expr<T>{Constant<T>{std::move(negated.value)}};
16571657
} else {
@@ -1691,7 +1691,7 @@ Expr<T> FoldOperation(FoldingContext &context, Add<T> &&x) {
16911691
auto sum{folded->first.AddSigned(folded->second)};
16921692
if (sum.overflow) {
16931693
context.messages().Say(
1694-
"INTEGER(%d) addition overflowed"_en_US, T::kind);
1694+
"INTEGER(%d) addition overflowed"_warn_en_US, T::kind);
16951695
}
16961696
return Expr<T>{Constant<T>{sum.value}};
16971697
} else {
@@ -1716,7 +1716,7 @@ Expr<T> FoldOperation(FoldingContext &context, Subtract<T> &&x) {
17161716
auto difference{folded->first.SubtractSigned(folded->second)};
17171717
if (difference.overflow) {
17181718
context.messages().Say(
1719-
"INTEGER(%d) subtraction overflowed"_en_US, T::kind);
1719+
"INTEGER(%d) subtraction overflowed"_warn_en_US, T::kind);
17201720
}
17211721
return Expr<T>{Constant<T>{difference.value}};
17221722
} else {
@@ -1742,7 +1742,7 @@ Expr<T> FoldOperation(FoldingContext &context, Multiply<T> &&x) {
17421742
auto product{folded->first.MultiplySigned(folded->second)};
17431743
if (product.SignedMultiplicationOverflowed()) {
17441744
context.messages().Say(
1745-
"INTEGER(%d) multiplication overflowed"_en_US, T::kind);
1745+
"INTEGER(%d) multiplication overflowed"_warn_en_US, T::kind);
17461746
}
17471747
return Expr<T>{Constant<T>{product.lower}};
17481748
} else {
@@ -1780,12 +1780,13 @@ Expr<T> FoldOperation(FoldingContext &context, Divide<T> &&x) {
17801780
if constexpr (T::category == TypeCategory::Integer) {
17811781
auto quotAndRem{folded->first.DivideSigned(folded->second)};
17821782
if (quotAndRem.divisionByZero) {
1783-
context.messages().Say("INTEGER(%d) division by zero"_en_US, T::kind);
1783+
context.messages().Say(
1784+
"INTEGER(%d) division by zero"_warn_en_US, T::kind);
17841785
return Expr<T>{std::move(x)};
17851786
}
17861787
if (quotAndRem.overflow) {
17871788
context.messages().Say(
1788-
"INTEGER(%d) division overflowed"_en_US, T::kind);
1789+
"INTEGER(%d) division overflowed"_warn_en_US, T::kind);
17891790
}
17901791
return Expr<T>{Constant<T>{quotAndRem.quotient}};
17911792
} else {
@@ -1810,12 +1811,13 @@ Expr<T> FoldOperation(FoldingContext &context, Power<T> &&x) {
18101811
auto power{folded->first.Power(folded->second)};
18111812
if (power.divisionByZero) {
18121813
context.messages().Say(
1813-
"INTEGER(%d) zero to negative power"_en_US, T::kind);
1814+
"INTEGER(%d) zero to negative power"_warn_en_US, T::kind);
18141815
} else if (power.overflow) {
1815-
context.messages().Say("INTEGER(%d) power overflowed"_en_US, T::kind);
1816+
context.messages().Say(
1817+
"INTEGER(%d) power overflowed"_warn_en_US, T::kind);
18161818
} else if (power.zeroToZero) {
18171819
context.messages().Say(
1818-
"INTEGER(%d) 0**0 is not defined"_en_US, T::kind);
1820+
"INTEGER(%d) 0**0 is not defined"_warn_en_US, T::kind);
18191821
}
18201822
return Expr<T>{Constant<T>{power.power}};
18211823
} else {
@@ -1824,7 +1826,8 @@ Expr<T> FoldOperation(FoldingContext &context, Power<T> &&x) {
18241826
Constant<T>{(*callable)(context, folded->first, folded->second)}};
18251827
} else {
18261828
context.messages().Say(
1827-
"Power for %s cannot be folded on host"_en_US, T{}.AsFortran());
1829+
"Power for %s cannot be folded on host"_warn_en_US,
1830+
T{}.AsFortran());
18281831
}
18291832
}
18301833
}
@@ -1907,7 +1910,7 @@ Expr<Type<TypeCategory::Real, KIND>> ToReal(
19071910
From converted{From::ConvertUnsigned(real.RawBits()).value};
19081911
if (original != converted) { // C1601
19091912
context.messages().Say(
1910-
"Nonzero bits truncated from BOZ literal constant in REAL intrinsic"_en_US);
1913+
"Nonzero bits truncated from BOZ literal constant in REAL intrinsic"_warn_en_US);
19111914
}
19121915
} else if constexpr (IsNumericCategoryExpr<From>()) {
19131916
result = Fold(context, ConvertToType<Result>(std::move(x)));

flang/lib/Evaluate/fold-integer.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
420420
typename Scalar<T>::ValueWithOverflow j{i.ABS()};
421421
if (j.overflow) {
422422
context.messages().Say(
423-
"abs(integer(kind=%d)) folding overflowed"_en_US, KIND);
423+
"abs(integer(kind=%d)) folding overflowed"_warn_en_US, KIND);
424424
}
425425
return j.value;
426426
}));
@@ -440,7 +440,7 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
440440
auto y{x.template ToInteger<Scalar<T>>(mode)};
441441
if (y.flags.test(RealFlag::Overflow)) {
442442
context.messages().Say(
443-
"%s intrinsic folding overflow"_en_US, name);
443+
"%s intrinsic folding overflow"_warn_en_US, name);
444444
}
445445
return y.value;
446446
}));
@@ -506,7 +506,7 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
506506
if (len.value() != 1) {
507507
// Do not die, this was not checked before
508508
context.messages().Say(
509-
"Character in intrinsic function %s must have length one"_en_US,
509+
"Character in intrinsic function %s must have length one"_warn_en_US,
510510
name);
511511
} else {
512512
return std::visit(
@@ -761,9 +761,9 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
761761
const Scalar<T> &y) -> Scalar<T> {
762762
auto quotRem{x.DivideSigned(y)};
763763
if (quotRem.divisionByZero) {
764-
context.messages().Say("mod() by zero"_en_US);
764+
context.messages().Say("mod() by zero"_warn_en_US);
765765
} else if (quotRem.overflow) {
766-
context.messages().Say("mod() folding overflowed"_en_US);
766+
context.messages().Say("mod() folding overflowed"_warn_en_US);
767767
}
768768
return quotRem.remainder;
769769
}));
@@ -774,7 +774,8 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
774774
const Scalar<T> &y) -> Scalar<T> {
775775
auto result{x.MODULO(y)};
776776
if (result.overflow) {
777-
context.messages().Say("modulo() folding overflowed"_en_US);
777+
context.messages().Say(
778+
"modulo() folding overflowed"_warn_en_US);
778779
}
779780
return result.value;
780781
}));
@@ -894,7 +895,8 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
894895
typename Scalar<T>::ValueWithOverflow result{j.SIGN(k)};
895896
if (result.overflow) {
896897
context.messages().Say(
897-
"sign(integer(kind=%d)) folding overflowed"_en_US, KIND);
898+
"sign(integer(kind=%d)) folding overflowed"_warn_en_US,
899+
KIND);
898900
}
899901
return result.value;
900902
}));
@@ -915,7 +917,7 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
915917
}
916918
} else {
917919
context.messages().Say(
918-
"size(array,dim=%jd) dimension is out of range for rank-%d array"_en_US,
920+
"size(array,dim=%jd) dimension is out of range for rank-%d array"_warn_en_US,
919921
*dim, rank);
920922
}
921923
}

flang/lib/Evaluate/fold-real.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
3535
context, std::move(funcRef), *callable);
3636
} else {
3737
context.messages().Say(
38-
"%s(real(kind=%d)) cannot be folded on host"_en_US, name, KIND);
38+
"%s(real(kind=%d)) cannot be folded on host"_warn_en_US, name, KIND);
3939
}
4040
} else if (name == "amax0" || name == "amin0" || name == "amin1" ||
4141
name == "amax1" || name == "dmin1" || name == "dmax1") {
@@ -48,7 +48,7 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
4848
context, std::move(funcRef), *callable);
4949
} else {
5050
context.messages().Say(
51-
"%s(real(kind=%d), real(kind%d)) cannot be folded on host"_en_US,
51+
"%s(real(kind=%d), real(kind%d)) cannot be folded on host"_warn_en_US,
5252
name, KIND, KIND);
5353
}
5454
} else if (name == "bessel_jn" || name == "bessel_yn") {
@@ -60,7 +60,7 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
6060
context, std::move(funcRef), *callable);
6161
} else {
6262
context.messages().Say(
63-
"%s(integer(kind=4), real(kind=%d)) cannot be folded on host"_en_US,
63+
"%s(integer(kind=4), real(kind=%d)) cannot be folded on host"_warn_en_US,
6464
name, KIND);
6565
}
6666
}
@@ -90,7 +90,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
9090
const Scalar<T> &x) -> Scalar<T> {
9191
ValueWithRealFlags<Scalar<T>> y{x.ToWholeNumber(mode)};
9292
if (y.flags.test(RealFlag::Overflow)) {
93-
context.messages().Say("%s intrinsic folding overflow"_en_US, name);
93+
context.messages().Say(
94+
"%s intrinsic folding overflow"_warn_en_US, name);
9495
}
9596
return y.value;
9697
}));
@@ -148,7 +149,7 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
148149
SCALE(y)};
149150
if (result.flags.test(RealFlag::Overflow)) {
150151
context.messages().Say(
151-
"SCALE intrinsic folding overflow"_en_US);
152+
"SCALE intrinsic folding overflow"_warn_en_US);
152153
}
153154
return result.value;
154155
}));

flang/lib/Evaluate/fold-reduction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static Expr<T> FoldProduct(
173173
}};
174174
if (overflow) {
175175
context.messages().Say(
176-
"PRODUCT() of %s data overflowed"_en_US, T::AsFortran());
176+
"PRODUCT() of %s data overflowed"_warn_en_US, T::AsFortran());
177177
} else {
178178
return Expr<T>{DoReduction<T>(*array, dim, identity, accumulator)};
179179
}
@@ -212,7 +212,7 @@ static Expr<T> FoldSum(FoldingContext &context, FunctionRef<T> &&ref) {
212212
}};
213213
if (overflow) {
214214
context.messages().Say(
215-
"SUM() of %s data overflowed"_en_US, T::AsFortran());
215+
"SUM() of %s data overflowed"_warn_en_US, T::AsFortran());
216216
} else {
217217
return Expr<T>{DoReduction<T>(*array, dim, identity, accumulator)};
218218
}

flang/lib/Evaluate/host.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void HostFloatingPointEnvironment::SetUpHostFloatingPointEnvironment(
102102
fesetround(FE_TONEAREST);
103103
context.messages().Say(
104104
"TiesAwayFromZero rounding mode is not available when folding constants"
105-
" with host runtime; using TiesToEven instead"_en_US);
105+
" with host runtime; using TiesToEven instead"_warn_en_US);
106106
break;
107107
}
108108
flags_.clear();

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,7 @@ std::optional<SpecificCall> IntrinsicProcTable::Implementation::Probe(
24762476
context.messages().Say(
24772477
"argument types do not match specific intrinsic '%s' "
24782478
"requirements; using '%s' generic instead and converting the "
2479-
"result to %s if needed"_en_US,
2479+
"result to %s if needed"_port_en_US,
24802480
call.name, genericName, newType.AsFortran());
24812481
specificCall->specificIntrinsic.name = call.name;
24822482
specificCall->specificIntrinsic.characteristics.value()

flang/lib/Evaluate/variable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,14 @@ std::optional<Expr<SomeCharacter>> Substring::Fold(FoldingContext &context) {
223223
if (!result) { // error cases
224224
if (*lbi < 1) {
225225
context.messages().Say(
226-
"Lower bound (%jd) on substring is less than one"_en_US,
226+
"Lower bound (%jd) on substring is less than one"_warn_en_US,
227227
static_cast<std::intmax_t>(*lbi));
228228
*lbi = 1;
229229
lower_ = AsExpr(Constant<SubscriptInteger>{1});
230230
}
231231
if (length && *ubi > *length) {
232232
context.messages().Say(
233-
"Upper bound (%jd) on substring is greater than character length (%jd)"_en_US,
233+
"Upper bound (%jd) on substring is greater than character length (%jd)"_warn_en_US,
234234
static_cast<std::intmax_t>(*ubi),
235235
static_cast<std::intmax_t>(*length));
236236
*ubi = *length;

flang/lib/Parser/basic-parsers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ template <LanguageFeature LF, typename PA> class NonstandardParser {
856856
auto result{parser_.Parse(state)};
857857
if (result) {
858858
state.Nonstandard(CharBlock{at, std::max(state.GetLocation(), at + 1)},
859-
LF, "nonstandard usage"_en_US);
859+
LF, "nonstandard usage"_port_en_US);
860860
}
861861
return result;
862862
}
@@ -887,8 +887,8 @@ template <LanguageFeature LF, typename PA> class DeprecatedParser {
887887
auto at{state.GetLocation()};
888888
auto result{parser_.Parse(state)};
889889
if (result) {
890-
state.Nonstandard(
891-
CharBlock{at, state.GetLocation()}, LF, "deprecated usage"_en_US);
890+
state.Nonstandard(CharBlock{at, state.GetLocation()}, LF,
891+
"deprecated usage"_port_en_US);
892892
}
893893
return result;
894894
}

0 commit comments

Comments
 (0)