Skip to content

Commit 8b38707

Browse files
committed
Auto merge of #128796 - matthiaskrgr:rollup-r7l68ph, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #128221 (Add implied target features to target_feature attribute) - #128261 (impl `Default` for collection iterators that don't already have it) - #128353 (Change generate-copyright to generate HTML, with cargo dependencies included) - #128679 (codegen: better centralize function declaration attribute computation) - #128732 (make `import.vis` is immutable) - #128755 (Integrate crlf directly into related test file instead via of .gitattributes) - #128772 (rustc_codegen_ssa: Set architecture for object crate for 32-bit SPARC) - #128782 (unused_parens: do not lint against parens around &raw) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ce20e15 + aba506b commit 8b38707

File tree

56 files changed

+1311
-673
lines changed

Some content is hidden

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

56 files changed

+1311
-673
lines changed

Cargo.lock

+6
Original file line numberDiff line numberDiff line change
@@ -1406,8 +1406,11 @@ name = "generate-copyright"
14061406
version = "0.1.0"
14071407
dependencies = [
14081408
"anyhow",
1409+
"cargo_metadata 0.18.1",
1410+
"rinja",
14091411
"serde",
14101412
"serde_json",
1413+
"thiserror",
14111414
]
14121415

14131416
[[package]]
@@ -3094,7 +3097,10 @@ version = "0.3.0"
30943097
source = "registry+https://github.com/rust-lang/crates.io-index"
30953098
checksum = "6d3762e3740cdbf2fd2be465cc2c26d643ad17353cc2e0223d211c1b096118bd"
30963099
dependencies = [
3100+
"humansize",
30973101
"itoa",
3102+
"num-traits",
3103+
"percent-encoding",
30983104
"rinja_derive",
30993105
]
31003106

REUSE.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ SPDX-License-Identifier = "MIT OR Apache-2.0"
163163
path = "src/llvm-project/**"
164164
precedence = "override"
165165
SPDX-FileCopyrightText = [
166-
"2003-2019 by the contributors listed in [CREDITS.TXT](https://github.com/rust-lang/llvm-project/blob/7738295178045041669876bf32b0543ec8319a5c/llvm/CREDITS.TXT)",
166+
"2003-2019 by the contributors listed in CREDITS.TXT (https://github.com/rust-lang/llvm-project/blob/7738295178045041669876bf32b0543ec8319a5c/llvm/CREDITS.TXT)",
167167
"2010 Apple Inc",
168168
"2003-2019 University of Illinois at Urbana-Champaign.",
169169
]

compiler/rustc_codegen_gcc/src/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
7575
let function_features = codegen_fn_attrs
7676
.target_features
7777
.iter()
78-
.map(|features| features.as_str())
78+
.map(|features| features.name.as_str())
7979
.collect::<Vec<&str>>();
8080

8181
if let Some(features) = check_tied_features(

compiler/rustc_codegen_gcc/src/gcc_util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
6565

6666
let feature = backend_feature_name(s)?;
6767
// Warn against use of GCC specific feature names on the CLI.
68-
if diagnostics && !supported_features.iter().any(|&(v, _)| v == feature) {
69-
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _)| {
68+
if diagnostics && !supported_features.iter().any(|&(v, _, _)| v == feature) {
69+
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _, _)| {
7070
let gcc_features = to_gcc_features(sess, rust_feature);
7171
if gcc_features.contains(&feature) && !gcc_features.contains(&rust_feature) {
7272
Some(rust_feature)

compiler/rustc_codegen_gcc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ pub fn target_features(
486486
sess.target
487487
.supported_target_features()
488488
.iter()
489-
.filter_map(|&(feature, gate)| {
489+
.filter_map(|&(feature, gate, _)| {
490490
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
491491
Some(feature)
492492
} else {

compiler/rustc_codegen_llvm/src/abi.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
55
use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue};
66
use rustc_codegen_ssa::traits::*;
77
use rustc_codegen_ssa::MemFlags;
8-
use rustc_middle::bug;
98
use rustc_middle::ty::layout::LayoutOf;
109
pub use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
1110
use rustc_middle::ty::Ty;
11+
use rustc_middle::{bug, ty};
1212
use rustc_session::config;
1313
pub use rustc_target::abi::call::*;
1414
use rustc_target::abi::{self, HasDataLayout, Int, Size};
1515
pub use rustc_target::spec::abi::Abi;
1616
use rustc_target::spec::SanitizerSet;
1717
use smallvec::SmallVec;
1818

19+
use crate::attributes::llfn_attrs_from_instance;
1920
use crate::builder::Builder;
2021
use crate::context::CodegenCx;
2122
use crate::llvm::{self, Attribute, AttributePlace};
@@ -310,7 +311,16 @@ pub trait FnAbiLlvmExt<'ll, 'tcx> {
310311
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
311312
fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
312313
fn llvm_cconv(&self) -> llvm::CallConv;
313-
fn apply_attrs_llfn(&self, cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value);
314+
315+
/// Apply attributes to a function declaration/definition.
316+
fn apply_attrs_llfn(
317+
&self,
318+
cx: &CodegenCx<'ll, 'tcx>,
319+
llfn: &'ll Value,
320+
instance: Option<ty::Instance<'tcx>>,
321+
);
322+
323+
/// Apply attributes to a function call.
314324
fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value);
315325
}
316326

@@ -396,7 +406,12 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
396406
self.conv.into()
397407
}
398408

399-
fn apply_attrs_llfn(&self, cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value) {
409+
fn apply_attrs_llfn(
410+
&self,
411+
cx: &CodegenCx<'ll, 'tcx>,
412+
llfn: &'ll Value,
413+
instance: Option<ty::Instance<'tcx>>,
414+
) {
400415
let mut func_attrs = SmallVec::<[_; 3]>::new();
401416
if self.ret.layout.abi.is_uninhabited() {
402417
func_attrs.push(llvm::AttributeKind::NoReturn.create_attr(cx.llcx));
@@ -477,6 +492,11 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
477492
}
478493
}
479494
}
495+
496+
// If the declaration has an associated instance, compute extra attributes based on that.
497+
if let Some(instance) = instance {
498+
llfn_attrs_from_instance(cx, llfn, instance);
499+
}
480500
}
481501

482502
fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value) {

compiler/rustc_codegen_llvm/src/attributes.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,10 @@ fn create_alloc_family_attr(llcx: &llvm::Context) -> &llvm::Attribute {
324324
llvm::CreateAttrStringValue(llcx, "alloc-family", "__rust_alloc")
325325
}
326326

327+
/// Helper for `FnAbi::apply_attrs_llfn`:
327328
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
328329
/// attributes.
329-
pub fn from_fn_attrs<'ll, 'tcx>(
330+
pub fn llfn_attrs_from_instance<'ll, 'tcx>(
330331
cx: &CodegenCx<'ll, 'tcx>,
331332
llfn: &'ll Value,
332333
instance: ty::Instance<'tcx>,
@@ -496,7 +497,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
496497
to_add.extend(tune_cpu_attr(cx));
497498

498499
let function_features =
499-
codegen_fn_attrs.target_features.iter().map(|f| f.as_str()).collect::<Vec<&str>>();
500+
codegen_fn_attrs.target_features.iter().map(|f| f.name.as_str()).collect::<Vec<&str>>();
500501

501502
if let Some(f) = llvm_util::check_tied_features(
502503
cx.tcx.sess,

compiler/rustc_codegen_llvm/src/back/write.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,14 @@ pub fn write_output_file<'ll>(
9595
}
9696
}
9797

98-
pub fn create_informational_target_machine(sess: &Session) -> OwnedTargetMachine {
98+
pub fn create_informational_target_machine(
99+
sess: &Session,
100+
only_base_features: bool,
101+
) -> OwnedTargetMachine {
99102
let config = TargetMachineFactoryConfig { split_dwarf_file: None, output_obj_file: None };
100103
// Can't use query system here quite yet because this function is invoked before the query
101104
// system/tcx is set up.
102-
let features = llvm_util::global_llvm_features(sess, false);
105+
let features = llvm_util::global_llvm_features(sess, false, only_base_features);
103106
target_machine_factory(sess, config::OptLevel::No, &features)(config)
104107
.unwrap_or_else(|err| llvm_err(sess.dcx(), err).raise())
105108
}

compiler/rustc_codegen_llvm/src/callee.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_middle::ty::{self, Instance, TypeVisitableExt};
1010
use tracing::debug;
1111

1212
use crate::context::CodegenCx;
13+
use crate::llvm;
1314
use crate::value::Value;
14-
use crate::{attributes, llvm};
1515

1616
/// Codegens a reference to a fn/method item, monomorphizing and
1717
/// inlining as it goes.
@@ -78,8 +78,6 @@ pub fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) ->
7878
};
7979
debug!("get_fn: not casting pointer!");
8080

81-
attributes::from_fn_attrs(cx, llfn, instance);
82-
8381
// Apply an appropriate linkage/visibility value to our item that we
8482
// just declared.
8583
//

compiler/rustc_codegen_llvm/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub unsafe fn create_module<'ll>(
149149

150150
// Ensure the data-layout values hardcoded remain the defaults.
151151
{
152-
let tm = crate::back::write::create_informational_target_machine(tcx.sess);
152+
let tm = crate::back::write::create_informational_target_machine(tcx.sess, false);
153153
unsafe {
154154
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, &tm);
155155
}

compiler/rustc_codegen_llvm/src/declare.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
137137
llvm::Visibility::Default,
138138
fn_abi.llvm_type(self),
139139
);
140-
fn_abi.apply_attrs_llfn(self, llfn);
140+
fn_abi.apply_attrs_llfn(self, llfn, instance);
141141

142142
if self.tcx.sess.is_sanitizer_cfi_enabled() {
143143
if let Some(instance) = instance {

compiler/rustc_codegen_llvm/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl CodegenBackend for LlvmCodegenBackend {
269269

270270
fn provide(&self, providers: &mut Providers) {
271271
providers.global_backend_features =
272-
|tcx, ()| llvm_util::global_llvm_features(tcx.sess, true)
272+
|tcx, ()| llvm_util::global_llvm_features(tcx.sess, true, false)
273273
}
274274

275275
fn print(&self, req: &PrintRequest, out: &mut String, sess: &Session) {
@@ -434,7 +434,7 @@ impl ModuleLlvm {
434434
ModuleLlvm {
435435
llmod_raw,
436436
llcx,
437-
tm: ManuallyDrop::new(create_informational_target_machine(tcx.sess)),
437+
tm: ManuallyDrop::new(create_informational_target_machine(tcx.sess, false)),
438438
}
439439
}
440440
}

0 commit comments

Comments
 (0)