R-bitops-1.0.5 is FTBS on ARM. 1.0.4 previously built fine. It fails on F-18/19/rawhide Error is: * checking compiled code ... OK * checking examples ... ERROR Running examples in 'bitops-Ex.R' failed The error most likely occurred in: > ### Name: bitFlip > ### Title: Binary Flip (Not) Operator > ### Aliases: bitFlip > ### Keywords: arith utilities > > ### ** Examples > > stopifnot( + bitFlip(-1) == 0, + bitFlip(0 ) == 4294967295, + bitFlip(0, bitWidth=8) == 255 + ) Error: bitFlip(-1) == 0 is not TRUE Execution halted Full logs can be found here: http://arm.koji.fedoraproject.org/koji/packageinfo?packageID=184
Any update? This is blocking a number of other R packages on ARM that all previously built fine
1.0.4.1 has the same bug, just not triggered by the less strict test. bitflip(-1) should be 0, but on arm, it is 4294967295. Something in this function is not correct on ARM: SEXP bitFlip(SEXP a, SEXP bitWidth ) { int i, n, *xbitWidth; unsigned int mask ; unsigned int tmp ; double *xa, *xaflip ; SEXP aflip ; PROTECT (a = AS_NUMERIC(a) ) ; PROTECT (bitWidth = AS_INTEGER(bitWidth) ) ; n=LENGTH(a) ; PROTECT (aflip = NEW_NUMERIC(n) ) ; xa=NUMERIC_POINTER(a) ; xaflip=NUMERIC_POINTER(aflip) ; xbitWidth=INTEGER_POINTER(bitWidth) ; mask = ( unsigned int ) -1 >> (32 - *xbitWidth) ; for (i=0; i<n; i++ ) { if ( !R_FINITE(xa[i]) || logb(xa[i])>31 ) xaflip[i]=NA_REAL ; else { tmp=(unsigned int) xa[i] ; xaflip[i]=(double) ( ~tmp & mask ) ; } } UNPROTECT(3) ; return (aflip) ; }
This is the bug: tmp=(unsigned int) xa[i] ; Casting double to unsigned is undefined if the value is negative. Use this instead: tmp=xa[i] < 0 ? (int) xa[i] : (unsigned) xa[i]; Here's a small reproducer if you want to play with it: #include <stdio.h> int main(int argc, char **argv) { double v = 0.0; sscanf(argv[1], "%lf", &v); unsigned i = (int) v; printf("int = %08x\n", i); unsigned u = (unsigned) v; printf("unsigned = %08x\n", u); return 0; } [root@calxeda-arm-soc-02 ~]# ./a.out -1 int = ffffffff unsigned = 00000000
Thanks Florian! Fixed in R-bitops-1.0.5-3.fc20. Patch sent to upstream.