Skip to content

Fix unaligned_volatile_store by removing MemFlags::UNALIGNED#158899

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
scottmcm:better-volatile-store
Jul 10, 2026
Merged

Fix unaligned_volatile_store by removing MemFlags::UNALIGNED#158899
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
scottmcm:better-volatile-store

Conversation

@scottmcm

@scottmcm scottmcm commented Jul 7, 2026

Copy link
Copy Markdown
Member

Fixes #158897

There seems to be no reason to have this flag at all, as anything that wants it should just adjust the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/place/struct.PlaceValue.html#structfield.align instead.

r? codegen

@rustbot

rustbot commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

@rustbot rustbot added 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. labels Jul 7, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 7, 2026
Comment on lines -165 to -166
pub unsafe fn unaligned_volatile_store(a: *mut u8, b: u8) {
// CHECK: store volatile

@scottmcm scottmcm Jul 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that this test was essentially useless, since

  1. It didn't actually test the alignment used in the store, and
  2. It used u8 which always has alignment 1 even if you don't use unaligned.

So I expanded them to actually test things.

View changes since the review

// Note that only the store side is unaligned; the load from the argument is aligned.

// CHECK-NOT: memcpy
// CHECK: call void @llvm.memcpy{{.+}}(ptr align 1 %a, ptr align 2 %b, {{i16|i32|i64}} 14, i1 true)

@scottmcm scottmcm Jul 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A volatile memcpy is not actually a good way to do this, but it's not a regression at least since it's what this emits in nightly today (https://rust.godbolt.org/z/josnWhGa6).

(See danlehmann/bitfield#136 for more -- it's looking at this problem that had me looking at volatile stores at all. I'll make another PR after this one to work on that problem.)

View changes since the review

@saethlin

saethlin commented Jul 9, 2026

Copy link
Copy Markdown
Member

@bors r+ rollup=iffy (Scott's codegen tests are usually good but codegen tests are famous for failing due to surprise target sensitivity)

@rust-bors

rust-bors Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 9116f7d has been approved by saethlin

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 Jul 9, 2026
@scottmcm

scottmcm commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

I appreciate your confidence in me, but also 100% agree with marking my codegen tests as iffy. I've had plenty of problems too 🙃

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 9, 2026
…saethlin

Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`

Fixes rust-lang#158897

There seems to be no reason to have this flag at all, as anything that wants it should just adjust the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/place/struct.PlaceValue.html#structfield.align instead.

r? codegen
rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
…uwer

Rollup of 17 pull requests

Successful merges:

 - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets)
 - #158541 (Move `std::io::Write` to `core::io`)
 - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`)
 - #155429 (Support `u128`/`i128` c-variadic arguments)
 - #156370 (Reject linked dylib EII default overrides)
 - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s)
 - #158535 (Support `#[track_caller]` on EII declarations)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158988 (Redo `TokenStreamIter`)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158739 (view-types: HIR lowering)
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158886 (Add documentation for the `no_std` attribute)
 - #158951 (Merge three `MaxUniverse`s into one)
 - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places")
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 9, 2026
…saethlin

Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`

Fixes rust-lang#158897

There seems to be no reason to have this flag at all, as anything that wants it should just adjust the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/place/struct.PlaceValue.html#structfield.align instead.

r? codegen
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 9, 2026
…saethlin

Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`

Fixes rust-lang#158897

There seems to be no reason to have this flag at all, as anything that wants it should just adjust the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/place/struct.PlaceValue.html#structfield.align instead.

r? codegen
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 9, 2026
…saethlin

Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`

Fixes rust-lang#158897

There seems to be no reason to have this flag at all, as anything that wants it should just adjust the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/place/struct.PlaceValue.html#structfield.align instead.

r? codegen
rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #150946 (intrinsics: Add a fallback for non-const libm float functions)
 - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets)
 - #158541 (Move `std::io::Write` to `core::io`)
 - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`)
 - #155429 (Support `u128`/`i128` c-variadic arguments)
 - #156370 (Reject linked dylib EII default overrides)
 - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158859 (Improve `-Zls` diagnostic message on `.rs` files)
 - #158988 (Redo `TokenStreamIter`)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158739 (view-types: HIR lowering)
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158886 (Add documentation for the `no_std` attribute)
 - #158940 (Implement feature `char_to_u32`)
 - #158951 (Merge three `MaxUniverse`s into one)
 - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places")
 - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes)
 - #159005 (Use `as_lang_item` instead of repeatedly matching)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 9, 2026
…saethlin

Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`

Fixes rust-lang#158897

There seems to be no reason to have this flag at all, as anything that wants it should just adjust the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/place/struct.PlaceValue.html#structfield.align instead.

r? codegen
rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
…uwer

Rollup of 24 pull requests

Successful merges:

 - #150946 (intrinsics: Add a fallback for non-const libm float functions)
 - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets)
 - #158541 (Move `std::io::Write` to `core::io`)
 - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`)
 - #156027 (Consider captured regions for opaque type region liveness.)
 - #156370 (Reject linked dylib EII default overrides)
 - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`)
 - #157561 (rustdoc: do not include extra stuff in span)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158859 (Improve `-Zls` diagnostic message on `.rs` files)
 - #158988 (Redo `TokenStreamIter`)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158384 (Allow BackwardIncompatibleDropHint in polonius legacy)
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158739 (view-types: HIR lowering)
 - #158877 (borrowck: Keep returned `path` from `best_blame_constraint()` consistent)
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158886 (Add documentation for the `no_std` attribute)
 - #158940 (Implement feature `char_to_u32`)
 - #158951 (Merge three `MaxUniverse`s into one)
 - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places")
 - #158995 (Use REST API in linkchecker script)
 - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes)
@jhpratt

jhpratt commented Jul 9, 2026

Copy link
Copy Markdown
Member

I presume this is the cause of #159037 (comment), as I don't see any other PRs in that rollup that could possibly cause over 4,000 tests to fail.

@bors r-

@bors try jobs=dist-i586-gnu-i586-i686-musl

@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 9, 2026
@rust-bors

rust-bors Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#159037), which was unapproved.

View changes since this unapproval

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`


try-job: dist-i586-gnu-i586-i686-musl
@scottmcm

Copy link
Copy Markdown
Member Author

Oh, joy, i586 :/

@scottmcm

Copy link
Copy Markdown
Member Author

@jhpratt Hmm, #158510 looks potentially interesting?

Enable static_position_independent_executables on all gnu and musl targets

If the failing job is both gnu and musl...

@jhpratt

jhpratt commented Jul 10, 2026

Copy link
Copy Markdown
Member

Good catch, I didn't see there was another codegen PR. I'll exclude both from rollups for the time being.

@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 421a606 failed: CI. Failed job:

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job dist-i586-gnu-i586-i686-musl failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test [debuginfo-gdb] tests/debuginfo/zst-interferes-with-prologue.rs ... ok

failures:

---- [debuginfo-gdb] tests/debuginfo/function-call.rs stdout ----
NOTE: compiletest thinks it is using GDB version 12001000
------gdb stdout------------------------------
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Breakpoint 1 at 0x804f592: file /checkout/tests/debuginfo/function-call.rs, line 36.

Breakpoint 1, function_call::main () at /checkout/tests/debuginfo/function-call.rs:36
36     zzz(); // #break

------gdb stderr------------------------------
/checkout/obj/build/x86_64-unknown-linux-gnu/test/debuginfo/function-call.gdb/function-call.debugger.script:11: Error in sourced command file:
Couldn't write extended state status: Bad address.

------------------------------------------

error: gdb failed to execute
status: exit status: 1
command: PYTHONPATH="/checkout/src/etc" "/usr/bin/gdb" "-quiet" "-batch" "-nx" "-command=/checkout/obj/build/x86_64-unknown-linux-gnu/test/debuginfo/function-call.gdb/function-call.debugger.script"
--- stdout -------------------------------
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Breakpoint 1 at 0x804f592: file /checkout/tests/debuginfo/function-call.rs, line 36.

Breakpoint 1, function_call::main () at /checkout/tests/debuginfo/function-call.rs:36
36     zzz(); // #break
------------------------------------------
--- stderr -------------------------------
/checkout/obj/build/x86_64-unknown-linux-gnu/test/debuginfo/function-call.gdb/function-call.debugger.script:11: Error in sourced command file:
Couldn't write extended state status: Bad address.
------------------------------------------

@scottmcm

Copy link
Copy Markdown
Member Author

That's not the "every UI test" failure, so let's see if it's transient...

@bors try jobs=dist-i586-gnu-i586-i686-musl

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 10, 2026
Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`


try-job: dist-i586-gnu-i586-i686-musl
@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 066e1fb (066e1fbbb183e71b867e3251fcbb722464c3b3b4)
Base parent: d465559 (d465559281ebfb5b586913285f4d40f9b518b729)

@scottmcm

Copy link
Copy Markdown
Member Author

Re-approving since the try job above confirms this wasn't the source of the rollup issue

@bors r=saethlin

@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 9116f7d has been approved by saethlin

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 10, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 10, 2026
Rollup of 7 pull requests

Successful merges:

 - #155429 (Support `u128`/`i128` c-variadic arguments)
 - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`)
 - #158640 (Handle nested inline consts in const argument checks)
 - #158866 ([perf] Add explicit `Iterator::count` impl for `ChunkBy`.)
 - #158912 (Introduce new bootstrap config section for PGO configuration)
 - #159040 (Print step stack trace when bootstrap panics)
 - #159056 (Print a loud error if the configured LLDB cannot be found)
@rust-bors rust-bors Bot merged commit 731d820 into rust-lang:main Jul 10, 2026
14 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 10, 2026
rust-timer added a commit that referenced this pull request Jul 10, 2026
Rollup merge of #158899 - scottmcm:better-volatile-store, r=saethlin

Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`

Fixes #158897

There seems to be no reason to have this flag at all, as anything that wants it should just adjust the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/place/struct.PlaceValue.html#structfield.align instead.

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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.

unaligned_volatile_store emits aligned stores for some types

5 participants