Skip to content

Commit f5e4451

Browse files
committed
[flang] Fix interpretation of intrinsic names as arguments
If an unrestricted specific intrinsic function name is first encountered as an actual argument, it should be interpreted as an object entity, not a procedure entity. Fix some tests that depended on the previous interpretation by adding explicit INTRINSIC statements. Differential Revision: https://reviews.llvm.org/D85792
1 parent c6f5137 commit f5e4451

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,6 @@ class ResolveNamesVisitor : public virtual ScopeHandler,
12901290
ResolveName(*parser::Unwrap<parser::Name>(x.name));
12911291
}
12921292
void Post(const parser::ProcComponentRef &);
1293-
bool Pre(const parser::ActualArg &);
12941293
bool Pre(const parser::FunctionReference &);
12951294
bool Pre(const parser::CallStmt &);
12961295
bool Pre(const parser::ImportStmt &);
@@ -5317,23 +5316,6 @@ const DeclTypeSpec &ConstructVisitor::ToDeclTypeSpec(
53175316

53185317
// ResolveNamesVisitor implementation
53195318

5320-
// Ensures that bare undeclared intrinsic procedure names passed as actual
5321-
// arguments get recognized as being intrinsics.
5322-
bool ResolveNamesVisitor::Pre(const parser::ActualArg &arg) {
5323-
if (const auto *expr{std::get_if<Indirection<parser::Expr>>(&arg.u)}) {
5324-
if (const auto *designator{
5325-
std::get_if<Indirection<parser::Designator>>(&expr->value().u)}) {
5326-
if (const auto *dataRef{
5327-
std::get_if<parser::DataRef>(&designator->value().u)}) {
5328-
if (const auto *name{std::get_if<parser::Name>(&dataRef->u)}) {
5329-
NameIsKnownOrIntrinsic(*name);
5330-
}
5331-
}
5332-
}
5333-
}
5334-
return true;
5335-
}
5336-
53375319
bool ResolveNamesVisitor::Pre(const parser::FunctionReference &x) {
53385320
HandleCall(Symbol::Flag::Function, x.v);
53395321
return false;

flang/test/Semantics/call02.f90

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ subroutine badsubr(dummy)
1515
procedure(elem) :: dummy
1616
end subroutine
1717
end interface
18+
intrinsic :: cos
1819
call subr(cos) ! not an error
1920
!ERROR: Non-intrinsic ELEMENTAL procedure 'elem' may not be passed as an actual argument
2021
call subr(elem) ! C1533
@@ -35,6 +36,7 @@ elemental real function elem03(x)
3536
real, value :: x
3637
end function
3738
subroutine test
39+
intrinsic :: cos
3840
call callme(cos) ! not an error
3941
!ERROR: Non-intrinsic ELEMENTAL procedure 'elem01' may not be passed as an actual argument
4042
call callme(elem01) ! C1533
@@ -65,3 +67,25 @@ subroutine test
6567
call callee(coarray[1]) ! C1537
6668
end subroutine
6769
end module
70+
71+
program p03
72+
logical :: l
73+
call s1(index)
74+
l = index .eq. 0 ! index is an object entity, not an intrinsic
75+
call s2(sin)
76+
!ERROR: Actual argument associated with procedure dummy argument 'p=' is not a procedure
77+
call s3(cos)
78+
contains
79+
subroutine s2(x)
80+
real :: x
81+
end
82+
subroutine s3(p)
83+
procedure(real) :: p
84+
end
85+
end
86+
87+
program p04
88+
implicit none
89+
!ERROR: No explicit type declared for 'index'
90+
call s1(index)
91+
end

flang/test/Semantics/call09.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function intprocptr()
4343
end function
4444

4545
subroutine test1 ! 15.5.2.9(5)
46+
intrinsic :: sin
4647
procedure(realfunc), pointer :: p
4748
procedure(intfunc), pointer :: ip
4849
p => realfunc

0 commit comments

Comments
 (0)