Skip to content

add llvm writable attribute conditionally#155207

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
quiode:writable
Apr 17, 2026
Merged

add llvm writable attribute conditionally#155207
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
quiode:writable

Conversation

@quiode
Copy link
Copy Markdown
Contributor

@quiode quiode commented Apr 12, 2026

View all comments

This PR tries to address rust-lang/unsafe-code-guidelines#584 (comment). It is part of a bachelor thesis supervised by @JoJoDeveloping and @RalfJung, for more information, see: Project_Description.pdf.
If the new -Zllvm-writable flag is set, the llvm writable attribute is inserted for all mutable borrows. This can be conditionally turned off on a per-function basis using the #[rustc_no_writable] attribute. The new Undefined Behaviour introduced by this can detected by Miri, which is implemented here: rust-lang/miri#4947.

Two library functions already received the #[rustc_no_writable] attribute, as they are known to cause problems under the Tree Borrows aliasing model with implicit writes enabled.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 12, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

r? @mati865

rustbot has assigned @mati865.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 12 candidates

@quiode
Copy link
Copy Markdown
Contributor Author

quiode commented Apr 12, 2026

r? @RalfJung

@rustbot rustbot assigned RalfJung and unassigned mati865 Apr 12, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@rustbot

This comment has been minimized.

Copy link
Copy Markdown
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

This generally looks good, thanks! I just hope this larger ArgAttribute won't cause us problems. Cc @nikic for the LLVM parts, in case you want to take a 2nd look.

I am not sure if there's anything special to look out for in the new attribute infrastructure; @jdonszelmann would be great if you could take a brief look at that part.

@rustbot author

View changes since this review

Comment thread compiler/rustc_feature/src/builtin_attrs.rs Outdated
Comment thread compiler/rustc_session/src/options.rs Outdated
// The subset of llvm::Attribute needed for arguments, packed into a bitfield.
#[derive(Clone, Copy, Default, Hash, PartialEq, Eq, HashStable_Generic)]
pub struct ArgAttribute(u8);
pub struct ArgAttribute(u16);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, this is unfortunate. We should benchmark this to ensure the larger bitfield isn't a problem.

Comment thread compiler/rustc_ty_utils/src/abi.rs Outdated
Comment thread compiler/rustc_ty_utils/src/abi.rs
Comment thread compiler/rustc_ty_utils/src/abi.rs Outdated
Comment thread compiler/rustc_ty_utils/src/abi.rs Outdated
Comment thread src/doc/unstable-book/src/compiler-flags/llvm-writable.md Outdated
Comment thread tests/codegen-llvm/llvm-writable.rs
@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 Apr 14, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 14, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Comment thread compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs Outdated
Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer left a comment

Choose a reason for hiding this comment

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

r=me on the attribute changes, didn't check the other part of this PR

View changes since this review

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 14, 2026
rust-bors bot pushed a commit that referenced this pull request Apr 14, 2026
add llvm writable attribute conditionally
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 14, 2026

💔 Test for 37fa495 failed: CI. Failed job:

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

^ The PR needs to be rebased

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Apr 16, 2026
add llvm writable attribute conditionally
@RalfJung
Copy link
Copy Markdown
Member

RalfJung commented Apr 16, 2026

This looks great, thanks! Please squash the commits.

Let's hope the larger ArgAttribute does not cause a perf issue -- I kicked of a benchmark run to check this.

@quiode
Copy link
Copy Markdown
Contributor Author

quiode commented Apr 16, 2026

@bors squash msg="add llvm writable attribute conditionally"

@rust-bors

This comment has been minimized.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 16, 2026

🔨 11 commits were squashed into da2bbfb.

@RalfJung
Copy link
Copy Markdown
Member

Nice, I've not seen this in action before. :)

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 16, 2026

☀️ Try build successful (CI)
Build commit: 84b05e7 (84b05e789a7194a627e1ca3cda715fe05e5ca3f6, parent: e8e4541ff19649d95afab52fdde2c2eaa6829965)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (84b05e7): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

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

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

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

Max RSS (memory usage)

Results (primary 3.1%, secondary 1.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.1% [2.6%, 3.7%] 2
Regressions ❌
(secondary)
4.5% [2.8%, 6.3%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.0% [-4.0%, -4.0%] 1
All ❌✅ (primary) 3.1% [2.6%, 3.7%] 2

Cycles

Results (primary 2.3%, secondary 1.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.3% [2.2%, 2.4%] 2
Regressions ❌
(secondary)
2.7% [1.8%, 4.4%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.6% [-3.6%, -3.6%] 1
All ❌✅ (primary) 2.3% [2.2%, 2.4%] 2

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 490.756s -> 493.416s (0.54%)
Artifact size: 394.16 MiB -> 394.14 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 16, 2026
@RalfJung
Copy link
Copy Markdown
Member

That looks good! This is just a secondary benchmark that has been rather noisy recently already, nothing to worry about IMO.

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 16, 2026

📌 Commit da2bbfb has been approved by RalfJung

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Apr 16, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 17, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 17, 2026

☀️ Test successful - CI
Approved by: RalfJung
Duration: 3h 21m 21s
Pushing 1b8f2e4 to main...

@rust-bors rust-bors bot merged commit 1b8f2e4 into rust-lang:main Apr 17, 2026
12 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 0204aca (parent) -> 1b8f2e4 (this PR)

Test differences

Show 930 test diffs

Stage 1

  • [codegen] tests/codegen-llvm/llvm-writable.rs: [missing] -> pass (J0)

Stage 2

  • [codegen] tests/codegen-llvm/llvm-writable.rs: [missing] -> pass (J1)

Additionally, 928 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 1b8f2e46e14b08208a53585570edd9206374aae8 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-gnu-gcc: 48m 9s -> 1h 12m (+50.7%)
  2. x86_64-msvc-ext1: 1h 41m -> 2h 18m (+37.1%)
  3. dist-i686-msvc: 1h 51m -> 2h 26m (+32.0%)
  4. dist-x86_64-msvc-alt: 2h 12m -> 2h 43m (+24.0%)
  5. i686-msvc-2: 2h 11m -> 1h 41m (-22.6%)
  6. dist-powerpc-linux: 1h 15m -> 1h 31m (+22.1%)
  7. test-various: 1h 45m -> 2h 7m (+20.9%)
  8. x86_64-gnu-llvm-21-2: 1h 35m -> 1h 17m (-19.1%)
  9. dist-x86_64-apple: 2h 7m -> 2h 31m (+18.9%)
  10. optional-x86_64-gnu-parallel-frontend: 2h 17m -> 2h 41m (+17.8%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (1b8f2e4): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (primary 2.1%, secondary -1.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Cycles

Results (primary 8.7%, secondary 6.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
8.7% [3.0%, 14.2%] 11
Regressions ❌
(secondary)
6.0% [4.5%, 7.5%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 8.7% [3.0%, 14.2%] 11

Binary size

Results (primary 0.1%, secondary 0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.1%] 15
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 18
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.0%, 0.1%] 15

Bootstrap: 490.004s -> 504.175s (2.89%)
Artifact size: 394.09 MiB -> 394.15 MiB (0.02%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants