kalibera / rchk

102 stars 10 forks source link

Possible Spurious "unprotected" Error #8

Closed brodieG closed 6 years ago

brodieG commented 6 years ago

I'm not 100% certain this is a spurious error, but I'm guessing it is. In:

SEXP TEST_test_fun(SEXP x) {
  if(TYPEOF(x) != STRSXP) error("Internal Error: type mismatch");

  SEXP x_prev = STRING_ELT(x, 0);
  SEXP x_cur = STRING_ELT(x, 1);
  const char * prev = CHAR(x_prev);

  return x;
}

I get:

ERROR: too many states (abstraction error?) in function RunGenCollect
ERROR: too many states (abstraction error?) in function tre_tnfa_run_backtrack
ERROR: too many states (abstraction error?) in function tre_tnfa_run_parallel

Function TEST_test_fun
  [UP] unprotected variable x_prev while calling allocating function STRING_ELT /vagrant/test/src/test.c:7
Analyzed 2 functions, traversed 10 states.

presumably because it is not recognized x_prev is pointing to a CHARSXP that is protected by virtue of being a member of the input to the function (in my case x is provided via .Call).

This is a simplified example. In my actual use case I'm keeping track of the previous CHARSXP in a loop.

I'm not sure it's worth the trouble to fix this, but figured having the info could still be useful to you. Of course, there is the possibility I'm wrong about this.

Sample package on github

joshuaulrich commented 6 years ago

I believe this is caused by the ALTREP functionality now in R-devel. One of the impacts of ALTREP is that some functions that previously did not allocate do now. STRING_ELT() is one such function.

kalibera commented 6 years ago

Yes, it will probably work with the trunk of rchk which has been updated for ALTREP, but the image uses an older version. I am now updating the image.

kalibera commented 6 years ago

I've updated rchk image, now it uses LLVM4.0 and the (now) most recent version of rchk. Your example package seems to be working (STRING_ELT does not allocate, so no error is reported).