[flang-commits] [flang] 1759f3b - [flang] Improve error messages about overflowed integer conversions (#110031)
via flang-commits
flang-commits at lists.llvm.org
Mon Sep 30 12:38:09 PDT 2024
Author: Peter Klausler
Date: 2024-09-30T12:38:06-07:00
New Revision: 1759f3b404a5bd73c6412b8a110f850ff1c43c24
URL: https://github.com/llvm/llvm-project/commit/1759f3b404a5bd73c6412b8a110f850ff1c43c24
DIFF: https://github.com/llvm/llvm-project/commit/1759f3b404a5bd73c6412b8a110f850ff1c43c24.diff
LOG: [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.
Added:
Modified:
flang/lib/Evaluate/fold-implementation.h
flang/test/Evaluate/errors01.f90
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index 1b14a305b87f4f..89477dfb364351 100644
--- a/flang/lib/Evaluate/fold-implementation.h
+++ b/flang/lib/Evaluate/fold-implementation.h
@@ -1736,8 +1736,9 @@ Expr<TO> FoldOperation(
msvcWorkaround.context.languageFeatures().ShouldWarn(
common::UsageWarning::FoldingException)) {
ctx.messages().Say(
- "INTEGER(%d) to INTEGER(%d) conversion overflowed"_warn_en_US,
- Operand::kind, TO::kind);
+ "conversion of %s_%d to INTEGER(%d) overflowed; result is %s"_warn_en_US,
+ value->SignedDecimal(), Operand::kind, TO::kind,
+ converted.value.SignedDecimal());
}
return ScalarConstantToExpr(std::move(converted.value));
} else if constexpr (FromCat == TypeCategory::Real) {
diff --git a/flang/test/Evaluate/errors01.f90 b/flang/test/Evaluate/errors01.f90
index bad73f2e8b160f..684f3fc34e6872 100644
--- a/flang/test/Evaluate/errors01.f90
+++ b/flang/test/Evaluate/errors01.f90
@@ -192,6 +192,8 @@ subroutine warnings
real, parameter :: bad10 = product([huge(1.),huge(1.)])
!CHECK: warning: PRODUCT() of COMPLEX(4) data overflowed
complex, parameter :: bad11 = product([(huge(1.),0.),(huge(1.),0.)])
+ !CHECK: warning: conversion of 111111111111111111111_16 to INTEGER(8) overflowed; result is 430646668853801415
+ integer(8), parameter :: bad12 = int(111111111111111111111, 8)
!CHECK: warning: overflow on REAL(8) to REAL(4) conversion
x = 1.D40
!CHECK-NOT: warning: invalid argument
More information about the flang-commits
mailing list