This is an archive of the discontinued LLVM Phabricator instance.

[flang] Add one semantic check for implicit interface
ClosedPublic

Authored by peixin on Apr 25 2022, 4:38 AM.

Details

Summary

As Fortran 2018 C1533, a nonintrinsic elemental procedure shall not be
used as an actual argument. The semantic check for implicit iterface is
missed.

Diff Detail

Event Timeline

peixin created this revision.Apr 25 2022, 4:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 4:38 AM
Herald added a subscriber: jdoerfert. · View Herald Transcript
peixin requested review of this revision.Apr 25 2022, 4:38 AM

Without this patch, the result is as follows:

$ cat sub.f90 
subroutine sub(f)
  integer, external :: f
  print *, f()
end
$ flang-new sub.f90 -c
$ cat main.f90 
program m
  call sub(func)
contains
  elemental integer function func()
    func = 1
  end function
end
$ flang-new main.f90 -c
$ cat test.f90 
program m
  call sub(func)
contains
  elemental integer function func()
    func = 1
  end function
end
subroutine sub(f)
  integer, external :: f
  print *, f()
end
$ flang-new test.f90 -c
./test.f90:2:3: warning: If the procedure's interface were explicit, this reference would be in error:
    call sub(func)
    ^^^^^^^^^^^^^^
./test.f90:2:12: because: Non-intrinsic ELEMENTAL procedure 'func' may not be passed as an actual argument
    call sub(func)
             ^^^^
./test.f90:4:30: Declaration of 'func'
    elemental integer function func()
                               ^^^^
klausler added inline comments.Apr 25 2022, 8:38 AM
flang/lib/Semantics/check-call.cpp
84

It would be more clear if you either (1) combined the two if() statement predicates into one, or (2) moved the declaration of argProcSymbol into the predicate of the inner if() statement.

peixin updated this revision to Diff 425088.Apr 25 2022, 6:20 PM

Combine the two if statement predicates into one.

peixin updated this revision to Diff 425092.Apr 25 2022, 6:34 PM

Fix the clang format using the new built clang-format. I used one old version causing the format issue previously.

klausler accepted this revision.Apr 29 2022, 7:29 AM
This revision is now accepted and ready to land.Apr 29 2022, 7:29 AM
This revision was automatically updated to reflect the committed changes.