Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 37 additions & 16 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,24 +261,45 @@ impl<'hir> LoweringContext<'_, 'hir> {
if class == asm::InlineAsmRegClass::Err {
continue;
}
let valid_modifiers = class.valid_modifiers(asm_arch.unwrap());
let valid_modifiers =
class.valid_modifiers(asm_arch.unwrap(), allow_experimental_reg);
if !valid_modifiers.contains(&modifier) {
let sub = if valid_modifiers.is_empty() {
InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier {
class_name: class.name(),
}
// First check if the requested modifier is missing from the valid
// values because experimental registers are disabled.
let unstable_modifiers = class.valid_modifiers(asm_arch.unwrap(), true);
if !allow_experimental_reg && unstable_modifiers.contains(&modifier) {
self.tcx.sess.create_feature_err(
InvalidAsmTemplateModifierRegClass {
placeholder_span,
op_span: op_sp,
modifier: modifier.to_string(),
sub: InvalidAsmTemplateModifierRegClassSub::ModifierIsGated {
class_name: class.name(),
feature: sym::asm_experimental_reg,
stable_modifiers: valid_modifiers.to_vec().into(),
all_modifiers: unstable_modifiers.to_vec().into(),
},
},
sym::asm_experimental_reg,
).emit();
} else {
InvalidAsmTemplateModifierRegClassSub::SupportModifier {
class_name: class.name(),
modifiers: valid_modifiers.to_vec().into(),
}
};
self.dcx().emit_err(InvalidAsmTemplateModifierRegClass {
placeholder_span,
op_span: op_sp,
modifier: modifier.to_string(),
sub,
});
let sub = if valid_modifiers.is_empty() {
InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier {
class_name: class.name(),
}
} else {
InvalidAsmTemplateModifierRegClassSub::SupportModifier {
class_name: class.name(),
modifiers: valid_modifiers.to_vec().into(),
}
};
self.dcx().emit_err(InvalidAsmTemplateModifierRegClass {
placeholder_span,
op_span: op_sp,
modifier: modifier.to_string(),
sub,
});
}
}
}
hir::InlineAsmOperand::Const { .. } => {
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_ast_lowering/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ pub(crate) enum InvalidAsmTemplateModifierRegClassSub {
SupportModifier { class_name: Symbol, modifiers: DiagSymbolList<char> },
#[note("the `{$class_name}` register class does not support template modifiers")]
DoesNotSupportModifier { class_name: Symbol },

/// Enabling a feature is needed to use the requested modifier.
#[note(
"the `{$class_name}` register class only supports the following template modifiers on stable: {$stable_modifiers}"
)]
#[note("enabling the `{$feature}` feature will allow using: {$all_modifiers}")]
ModifierIsGated {
class_name: Symbol,
feature: Symbol,
stable_modifiers: DiagSymbolList<char>,
all_modifiers: DiagSymbolList<char>,
},
}

#[derive(Diagnostic)]
Expand Down
21 changes: 9 additions & 12 deletions compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::fmt::Write;

use hir::HirId;
use hir::def_id::DefId;
use hir::{HirId, ItemKind};
use rustc_ast::join_path_idents;
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level};
use rustc_hir as hir;
use rustc_hir::{self as hir, Node};
use rustc_hir::attrs::lang_items::LangItem;
use rustc_lint::{ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER};
use rustc_lint_defs::builtin::{RUST_2021_PRELUDE_COLLISIONS, RUST_2024_PRELUDE_COLLISIONS};
Expand Down Expand Up @@ -436,12 +436,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let import_items: Vec<_> = applicable_trait
.import_ids
.iter()
.map(|&import_id| self.tcx.hir_expect_item(import_id))
.map(|&import_id| match self.tcx.hir_node_by_def_id(import_id) {
Node::NestedUseTree(tree) => *tree,
Node::Item(it) => it.expect_use(),
node => span_bug!(span, "expected use tree, found {node:#?}"),
})
.collect();

// Find an identifier with which this trait was imported (note that `_` doesn't count).
for item in import_items.iter() {
match item.expect_use().kind {
match item.kind {
hir::UseKind::Single(ident) => {
if ident.name != kw::Underscore {
return Some(format!("{}", ident.name));
Expand All @@ -454,14 +458,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// All that is left is `_`! We need to use the full path. It doesn't matter which one we
// pick, so just take the first one.
match import_items[0].kind {
ItemKind::Use(tree) => {
Some(join_path_idents(tree.prefix.segments.iter().map(|seg| seg.ident)))
}
_ => {
span_bug!(span, "unexpected item kind, expected a use: {:?}", import_items[0].kind);
}
}
Some(join_path_idents(import_items[0].prefix.segments.iter().map(|seg| seg.ident)))
}

/// Creates a string version of the `expr` that includes explicit adjustments.
Expand Down
15 changes: 13 additions & 2 deletions compiler/rustc_target/src/asm/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ def_reg_class! {
}

impl AArch64InlineAsmRegClass {
pub fn valid_modifiers(self, _arch: super::InlineAsmArch) -> &'static [char] {
pub fn valid_modifiers(
self,
_arch: super::InlineAsmArch,
allow_experimental_reg: bool,
) -> &'static [char] {
match self {
Self::reg => &['w', 'x'],
Self::vreg | Self::vreg_low16 => &['b', 'h', 's', 'd', 'q', 'v', 'z'],
Self::vreg | Self::vreg_low16 => {
if allow_experimental_reg {
&['b', 'h', 's', 'd', 'q', 'v', 'z']
} else {
&['b', 'h', 's', 'd', 'q', 'v']
}
}

Self::preg | Self::ffr => &[],
}
}
Expand Down
14 changes: 10 additions & 4 deletions compiler/rustc_target/src/asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,13 +711,19 @@ impl InlineAsmRegClass {
})
}

/// Returns the list of template modifiers that can be used with this
/// register class.
pub fn valid_modifiers(self, arch: InlineAsmArch) -> &'static [char] {
/// Returns the list of template modifiers that can be used with this register class, as well as
/// whether the `asm_experimental_reg` feature is enabled: there can be template modifiers that
/// apply to currently unstable registers, and we don't want to make these modifiers usable
/// without the feature gate.
pub fn valid_modifiers(
self,
arch: InlineAsmArch,
allow_experimental_reg: bool,
) -> &'static [char] {
match self {
Self::X86(r) => r.valid_modifiers(arch),
Self::Arm(r) => r.valid_modifiers(arch),
Self::AArch64(r) => r.valid_modifiers(arch),
Self::AArch64(r) => r.valid_modifiers(arch, allow_experimental_reg),
Self::Amdgpu(r) => r.valid_modifiers(arch),
Self::RiscV(r) => r.valid_modifiers(arch),
Self::Nvptx(r) => r.valid_modifiers(arch),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,9 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("a", Stable, &["zaamo", "zalrsc"]),
("b", Stable, &["zba", "zbb", "zbs"]),
("c", Stable, &["zca"]),
("d", Stable, &["f"]),
("e", Unstable(sym::riscv_target_feature), &[]), // negative feature! needs special care.
("f", Stable, &["zicsr"]),
("d", Unstable(sym::riscv_target_feature), &["f"]),
("e", Unstable(sym::riscv_target_feature), &[]),
("f", Unstable(sym::riscv_target_feature), &["zicsr"]),
(
"forced-atomics",
// Not implied by any CPU model or other feature.
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3219,7 +3219,7 @@ fn clean_use_statement<'tcx>(
for (tree, hir_id, def_id) in items {
let mut segments = path.segments.to_vec();
segments.extend(tree.prefix.segments.iter());
if segments.last().unwrap().ident.name == kw::SelfLower {
if segments.last().is_some_and(|seg| seg.ident.name == kw::SelfLower) {
segments.pop();
}
let path = hir::UsePath {
Expand Down
20 changes: 14 additions & 6 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ pub(crate) struct RunnableDocTest<'a> {
/// In a standalone test this is just the regular test code.
full_test_code: String,
full_test_line_offset: usize,
test_opts: &'a IndividualTestOptions,
test_opts: IndividualTestOptions,
global_opts: &'a GlobalTestOptions,
langstr: LangString,
line: usize,
Expand Down Expand Up @@ -1151,8 +1151,6 @@ fn generate_test_desc_and_fn(
unused_externs: Arc<Mutex<Vec<UnusedExterns>>>,
) -> test::TestDescAndFn {
let target_str = rustdoc_options.target.to_string();
let rustdoc_test_options =
IndividualTestOptions::new(&rustdoc_options, &test.test_id, scraped_test.path());

debug!("creating test {}: {}", scraped_test.name, scraped_test.text);
test::TestDescAndFn {
Expand All @@ -1177,8 +1175,13 @@ fn generate_test_desc_and_fn(
},
#[cfg(bootstrap)]
testfn: test::DynTestFn(Box::new(move || {
let rustdoc_test_options = IndividualTestOptions::new(
&rustdoc_options,
&test.test_id,
scraped_test.path(),
);
doctest_run_fn(
&rustdoc_test_options,
rustdoc_test_options,
&opts,
&test,
&scraped_test,
Expand All @@ -1188,8 +1191,13 @@ fn generate_test_desc_and_fn(
})),
#[cfg(not(bootstrap))]
testfn: test::DynTestFn(Arc::new(move || {
let rustdoc_test_options = IndividualTestOptions::new(
&rustdoc_options,
&test.test_id,
scraped_test.path(),
);
doctest_run_fn(
&rustdoc_test_options,
rustdoc_test_options,
&opts,
&test,
&scraped_test,
Expand All @@ -1201,7 +1209,7 @@ fn generate_test_desc_and_fn(
}

fn doctest_run_fn(
test_opts: &IndividualTestOptions,
test_opts: IndividualTestOptions,
global_opts: &GlobalTestOptions,
doctest: &DocTestBuilder,
scraped_test: &ScrapedDocTest,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ test::test_main(test_args, tests)
let runnable_test = RunnableDocTest {
full_test_code: format!("{code_prefix}{code}", code = self.output),
full_test_line_offset: 0,
test_opts: &test_options,
test_opts: test_options,
global_opts: opts,
langstr: LangString::default(),
line: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-project
Submodule llvm-project updated 63 files
+0 −6 clang/lib/Driver/ToolChains/OpenBSD.cpp
+0 −3 clang/lib/Driver/ToolChains/OpenBSD.h
+1 −1 clang/lib/Sema/SemaExprCXX.cpp
+12 −2 clang/test/Driver/openbsd.cpp
+15 −0 clang/test/SemaTemplate/concepts-lambda.cpp
+1 −1 cmake/Modules/LLVMVersion.cmake
+3 −3 flang/lib/Semantics/check-omp-loop.cpp
+5 −0 flang/lib/Semantics/check-omp-structure.cpp
+4 −4 flang/test/Lower/OpenMP/declare-simd.f90
+1 −0 flang/test/Semantics/OpenMP/cray-pointer-usage.f90
+2 −0 flang/test/Semantics/OpenMP/declarative-directive01.f90
+2 −1 flang/test/Semantics/OpenMP/declare-simd-empty.f90
+5 −1 flang/test/Semantics/OpenMP/declare-simd-interface-body.f90
+2 −0 flang/test/Semantics/OpenMP/declare-simd-uniform.f90
+5 −1 flang/test/Semantics/OpenMP/declare-simd.f90
+1 −0 flang/test/Semantics/OpenMP/future-directive-spellings.f90
+27 −1 flang/test/Semantics/OpenMP/linear-clause01.f90
+2 −0 flang/test/Semantics/OpenMP/linear-clause02.f90
+2 −1 flang/test/Semantics/OpenMP/linear-clause03.f90
+3 −2 flang/test/Semantics/OpenMP/simd-linear-array.f90
+1 −1 libcxx/include/__config
+8 −8 libcxx/utils/ci/buildkite-pipeline.yml
+52 −53 lldb/source/Host/openbsd/Host.cpp
+6 −0 llvm/docs/RISCVUsage.rst
+3 −0 llvm/include/llvm/HTTP/StreamedHTTPResponseHandler.h
+1 −1 llvm/include/llvm/Support/Allocator.h
+20 −3 llvm/include/llvm/Support/Caching.h
+6 −0 llvm/lib/CodeGen/CodeGenPrepare.cpp
+11 −7 llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+3 −1 llvm/lib/Debuginfod/Debuginfod.cpp
+6 −0 llvm/lib/HTTP/StreamedHTTPResponseHandler.cpp
+6 −0 llvm/lib/Support/Caching.cpp
+4 −0 llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+80 −40 llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+18 −0 llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
+7 −0 llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
+4 −3 llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
+1 −0 llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
+4 −16 llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+16 −11 llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+34 −2 llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+6 −2 llvm/lib/Transforms/Vectorize/VPlanUtils.h
+16 −0 llvm/test/CodeGen/AArch64/abdu.ll
+57 −0 llvm/test/CodeGen/AArch64/neon-abd.ll
+25 −0 llvm/test/CodeGen/ARM/abdu.ll
+407 −118 llvm/test/CodeGen/LoongArch/lsx/ir-instruction/sitofp.ll
+8 −7 llvm/test/CodeGen/RISCV/saverestore-scs.ll
+136 −0 llvm/test/CodeGen/RISCV/shadow-stack-frame-opts-v.ll
+2,837 −0 llvm/test/CodeGen/RISCV/shadow-stack-frame-opts.ll
+102 −0 llvm/test/CodeGen/X86/abdu-vector-128.ll
+36 −0 llvm/test/CodeGen/X86/abdu.ll
+73 −0 llvm/test/Transforms/CodeGenPrepare/X86/optimize-ext-uses-nneg.ll
+107 −0 llvm/test/Transforms/LoopUnroll/scev-invalidation-lcssa.ll
+66 −0 llvm/test/Transforms/LoopVectorize/AArch64/vector-call-linear-args-no-wide-iv.ll
+167 −0 llvm/test/Transforms/LoopVectorize/VPlan/vplan-narrow-iv-users.ll
+36 −0 llvm/test/Transforms/TailCallElim/accum_recursion.ll
+33 −0 llvm/test/tools/llvm-debuginfod-find/Inputs/partial_response.py
+15 −0 llvm/test/tools/llvm-debuginfod-find/partial-response.test
+41 −0 llvm/unittests/Support/Caching.cpp
+1 −1 llvm/utils/gn/secondary/llvm/version.gni
+1 −1 llvm/utils/lit/lit/__init__.py
+1 −1 llvm/utils/mlgo-utils/mlgo/__init__.py
+7 −0 mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
59 changes: 0 additions & 59 deletions src/tools/rustfmt/src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,65 +423,6 @@ macro_rules! create_config {
)+
}

/// Reduces the maximum width of the configuration.
///
/// This method is intended to be used when creating a forked
/// configuration for a particular formatting context in which the
/// total available width needs to be reduced. This reduces the
/// size of max_width, and all other properties affected by small
/// heuristics, without treating those adjustments as overrides.
///
/// As an example use case, this method is used when formatting
/// arms within a declarative macro.
#[allow(unreachable_pub)]
pub fn reduce_max_width(&mut self, delta: usize) {
self.adjust_max_width(-(delta.min(isize::MAX as usize) as isize));
}

/// Increases the maximum width of the configuration.
///
/// This method is intended to be used when creating a forked
/// configuration for a particular formatting context in which the
/// total available width needs to be increased. This increases the
/// size of max_width, and all other properties affected by small
/// heuristics, without treating those adjustments as overrides.
///
/// As an example use case, this method is used when formatting
/// arms within a declarative macro.
#[allow(unreachable_pub)]
pub fn increase_max_width(&mut self, delta: usize) {
self.adjust_max_width(delta.min(isize::MAX as usize) as isize);
}

/// Adjusts the maximum width of the configuration.
///
/// This method is intended to be used when creating a forked
/// configuration for a particular formatting context in which the
/// total available width needs to be reduced. This adjusts the
/// size of max_width, and all other properties affected by small
/// heuristics, without treating those adjustments as overrides.
///
/// As an example use case, this method is used when formatting
/// arms within a declarative macro.
fn adjust_max_width(&mut self, delta: isize) {
// NB: we need to either saturate or report an error (or some kind of testable
// warning). I picked to saturate here.
let adjust = |value: usize| value.saturating_add_signed(delta);

self.array_width.2 = adjust(self.array_width.2);
self.attr_fn_like_width.2 = adjust(self.attr_fn_like_width.2);
self.chain_width.2 = adjust(self.chain_width.2);
self.fn_call_width.2 = adjust(self.fn_call_width.2);
self.single_line_if_else_max_width.2 = adjust(self.single_line_if_else_max_width.2);
self.single_line_let_else_max_width.2 =
adjust(self.single_line_let_else_max_width.2);
self.struct_lit_width.2 = adjust(self.struct_lit_width.2);
self.struct_variant_width.2 = adjust(self.struct_variant_width.2);

self.max_width.2 = adjust(self.max_width.2);
self.set_heuristics();
}

fn set_width_heuristics(&mut self, heuristics: WidthHeuristics) {
let max_width = self.max_width.2;
let get_width_value = |
Expand Down
17 changes: 0 additions & 17 deletions src/tools/rustfmt/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,23 +701,6 @@ mod test {
assert_eq!(config.verbose(), Verbosity::Normal);
}

#[test]
fn test_adjust_max_width() {
// Regression tests for #7147, where we didn't handle overflows / integral cast outside of
// range properly.

// Reduce with huge amount saturates to zero instead of wraparound.
let mut config = Config::default();
config.reduce_max_width(usize::MAX);
assert_eq!(config.max_width(), 0);

// Increase with huge amount saturates instead of wraparound.
let mut config = Config::default();
config.set().max_width(usize::MAX - 1);
config.increase_max_width(2);
assert_eq!(config.max_width(), usize::MAX);
}

#[test]
fn test_config_used_to_toml() {
let config = Config::default();
Expand Down
6 changes: 4 additions & 2 deletions src/tools/rustfmt/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,13 +1361,15 @@ impl MacroBranch {
} else {
shape.indent.block_indent(&config)
};
config.reduce_max_width(body_indent.width());
let new_width = config.max_width() - body_indent.width();
config.set().max_width(new_width);

// First try to format as items, then as statements.
let new_body_snippet = match crate::format_snippet(&body_str, &config, true) {
Some(new_body) => new_body,
None => {
config.increase_max_width(config.tab_spaces());
let new_width = new_width + config.tab_spaces();
config.set().max_width(new_width);
match crate::format_code_block(&body_str, &config, true) {
Some(new_body) => new_body,
None => {
Expand Down
7 changes: 1 addition & 6 deletions src/tools/rustfmt/tests/target/issue-6651/custom_width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ macro_rules! medium {

macro_rules! long {
() => {
m!(
aaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbb,
cccccccccccccccc,
ddddddddddddddd
);
m!(aaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbb, cccccccccccccccc, ddddddddddddddd);
};
}
2 changes: 1 addition & 1 deletion tests/assembly-llvm/asm/aarch64-modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ compile-flags: -Zmerge-functions=disabled
//@ needs-llvm-components: aarch64

#![feature(no_core)]
#![feature(asm_experimental_reg, no_core)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register)]
Expand Down
Loading
Loading