Skip to content

[R-pkg-devel] warning: type of ‘zhpevx_’ does not match original declaration [-Wlto-type-mismatch]

2 messages · Pierre Lafaye de Micheaux, Tomas Kalibera

#
Dear Tomas,

Apologies for the very long delay.

I was able to create a minimal version of the package (attached) that gives the same exact warnings:

myzhpevx.cpp:22:16: warning: type of ?zhpevx_? does not match original declaration [-Wlto-type-mismatch]
           void F77_NAME(zhpevx)(char *jobz, char *range, char *uplo,
                ^
zhpevx.f:232:14: note: type mismatch in parameter 20
       SUBROUTINE zhpevx(JOBZ, RANGE, UPLO, N, AP, VL, VU, IL, IU,
              ^
zhpevx.f:232:14: note: type ?long int? should match type ?size_t?
zhpevx.f:232:14: note: ?zhpevx? was previously declared here
zhpevx.f:232:14: note: code may be misoptimized unless -fno-strict-aliasing is used

I am under the impression that I am following quite closely what is written here: https://cran.csiro.au/doc/manuals/r-patched/R-exts.html#Fortran-character-strings

I tried many different things but I always end up with the same main warning (i.e., type of ?zhpevx_? does not match original declaration ).

My version of fortran: GNU Fortran (Debian 8.3.0-6) 8.3.0 under Debian 10.

Thank you very much for any further help you could provide so that I could have my package back to the CRAN.

Kind regards,
Pierre L.
#
Dear Pierre,

your code checks fine on my Ubuntu 20.04 (gcc/gfortran 9.3), but I can 
reproduce what you are seeing on Debian 10 with gcc 8.3.

There seem to be two problems.

The first one is that the hidden character length arguments are signed, 
they are of type "long int" (not "size_t"). This is compiler specific 
and can (and does) change between Fortran compiler versions and I think 
you can just ignore it. R assumes the type is "size_t", which happens to 
be correct for newer compilers. The signedness mismatch in this case is 
benign. FC_LEN_T is defined in R, so if anywhere, this would have to be 
fixed in R, but we cannot realistically know what the type is for each 
compiler.

The second problem is that gcc/LTO is complaining about incompatibility 
between Rcomplex and "COMPLEX*16" types. This was rather tedious to 
find, I had to minimize the example for that a bit more (remove the 
Fortran code, just left the subroutine taking the same args, and then 
removing the args one by one - this is what I meant by minimizing the 
example). I don't know why the mismatch is reported. Gcc 9.3 is happy.

I would recommend to use a newer compiler, at least for these checks. 
The warnings have improved (become more informative), you can use 
-fc-prototypes-external to see what the types should be exactly for your 
compiler, and perhaps some of the warnings were false positives and have 
been fixed since.

If you want to stick to the FC_LEN_T and similar macros, I would 
recommend to check how R does it so that the code compiles also when the 
extra hidden length arguments are not used by the compiler. Still, a 
portable way to solve these issues would be via iso_c_binding, with 
FC_LEN_T we are relying on undocumented/not-standardized behavior of the 
compiler.

Best,
Tomas
On 12/15/20 7:56 AM, Pierre Lafaye de Micheaux wrote: