Skip to content

Rollup of 23 pull requests #140231

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

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
fe03f76
std: Add performance warnings to HashMap::get_disjoint_mut
xizheyin Apr 3, 2025
2678d04
mitigate MSVC unsoundness by not emitting alignment attributes on win…
RalfJung Apr 2, 2025
e702f96
check_align: we can still check low alignments on MSVC
RalfJung Apr 4, 2025
75f86e6
fix LooseTypes flag and PrintMod behaviour, add debug helper
ZuseZ4 Apr 12, 2025
31578dc
fix "could not find source function" error by preventing function mer…
ZuseZ4 Apr 12, 2025
5ea9125
update documentation
ZuseZ4 Apr 12, 2025
f79a992
add tests for merge_function handling
ZuseZ4 Apr 12, 2025
35a20de
Implement `SmirInterface`
makai410 Apr 18, 2025
16381b3
Use `currently` for futher improvement
xizheyin Apr 20, 2025
2ef4f78
rustc_target: Adjust RISC-V feature implication
a4lg Apr 22, 2025
90fe280
Move `sys::pal::os::Env` into `sys::env`
thaliaarchi Apr 22, 2025
6518bcb
Fix `unsafe_op_in_unsafe_fn` for Unix env
thaliaarchi Apr 22, 2025
1b00ebe
Update !DynSend and !DynSync platform impls
thaliaarchi Apr 22, 2025
4695212
Deduplicate unsupported env items
thaliaarchi Apr 22, 2025
01485c9
Unify owned `Env` types between platforms
thaliaarchi Apr 22, 2025
08baec4
add a test for byte string literal pattern mutability mismatches
dianne Apr 22, 2025
6184025
make `str` literal patterns usable in deref patterns
dianne Mar 25, 2025
3250344
make `[u8]` and `[u8;N]` literal patterns usable in deref patterns
dianne Apr 16, 2025
4c7e866
update unstable book to mention string/bytestring typing
dianne Apr 19, 2025
19e44d4
Don't warn about `v128` in wasm ABI transition
alexcrichton Apr 14, 2025
09e36ce
[compiletest] Parallelize test discovery
tmandry Apr 22, 2025
51088fd
Remove `synstructure::Structure::underscore_const` calls.
nnethercote Apr 23, 2025
e18e599
set subsections_via_symbols for ld64 helper sections
usamoi Apr 13, 2025
17664d1
Update doc of cygwin target
Berrysoft Apr 23, 2025
fdf2c47
[AIX] Handle AIX dynamic library extensions within c-link-to-rust-dyl…
amy-kwan Apr 23, 2025
0a76ef8
Rename `compute_x` methods
BoxyUwU Apr 23, 2025
c6e6ac9
Module docs
BoxyUwU Apr 23, 2025
5b390cd
Make `SmirInterface` pub(crate) and rename `Context` to `SmirContext`
makai410 Apr 23, 2025
0296f05
Make algebraic intrinsics into 'const fn' items; Make algebraic funct…
bjoernager Apr 22, 2025
a4b9a1b
Remove `git_repository` field from `GitConfig`
Kobzol Apr 23, 2025
91da45a
Remove `git_repository` from the `stage0` file
Kobzol Apr 23, 2025
e3296cd
compiletest: `//@ add-core-stubs` implies `-Cforce-unwind-tables=yes`
jieyouxu Apr 23, 2025
c79f156
tests: account for CFI directives in `tests/assembly/x86-return-float…
jieyouxu Apr 23, 2025
f2ab763
rustc-dev-guide: document that `//@ add-core-stubs` imply `-Cforce-un…
jieyouxu Apr 23, 2025
f0399b8
triagebot: label minicore changes w/ `A-test-infra-minicore`
jieyouxu Apr 23, 2025
18c3370
CI: use aws codebuild for job dist-arm-linux
marcoieni Apr 23, 2025
157caee
fix f*::MAX_EXP and MIN_EXP docs
RalfJung Apr 22, 2025
7493e1c
Make #![feature(let_chains)] bootstrap conditional in compiler/
est31 Apr 23, 2025
1162f42
Remove hack
compiler-errors Apr 23, 2025
2a5c349
Extend HIR to track the source and syntax of a lifetime
shepmaster Mar 28, 2025
308cfb8
Rollup merge of #139261 - RalfJung:msvc-align-mitigation, r=oli-obk
Zalathar Apr 24, 2025
83ecddd
Rollup merge of #139307 - xizheyin:issue-139296, r=joboet
Zalathar Apr 24, 2025
331e4b0
Rollup merge of #139700 - EnzymeAD:autodiff-flags, r=oli-obk
Zalathar Apr 24, 2025
66979b2
Rollup merge of #139752 - usamoi:macos-used, r=saethlin,madsmtm
Zalathar Apr 24, 2025
54c65e6
Rollup merge of #139809 - alexcrichton:wasm-simd-safe, r=RalfJung
Zalathar Apr 24, 2025
1ba0ffe
Rollup merge of #139852 - makai410:smir-refactor, r=celinval
Zalathar Apr 24, 2025
570302d
Rollup merge of #139945 - shepmaster:hir-lifetime-syntax-source, r=nn…
Zalathar Apr 24, 2025
7a32312
Rollup merge of #140028 - dianne:lit-deref-pats-p1, r=oli-obk
Zalathar Apr 24, 2025
01271ba
Rollup merge of #140139 - a4lg:riscv-feature-imply-adjust-1, r=Amanieu
Zalathar Apr 24, 2025
6c1d167
Rollup merge of #140143 - thaliaarchi:move-env-pal, r=joboet
Zalathar Apr 24, 2025
9c368a8
Rollup merge of #140148 - marcoieni:ci-aws-codebuild, r=Kobzol
Zalathar Apr 24, 2025
8e8293e
Rollup merge of #140150 - RalfJung:MAX_EXP, r=tgross35
Zalathar Apr 24, 2025
42bc414
Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung
Zalathar Apr 24, 2025
8d4283f
Rollup merge of #140177 - tmandry:compiletest-par, r=jieyouxu
Zalathar Apr 24, 2025
0f1f49a
Rollup merge of #140181 - nnethercote:rm-underscore_const, r=compiler…
Zalathar Apr 24, 2025
bd71363
Rollup merge of #140184 - Berrysoft:cygwin-target-doc, r=Noratrieb
Zalathar Apr 24, 2025
ca9a2d1
Rollup merge of #140186 - BoxyUwU:compute_what, r=compiler-errors
Zalathar Apr 24, 2025
81d17e6
Rollup merge of #140187 - amy-kwan:amy-kwan/update_runmake_tests_AIX,…
Zalathar Apr 24, 2025
11c4cc9
Rollup merge of #140191 - Kobzol:remove-git-repository-from-git-confi…
Zalathar Apr 24, 2025
d531fae
Rollup merge of #140194 - jieyouxu:minicore-force-unwind-tables, r=bj…
Zalathar Apr 24, 2025
6d371c5
Rollup merge of #140195 - jieyouxu:minicore-triagebot, r=jieyouxu
Zalathar Apr 24, 2025
f108448
Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr
Zalathar Apr 24, 2025
a415a28
Rollup merge of #140214 - compiler-errors:remove-hack, r=lcnr
Zalathar Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mitigate MSVC unsoundness by not emitting alignment attributes on win…
…32-msvc targets

also mention the MSVC alignment issue in platform-support.md
  • Loading branch information
RalfJung committed Apr 7, 2025
commit 2678d04dd97444cf444c31be92bfd281f9986a47
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
fn load(&mut self, ty: &'ll Type, ptr: &'ll Value, align: Align) -> &'ll Value {
unsafe {
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED);
let align = align.min(self.cx().tcx.sess.target.max_reliable_alignment());
llvm::LLVMSetAlignment(load, align.bytes() as c_uint);
load
}
Expand Down Expand Up @@ -807,6 +808,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
assert_eq!(self.cx.type_kind(self.cx.val_ty(ptr)), TypeKind::Pointer);
unsafe {
let store = llvm::LLVMBuildStore(self.llbuilder, val, ptr);
let align = align.min(self.cx().tcx.sess.target.max_reliable_alignment());
let align =
if flags.contains(MemFlags::UNALIGNED) { 1 } else { align.bytes() as c_uint };
llvm::LLVMSetAlignment(store, align);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/check_alignment.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rustc_abi::Align;
use rustc_index::IndexVec;
use rustc_middle::mir::interpret::Scalar;
use rustc_middle::mir::visit::PlaceContext;
Expand All @@ -11,8 +12,7 @@ pub(super) struct CheckAlignment;

impl<'tcx> crate::MirPass<'tcx> for CheckAlignment {
fn is_enabled(&self, sess: &Session) -> bool {
// FIXME(#112480) MSVC and rustc disagree on minimum stack alignment on x86 Windows
if sess.target.llvm_target == "i686-pc-windows-msvc" {
if sess.target.max_reliable_alignment() < Align::MAX {
return false;
}
sess.ub_checks()
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/callconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub struct ArgAttributes {
/// (corresponding to LLVM's dereferenceable_or_null attributes, i.e., it is okay for this to be
/// set on a null pointer, but all non-null pointers must be dereferenceable).
pub pointee_size: Size,
/// The minimum alignment of the pointee, if any.
pub pointee_align: Option<Align>,
}

Expand Down
23 changes: 22 additions & 1 deletion compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{fmt, io};

use rustc_abi::{Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors};
use rustc_abi::{
Align, Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors,
};
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
use rustc_fs_util::try_canonicalize;
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
Expand Down Expand Up @@ -3598,6 +3600,25 @@ impl Target {
_ => return None,
})
}

/// Returns whether this target is known to have unreliable alignment:
/// native C code for the target fails to align some data to the degree
/// required by the C standard. We can't *really* do anything about that
/// since unsafe Rust code may assume alignment any time, but we can at least
/// inhibit some optimizations, and we suppress the alignment checks that
/// would detect this unsoundness.
///
/// Every target that returns less than `Align::MAX` here is still has a soundness bug.
pub fn max_reliable_alignment(&self) -> Align {
// FIXME(#112480) MSVC on x86-32 is unsound and fails to properly align many types with
// more-than-4-byte-alignment on the stack. This makes alignments larger than 4 generally
// unreliable on 32bit Windows.
if self.is_like_windows && self.arch == "x86" {
Align::from_bytes(4).unwrap()
} else {
Align::MAX
}
}
}

/// Either a target tuple string or a path to a JSON file.
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ty_utils/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ fn adjust_for_rust_scalar<'tcx>(
None
};
if let Some(kind) = kind {
attrs.pointee_align = Some(pointee.align);
attrs.pointee_align =
Some(pointee.align.min(cx.tcx().sess.target.max_reliable_alignment()));

// `Box` are not necessarily dereferenceable for the entire duration of the function as
// they can be deallocated at any time. Same for non-frozen shared references (see
Expand Down
12 changes: 7 additions & 5 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ target | notes
-------|-------
[`aarch64-apple-darwin`](platform-support/apple-darwin.md) | ARM64 macOS (11.0+, Big Sur+)
`aarch64-unknown-linux-gnu` | ARM64 Linux (kernel 4.1, glibc 2.17+)
`i686-pc-windows-msvc` | 32-bit MSVC (Windows 10+, Windows Server 2016+, Pentium 4) [^x86_32-floats-return-ABI]
`i686-pc-windows-msvc` | 32-bit MSVC (Windows 10+, Windows Server 2016+, Pentium 4) [^x86_32-floats-return-ABI] [^win32-msvc-alignment]
`i686-unknown-linux-gnu` | 32-bit Linux (kernel 3.2+, glibc 2.17+, Pentium 4) [^x86_32-floats-return-ABI]
[`x86_64-apple-darwin`](platform-support/apple-darwin.md) | 64-bit macOS (10.12+, Sierra+)
[`x86_64-pc-windows-gnu`](platform-support/windows-gnu.md) | 64-bit MinGW (Windows 10+, Windows Server 2016+)
Expand All @@ -43,6 +43,8 @@ target | notes

[^x86_32-floats-return-ABI]: Due to limitations of the C ABI, floating-point support on `i686` targets is non-compliant: floating-point return values are passed via an x87 register, so NaN payload bits can be lost. Functions with the default Rust ABI are not affected. See [issue #115567][x86-32-float-return-issue].

[^win32-msvc-alignment]: Due to non-standard behavior of MSVC, native C code on this target can cause types with an alignment of more than 4 bytes to be incorrectly aligned to only 4 bytes (this affects, e.g., `u64` and `i64`). Rust applies some mitigations to reduce the impact of this issue, but this can still cause unsoundness due to unsafe code that (correctly) assumes that references are always properly aligned. See [issue #112480](https://github.com/rust-lang/rust/issues/112480).

[77071]: https://github.com/rust-lang/rust/issues/77071
[x86-32-float-return-issue]: https://github.com/rust-lang/rust/issues/115567

Expand Down Expand Up @@ -95,7 +97,7 @@ target | notes
[`armv7-unknown-linux-ohos`](platform-support/openharmony.md) | Armv7-A OpenHarmony
[`loongarch64-unknown-linux-gnu`](platform-support/loongarch-linux.md) | LoongArch64 Linux, LP64D ABI (kernel 5.19, glibc 2.36)
[`loongarch64-unknown-linux-musl`](platform-support/loongarch-linux.md) | LoongArch64 Linux, LP64D ABI (kernel 5.19, musl 1.2.5)
[`i686-pc-windows-gnu`](platform-support/windows-gnu.md) | 32-bit MinGW (Windows 10+, Windows Server 2016+, Pentium 4) [^x86_32-floats-return-ABI]
[`i686-pc-windows-gnu`](platform-support/windows-gnu.md) | 32-bit MinGW (Windows 10+, Windows Server 2016+, Pentium 4) [^x86_32-floats-return-ABI] [^win32-msvc-alignment]
`powerpc-unknown-linux-gnu` | PowerPC Linux (kernel 3.2, glibc 2.17)
`powerpc64-unknown-linux-gnu` | PPC64 Linux (kernel 3.2, glibc 2.17)
[`powerpc64le-unknown-linux-gnu`](platform-support/powerpc64le-unknown-linux-gnu.md) | PPC64LE Linux (kernel 3.10, glibc 2.17)
Expand Down Expand Up @@ -169,7 +171,7 @@ target | std | notes
[`i686-pc-windows-gnullvm`](platform-support/windows-gnullvm.md) | ✓ | 32-bit x86 MinGW (Windows 10+, Pentium 4), LLVM ABI [^x86_32-floats-return-ABI]
[`i686-unknown-freebsd`](platform-support/freebsd.md) | ✓ | 32-bit x86 FreeBSD (Pentium 4) [^x86_32-floats-return-ABI]
`i686-unknown-linux-musl` | ✓ | 32-bit Linux with musl 1.2.3 (Pentium 4) [^x86_32-floats-return-ABI]
[`i686-unknown-uefi`](platform-support/unknown-uefi.md) | ? | 32-bit UEFI (Pentium 4, softfloat)
[`i686-unknown-uefi`](platform-support/unknown-uefi.md) | ? | 32-bit UEFI (Pentium 4, softfloat) [^win32-msvc-alignment]
[`loongarch64-unknown-none`](platform-support/loongarch-none.md) | * | LoongArch64 Bare-metal (LP64D ABI)
[`loongarch64-unknown-none-softfloat`](platform-support/loongarch-none.md) | * | LoongArch64 Bare-metal (LP64S ABI)
[`nvptx64-nvidia-cuda`](platform-support/nvptx64-nvidia-cuda.md) | * | --emit=asm generates PTX code that [runs on NVIDIA GPUs]
Expand Down Expand Up @@ -317,9 +319,9 @@ target | std | host | notes
[`i686-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/i386 (Pentium 4) [^x86_32-floats-return-ABI]
[`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD (Pentium 4) [^x86_32-floats-return-ABI]
`i686-uwp-windows-gnu` | ✓ | | [^x86_32-floats-return-ABI]
[`i686-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | ✓ | | [^x86_32-floats-return-ABI]
[`i686-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | ✓ | | [^x86_32-floats-return-ABI] [^win32-msvc-alignment]
[`i686-win7-windows-gnu`](platform-support/win7-windows-gnu.md) | ✓ | | 32-bit Windows 7 support [^x86_32-floats-return-ABI]
[`i686-win7-windows-msvc`](platform-support/win7-windows-msvc.md) | ✓ | | 32-bit Windows 7 support [^x86_32-floats-return-ABI]
[`i686-win7-windows-msvc`](platform-support/win7-windows-msvc.md) | ✓ | | 32-bit Windows 7 support [^x86_32-floats-return-ABI] [^win32-msvc-alignment]
[`i686-wrs-vxworks`](platform-support/vxworks.md) | ✓ | | [^x86_32-floats-return-ABI]
[`loongarch64-unknown-linux-ohos`](platform-support/openharmony.md) | ✓ | | LoongArch64 OpenHarmony
[`m68k-unknown-linux-gnu`](platform-support/m68k-unknown-linux-gnu.md) | ? | | Motorola 680x0 Linux
Expand Down
4 changes: 3 additions & 1 deletion tests/codegen/align-struct.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0
//
// 32bit MSVC does not align things properly so we suppress high alignment annotations (#112480)
//@ ignore-i686-pc-windows-msvc
//@ ignore-i686-pc-windows-gnu

#![crate_type = "lib"]

Expand Down
3 changes: 3 additions & 0 deletions tests/codegen/issues/issue-56927.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//@ compile-flags: -C no-prepopulate-passes
// 32bit MSVC does not align things properly so we suppress high alignment annotations (#112480)
//@ ignore-i686-pc-windows-msvc
//@ ignore-i686-pc-windows-gnu

#![crate_type = "rlib"]

Expand Down