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

Add a test for #107975 #127003

Merged
merged 1 commit into from
Jul 20, 2024
Merged

Add a test for #107975 #127003

merged 1 commit into from
Jul 20, 2024

Conversation

GrigorenkoPV
Copy link
Contributor

@GrigorenkoPV GrigorenkoPV commented Jun 26, 2024

The int is zero. But also not zero. This is so much fun.

This is a part of #105107.

Initially I was going to just rebase #108445, but quite a few things changed since then:

As an aside, the naming for addr_of! is quite unfortunate in context of provenance APIs. Because addr_of! gives you a pointer, but what provenance APIs refer to as "address" is the usize value. Oh well.

UPD1: GitHub is incapable of parsing #107975 in the PR name, so let's add it here.

Footnotes

  1. UPD2: The other mcve does not work anymore either, saying "this behavior recently changed as a result of a bug fix; see Tracking issue for future-incompatibility lint coherence_leak_check #56105 for details."

@rustbot
Copy link
Collaborator

rustbot commented Jun 26, 2024

r? @pnkfelix

rustbot has assigned @pnkfelix.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 26, 2024
@GrigorenkoPV
Copy link
Contributor Author

@rustbot author

@rustbot rustbot 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 Jun 30, 2024
@rust-log-analyzer

This comment has been minimized.

@GrigorenkoPV GrigorenkoPV force-pushed the 107975 branch 2 times, most recently from a7c36d1 to 562aaa4 Compare July 6, 2024 18:12
@GrigorenkoPV
Copy link
Contributor Author

@rustbot ready

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

@SparrowLii SparrowLii left a comment

Choose a reason for hiding this comment

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

Thanks! It looks much better, just needs some structural adjustment

@GrigorenkoPV
Copy link
Contributor Author

@rustbot author

@rustbot rustbot 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 Jul 8, 2024
@GrigorenkoPV
Copy link
Contributor Author

@rustbot ready

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

@bors r+

@bors
Copy link
Contributor

bors commented Jul 16, 2024

📌 Commit 562aaa4 has been approved by SparrowLii

It is now in the queue for this repository.

@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 Jul 16, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 16, 2024
Add a test for rust-lang#107975

The int is zero. But also not zero. This is so much fun.

This is a part of rust-lang#105107.

Initially I was going to just rebase rust-lang#108445, but quite a few things changed since then:
* The [mcve](rust-lang#105787 (comment)) used for rust-lang#105787 got fixed.[^upd2]
* You can't just `a ?= b` for rust-lang#107975 anymore. Now you have to `a-b ?= 0`. This is what this PR does. As an additional flex, it show that three ways of converting a pointer to its address have this issue:
  1. `as usize`
  2. `.expose_provenance()`
  3. `.addr()`
* rust-lang#108425 simply got fixed. Yay.

As an aside, the naming for `addr_of!` is quite unfortunate in context of provenance APIs. Because `addr_of!` gives you a pointer, but what provenance APIs refer to as "address" is the `usize` value. Oh well.

UPD1: GitHub is incapable of parsing rust-lang#107975 in the PR name, so let's add it here.

[^upd2]: UPD2: [The other mcve](rust-lang#105787 (comment)) does not work anymore either, saying "this behavior recently changed as a result of a bug fix; see rust-lang#56105 for details."
@bors
Copy link
Contributor

bors commented Jul 16, 2024

⌛ Testing commit 562aaa4 with merge 6364ce8...

@rust-log-analyzer

This comment has been minimized.

@GrigorenkoPV
Copy link
Contributor Author

Opened #127914, because it does not look like it is my fault. Let's hack around it for now.

@GrigorenkoPV
Copy link
Contributor Author

Hopefully, this will fix it


// The `Box` has been deallocated by now, so this is a dangling reference!
let r: &u8 = &*r;
println!("{:p}", r);
Copy link
Member

@SparrowLii SparrowLii Jul 19, 2024

Choose a reason for hiding this comment

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

Could we use let _: u8 = *r here so we don't need the .stdout file anymore. As the ui test tool doesn't care about the specific value of r.

@GrigorenkoPV
Copy link
Contributor Author

@rustbot author
I will try to get rid of check-run-results when I have time.

@rustbot rustbot 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 Jul 19, 2024
@GrigorenkoPV
Copy link
Contributor Author

I will try to get rid of check-run-results when I have time.

Done.

I think I will rebase on top of master just to make sure nothing has changed in the meantime. Because finding it out through another failed 60+ minutes CI run would be sad.

@GrigorenkoPV
Copy link
Contributor Author

GrigorenkoPV commented Jul 19, 2024

I think I will rebase on top of master just to make sure nothing has changed in the meantime.

Things seem to be ok

@rustbot ready

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

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Jul 20, 2024

📌 Commit 2b08914 has been approved by SparrowLii

It is now in the queue for this repository.

@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 Jul 20, 2024
@bors
Copy link
Contributor

bors commented Jul 20, 2024

⌛ Testing commit 2b08914 with merge 41ff460...

@bors
Copy link
Contributor

bors commented Jul 20, 2024

☀️ Test successful - checks-actions
Approved by: SparrowLii
Pushing 41ff460 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 20, 2024
@bors bors merged commit 41ff460 into rust-lang:master Jul 20, 2024
7 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jul 20, 2024
@GrigorenkoPV GrigorenkoPV deleted the 107975 branch July 20, 2024 08:32
@GrigorenkoPV GrigorenkoPV restored the 107975 branch July 20, 2024 08:33
@GrigorenkoPV GrigorenkoPV deleted the 107975 branch July 20, 2024 08:33
@GrigorenkoPV
Copy link
Contributor Author

No.Way.mp4

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (41ff460): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.8% [-1.8%, -1.8%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results (secondary -2.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 770.598s -> 769.168s (-0.19%)
Artifact size: 328.83 MiB -> 328.88 MiB (0.01%)


// Let's borrow the `i`-th element.
// If `i` is out of bounds, indexing will panic.
let r: Ref<Option<Box<u8>>> = arr[i].borrow();
Copy link
Member

Choose a reason for hiding this comment

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

This seems to assume that the difference between addresses of the two stack variables will never be larger than 3. This is not true with cg_clif where the difference is 16.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems to assume that the difference between addresses of the two stack variables will never be larger than 3.

Not really. It assumes that the difference is precisely 0 and non-0 at the same time. The test in question should ALWAYS panic in one place or another (even without the assert_ne!(i, 0)). But it doesn't, because some parts gets optimized as if i is 0, while others are optimized as if it is not.

What I'm trying to say is that the length choice is arbitrary and that the test will fail no matter the value of i (be it 0, or 1, or 3, or 16, or whatever) as long as compiler does not make contradictory assumptions during optimization.

It might actually even break if compiler still makes contradictory assumptions, but optimizes things differently.

The point of the test is to capture the current buggy behavior and demonstrate that it can lead to unsoundness in safe code.

Copy link
Member

@bjorn3 bjorn3 Jul 25, 2024

Choose a reason for hiding this comment

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

I thought the //@ known-bug would cause a //@ run-pass test like this one to fail if it doesn't panic/crash, but I guess that is not the case. Because of that I thought a non-broke backend like cg_clif is expected to not panic anywhere on this test as opposed to be supposed to panic somewhere like actually happened with cg_clif.

It would have been nice to mark this test as //@ codegen-backend: llvm, but no such test annotation is currently implemented unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

9 participants