Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Optional argument confusion when using '-standard-semantics'

Bálint_A_
Beginner
295 Views

Dear all,

It seems to me that ifort 16.0.3 has some difficulties with optional argument passing, when using the -standard-semantics option. The code below demonstrates the issue. The present() query in the subroutine returns false, although the actual argument is an allocated pointer. Changing the dummy argument to be an assumed-shape array cures the problem, the same way as leaving away the -standard-semantics option does it as well.

Bálint

module bugtestmod
  implicit none

contains

  subroutine optarg(array)
    real, intent(in), optional :: array(3,3)

    print *, 'PRESENT?', present(array)

  end subroutine optarg

end module bugtestmod


program bugtest
  use bugtestmod
  implicit none

  real, pointer :: array(:,:)

  allocate(array(3,3))
  array(:,:) = 1.0
  call optarg(array)

end program bugtest

 

0 Kudos
5 Replies
Steven_L_Intel1
Employee
295 Views

Very interesting. I can reproduce this and we'll investigate.

0 Kudos
Steven_L_Intel1
Employee
295 Views

The specific option that triggers the problem is -fpscomp logicals, which is implied by -standard-semantics. It's not PRESENT that is the issue but rather the argument is being passed incorrectly, causing PRESENT to fail (and also the dummy argument to be unusable.) Why -fpscomp logicals should have such an effect, I have no idea, and I have asked the developers to figure it out. Issue ID is DPD200412406.

If you want a workaround, add -fpscomp nologicals.

0 Kudos
Bálint_A_
Beginner
295 Views

Indeed an interesting cross-effect. Dear Steve, thank you for your fast response and workaround suggestion.

Bálint

0 Kudos
Steven_L_Intel1
Employee
295 Views

This problem has been fixed. I think the fix will be in the 17.0 product release.

0 Kudos
Steven_L_Intel1
Employee
295 Views

The fix should also appear in 16.0.4.

0 Kudos
Reply