- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I stumbled onto a bug on the Intel Fortran compilers, starting with ifort versions 2021.6.0+ and ifx 2022.1.0+. I am receiving error messages during compilation, specifically `error #8284` about argument mismatch with an interface, which I suspect is erroneous.
MWE
program main
use iso_c_binding
call foo("Fortran Arg")
contains
function istring_(o) result(v)
character(len=*), intent(in) :: o
character(len=:, kind=c_char), allocatable :: v
v = trim(o)//c_null_char
end function istring_
subroutine foo(fileName)
interface
subroutine C_API(fileName) bind(C, name="foo")
use, intrinsic :: iso_c_binding
character(len=1, kind=c_char), dimension(*), intent(in) :: fileName
end subroutine C_API
end interface
character(len=*), intent(in) :: fileName
call C_API(fileName=istring_(fileName))
end subroutine foo
end program main
#include "stdio.h"
void foo(const char* fileName) { printf("%s\n", fileName); }
Output
/app/example.f90(21): error #8284: If the actual argument is scalar, the dummy argument shall be scalar unless the actual argument is of type character or is an element of an array that is not assumed shape, pointer, or polymorphic. [FILENAME]
call C_API(fileName=istring_(fileName))
---------^
Fix
Replacing the `istring_` call in the interface with a local variable compiles which seems to indicate to me that this is a potential bug/regression.
--- tmp.f90 2023-01-05 10:19:30.778230819 +0000
+++ tmp2.f90 2023-01-05 10:19:36.342418329 +0000
@@ -18,6 +18,8 @@
end subroutine C_API
end interface
character(len=*), intent(in) :: fileName
- call C_API(fileName=istring_(fileName))
+ character(len=:), allocatable :: fileNameC
+ fileNameC = istring_(fileName)
+ call C_API(fileName=fileNameC)
end subroutine foo
end program main
Additional Info
GFortran, Intel's older versions compilers and flang-trunk all can compile the MWE.
The original description Stack Overflow post can be found here, https://stackoverflow.com/questions/75017185/intel-fortran-error-8284-for-character-type-arguments
cc @Ron_Green
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@gnikit ,
I reckon Intel Fortran compiler is in the wrong in issuing the error and that it is getting confused with the function result characteristics per the standard. I also think you can greatly reduce your example and use something the following to make the case:
use iso_c_binding, only : c_char
interface
subroutine sub(s) bind(C)
import :: c_char
character(kind=c_char,len=1), intent(in) :: s(*)
end subroutine
end interface
character(kind=c_char, len=0) :: s
call sub( s=s ) !<-- A
call sub( s=fs() ) !<-- B, and it is equivalent to A
contains
function fs() result(r)
character(kind=c_char, len=:), allocatable :: r
r = c_char_""
end function
end
Give this a try and check how the compiler responds with the statement labeled as B. It is equivalent to A in terms of characteristics. I presume the compiler doesn't raise an error with A and it shouldn't with B either. What does gfortran (or NAG if you have it) do with this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I agree that the error is inappropriate and note that NAG Fortran does not complain. The function result is just a scalar character value at the point of use.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will get a bug report open, and use both testcases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bug ID CMPLRLLVM-43333
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
this bug is fixed in the 2024.0 release.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page