Skip to content

Directly use raw pointers in AtomicPtr store/load #77611

New issue

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

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

Already on GitHub? # to your account

Merged
merged 4 commits into from
Dec 9, 2020

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Oct 6, 2020

I was unable to find any reason for this limitation in the latest source of LLVM or in the documentation here.

fixes rust-lang/miri#1574

@rust-highfive
Copy link
Contributor

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 6, 2020
@oli-obk oli-obk force-pushed the atomic_miri_leakage branch from 9d1626f to 2da5960 Compare October 6, 2020 10:39
@RalfJung
Copy link
Member

RalfJung commented Oct 6, 2020

With this you can probably remove the use of miri_static_root in library/std/src/sys/windows/thread_local_key.rs.

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 6, 2020

Removed that and miri still tests successfully

@jyn514 jyn514 added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 6, 2020
@camelid camelid added A-codegen Area: Code generation S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2020
@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 28, 2020

r? @nagisa (I don't know who else to ping for llvm stuff)

@rust-highfive rust-highfive assigned nagisa and unassigned sfackler Oct 28, 2020
@RalfJung
Copy link
Member

AFAIK @cuviper is also knowledgeable for matters of LLVM

@nagisa
Copy link
Member

nagisa commented Oct 28, 2020

There's an entire workgroup of us! (rust-lang/wg-llvm)

This seems just fine to me, @bors r+ rollup=iffy

@bors
Copy link
Collaborator

bors commented Oct 28, 2020

📌 Commit 31c1dfbe12870cea1144b5d0c77785acc1b4ce70 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 28, 2020
@bors
Copy link
Collaborator

bors commented Oct 28, 2020

⌛ Testing commit 31c1dfbe12870cea1144b5d0c77785acc1b4ce70 with merge 3610b9b4bb45c31e2e7af4814c95fe2106738100...

@bors
Copy link
Collaborator

bors commented Oct 28, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 28, 2020
@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 28, 2020

😆 nevermind, we found a platform where this doesn't work

Intrinsic has incorrect argument type!
void ({}*)* @llvm.ppc.cfence.p0sl_s
in function rust_oom
LLVM ERROR: Broken function found, compilation aborted!
[RUSTC-TIMING] std test:false 20.161
error: could not compile `std`

I'll adjust the llvm backend to do the appropriate transformation instead of having that in libcore

@kennytm
Copy link
Member

kennytm commented Nov 12, 2020

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 12, 2020
@RalfJung
Copy link
Member

Oh, this looks great, I feared it would be much more complicated. :)

If I understood correctly, since this happens in the general SSA backend, the Cranelift backend will not need to do anything itself? Cc @bjorn3

@bjorn3
Copy link
Member

bjorn3 commented Nov 29, 2020

I don't use cg_ssa yet. Cranelift doesn't have a separate pointer type, so no changes to the actual codegen are necessary. There is a validation for the used type though. The fix for cg_clif should be a matter of adding ty::RawPtr to the match arm at

ty::Uint(_) | ty::Int(_) => {}

Copy link
Member

@bjorn3 bjorn3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cg_clif change LGTM

// SAFETY: This intrinsic is unsafe because it operates on a raw pointer
// but we know for sure that the pointer is valid (we just got it from
// an `UnsafeCell` that we have by reference) and the atomic operation
// itself allows us to safely mutate the `UnsafeCell` contents.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the safety comment for the #[cfg(bootstrap)] case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but I felt like it wasn't worth updating that, too, since it'll go away with the next beta anyway

@nagisa
Copy link
Member

nagisa commented Dec 9, 2020

@bors r+ rollup=never

@bors
Copy link
Collaborator

bors commented Dec 9, 2020

📌 Commit 41f988e has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 9, 2020
@bors
Copy link
Collaborator

bors commented Dec 9, 2020

⌛ Testing commit 41f988e with merge 0bddb8da0ff78a761169b9ac1b18cde962fb88f6...

@bors
Copy link
Collaborator

bors commented Dec 9, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 9, 2020
@bjorn3
Copy link
Member

bjorn3 commented Dec 9, 2020

It says "This check failed" without any logs. I guess it is spurious

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 9, 2020
@bors
Copy link
Collaborator

bors commented Dec 9, 2020

⌛ Testing commit 41f988e with merge f0f6877...

@bors
Copy link
Collaborator

bors commented Dec 9, 2020

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing f0f6877 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 9, 2020
@bors bors merged commit f0f6877 into rust-lang:master Dec 9, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 9, 2020
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Dec 27, 2020
Directly use raw pointers in `AtomicPtr` store/load

I was unable to find any reason for this limitation in the latest source of LLVM or in the documentation [here](http://llvm.org/docs/Atomics.html#libcalls-atomic).

fixes rust-lang/miri#1574
@oli-obk oli-obk deleted the atomic_miri_leakage branch March 16, 2021 12:14
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 13, 2024
…li-obk

Only generate a ptrtoint in AtomicPtr codegen when absolutely necessary

This special case was added in this PR: rust-lang#77611 in response to this error message:
```
Intrinsic has incorrect argument type!
void ({}*)* `@llvm.ppc.cfence.p0sl_s`
in function rust_oom
LLVM ERROR: Broken function found, compilation aborted!
[RUSTC-TIMING] std test:false 20.161
error: could not compile `std`
```
But when I tried searching for more information about that intrinsic I found this: llvm/llvm-project#55983 which is a report of someone hitting this same error and a fix was landed in LLVM, 2 years after the above Rust PR.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Mar 14, 2024
Only generate a ptrtoint in AtomicPtr codegen when absolutely necessary

This special case was added in this PR: rust-lang/rust#77611 in response to this error message:
```
Intrinsic has incorrect argument type!
void ({}*)* `@llvm.ppc.cfence.p0sl_s`
in function rust_oom
LLVM ERROR: Broken function found, compilation aborted!
[RUSTC-TIMING] std test:false 20.161
error: could not compile `std`
```
But when I tried searching for more information about that intrinsic I found this: llvm/llvm-project#55983 which is a report of someone hitting this same error and a fix was landed in LLVM, 2 years after the above Rust PR.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Apr 7, 2024
Only generate a ptrtoint in AtomicPtr codegen when absolutely necessary

This special case was added in this PR: rust-lang/rust#77611 in response to this error message:
```
Intrinsic has incorrect argument type!
void ({}*)* `@llvm.ppc.cfence.p0sl_s`
in function rust_oom
LLVM ERROR: Broken function found, compilation aborted!
[RUSTC-TIMING] std test:false 20.161
error: could not compile `std`
```
But when I tried searching for more information about that intrinsic I found this: llvm/llvm-project#55983 which is a report of someone hitting this same error and a fix was landed in LLVM, 2 years after the above Rust PR.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
Only generate a ptrtoint in AtomicPtr codegen when absolutely necessary

This special case was added in this PR: rust-lang/rust#77611 in response to this error message:
```
Intrinsic has incorrect argument type!
void ({}*)* `@llvm.ppc.cfence.p0sl_s`
in function rust_oom
LLVM ERROR: Broken function found, compilation aborted!
[RUSTC-TIMING] std test:false 20.161
error: could not compile `std`
```
But when I tried searching for more information about that intrinsic I found this: llvm/llvm-project#55983 which is a report of someone hitting this same error and a fix was landed in LLVM, 2 years after the above Rust PR.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory leak checker misses AtomicPtr