Issues with clang-UBSAN

Hi!

I am having trouble updating my OncoBayes2 package on CRAN as CRAN complains about clang-UBSAN issues and I am lost right now. To me it looks as if I am using some feature of Stan which has an issue in the used 2.19 RStan release.

From the error output from CRAN here https://www.stats.ox.ac.uk/pub/bdr/memtests/clang-UBSAN/OncoBayes2/

you can see this strange error message in tests/testthat.Rout which I don’t quite follow as to what my Stan program is triggering here, see below.

If anyone - maybe @bgoodri - has an idea as to where to look, then that would be great. It sounds to me as if I would have to bachport some fix for Stan to 2.19 eventually.

Log file:

/data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/Block.h:347:25: runtime error: applying non-zero offset 8 to null pointer
    #0 0x7f4015b93b11 in Eigen::internal::BlockImpl_dense<Eigen::Matrix<double, -1, -1, 0, -1, -1> const, 1, -1, false, true>::BlockImpl_dense(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, long) /data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/Block.h:347:25
    #1 0x7f4015b93689 in Eigen::BlockImpl<Eigen::Matrix<double, -1, -1, 0, -1, -1> const, 1, -1, false, Eigen::Dense>::BlockImpl(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, long) /data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/Block.h:162:65
    #2 0x7f4015b93689 in Eigen::Block<Eigen::Matrix<double, -1, -1, 0, -1, -1> const, 1, -1, false>::Block(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, long) /data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/Block.h:118:43
    #3 0x7f4015b93689 in Eigen::DenseBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >::row(long) const /data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/SparseCore/../plugins/BlockMethods.h:868:10
    #4 0x7f4015b6a4c2 in boost::disable_if<boost::is_same<stan::model::index_multi, stan::model::index_uni>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >::type stan::model::rvalue<double, stan::model::index_multi>(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, stan::model::cons_index_list<stan::model::index_multi, stan::model::nil_index_list> const&, char const*, int) /data/gannet/ripley/R/test-clang/StanHeaders/include/src/stan/model/indexing/rvalue.hpp:194:22
    #5 0x7f4015b4c2e3 in double model_blrm_exnex_namespace::model_blrm_exnex::log_prob<false, true, double>(std::__1::vector<double, std::__1::allocator<double> >&, std::__1::vector<int, std::__1::allocator<int> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*) const /data/gannet/ripley/R/packages/tests-clang-SAN/OncoBayes2/src/./stanExports_blrm_exnex.h:3572:682
    #6 0x7f4015b2ecb4 in std::__1::vector<double, std::__1::allocator<double> > stan::services::util::initialize<true, model_blrm_exnex_namespace::model_blrm_exnex, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >(model_blrm_exnex_namespace::model_blrm_exnex&, stan::io::var_context&, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> >&, double, bool, stan::callbacks::logger&, stan::callbacks::writer&) /data/gannet/ripley/R/test-clang/StanHeaders/include/src/stan/services/util/initialize.hpp:132:33
    #7 0x7f4015d478f9 in int stan::services::sample::hmc_nuts_diag_e_adapt<model_blrm_exnex_namespace::model_blrm_exnex>(model_blrm_exnex_namespace::model_blrm_exnex&, stan::io::var_context&, stan::io::var_context&, unsigned int, unsigned int, double, int, int, int, bool, int, double, double, int, double, double, double, double, unsigned int, unsigned int, unsigned int, stan::callbacks::interrupt&, stan::callbacks::logger&, stan::callbacks::writer&, stan::callbacks::writer&, stan::callbacks::writer&) /data/gannet/ripley/R/test-clang/StanHeaders/include/src/stan/services/sample/hmc_nuts_diag_e_adapt.hpp:76:13
    #8 0x7f4015b0da08 in int stan::services::sample::hmc_nuts_diag_e_adapt<model_blrm_exnex_namespace::model_blrm_exnex>(model_blrm_exnex_namespace::model_blrm_exnex&, stan::io::var_context&, unsigned int, unsigned int, double, int, int, int, bool, int, double, double, int, double, double, double, double, unsigned int, unsigned int, unsigned int, stan::callbacks::interrupt&, stan::callbacks::logger&, stan::callbacks::writer&, stan::callbacks::writer&, stan::callbacks::writer&) /data/gannet/ripley/R/test-clang/StanHeaders/include/src/stan/services/sample/hmc_nuts_diag_e_adapt.hpp:164:16
    #9 0x7f40159bb285 in int rstan::(anonymous namespace)::command<model_blrm_exnex_namespace::model_blrm_exnex, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >(rstan::stan_args&, model_blrm_exnex_namespace::model_blrm_exnex&, Rcpp::Vector<19, Rcpp::PreserveStorage>&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> >&) /data/gannet/ripley/R/test-clang/rstan/include/rstan/stan_fit.hpp:653:25
    #10 0x7f40159cbc50 in rstan::stan_fit<model_blrm_exnex_namespace::model_blrm_exnex, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >::call_sampler(SEXPREC*) /data/gannet/ripley/R/test-clang/rstan/include/rstan/stan_fit.hpp:1201:11
    #11 0x7f4015db1136 in Rcpp::CppMethod1<rstan::stan_fit<model_blrm_exnex_namespace::model_blrm_exnex, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >, SEXPREC*, SEXPREC*>::operator()(rstan::stan_fit<model_blrm_exnex_namespace::model_blrm_exnex, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >*, SEXPREC**) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/module/Module_generated_CppMethod.h:111:55
    #12 0x7f4015a4d49a in Rcpp::class_<rstan::stan_fit<model_blrm_exnex_namespace::model_blrm_exnex, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > > >::invoke_notvoid(SEXPREC*, SEXPREC*, SEXPREC**, int) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/module/class.h:234:23
    #13 0x7f40187d3489 in CppMethod__invoke_notvoid(SEXPREC*) /tmp/RtmpjzdNeY/R.INSTALL8afa7606c1f3/Rcpp/src/module.cpp:220:19
    #14 0x6d146e in do_External /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c:576:11
    #15 0x8209e8 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:791:9
    #16 0x893aa2 in do_begin /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:2471:10
    #17 0x8203fc in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:763:12

Are you / we using headers from SparseCore (on purpose)?

No, I am not.

I have no idea what this is and if this is something which I “ordered” or where this is coming from nor how to avoid it.

In short: What do you suggest to do about to make it go away? Or where can I follow this up?

I don’t know yet, but I am working on it. I don’t see that issue with rstanarm, RBesT, etc. so it presumably has something to do with the specific Stan / C++ code in OncoBayes2 that is triggering it.

Thanks for looking into it. Yes, I agree with you than I am apprently hitting some Stan feature which is buggy. I also checked a few random other packages which use rstan and they all seemed fine. So its some specific feature with the bug is what I also speculate (though it’s really nothing special to my knowledge).

Maybe the fastet solution here is to use this sanitizer with cmdstan?

1 Like

Big thread bump here, but I’m facing the same thing on CRAN with my LMMELSM package. LMMELSM has been on CRAN for a little over a year with no changes, then they sent me a notice about the clang-UBSAN error. I checkpointed the latest version of lmmelsm from github, then updated the rstantools configuration for it, just in case that was the issue.

But it’s still failing on CRAN:

Thanks, we see with clang_UBSAN still

LMMELSM.Rcheck/tests/testthat.Rout:/data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/Block.h:347:25: runtime error: applying non-zero offset 400 to null pointer
LMMELSM.Rcheck/tests/testthat.Rout:/data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/Block.h:347:25: runtime error: applying non-zero offset 8 to null pointer
LMMELSM.Rcheck/tests/testthat.Rout:/data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/Block.h:374:24: runtime error: applying non-zero offset 8 to null pointer
LMMELSM.Rcheck/tests/testthat.Rout:/data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/Block.h:374:81: runtime error: subtraction of unsigned offset from 0x000000000008 overflowed to 0x000000000008
LMMELSM.Rcheck/tests/testthat.Rout:/data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/Block.h:374:24: runtime error: applying non-zero offset 8 to null pointer
LMMELSM.Rcheck/tests/testthat.Rout:/data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/Block.h:374:81: runtime error: subtraction of unsigned offset from 0x000000000008 overflowed to 0x000000000008
Please fix and resubmit. 

it’s about some fancy indexing things which cause the problem here… that’s what I guess at least. Hopefully we get rstan 2.26 on CRAN which may solve these issues (but do not wait for that)!