[flang-commits] [flang] [flang] Improve error messages about overflowed integer conversions (PR #110031)
via flang-commits
flang-commits at lists.llvm.org
Wed Sep 25 12:45:33 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/110031.diff
2 Files Affected:
- (modified) flang/lib/Evaluate/fold-implementation.h (+3-2)
- (modified) flang/test/Evaluate/errors01.f90 (+2)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/110031
More information about the flang-commits
mailing list