[Rd] Optimization bug when byte compiling with gcc 5.2.0 on windows

Jeroen Ooms jeroen.ooms at stat.ucla.edu
Mon Sep 14 14:49:27 CEST 2015

When building R-devel with gcc 5.2.0 (mingw-w64 v4) on Windows, make
check fails reg-tests-1b.R at the following check:

  x <- c(1:2, NA)
  sx <- sd(x)

Here 'sx' should be 'NA' but it is 'NaN'. It turns out this problem
only appears when the function is byte compiled with optimization
level 3:

  mysd <- function (x, na.rm = FALSE)
    sqrt(var(if (is.vector(x)) x else as.double(x), na.rm = na.rm))

  # [1] NA
  compiler::cmpfun(mysd, list(optimize = 1L))(x)
  # [1] NA
  compiler::cmpfun(mysd, list(optimize = 2L))(x)
  # [1] NA
  compiler::cmpfun(mysd, list(optimize = 3L))(x)
  # [1] NaN

The problem does not appear with gcc 5.2.0 on Debian, and also not
with gcc 4.9.3 on Windows. Where do I start debugging this? The
disassembled output from the compiled functions is here:

More information about the R-devel mailing list