From b780fa9219c4c921e3334971a9e673e22cbea375 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Wed, 15 May 2024 10:01:55 +0200 Subject: [PATCH] Use an error struct instead of a panic --- compiler/rustc_codegen_llvm/messages.ftl | 2 ++ compiler/rustc_codegen_llvm/src/errors.rs | 6 +++++ compiler/rustc_codegen_llvm/src/llvm_util.rs | 9 ++++---- tests/ui/abi/fixed_x18.aarch64.stderr | 2 ++ tests/ui/abi/fixed_x18.arm.stderr | 2 ++ tests/ui/abi/fixed_x18.i686.stderr | 2 ++ tests/ui/abi/fixed_x18.riscv32.stderr | 2 ++ tests/ui/abi/fixed_x18.riscv64.stderr | 2 ++ tests/ui/abi/fixed_x18.rs | 23 ++++++++++++++++++++ tests/ui/abi/fixed_x18.x64.stderr | 2 ++ 10 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 tests/ui/abi/fixed_x18.aarch64.stderr create mode 100644 tests/ui/abi/fixed_x18.arm.stderr create mode 100644 tests/ui/abi/fixed_x18.i686.stderr create mode 100644 tests/ui/abi/fixed_x18.riscv32.stderr create mode 100644 tests/ui/abi/fixed_x18.riscv64.stderr create mode 100644 tests/ui/abi/fixed_x18.rs create mode 100644 tests/ui/abi/fixed_x18.x64.stderr diff --git a/compiler/rustc_codegen_llvm/messages.ftl b/compiler/rustc_codegen_llvm/messages.ftl index d14fe0299e6..1c126e79762 100644 --- a/compiler/rustc_codegen_llvm/messages.ftl +++ b/compiler/rustc_codegen_llvm/messages.ftl @@ -18,6 +18,8 @@ codegen_llvm_error_creating_import_library = codegen_llvm_error_writing_def_file = Error writing .DEF file: {$error} +codegen_llvm_fixed_x18_invalid_arch = the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture + codegen_llvm_from_llvm_diag = {$message} codegen_llvm_from_llvm_optimization_diag = {$filename}:{$line}:{$column} {$pass_name} ({$kind}): {$message} diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs index e15eda7c66c..9d83dc81163 100644 --- a/compiler/rustc_codegen_llvm/src/errors.rs +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -254,3 +254,9 @@ pub struct MismatchedDataLayout<'a> { pub(crate) struct InvalidTargetFeaturePrefix<'a> { pub feature: &'a str, } + +#[derive(Diagnostic)] +#[diag(codegen_llvm_fixed_x18_invalid_arch)] +pub(crate) struct FixedX18InvalidArch<'a> { + pub arch: &'a str, +} diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index b3359b81602..53b9b530e9b 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -1,6 +1,6 @@ use crate::back::write::create_informational_target_machine; use crate::errors::{ - InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable, + FixedX18InvalidArch, InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable, UnknownCTargetFeature, UnknownCTargetFeaturePrefix, UnstableCTargetFeature, }; use crate::llvm; @@ -618,11 +618,10 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec