Skip to content

Commit 015d2bc

Browse files
committed
Auto merge of #83864 - Dylan-DPC:rollup-78an86n, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #80525 (wasm64 support) - #83019 (core: disable `ptr::swap_nonoverlapping_one`'s block optimization on SPIR-V.) - #83717 (rustdoc: Separate filter-empty-string out into its own function) - #83807 (Tests: Remove redundant `ignore-tidy-linelength` annotations) - #83815 (ptr::addr_of documentation improvements) - #83820 (Remove attribute `#[link_args]`) - #83841 (Allow clobbering unsupported registers in asm!) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 35aa636 + f8709ec commit 015d2bc

File tree

319 files changed

+1914
-2142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

319 files changed

+1914
-2142
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+50-32
Original file line numberDiff line numberDiff line change
@@ -1499,46 +1499,64 @@ impl<'hir> LoweringContext<'_, 'hir> {
14991499
// previous iteration.
15001500
required_features.clear();
15011501

1502-
// Validate register classes against currently enabled target
1503-
// features. We check that at least one type is available for
1504-
// the current target.
15051502
let reg_class = reg.reg_class();
15061503
if reg_class == asm::InlineAsmRegClass::Err {
15071504
continue;
15081505
}
1509-
for &(_, feature) in reg_class.supported_types(asm_arch.unwrap()) {
1510-
if let Some(feature) = feature {
1511-
if self.sess.target_features.contains(&Symbol::intern(feature)) {
1506+
1507+
// We ignore target feature requirements for clobbers: if the
1508+
// feature is disabled then the compiler doesn't care what we
1509+
// do with the registers.
1510+
//
1511+
// Note that this is only possible for explicit register
1512+
// operands, which cannot be used in the asm string.
1513+
let is_clobber = matches!(
1514+
op,
1515+
hir::InlineAsmOperand::Out {
1516+
reg: asm::InlineAsmRegOrRegClass::Reg(_),
1517+
late: _,
1518+
expr: None
1519+
}
1520+
);
1521+
1522+
if !is_clobber {
1523+
// Validate register classes against currently enabled target
1524+
// features. We check that at least one type is available for
1525+
// the current target.
1526+
for &(_, feature) in reg_class.supported_types(asm_arch.unwrap()) {
1527+
if let Some(feature) = feature {
1528+
if self.sess.target_features.contains(&Symbol::intern(feature)) {
1529+
required_features.clear();
1530+
break;
1531+
} else {
1532+
required_features.push(feature);
1533+
}
1534+
} else {
15121535
required_features.clear();
15131536
break;
1514-
} else {
1515-
required_features.push(feature);
15161537
}
1517-
} else {
1518-
required_features.clear();
1519-
break;
15201538
}
1521-
}
1522-
// We are sorting primitive strs here and can use unstable sort here
1523-
required_features.sort_unstable();
1524-
required_features.dedup();
1525-
match &required_features[..] {
1526-
[] => {}
1527-
[feature] => {
1528-
let msg = format!(
1529-
"register class `{}` requires the `{}` target feature",
1530-
reg_class.name(),
1531-
feature
1532-
);
1533-
sess.struct_span_err(op_sp, &msg).emit();
1534-
}
1535-
features => {
1536-
let msg = format!(
1537-
"register class `{}` requires at least one target feature: {}",
1538-
reg_class.name(),
1539-
features.join(", ")
1540-
);
1541-
sess.struct_span_err(op_sp, &msg).emit();
1539+
// We are sorting primitive strs here and can use unstable sort here
1540+
required_features.sort_unstable();
1541+
required_features.dedup();
1542+
match &required_features[..] {
1543+
[] => {}
1544+
[feature] => {
1545+
let msg = format!(
1546+
"register class `{}` requires the `{}` target feature",
1547+
reg_class.name(),
1548+
feature
1549+
);
1550+
sess.struct_span_err(op_sp, &msg).emit();
1551+
}
1552+
features => {
1553+
let msg = format!(
1554+
"register class `{}` requires at least one target feature: {}",
1555+
reg_class.name(),
1556+
features.join(", ")
1557+
);
1558+
sess.struct_span_err(op_sp, &msg).emit();
1559+
}
15421560
}
15431561
}
15441562

compiler/rustc_codegen_llvm/src/asm.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxHashMap;
1414
use rustc_hir as hir;
1515
use rustc_middle::ty::layout::TyAndLayout;
1616
use rustc_middle::{bug, span_bug};
17-
use rustc_span::{Pos, Span};
17+
use rustc_span::{Pos, Span, Symbol};
1818
use rustc_target::abi::*;
1919
use rustc_target::asm::*;
2020

@@ -125,15 +125,39 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
125125

126126
// Collect the types of output operands
127127
let mut constraints = vec![];
128+
let mut clobbers = vec![];
128129
let mut output_types = vec![];
129130
let mut op_idx = FxHashMap::default();
130131
for (idx, op) in operands.iter().enumerate() {
131132
match *op {
132133
InlineAsmOperandRef::Out { reg, late, place } => {
134+
let is_target_supported = |reg_class: InlineAsmRegClass| {
135+
for &(_, feature) in reg_class.supported_types(asm_arch) {
136+
if let Some(feature) = feature {
137+
if self.tcx.sess.target_features.contains(&Symbol::intern(feature))
138+
{
139+
return true;
140+
}
141+
} else {
142+
// Register class is unconditionally supported
143+
return true;
144+
}
145+
}
146+
false
147+
};
148+
133149
let mut layout = None;
134150
let ty = if let Some(ref place) = place {
135151
layout = Some(&place.layout);
136152
llvm_fixup_output_type(self.cx, reg.reg_class(), &place.layout)
153+
} else if !is_target_supported(reg.reg_class()) {
154+
// We turn discarded outputs into clobber constraints
155+
// if the target feature needed by the register class is
156+
// disabled. This is necessary otherwise LLVM will try
157+
// to actually allocate a register for the dummy output.
158+
assert!(matches!(reg, InlineAsmRegOrRegClass::Reg(_)));
159+
clobbers.push(format!("~{}", reg_to_llvm(reg, None)));
160+
continue;
137161
} else {
138162
// If the output is discarded, we don't really care what
139163
// type is used. We're just using this to tell LLVM to
@@ -244,6 +268,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
244268
}
245269
}
246270

271+
constraints.append(&mut clobbers);
247272
if !options.contains(InlineAsmOptions::PRESERVES_FLAGS) {
248273
match asm_arch {
249274
InlineAsmArch::AArch64 | InlineAsmArch::Arm => {

compiler/rustc_codegen_llvm/src/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
317317
// Note that currently the `wasm-import-module` doesn't do anything, but
318318
// eventually LLVM 7 should read this and ferry the appropriate import
319319
// module to the output file.
320-
if cx.tcx.sess.target.arch == "wasm32" {
320+
if cx.tcx.sess.target.is_like_wasm {
321321
if let Some(module) = wasm_import_module(cx.tcx, instance.def_id()) {
322322
llvm::AddFunctionAttrStringValue(
323323
llfn,

compiler/rustc_codegen_llvm/src/back/write.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,7 @@ pub fn target_machine_factory(
170170
// On the wasm target once the `atomics` feature is enabled that means that
171171
// we're no longer single-threaded, or otherwise we don't want LLVM to
172172
// lower atomic operations to single-threaded operations.
173-
if singlethread
174-
&& sess.target.llvm_target.contains("wasm32")
175-
&& sess.target_features.contains(&sym::atomics)
176-
{
173+
if singlethread && sess.target.is_like_wasm && sess.target_features.contains(&sym::atomics) {
177174
singlethread = false;
178175
}
179176

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,9 @@ pub fn compile_unit_metadata(
10831083
);
10841084
}
10851085

1086-
// Insert `llvm.ident` metadata on the wasm32 targets since that will
1086+
// Insert `llvm.ident` metadata on the wasm targets since that will
10871087
// get hooked up to the "producer" sections `processed-by` information.
1088-
if tcx.sess.opts.target_triple.triple().starts_with("wasm32") {
1088+
if tcx.sess.target.is_like_wasm {
10891089
let name_metadata = llvm::LLVMMDStringInContext(
10901090
debug_context.llcontext,
10911091
rustc_producer.as_ptr().cast(),

compiler/rustc_codegen_ssa/src/back/link.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1411,15 +1411,10 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty
14111411
}
14121412
}
14131413

1414-
/// Add arbitrary "user defined" args defined from command line and by `#[link_args]` attributes.
1414+
/// Add arbitrary "user defined" args defined from command line.
14151415
/// FIXME: Determine where exactly these args need to be inserted.
1416-
fn add_user_defined_link_args(
1417-
cmd: &mut dyn Linker,
1418-
sess: &Session,
1419-
codegen_results: &CodegenResults,
1420-
) {
1416+
fn add_user_defined_link_args(cmd: &mut dyn Linker, sess: &Session) {
14211417
cmd.args(&sess.opts.cg.link_args);
1422-
cmd.args(&*codegen_results.crate_info.link_args);
14231418
}
14241419

14251420
/// Add arbitrary "late link" args defined by the target spec.
@@ -1761,7 +1756,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
17611756
add_rpath_args(cmd, sess, codegen_results, out_filename);
17621757

17631758
// OBJECT-FILES-MAYBE, CUSTOMIZATION-POINT
1764-
add_user_defined_link_args(cmd, sess, codegen_results);
1759+
add_user_defined_link_args(cmd, sess);
17651760

17661761
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
17671762
cmd.finalize();

compiler/rustc_codegen_ssa/src/back/linker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a> GccLinker<'a> {
186186
// * On OSX they have their own linker, not binutils'
187187
// * For WebAssembly the only functional linker is LLD, which doesn't
188188
// support hint flags
189-
!self.sess.target.is_like_osx && self.sess.target.arch != "wasm32"
189+
!self.sess.target.is_like_osx && !self.sess.target.is_like_wasm
190190
}
191191

192192
// Some platforms take hints about whether a library is static or dynamic.

compiler/rustc_codegen_ssa/src/base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@ impl CrateInfo {
754754
is_no_builtins: Default::default(),
755755
native_libraries: Default::default(),
756756
used_libraries: tcx.native_libraries(LOCAL_CRATE).iter().map(Into::into).collect(),
757-
link_args: tcx.link_args(LOCAL_CRATE),
758757
crate_name: Default::default(),
759758
used_crates_dynamic: cstore::used_crates(tcx, LinkagePreference::RequireDynamic),
760759
used_crates_static: cstore::used_crates(tcx, LinkagePreference::RequireStatic),

compiler/rustc_codegen_ssa/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ pub struct CrateInfo {
139139
pub native_libraries: FxHashMap<CrateNum, Vec<NativeLib>>,
140140
pub crate_name: FxHashMap<CrateNum, String>,
141141
pub used_libraries: Vec<NativeLib>,
142-
pub link_args: Lrc<Vec<String>>,
143142
pub used_crate_source: FxHashMap<CrateNum, Lrc<CrateSource>>,
144143
pub used_crates_static: Vec<(CrateNum, LibSource)>,
145144
pub used_crates_dynamic: Vec<(CrateNum, LibSource)>,

compiler/rustc_codegen_ssa/src/target_features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
161161
"mips" | "mips64" => MIPS_ALLOWED_FEATURES,
162162
"powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
163163
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
164-
"wasm32" => WASM_ALLOWED_FEATURES,
164+
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
165165
_ => &[],
166166
}
167167
}

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ declare_features! (
258258
// feature-group-start: actual feature gates
259259
// -------------------------------------------------------------------------
260260

261-
/// Allows using the `#[link_args]` attribute.
262-
(active, link_args, "1.0.0", Some(29596), None),
263-
264261
/// Allows defining identifiers beyond ASCII.
265262
(active, non_ascii_idents, "1.0.0", Some(55467), None),
266263

compiler/rustc_feature/src/builtin_attrs.rs

-5
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
279279

280280
// Linking:
281281
gated!(naked, AssumedUsed, template!(Word), naked_functions, experimental!(naked)),
282-
gated!(
283-
link_args, Normal, template!(NameValueStr: "args"),
284-
"the `link_args` attribute is experimental and not portable across platforms, \
285-
it is recommended to use `#[link(name = \"foo\")] instead",
286-
),
287282
gated!(
288283
link_ordinal, AssumedUsed, template!(List: "ordinal"), raw_dylib,
289284
experimental!(link_ordinal)

compiler/rustc_feature/src/removed.rs

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ declare_features! (
128128
/// Allows comparing raw pointers during const eval.
129129
(removed, const_compare_raw_pointers, "1.46.0", Some(53020), None,
130130
Some("cannot be allowed in const eval in any meaningful way")),
131+
/// Allows using the `#[link_args]` attribute.
132+
(removed, link_args, "1.53.0", Some(29596), None,
133+
Some("removed in favor of using `-C link-arg=ARG` on command line, \
134+
which is available from cargo build scripts with `cargo:rustc-link-arg` now")),
131135

132136
// -------------------------------------------------------------------------
133137
// feature-group-end: removed features

compiler/rustc_metadata/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub use rmeta::{provide, provide_extern};
2626

2727
mod dependency_format;
2828
mod foreign_modules;
29-
mod link_args;
3029
mod native_libs;
3130
mod rmeta;
3231

compiler/rustc_metadata/src/link_args.rs

-57
This file was deleted.

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::creader::{CStore, LoadedMacro};
22
use crate::foreign_modules;
3-
use crate::link_args;
43
use crate::native_libs;
54
use crate::rmeta::{self, encoder};
65

@@ -295,10 +294,6 @@ pub fn provide(providers: &mut Providers) {
295294
foreign_modules::collect(tcx).into_iter().map(|m| (m.def_id, m)).collect();
296295
Lrc::new(modules)
297296
},
298-
link_args: |tcx, cnum| {
299-
assert_eq!(cnum, LOCAL_CRATE);
300-
Lrc::new(link_args::collect(tcx))
301-
},
302297

303298
// Returns a map from a sufficiently visible external item (i.e., an
304299
// external item that is visible from at least one local module) to a

compiler/rustc_middle/src/query/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1253,11 +1253,6 @@ rustc_queries! {
12531253
desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
12541254
}
12551255

1256-
query link_args(_: CrateNum) -> Lrc<Vec<String>> {
1257-
eval_always
1258-
desc { "looking up link arguments for a crate" }
1259-
}
1260-
12611256
/// Does lifetime resolution, but does not descend into trait items. This
12621257
/// should only be used for resolving lifetimes of on trait definitions,
12631258
/// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits

compiler/rustc_session/src/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,9 @@ pub fn default_configuration(sess: &Session) -> CrateConfig {
822822
}
823823
}
824824
ret.insert((sym::target_arch, Some(Symbol::intern(arch))));
825+
if sess.target.is_like_wasm {
826+
ret.insert((sym::wasm, None));
827+
}
825828
ret.insert((sym::target_endian, Some(Symbol::intern(end.as_str()))));
826829
ret.insert((sym::target_pointer_width, Some(Symbol::intern(&wordsz))));
827830
ret.insert((sym::target_env, Some(Symbol::intern(env))));

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,7 @@ symbols! {
12941294
vreg,
12951295
vreg_low16,
12961296
warn,
1297+
wasm,
12971298
wasm_import_module,
12981299
wasm_target_feature,
12991300
while_let,

0 commit comments

Comments
 (0)