Skip to content

Rollup of 8 pull requests #140245

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

Merged
merged 20 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
17664d1
Update doc of cygwin target
Berrysoft Apr 23, 2025
0a76ef8
Rename `compute_x` methods
BoxyUwU Apr 23, 2025
c6e6ac9
Module docs
BoxyUwU 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
1162f42
Remove hack
compiler-errors Apr 23, 2025
16da97b
Revert overzealous parse recovery for single colons
fmease Apr 24, 2025
e88b289
Mention average in midpoint documentations
Urgau Apr 20, 2025
a8ebfb2
Rollup merge of #139261 - RalfJung:msvc-align-mitigation, r=oli-obk
matthiaskrgr Apr 24, 2025
d08a527
Rollup merge of #140075 - Urgau:midpoint-average, r=tgross35
matthiaskrgr Apr 24, 2025
93c1e05
Rollup merge of #140184 - Berrysoft:cygwin-target-doc, r=Noratrieb
matthiaskrgr Apr 24, 2025
60c2c34
Rollup merge of #140186 - BoxyUwU:compute_what, r=compiler-errors
matthiaskrgr Apr 24, 2025
a90f31e
Rollup merge of #140194 - jieyouxu:minicore-force-unwind-tables, r=bj…
matthiaskrgr Apr 24, 2025
984ef2c
Rollup merge of #140195 - jieyouxu:minicore-triagebot, r=jieyouxu
matthiaskrgr Apr 24, 2025
1553cfa
Rollup merge of #140214 - compiler-errors:remove-hack, r=lcnr
matthiaskrgr Apr 24, 2025
f45d2bd
Rollup merge of #140228 - fmease:revert-overzealous-colon-recovery, r…
matthiaskrgr 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
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
32 changes: 28 additions & 4 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,10 +12,6 @@ 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" {
return false;
}
sess.ub_checks()
}

Expand Down Expand Up @@ -87,6 +84,33 @@ fn insert_alignment_check<'tcx>(
))),
});

// If this target does not have reliable alignment, further limit the mask by anding it with
// the mask for the highest reliable alignment.
#[allow(irrefutable_let_patterns)]
if let max_align = tcx.sess.target.max_reliable_alignment()
&& max_align < Align::MAX
{
let max_mask = max_align.bytes() - 1;
let max_mask = Operand::Constant(Box::new(ConstOperand {
span: source_info.span,
user_ty: None,
const_: Const::Val(
ConstValue::Scalar(Scalar::from_target_usize(max_mask, &tcx)),
tcx.types.usize,
),
}));
stmts.push(Statement {
source_info,
kind: StatementKind::Assign(Box::new((
alignment_mask,
Rvalue::BinaryOp(
BinOp::BitAnd,
Box::new((Operand::Copy(alignment_mask), max_mask)),
),
))),
});
}

// BitAnd the alignment mask with the pointer
let alignment_bits =
local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into();
Expand Down
12 changes: 0 additions & 12 deletions compiler/rustc_next_trait_solver/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,18 +1308,6 @@ where
return true;
}

// We don't consider a trait-bound global if it has a projection bound.
//
// See ui/traits/next-solver/normalization-shadowing/global-trait-with-project.rs
// for an example where this is necessary.
for p in goal.param_env.caller_bounds().iter() {
if let ty::ClauseKind::Projection(proj) = p.kind().skip_binder() {
if proj.projection_term.trait_ref(self.cx()) == trait_pred.trait_ref {
return true;
}
}
}

false
}
_ => false,
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,17 @@ impl<'a> Parser<'a> {
}
self.expect_field_ty_separator()?;
let ty = self.parse_ty()?;
if self.token == token::Colon && self.look_ahead(1, |&t| t != token::Colon) {
self.dcx()
.struct_span_err(self.token.span, "found single colon in a struct field type path")
.with_span_suggestion_verbose(
self.token.span,
"write a path separator here",
"::",
Applicability::MaybeIncorrect,
)
.emit();
}
let default = if self.token == token::Eq {
self.bump();
let const_expr = self.parse_expr_anon_const()?;
Expand Down
20 changes: 7 additions & 13 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,13 @@ impl<'a> Parser<'a> {
segments.push(segment);

if self.is_import_coupler() || !self.eat_path_sep() {
let ok_for_recovery = self.may_recover()
&& match style {
PathStyle::Expr => true,
PathStyle::Type if let Some((ident, _)) = self.prev_token.ident() => {
self.token == token::Colon
&& ident.as_str().chars().all(|c| c.is_lowercase())
&& self.token.span.lo() == self.prev_token.span.hi()
&& self
.look_ahead(1, |token| self.token.span.hi() == token.span.lo())
}
_ => false,
};
if ok_for_recovery
// IMPORTANT: We can *only ever* treat single colons as typo'ed double colons in
// expression contexts (!) since only there paths cannot possibly be followed by
// a colon and still form a syntactically valid construct. In pattern contexts,
// a path may be followed by a type annotation. E.g., `let pat:ty`. In type
// contexts, a path may be followed by a list of bounds. E.g., `where ty:bound`.
if self.may_recover()
&& style == PathStyle::Expr // (!)
&& self.token == token::Colon
&& self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident())
{
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 @@ -3599,6 +3601,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
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if !drcx.args_may_unify(obligation_args, bound_trait_ref.skip_binder().args) {
continue;
}
// FIXME(oli-obk): it is suspicious that we are dropping the constness and
// polarity here.
let wc = self.where_clause_may_apply(stack, bound_trait_ref)?;
if wc.may_apply() {
candidates.vec.push(ParamCandidate(bound));
Expand Down
Loading
Loading