[R-pkg-devel] Warnings related to functions from the survival package

Ivan Krylov |kry|ov @end|ng |rom d|@root@org
Thu Oct 31 17:39:14 CET 2024


В Thu, 31 Oct 2024 12:06:25 -0400
Kaifeng Lu <kaifenglu using gmail.com> пишет:

>   /home/hornik/src/R/src/main/dotcode.c:1978:2: runtime error: call to
> function coxph_wtest through pointer to incorrect function type 'void
> (*)(void *, void *, void *, void *, void *, void *)'
>   /home/hornik/src/R/src/main/dotcode.c:1994:2: runtime error: call to
> function agsurv5 through pointer to incorrect function type 'void
> (*)(void *, void *, void *, void *, void *, void *, void *, void *,
> void *, void *)' /home/hornik/src/R/src/main/dotcode.c:2008:2:
> runtime error: call to function survdiff2 through pointer to
> incorrect function type 'void (*)(void *, void *, void *, void *,
> void *, void *, void *, void *, void *, void *, void *, void *, void
> *)' /home/hornik/src/R/src/main/dotcode.c:1986:2: runtime error: call
> to function coxmart through pointer to incorrect function type 'void
> (*)(void *, void *, void *, void *, void *, void *, void *, void *)'

This is something R does to call all .C() / .Fortran() functions. For
example, coxph_wtest actually takes int*, int*, double*, double*,
double*, double *, but R assumes that the calling convention is the
same as if it took 6 times void* and calls it through a pointer of a
different type [1]. In practice it works well, but formally, calling a
function through a pointer of a different type is undefined behaviour.
Unfortunately, there is no easy way to call arbitrary functions, like
.C() and .Fortran() do, without either breaking some rules (which
happens here) or generating function calls at runtime (like some
foreign function interfaces do, which is less portable).

This check may need suppressions for src/main/dotcode.c or special
attributes [2] on R's do_dotCode.

-- 
Best regards,
Ivan

[1]
https://github.com/r-devel/r-svn/blob/91a84c048a26b2b776603482545e4678625a54c3/src/main/dotcode.c#L1977-L1979

[2]
https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#issue-suppression



More information about the R-package-devel mailing list