Skip to content

The miri engine may create pointers to thread locals #70684

Closed
@oli-obk

Description

@oli-obk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions