stan-dev / cmdstan

CmdStan, the command line interface to Stan
https://mc-stan.org/users/interfaces/cmdstan
BSD 3-Clause "New" or "Revised" License
210 stars 93 forks source link

bernoulli example fails to run on latest release #1238

Closed iyanmv closed 7 months ago

iyanmv commented 7 months ago

Summary:

Provided example (bernoulli) fails to run on latest release

Description:

I'm trying to package Stan (together with cmdstan) to Arch Linux. I followed the building instructions using the tarball from the latest release. There are no issues while generating the binaries (stanc, stansummary and diagnose) but then trying to run the example from the docs: 1.3 Checking the Stan compiler, I get the following error:

--- Linking model ---
g++ -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security         -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -g -ffile-prefix-map=/build/cmdstan/src=/usr/src/debug/cmdstan -flto=auto -std=c++1y -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.81.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials    -DBOOST_DISABLE_ASSERTS         -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -flto=auto       -Wl,-L,"/build/cmdstan/src/cmdstan-2.34.0/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/build/cmdstan/src/cmdstan-2.34.0/stan/lib/stan_math/lib/tbb"        examples/bernoulli/bernoulli.o src/cmdstan/main.o       -ltbb   stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_cvodes.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_idas.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_kinsol.a  stan/lib/stan_math/lib/tbb/libtbb.so.2 -o examples/bernoulli/bernoulli
rm examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp
/usr/include/c++/13.2.1/bits/basic_string.h:1226: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::const_reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; const_reference = const char&; size_type = long unsigned int]: Assertion '__pos <= size()' failed.
/startdir/PKGBUILD: line 21:  1592 Aborted                 (core dumped) ./examples/bernoulli/bernoulli sample data file=examples/bernoulli/bernoulli.data.json

Reproducible Steps:

I'm writing a PKGBUILD for Arch Linux, but here are the relevant steps:

  1. curl -OL https://github.com/stan-dev/cmdstan/releases/download/v2.34.0/cmdstan-2.34.0.tar.gz
  2. tar -xf cmdstan-2.34.0.tar.gz
  3. cd cmdstan-2.34.0
  4. make -j$(nproc) build
  5. make -j$(nproc) examples/bernoulli/bernoulli
  6. ./examples/bernoulli/bernoulli sample data file=examples/bernoulli/bernoulli.data.json

At this point I get the error from above.

Additional Information:

I don't observe this issue with previous release (v2.33.1).

I will try to bisect when it stopped working.

Current Version:

v2.34.0

WardBrian commented 7 months ago

It appears the crash only arises with the additional flags you're using (I was able to re-create on Ubuntu with CXXFLAGS=-Wp,-D_GLIBCXX_ASSERTIONS -flto=auto -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2)

I think it's pointing to a valid issue though. I would bet on #1228

iyanmv commented 7 months ago

It is actually this commit: 810fe93fcfb5121a50f232f13eafc4e32321667d

WardBrian commented 7 months ago

Makes sense. The code introduced in that commit was later pulled into a function validate_output_filename, which is where I tracked it to in GDB. The branch in #1239 should fix

iyanmv commented 7 months ago

Makes sense. The code introduced in that commit was later pulled into a function validate_output_filename, which is where I tracked it to in GDB. The branch in #1239 should fix

Yes, I can confirm that branch works again

WardBrian commented 7 months ago

Thanks for reporting. We will probably wait a couple days to see if anything else comes in before releasing a 2.34.1 that will include that patch