Skip to content

Statics should not be able to take the address of a thread_local static #18712

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
alexcrichton opened this issue Nov 6, 2014 · 7 comments
Closed
Labels
A-codegen Area: Code generation C-bug Category: This is a bug.

Comments

@alexcrichton
Copy link
Member

Not sure if this is a codegen bug or just something that's not supported by LLVM

#![feature(thread_local)]

#[thread_local]
static FOO: uint = 0;
static BAR: &'static uint = &FOO;

fn main() {
    println!("{}", *BAR);
}
$ rustc foo.rs && ./foo
282584257676671
$ rustc foo.rs --opt-level=3 && ./foo
0
@steveklabnik
Copy link
Member

I'm now getting zero even with -O, so this is fixed, I think.

@alexcrichton
Copy link
Member Author

Ah I believe this is still an issue, the results here should be deterministic. The right answer is happening in the optimized case I believe due to LLVM being able to inline everything.

@alexcrichton alexcrichton reopened this Jan 27, 2015
@steveklabnik
Copy link
Member

Oh, I was getting zero in all cases no matter what. how do you trigger the bug?

@alexcrichton
Copy link
Member Author

Interesting, if I compile without optimizations then I get the bogus answer above. That being said, this is semantically just not a correct operation as there is no statically known global value for the address of a thread local (it varies per thread!)

@steveklabnik steveklabnik added the A-codegen Area: Code generation label Jan 29, 2015
@steveklabnik
Copy link
Member

Triage: updated code:

#![feature(thread_local)]

#[thread_local]
static FOO: usize = 0;
static BAR: &'static usize = &FOO;

fn main() {
    println!("{}", *BAR);
}

I still get zero in both cases here.

@Mark-Simulacrum Mark-Simulacrum changed the title Statics cannot reference other thread_local statics Statics can take the address of a thread_local static Apr 29, 2017
@Mark-Simulacrum
Copy link
Member

This bug is still present. Updated title to correspond to the fact that statics can reference thread locals, but they shouldn't be able to.

@Mark-Simulacrum Mark-Simulacrum changed the title Statics can take the address of a thread_local static Statics should not be able to take the address of a thread_local static Jul 22, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@alexcrichton
Copy link
Member Author

This has now been fixed on nightly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants