-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[flang][folding] fix i(a)char folding regression #155909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-flang-semantics Author: Andre Kuhlenschmidt (akuhlens) ChangesFixes a bug in folding "ichar" and "iachar" intrinsics introduced here. There was already a slight bug that the coded didn't fold when portability warnings were enabled which has also been fixed and tested for. Full diff: https://github.com/llvm/llvm-project/pull/155909.diff 3 Files Affected:
diff --git a/flang/lib/Evaluate/fold-integer.cpp b/flang/lib/Evaluate/fold-integer.cpp
index 00f92d3900c32..3628497531ef1 100644
--- a/flang/lib/Evaluate/fold-integer.cpp
+++ b/flang/lib/Evaluate/fold-integer.cpp
@@ -1050,12 +1050,13 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
context.messages().Say(
"Character in intrinsic function %s must have length one"_err_en_US,
name);
- } else if (len.value() > 1) {
- // Do not die, this was not checked before
- context.Warn(common::UsageWarning::Portability,
- "Character in intrinsic function %s should have length one"_port_en_US,
- name);
} else {
+ // Do not die, this was not checked before
+ if (len.value() > 1) {
+ context.Warn(common::UsageWarning::Portability,
+ "Character in intrinsic function %s should have length one"_port_en_US,
+ name);
+ }
return common::visit(
[&funcRef, &context, &FromInt64](const auto &str) -> Expr<T> {
using Char = typename std::decay_t<decltype(str)>::Result;
diff --git a/flang/test/Semantics/intrinsics03.f90 b/flang/test/Semantics/intrinsics03.f90
index 03109bc300caf..dbf0967c914fb 100644
--- a/flang/test/Semantics/intrinsics03.f90
+++ b/flang/test/Semantics/intrinsics03.f90
@@ -123,3 +123,12 @@ subroutine s4(ix)
call s4(index3)
call s4(index4) ! ok
end
+
+subroutine ichar_tests()
+ integer, parameter :: a1 = ichar('B')
+ !Without -Wportability, the warning isn't emitted and the parameter is constant.
+ integer, parameter :: a2 = ichar('B ')
+ !ERROR: Character in intrinsic function ichar must have length one
+ !ERROR: Must be a constant value
+ integer, parameter :: a3 = ichar('')
+end subroutine
\ No newline at end of file
diff --git a/flang/test/Semantics/intrinsics04.f90 b/flang/test/Semantics/intrinsics04.f90
index a7d646e5c016e..abb8fe321a572 100644
--- a/flang/test/Semantics/intrinsics04.f90
+++ b/flang/test/Semantics/intrinsics04.f90
@@ -1,4 +1,4 @@
-! RUN: %python %S/test_errors.py %s %flang_fc1
+! RUN: %python %S/test_errors.py %s %flang_fc1 -Wportability
! A potentially absent actual argument cannot require data type conversion.
subroutine s(o,a,p)
integer(2), intent(in), optional :: o
@@ -23,3 +23,12 @@ subroutine s(o,a,p)
print *, min(1_2, 2_2, a) ! ok
print *, min(1_2, 2_2, p) ! ok
end
+
+subroutine ichar_tests()
+ integer, parameter :: a1 = ichar('B')
+ !WARNING: Character in intrinsic function ichar should have length one [-Wportability]
+ integer, parameter :: a2 = ichar('B ')
+ !ERROR: Character in intrinsic function ichar must have length one
+ !ERROR: Must be a constant value
+ integer, parameter :: a3 = ichar('')
+end subroutine
|
eugeneepshteyn
approved these changes
Aug 28, 2025
klausler
reviewed
Aug 28, 2025
klausler
approved these changes
Aug 28, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes a bug in folding "ichar" and "iachar" intrinsics introduced here.
There was already a slight bug that the coded didn't fold when portability warnings were enabled which has also been fixed and tested for.