Skip to content

Commit d1fdc32

Browse files
akuhlensgithub-actions[bot]
authored andcommitted
Automerge: [flang][folding] fix i(a)char folding regression (#155909)
Fixes a bug in folding "ichar" and "iachar" intrinsics introduced [here](llvm/llvm-project@c649d31#r164779170). 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.
2 parents d7f4ba4 + c7fd821 commit d1fdc32

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

flang/lib/Evaluate/fold-integer.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,12 +1050,13 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
10501050
context.messages().Say(
10511051
"Character in intrinsic function %s must have length one"_err_en_US,
10521052
name);
1053-
} else if (len.value() > 1) {
1054-
// Do not die, this was not checked before
1055-
context.Warn(common::UsageWarning::Portability,
1056-
"Character in intrinsic function %s should have length one"_port_en_US,
1057-
name);
10581053
} else {
1054+
// Do not die, this was not checked before
1055+
if (len.value() > 1) {
1056+
context.Warn(common::UsageWarning::Portability,
1057+
"Character in intrinsic function %s should have length one"_port_en_US,
1058+
name);
1059+
}
10591060
return common::visit(
10601061
[&funcRef, &context, &FromInt64](const auto &str) -> Expr<T> {
10611062
using Char = typename std::decay_t<decltype(str)>::Result;

flang/test/Semantics/intrinsics03.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,12 @@ subroutine s4(ix)
123123
call s4(index3)
124124
call s4(index4) ! ok
125125
end
126+
127+
subroutine ichar_tests()
128+
integer, parameter :: a1 = ichar('B')
129+
!Without -Wportability, the warning isn't emitted and the parameter is constant.
130+
integer, parameter :: a2 = ichar('B ')
131+
!ERROR: Character in intrinsic function ichar must have length one
132+
!ERROR: Must be a constant value
133+
integer, parameter :: a3 = ichar('')
134+
end subroutine

flang/test/Semantics/intrinsics04.f90

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: %python %S/test_errors.py %s %flang_fc1
1+
! RUN: %python %S/test_errors.py %s %flang_fc1 -Wportability
22
! A potentially absent actual argument cannot require data type conversion.
33
subroutine s(o,a,p)
44
integer(2), intent(in), optional :: o
@@ -23,3 +23,12 @@ subroutine s(o,a,p)
2323
print *, min(1_2, 2_2, a) ! ok
2424
print *, min(1_2, 2_2, p) ! ok
2525
end
26+
27+
subroutine ichar_tests()
28+
integer, parameter :: a1 = ichar('B')
29+
!WARNING: Character in intrinsic function ichar should have length one [-Wportability]
30+
integer, parameter :: a2 = ichar('B ')
31+
!ERROR: Character in intrinsic function ichar must have length one
32+
!ERROR: Must be a constant value
33+
integer, parameter :: a3 = ichar('')
34+
end subroutine

0 commit comments

Comments
 (0)