[flang][semantics] fix IsConstantExpr for intrinsic with optional argument (#161915)
fixes https://github.com/llvm/llvm-project/issues/161694 Exposes that some sequences of duplicate messages are being printed, which is fixed in https://github.com/llvm/llvm-project/pull/161916 .
This commit is contained in:
parent
ad7334b067
commit
823094e407
4 changed files with 29 additions and 8 deletions
|
|
@ -135,16 +135,22 @@ bool IsConstantExprHelper<INVARIANT>::operator()(
|
|||
} else if (proc.IsPure()) {
|
||||
std::size_t j{0};
|
||||
for (const auto &arg : call.arguments()) {
|
||||
if (const auto *dataDummy{j < proc.dummyArguments.size()
|
||||
? std::get_if<characteristics::DummyDataObject>(
|
||||
&proc.dummyArguments[j].u)
|
||||
: nullptr};
|
||||
dataDummy &&
|
||||
const auto *dataDummy{j < proc.dummyArguments.size()
|
||||
? std::get_if<characteristics::DummyDataObject>(
|
||||
&proc.dummyArguments[j].u)
|
||||
: nullptr};
|
||||
if (dataDummy &&
|
||||
dataDummy->attrs.test(
|
||||
characteristics::DummyDataObject::Attr::OnlyIntrinsicInquiry)) {
|
||||
// The value of the argument doesn't matter
|
||||
} else if (!arg) {
|
||||
return false;
|
||||
if (dataDummy &&
|
||||
dataDummy->attrs.test(
|
||||
characteristics::DummyDataObject::Attr::Optional)) {
|
||||
// Missing optional arguments are okay.
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (const auto *expr{arg->UnwrapExpr()};
|
||||
!expr || !(*this)(*expr)) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -129,6 +129,6 @@ subroutine ichar_tests()
|
|||
!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
|
||||
!ERROR: Value of named constant 'a3' (ichar("")) cannot be computed as a constant value
|
||||
integer, parameter :: a3 = ichar('')
|
||||
end subroutine
|
||||
|
|
|
|||
|
|
@ -29,6 +29,6 @@ subroutine ichar_tests()
|
|||
!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
|
||||
!ERROR: Value of named constant 'a3' (ichar("")) cannot be computed as a constant value
|
||||
integer, parameter :: a3 = ichar('')
|
||||
end subroutine
|
||||
|
|
|
|||
15
flang/test/Semantics/type-parameter-constant.f90
Normal file
15
flang/test/Semantics/type-parameter-constant.f90
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
! RUN: %python %S/test_errors.py %s %flang_fc1
|
||||
type A (p, r)
|
||||
integer, kind :: p, r
|
||||
!ERROR: KIND parameter expression (int(selected_real_kind(six,twenty_three),kind=8)) of intrinsic type REAL did not resolve to a constant value
|
||||
real (selected_real_kind(p, r)) :: data
|
||||
end type
|
||||
integer :: six = 6, twenty_three = 23
|
||||
type(a(6,23)) :: a1
|
||||
!ERROR: Value of KIND type parameter 'p' must be constant
|
||||
!ERROR: Value of KIND type parameter 'r' must be constant
|
||||
!WARNING: specification expression refers to local object 'six' (initialized and saved) [-Wsaved-local-in-spec-expr]
|
||||
!WARNING: specification expression refers to local object 'twenty_three' (initialized and saved) [-Wsaved-local-in-spec-expr]
|
||||
type(a(six, twenty_three)) :: a2
|
||||
print *, a1%data%kind
|
||||
end
|
||||
Loading…
Reference in a new issue