Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::lognormal_distribution can overwrite const memory #52906

Closed
Quuxplusone opened this issue Dec 28, 2021 · 2 comments
Closed

std::lognormal_distribution can overwrite const memory #52906

Quuxplusone opened this issue Dec 28, 2021 · 2 comments
Assignees
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@Quuxplusone
Copy link
Contributor

#include <cassert>
#include <random>

int main() {
    typedef std::lognormal_distribution<> D;
    typedef D::param_type P;
    typedef std::mt19937 G;
    G g;
    D d;

    const P p1 = d.param();
    const P p2 = d.param();
    assert(p1 == p2);
    double r1 = d(g, p1); // This line must not modify p1.
    assert(p1 == p2);
}

libc++ fails the final assert, because D::param_type secretly contains a whole normal_distribution object(!) and then d(g, p1) secretly contains a const_cast so it can call that normal_distribution's operator().

@Quuxplusone Quuxplusone added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 28, 2021
@Quuxplusone Quuxplusone self-assigned this Dec 28, 2021
@Quuxplusone
Copy link
Contributor Author

This is now https://reviews.llvm.org/D116344

@cebowler
Copy link
Contributor

cebowler commented May 5, 2022

We haven't shipped this change on IBM's Open XL C++ compiler yet so I haven't been able to assess whether or not any customers will need to define _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION.

As a courtesy I would appreciate it if we can add a deprecation warning (when _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION is defined) in LLVM 15 with intention to remove it in LLVM 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants