Skip to content

Commit 1759f3b

Browse files
authored
[flang] Improve error messages about overflowed integer conversions (#110031)
When an INTEGER conversion to a smaller kind overflows in constant folding, report the truncated value so that it makes more sense later if it shows up in other messages.
1 parent b5aea32 commit 1759f3b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

flang/lib/Evaluate/fold-implementation.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,8 +1736,9 @@ Expr<TO> FoldOperation(
17361736
msvcWorkaround.context.languageFeatures().ShouldWarn(
17371737
common::UsageWarning::FoldingException)) {
17381738
ctx.messages().Say(
1739-
"INTEGER(%d) to INTEGER(%d) conversion overflowed"_warn_en_US,
1740-
Operand::kind, TO::kind);
1739+
"conversion of %s_%d to INTEGER(%d) overflowed; result is %s"_warn_en_US,
1740+
value->SignedDecimal(), Operand::kind, TO::kind,
1741+
converted.value.SignedDecimal());
17411742
}
17421743
return ScalarConstantToExpr(std::move(converted.value));
17431744
} else if constexpr (FromCat == TypeCategory::Real) {

flang/test/Evaluate/errors01.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ subroutine warnings
192192
real, parameter :: bad10 = product([huge(1.),huge(1.)])
193193
!CHECK: warning: PRODUCT() of COMPLEX(4) data overflowed
194194
complex, parameter :: bad11 = product([(huge(1.),0.),(huge(1.),0.)])
195+
!CHECK: warning: conversion of 111111111111111111111_16 to INTEGER(8) overflowed; result is 430646668853801415
196+
integer(8), parameter :: bad12 = int(111111111111111111111, 8)
195197
!CHECK: warning: overflow on REAL(8) to REAL(4) conversion
196198
x = 1.D40
197199
!CHECK-NOT: warning: invalid argument

0 commit comments

Comments
 (0)