Skip to content

Commit 3c877f6

Browse files
committed
Auto merge of rust-lang#140245 - matthiaskrgr:rollup-e0fwsfv, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#139261 (mitigate MSVC alignment issue on x86-32) - rust-lang#140075 (Mention average in midpoint documentations) - rust-lang#140184 (Update doc of cygwin target) - rust-lang#140186 (Rename `compute_x` methods) - rust-lang#140194 (minicore: Have `//@ add-core-stubs` also imply `-Cforce-unwind-tables=yes`) - rust-lang#140195 (triagebot: label minicore changes w/ `A-test-infra-minicore` and ping jieyouxu on changes) - rust-lang#140214 (Remove comment about handling non-global where bounds with corresponding projection) - rust-lang#140228 (Revert overzealous parse recovery for single colons in paths) r? `@ghost` `@rustbot` modify labels: rollup
2 parents dc8fe1f + f45d2bd commit 3c877f6

File tree

31 files changed

+252
-166
lines changed

31 files changed

+252
-166
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+2
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
594594
fn load(&mut self, ty: &'ll Type, ptr: &'ll Value, align: Align) -> &'ll Value {
595595
unsafe {
596596
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED);
597+
let align = align.min(self.cx().tcx.sess.target.max_reliable_alignment());
597598
llvm::LLVMSetAlignment(load, align.bytes() as c_uint);
598599
load
599600
}
@@ -807,6 +808,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
807808
assert_eq!(self.cx.type_kind(self.cx.val_ty(ptr)), TypeKind::Pointer);
808809
unsafe {
809810
let store = llvm::LLVMBuildStore(self.llbuilder, val, ptr);
811+
let align = align.min(self.cx().tcx.sess.target.max_reliable_alignment());
810812
let align =
811813
if flags.contains(MemFlags::UNALIGNED) { 1 } else { align.bytes() as c_uint };
812814
llvm::LLVMSetAlignment(store, align);

compiler/rustc_mir_transform/src/check_alignment.rs

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_abi::Align;
12
use rustc_index::IndexVec;
23
use rustc_middle::mir::interpret::Scalar;
34
use rustc_middle::mir::visit::PlaceContext;
@@ -11,10 +12,6 @@ pub(super) struct CheckAlignment;
1112

1213
impl<'tcx> crate::MirPass<'tcx> for CheckAlignment {
1314
fn is_enabled(&self, sess: &Session) -> bool {
14-
// FIXME(#112480) MSVC and rustc disagree on minimum stack alignment on x86 Windows
15-
if sess.target.llvm_target == "i686-pc-windows-msvc" {
16-
return false;
17-
}
1815
sess.ub_checks()
1916
}
2017

@@ -87,6 +84,33 @@ fn insert_alignment_check<'tcx>(
8784
))),
8885
});
8986

87+
// If this target does not have reliable alignment, further limit the mask by anding it with
88+
// the mask for the highest reliable alignment.
89+
#[allow(irrefutable_let_patterns)]
90+
if let max_align = tcx.sess.target.max_reliable_alignment()
91+
&& max_align < Align::MAX
92+
{
93+
let max_mask = max_align.bytes() - 1;
94+
let max_mask = Operand::Constant(Box::new(ConstOperand {
95+
span: source_info.span,
96+
user_ty: None,
97+
const_: Const::Val(
98+
ConstValue::Scalar(Scalar::from_target_usize(max_mask, &tcx)),
99+
tcx.types.usize,
100+
),
101+
}));
102+
stmts.push(Statement {
103+
source_info,
104+
kind: StatementKind::Assign(Box::new((
105+
alignment_mask,
106+
Rvalue::BinaryOp(
107+
BinOp::BitAnd,
108+
Box::new((Operand::Copy(alignment_mask), max_mask)),
109+
),
110+
))),
111+
});
112+
}
113+
90114
// BitAnd the alignment mask with the pointer
91115
let alignment_bits =
92116
local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into();

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1308,18 +1308,6 @@ where
13081308
return true;
13091309
}
13101310

1311-
// We don't consider a trait-bound global if it has a projection bound.
1312-
//
1313-
// See ui/traits/next-solver/normalization-shadowing/global-trait-with-project.rs
1314-
// for an example where this is necessary.
1315-
for p in goal.param_env.caller_bounds().iter() {
1316-
if let ty::ClauseKind::Projection(proj) = p.kind().skip_binder() {
1317-
if proj.projection_term.trait_ref(self.cx()) == trait_pred.trait_ref {
1318-
return true;
1319-
}
1320-
}
1321-
}
1322-
13231311
false
13241312
}
13251313
_ => false,

compiler/rustc_parse/src/parser/item.rs

+11
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,17 @@ impl<'a> Parser<'a> {
20582058
}
20592059
self.expect_field_ty_separator()?;
20602060
let ty = self.parse_ty()?;
2061+
if self.token == token::Colon && self.look_ahead(1, |&t| t != token::Colon) {
2062+
self.dcx()
2063+
.struct_span_err(self.token.span, "found single colon in a struct field type path")
2064+
.with_span_suggestion_verbose(
2065+
self.token.span,
2066+
"write a path separator here",
2067+
"::",
2068+
Applicability::MaybeIncorrect,
2069+
)
2070+
.emit();
2071+
}
20612072
let default = if self.token == token::Eq {
20622073
self.bump();
20632074
let const_expr = self.parse_expr_anon_const()?;

compiler/rustc_parse/src/parser/path.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,13 @@ impl<'a> Parser<'a> {
248248
segments.push(segment);
249249

250250
if self.is_import_coupler() || !self.eat_path_sep() {
251-
let ok_for_recovery = self.may_recover()
252-
&& match style {
253-
PathStyle::Expr => true,
254-
PathStyle::Type if let Some((ident, _)) = self.prev_token.ident() => {
255-
self.token == token::Colon
256-
&& ident.as_str().chars().all(|c| c.is_lowercase())
257-
&& self.token.span.lo() == self.prev_token.span.hi()
258-
&& self
259-
.look_ahead(1, |token| self.token.span.hi() == token.span.lo())
260-
}
261-
_ => false,
262-
};
263-
if ok_for_recovery
251+
// IMPORTANT: We can *only ever* treat single colons as typo'ed double colons in
252+
// expression contexts (!) since only there paths cannot possibly be followed by
253+
// a colon and still form a syntactically valid construct. In pattern contexts,
254+
// a path may be followed by a type annotation. E.g., `let pat:ty`. In type
255+
// contexts, a path may be followed by a list of bounds. E.g., `where ty:bound`.
256+
if self.may_recover()
257+
&& style == PathStyle::Expr // (!)
264258
&& self.token == token::Colon
265259
&& self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident())
266260
{

compiler/rustc_target/src/callconv/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ pub struct ArgAttributes {
144144
/// (corresponding to LLVM's dereferenceable_or_null attributes, i.e., it is okay for this to be
145145
/// set on a null pointer, but all non-null pointers must be dereferenceable).
146146
pub pointee_size: Size,
147+
/// The minimum alignment of the pointee, if any.
147148
pub pointee_align: Option<Align>,
148149
}
149150

compiler/rustc_target/src/spec/mod.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ use std::path::{Path, PathBuf};
4242
use std::str::FromStr;
4343
use std::{fmt, io};
4444

45-
use rustc_abi::{Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors};
45+
use rustc_abi::{
46+
Align, Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors,
47+
};
4648
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
4749
use rustc_fs_util::try_canonicalize;
4850
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
@@ -3599,6 +3601,25 @@ impl Target {
35993601
_ => return None,
36003602
})
36013603
}
3604+
3605+
/// Returns whether this target is known to have unreliable alignment:
3606+
/// native C code for the target fails to align some data to the degree
3607+
/// required by the C standard. We can't *really* do anything about that
3608+
/// since unsafe Rust code may assume alignment any time, but we can at least
3609+
/// inhibit some optimizations, and we suppress the alignment checks that
3610+
/// would detect this unsoundness.
3611+
///
3612+
/// Every target that returns less than `Align::MAX` here is still has a soundness bug.
3613+
pub fn max_reliable_alignment(&self) -> Align {
3614+
// FIXME(#112480) MSVC on x86-32 is unsound and fails to properly align many types with
3615+
// more-than-4-byte-alignment on the stack. This makes alignments larger than 4 generally
3616+
// unreliable on 32bit Windows.
3617+
if self.is_like_windows && self.arch == "x86" {
3618+
Align::from_bytes(4).unwrap()
3619+
} else {
3620+
Align::MAX
3621+
}
3622+
}
36023623
}
36033624

36043625
/// Either a target tuple string or a path to a JSON file.

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
240240
if !drcx.args_may_unify(obligation_args, bound_trait_ref.skip_binder().args) {
241241
continue;
242242
}
243-
// FIXME(oli-obk): it is suspicious that we are dropping the constness and
244-
// polarity here.
245243
let wc = self.where_clause_may_apply(stack, bound_trait_ref)?;
246244
if wc.may_apply() {
247245
candidates.vec.push(ParamCandidate(bound));

0 commit comments

Comments
 (0)