Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions flang/lib/Evaluate/fold-integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions flang/test/Semantics/intrinsics03.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion flang/test/Semantics/intrinsics04.f90
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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