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

do not add noalias in return position #106371

Merged
merged 1 commit into from
Jan 3, 2023

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jan 2, 2023

noalias as a return attribute in LLVM indicates that the returned pointer does not alias anything else that is reachable from the caller, including things reachable before this function call. This is clearly not the case with a function like fn id(Box<T>) -> Box<T>, so we cannot use this attribute.

Fixes rust-lang/unsafe-code-guidelines#385 (including an actual miscompilation that @comex managed to produce).

@rustbot
Copy link
Collaborator

rustbot commented Jan 2, 2023

r? @jackh726

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

@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 Jan 2, 2023
@nikic
Copy link
Contributor

nikic commented Jan 2, 2023

I think this is the right thing to do, and I intuitively wouldn't expect this to have a huge impact, because we still have noalias on the __rustc_alloc return, which is where it really matters. Still, let's do a sanity check...

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 2, 2023
@bors
Copy link
Contributor

bors commented Jan 2, 2023

⌛ Trying commit e7cad62 with merge 4921783924d104b60b4219521643e1d57e96d94e...

@bors
Copy link
Contributor

bors commented Jan 2, 2023

☀️ Try build successful - checks-actions
Build commit: 4921783924d104b60b4219521643e1d57e96d94e (4921783924d104b60b4219521643e1d57e96d94e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4921783924d104b60b4219521643e1d57e96d94e): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

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

Max RSS (memory usage)

Results

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)
-3.0% [-3.6%, -2.6%] 5
Improvements ✅
(secondary)
-2.6% [-3.6%, -0.8%] 31
All ❌✅ (primary) -3.0% [-3.6%, -2.6%] 5

Cycles

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 2, 2023
@nikic
Copy link
Contributor

nikic commented Jan 2, 2023

Okay, that was a pretty clear answer...

@bors r+

@bors
Copy link
Contributor

bors commented Jan 2, 2023

📌 Commit e7cad62 has been approved by nikic

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 Jan 2, 2023
@bors
Copy link
Contributor

bors commented Jan 3, 2023

⌛ Testing commit e7cad62 with merge 442f997...

@bors
Copy link
Contributor

bors commented Jan 3, 2023

☀️ Test successful - checks-actions
Approved by: nikic
Pushing 442f997 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 3, 2023
@bors bors merged commit 442f997 into rust-lang:master Jan 3, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 3, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (442f997): 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.2% [-1.3%, -1.2%] 3
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

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)
2.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
2.3% [1.2%, 3.5%] 21
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-3.0%, -3.0%] 1
All ❌✅ (primary) 2.6% [2.6%, 2.6%] 1

Cycles

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

@RalfJung RalfJung deleted the no-ret-position-noalias branch January 3, 2023 10:07
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
…nikic

do not add noalias in return position

`noalias` as a return attribute in LLVM indicates that the returned pointer does not alias anything else that is reachable from the caller, *including things reachable before this function call*. This is clearly not the case with a function like `fn id(Box<T>) -> Box<T>`, so we cannot use this attribute.

Fixes rust-lang/unsafe-code-guidelines#385 (including an actual miscompilation that `@comex` managed to produce).
@pnkfelix
Copy link
Member

pnkfelix commented Aug 8, 2023

I am now curious: We briefly touched on this PR (#106371) while discussing rust-lang/unsafe-code-guidelines#196, and I cannot immediately tell from a cursory look: Did this change end up removing noalias from every return position, include the return position of allocation functions?

@RalfJung said in the meeting that they believed we are still emitting noalias for return position of allocation functions, but skimming over this PR it is not obvious to me that is still the case. (Its possible there's a completely separate path that is being exercised for those functions, which would explain my confusion here.)

((I now also see there was significant discussion of the original motivations for return-position noalias being pretty narrow cases involving malloc and thin wrappers around malloc... as @RalfJung notes, "Any time that there is a "life after deallocation" inside the abstract machine, we cannot use this attribute." ... I haven't worked through the implications of that, in terms of what it means for whether we can continue to apply the attribute to Rust allocation methods themselves...))

@RalfJung
Copy link
Member Author

RalfJung commented Aug 8, 2023

__rust_alloc has the #[rustc_allocator] attribute which still lets us add noalias (even though for custom allocators this rests in somewhat shaky ground):

attributes::apply_to_llfn(llfn, AttributePlace::ReturnValue, &[no_alias]);

@bjorn3
Copy link
Member

bjorn3 commented Aug 8, 2023

I believe I broke applying this attribute for #[global_allocator] in #86844.

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.

Return-position noalias
8 participants