[R-pkg-devel] -fbounds-check on develop version of Win-builder

Benjamin Christoffersen boennecd at gmail.com
Fri Jun 9 14:44:05 CEST 2017


Dear sirs

I am writing regarding a question for the package dynamichazard which
I am the author of and the -fbounds-check flag used in R develop in
Win-Builder.

R develop version has following flags added to the Fortran rule
compared with R release on Win-builder: -pedantic -fbounds-check

Particularly, the line for dchur.o when building dynamichazard on the
release version is:
d:/Compiler/gcc-4.9.3/mingw_32/bin/gfortran -O3 -mtune=core2 -c
dchur.f -o dchur.o

and the line on the develop version is:
d:/Compiler/gcc-4.9.3/mingw_32/bin/gfortran -pedantic -fbounds-check
-O3 -mtune=core2 -c dchur.f -o dchur.o

The latter causes the following error when the tests on the package is run:
  At line 1 of file dchur.f
  Fortran runtime error: Actual string length is shorter than the
declared one for dummy argument 'uplo' (0/1)

The version of dynamichazard I submitted to the Win-Builder is at:
https://github.com/boennecd/dynamichazard/tree/d3a8b7d5f39fbfcc14df008f1fdd71f4f38ac25a

The relevant code in dynamichazard/src/LAPACK_BLAS_wrapper.cpp is:
#include <Rcpp.h>
#include <R_ext/BLAS.h>
#include <R_ext/Lapack.h>

extern "C"
{
  void F77_NAME(dchur)(
      const char *,   // UPLO
      const char *,   // TRANS
      int*,    // N
      int*,    // M
      double*, // R
      int*,    // LDR
      double*, // X
      double*, // Z
      int*,    // LDZ
      double*, // Y
      double*, // RHO
      double*, // C
      double*, // S
      int*     // INFO
  );
}

void ddhazard_dchur(double *R, double *x, int n, int ldr){
  int info;

  double *c = new double[n];
  double *s = new double[n];

  int m = 0;
  int ldz = 1;
  double z, y, rho;

  F77_CALL(dchur)(
      "L",
      "N",
      &n, &m, R, &ldr,
      x, &z, &ldz, &y, &rho, c, s, &info);

  // code abbreviated
};

// code abbreviated

I have tried to re-produce the error with R release on my own laptop
running Windows but failed to do so. Here is an example:
$ ./tmp.sh
+ cat foo.cpp
#include <iostream>

extern "C" {
        void bar_(const char *in);
}

int main()
{
    std::cout << "Running main" << std::endl;
    bar_("F");
    return 0;
}
+ cat bar.f
      subroutine bar(INPUT)
      CHARACTER INPUT

      print *, input
      end
+ c:/Rtools/mingw_32/bin/g++ -std=gnu++11 -O2 -Wall -mtune=core2 -c
foo.cpp -o foo.o
+ c:/Rtools/mingw_32/bin/gfortran -pedantic -fbounds-check -O3 -c bar.f -o bar.o
+ c:/Rtools/mingw_32/bin/g++ -o foo foo.o bar.o -lgfortran -lm -lquadmath
+ ./foo.exe
Running main
 F
+ Rscript.exe -e R.version
               _
platform       x86_64-w64-mingw32
arch           x86_64
os             mingw32
system         x86_64, mingw32
status
major          3
minor          4.0
year           2017
month          04
day            21
svn rev        72570
language       R
version.string R version 3.4.0 (2017-04-21)
nickname       You Stupid Darkness
+ head -1 c:/Rtools/Rtools.txt
                      Rtools Collection 3.4.0.1962

The example is not with a dynamic link library but comparable to the
example here: https://code.launchpad.net/~fluidity-core/fluidity/gmsh-on-sphere/+merge/99395/comments/216834

I stupidly tried to solve the problem in the current version 0.3.1 of
dynamichazard on CRAN by adding this rule in Makevars.win:
dchur.o:
$(F77) $(filter-out -fbounds-check,$(ALL_FFLAGS)) -c dchur.f -o dchur.o

This makes all my tests pass including those that uses the
ddhazard_dchur C++ function on the develop version of Win-builder.
However, it violates the second paragraph of "1.2.1 Using Makevars" in
"Writing R Extensions".

Please, let me know if I have made an obvious mistake or if there is a
straightforward solution.

Sincerely yours
Benjamin Christoffersen



More information about the R-package-devel mailing list