Skip to content

The miri engine may create pointers to thread locals #70684

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

Closed
oli-obk opened this issue Apr 2, 2020 · 3 comments
Closed

The miri engine may create pointers to thread locals #70684

oli-obk opened this issue Apr 2, 2020 · 3 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Apr 2, 2020

I haven't checked whether that is actually true, but we should have an unleash-the-miri-inside-of-you test for the following code snippet. In contrast to normal compilation I expect this to pass compilation and then segfault LLVM or similar, but we may catch it. No matter the result, we should have a test for it.

#![feature(thread_local)]

use std::thread;

#[thread_local]
static mut A: u8 = 0;

static B: &u8 = unsafe { &A };

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
warning: unused import: `std::thread`
 --> src/lib.rs:3:5
  |
3 | use std::thread;
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0625]: thread-local statics cannot be accessed at compile-time
 --> src/lib.rs:8:27
  |
8 | static B: &u8 = unsafe { &A };
  |                           ^

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

@oli-obk oli-obk added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) labels Apr 2, 2020
@eddyb
Copy link
Member

eddyb commented Apr 2, 2020

As I suggested elsewhere, I believe #[thread_local] statics should have their own separate access mechanism, probably their own Rvalue (or we could start extending what Rvalue::{Ref,RawPtr} can borrow).

That's because getting the address of a #[thread_local] static is a fundamentally runtime operation, and LLVM reusing the same syntax as for regular statics, is in the wrong here.

@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 2, 2020

The "elsewhere" now having a canonical issue: #70685

@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 2, 2020

Ah so this won't work even with unleash mode, because of

const IS_SUPPORTED_IN_MIRI: bool = false;

I guess we can address this together with #70685, our existing tests should be enough then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

2 participants