Description
This issue is to collect information from #3203 in one place.
Basic summary:
On GCC, since c71dd3e (#2642), both ./test/prob/poisson/poisson_ccdf_log_00000_generated_v_test
and ./test/prob/loglogistic/loglogistic_cdf_00001_generated_ffv_test
fail due to taking a reference to something on the stack. The first fails under normal optimization settings consistently, the second is sporadic but can be made consistent by compiling with ASAN.
ASAN specifically blames
math/stan/math/prim/prob/poisson_lccdf.hpp
Lines 55 to 57 in 3a196d4
and
math/stan/math/prim/prob/loglogistic_cdf.hpp
Line 116 in 3a196d4
as the problematic lines.
The discussion in #2414 (comment) seems relevant, as @bgoodri was running into segfaults with a similar line in poisson_lcdf
.
There are shockingly few places where we use to_ref_if on an expression which is the result of an apply_scalar_binary call, I believe it is only in:
stan/math/prim/prob/loglogistic_cdf.hpp
stan/math/prim/prob/loglogistic_lpdf.hpp
stan/math/prim/prob/pareto_type_2_lcdf.hpp
stan/math/prim/prob/poisson_cdf.hpp
stan/math/prim/prob/poisson_lccdf.hpp
stan/math/prim/prob/poisson_lcdf.hpp
stan/math/prim/prob/weibull_lpdf.hpp
@SteveBronder believes the correct fix is probably to make the apply_scalar_
functions and all callsites thereof into perfect forwarding templates. The other solution involves materializing a signficant number of copies which would have a performance impact