This is an archive of the discontinued LLVM Phabricator instance.

[flang] Emit warnings when results of folding some integer intrinsics overflow
ClosedPublic

Authored by klausler on Oct 28 2022, 1:02 PM.

Details

Summary

When the compile-time result value of a reference to an integer-valued intrinsic
function COUNT, ICHAR, IACHAR, INDEX, SCAN, or VERIFY cannot be represented in
the selected result kind, emit a warning.

Diff Detail

Event Timeline

klausler created this revision.Oct 28 2022, 1:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 28 2022, 1:02 PM
Herald added a subscriber: jdoerfert. · View Herald Transcript
klausler requested review of this revision.Oct 28 2022, 1:02 PM

folding05.f90 is not actually a binary file, but it does contain a NUL character that makes "diff" think that it is one. The diff on the file is:

diff --git a/flang/test/Evaluate/folding05.f90 b/flang/test/Evaluate/folding05.f90
index 3be3904ccab5..f876a56691b8 100644
--- a/flang/test/Evaluate/folding05.f90
+++ b/flang/test/Evaluate/folding05.f90
@@ -33,12 +33,14 @@ module character_intrinsic_tests

   logical, parameter :: test_ichar1 = char(ichar("a")).EQ."a"
   logical, parameter :: test_ichar2 = ichar(char(255)).EQ.255
+  !WARN: warning: Result of intrinsic function 'ichar' (255) overflows its result type
   logical, parameter :: test_ichar3 = ichar(char(-1_1), 1).EQ.-1_1
   logical, parameter :: test_ichar4 = ichar(char(2147483647_4, 4), 4).EQ.2147483647_4
   logical, parameter :: test_ichar5 = ichar(char(4294967295_8, 4), 8).EQ.4294967295_8
   logical, parameter :: test_ichar6 = ichar(char(4294967296_8, 4), 8).EQ.0_8
   logical, parameter :: test_iachar1 = achar(iachar("a")).EQ."a"
   logical, parameter :: test_iachar2 = iachar(achar(22)).EQ.22
+  !WARN: warning: Result of intrinsic function 'ichar' (2147483649) overflows its result type
   logical, parameter :: test_iachar3 = ichar(char(-2147483647_4, 4), 4).EQ.(-2147483647_4)
   logical, parameter :: test_iachar5 = ichar(char(65535_4, 2), 4).EQ.65535_4
   logical, parameter :: test_iachar6 = ichar(char(65536_4, 2), 4).EQ.0_4
vdonaldson accepted this revision.Oct 28 2022, 2:23 PM
This revision is now accepted and ready to land.Oct 28 2022, 2:23 PM
This revision was landed with ongoing or failed builds.Oct 30 2022, 11:03 AM
This revision was automatically updated to reflect the committed changes.