2022-08-26 19:01:22 +02:00
|
|
|
use std::borrow::Cow;
|
2022-08-19 14:48:15 +01:00
|
|
|
use std::ffi::CString;
|
|
|
|
use std::path::Path;
|
2022-08-26 19:01:22 +02:00
|
|
|
|
2022-10-13 10:13:02 +01:00
|
|
|
use crate::fluent_generated as fluent;
|
2022-08-19 14:48:15 +01:00
|
|
|
use rustc_data_structures::small_c_str::SmallCStr;
|
2023-12-18 14:12:39 +11:00
|
|
|
use rustc_errors::{DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level};
|
2022-10-30 14:33:27 +01:00
|
|
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
2022-08-25 23:30:17 +02:00
|
|
|
use rustc_span::Span;
|
2022-08-25 15:34:30 +02:00
|
|
|
|
2022-10-30 19:26:12 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_unknown_ctarget_feature_prefix)]
|
|
|
|
#[note]
|
|
|
|
pub(crate) struct UnknownCTargetFeaturePrefix<'a> {
|
|
|
|
pub feature: &'a str,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_unknown_ctarget_feature)]
|
|
|
|
#[note]
|
|
|
|
pub(crate) struct UnknownCTargetFeature<'a> {
|
|
|
|
pub feature: &'a str,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub rust_feature: PossibleFeature<'a>,
|
|
|
|
}
|
|
|
|
|
2023-11-05 18:06:19 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_unstable_ctarget_feature)]
|
|
|
|
#[note]
|
|
|
|
pub(crate) struct UnstableCTargetFeature<'a> {
|
|
|
|
pub feature: &'a str,
|
|
|
|
}
|
|
|
|
|
2022-10-30 19:26:12 +01:00
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub(crate) enum PossibleFeature<'a> {
|
2022-10-13 10:13:02 +01:00
|
|
|
#[help(codegen_llvm_possible_feature)]
|
2022-10-30 19:26:12 +01:00
|
|
|
Some { rust_feature: &'a str },
|
2022-10-13 10:13:02 +01:00
|
|
|
#[help(codegen_llvm_consider_filing_feature_request)]
|
2022-10-30 19:26:12 +01:00
|
|
|
None,
|
2022-08-25 15:42:20 +02:00
|
|
|
}
|
2022-08-25 21:01:36 +02:00
|
|
|
|
2022-10-30 14:33:27 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_error_creating_import_library)]
|
2022-08-25 21:01:36 +02:00
|
|
|
pub(crate) struct ErrorCreatingImportLibrary<'a> {
|
|
|
|
pub lib_name: &'a str,
|
|
|
|
pub error: String,
|
|
|
|
}
|
2022-08-25 23:08:18 +02:00
|
|
|
|
2022-10-30 14:33:27 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_symbol_already_defined)]
|
2022-08-25 23:30:17 +02:00
|
|
|
pub(crate) struct SymbolAlreadyDefined<'a> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub symbol_name: &'a str,
|
|
|
|
}
|
2022-08-26 00:03:53 +02:00
|
|
|
|
2022-10-30 14:33:27 +01:00
|
|
|
#[derive(Diagnostic)]
|
2023-05-17 10:30:14 +00:00
|
|
|
#[diag(codegen_llvm_invalid_minimum_alignment_not_power_of_two)]
|
|
|
|
pub(crate) struct InvalidMinimumAlignmentNotPowerOfTwo {
|
|
|
|
pub align: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_invalid_minimum_alignment_too_large)]
|
|
|
|
pub(crate) struct InvalidMinimumAlignmentTooLarge {
|
|
|
|
pub align: u64,
|
2022-08-26 10:40:48 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 14:33:27 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_sanitizer_memtag_requires_mte)]
|
2022-08-26 12:19:10 +02:00
|
|
|
pub(crate) struct SanitizerMemtagRequiresMte;
|
2022-08-26 14:11:47 +02:00
|
|
|
|
2022-10-30 14:33:27 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_error_writing_def_file)]
|
2022-08-26 14:17:15 +02:00
|
|
|
pub(crate) struct ErrorWritingDEFFile {
|
|
|
|
pub error: std::io::Error,
|
|
|
|
}
|
2022-08-26 14:29:33 +02:00
|
|
|
|
2022-10-30 14:33:27 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_error_calling_dlltool)]
|
2023-03-27 10:42:22 -07:00
|
|
|
pub(crate) struct ErrorCallingDllTool<'a> {
|
|
|
|
pub dlltool_path: Cow<'a, str>,
|
2022-08-26 14:29:33 +02:00
|
|
|
pub error: std::io::Error,
|
|
|
|
}
|
2022-08-26 19:01:22 +02:00
|
|
|
|
2022-10-30 14:33:27 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_dlltool_fail_import_library)]
|
2022-08-26 19:01:22 +02:00
|
|
|
pub(crate) struct DlltoolFailImportLibrary<'a> {
|
2023-06-13 16:16:06 +00:00
|
|
|
pub dlltool_path: Cow<'a, str>,
|
|
|
|
pub dlltool_args: String,
|
2022-08-26 19:01:22 +02:00
|
|
|
pub stdout: Cow<'a, str>,
|
|
|
|
pub stderr: Cow<'a, str>,
|
|
|
|
}
|
2022-08-26 19:42:29 +02:00
|
|
|
|
2022-10-30 16:07:04 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_dynamic_linking_with_lto)]
|
|
|
|
#[note]
|
|
|
|
pub(crate) struct DynamicLinkingWithLTO;
|
|
|
|
|
2022-08-19 14:48:15 +01:00
|
|
|
pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
|
|
|
|
|
2023-12-18 14:12:39 +11:00
|
|
|
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
|
|
|
|
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
|
|
|
let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(dcx, level);
|
2023-12-20 17:12:17 +11:00
|
|
|
let (message, _) = diag.messages().first().expect("`LlvmError` with no message");
|
2023-12-18 10:15:45 +11:00
|
|
|
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args());
|
2022-08-19 14:48:15 +01:00
|
|
|
|
2024-01-03 16:00:29 +11:00
|
|
|
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
|
2024-01-09 09:08:49 +11:00
|
|
|
.with_arg("error", message)
|
2022-08-19 14:48:15 +01:00
|
|
|
}
|
2022-10-30 16:07:04 +01:00
|
|
|
}
|
|
|
|
|
2022-08-26 21:27:17 +02:00
|
|
|
pub(crate) struct TargetFeatureDisableOrEnable<'a> {
|
|
|
|
pub features: &'a [&'a str],
|
|
|
|
pub span: Option<Span>,
|
2022-10-30 19:26:12 +01:00
|
|
|
pub missing_features: Option<MissingFeatures>,
|
2022-08-26 21:27:17 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 14:33:27 +01:00
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[help(codegen_llvm_missing_features)]
|
2022-08-26 21:27:17 +02:00
|
|
|
pub(crate) struct MissingFeatures;
|
|
|
|
|
2023-12-18 14:12:39 +11:00
|
|
|
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
|
|
|
|
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
|
|
|
let mut diag = DiagnosticBuilder::new(
|
|
|
|
dcx,
|
|
|
|
level,
|
|
|
|
fluent::codegen_llvm_target_feature_disable_or_enable,
|
|
|
|
);
|
2022-10-30 19:26:12 +01:00
|
|
|
if let Some(span) = self.span {
|
2023-12-24 09:08:41 +11:00
|
|
|
diag.span(span);
|
2022-08-26 21:27:17 +02:00
|
|
|
};
|
2022-10-30 19:26:12 +01:00
|
|
|
if let Some(missing_features) = self.missing_features {
|
|
|
|
diag.subdiagnostic(missing_features);
|
|
|
|
}
|
2023-12-24 09:08:41 +11:00
|
|
|
diag.arg("features", self.features.join(", "));
|
2022-08-26 21:27:17 +02:00
|
|
|
diag
|
|
|
|
}
|
|
|
|
}
|
2022-08-19 14:48:15 +01:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_lto_disallowed)]
|
|
|
|
pub(crate) struct LtoDisallowed;
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_lto_dylib)]
|
|
|
|
pub(crate) struct LtoDylib;
|
|
|
|
|
2023-09-23 17:08:43 +03:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_lto_proc_macro)]
|
|
|
|
pub(crate) struct LtoProcMacro;
|
|
|
|
|
2022-08-19 14:48:15 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_lto_bitcode_from_rlib)]
|
|
|
|
pub(crate) struct LtoBitcodeFromRlib {
|
|
|
|
pub llvm_err: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
pub enum LlvmError<'a> {
|
|
|
|
#[diag(codegen_llvm_write_output)]
|
|
|
|
WriteOutput { path: &'a Path },
|
|
|
|
#[diag(codegen_llvm_target_machine)]
|
|
|
|
CreateTargetMachine { triple: SmallCStr },
|
|
|
|
#[diag(codegen_llvm_run_passes)]
|
|
|
|
RunLlvmPasses,
|
|
|
|
#[diag(codegen_llvm_serialize_module)]
|
|
|
|
SerializeModule { name: &'a str },
|
|
|
|
#[diag(codegen_llvm_write_ir)]
|
|
|
|
WriteIr { path: &'a Path },
|
|
|
|
#[diag(codegen_llvm_prepare_thin_lto_context)]
|
|
|
|
PrepareThinLtoContext,
|
|
|
|
#[diag(codegen_llvm_load_bitcode)]
|
|
|
|
LoadBitcode { name: CString },
|
|
|
|
#[diag(codegen_llvm_write_thinlto_key)]
|
|
|
|
WriteThinLtoKey { err: std::io::Error },
|
|
|
|
#[diag(codegen_llvm_multiple_source_dicompileunit)]
|
|
|
|
MultipleSourceDiCompileUnit,
|
|
|
|
#[diag(codegen_llvm_prepare_thin_lto_module)]
|
|
|
|
PrepareThinLtoModule,
|
|
|
|
#[diag(codegen_llvm_parse_bitcode)]
|
|
|
|
ParseBitcode,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String);
|
|
|
|
|
2023-12-04 08:46:50 +11:00
|
|
|
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for WithLlvmError<'_> {
|
2023-12-18 14:12:39 +11:00
|
|
|
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
2022-08-19 14:48:15 +01:00
|
|
|
use LlvmError::*;
|
|
|
|
let msg_with_llvm_err = match &self.0 {
|
|
|
|
WriteOutput { .. } => fluent::codegen_llvm_write_output_with_llvm_err,
|
|
|
|
CreateTargetMachine { .. } => fluent::codegen_llvm_target_machine_with_llvm_err,
|
|
|
|
RunLlvmPasses => fluent::codegen_llvm_run_passes_with_llvm_err,
|
|
|
|
SerializeModule { .. } => fluent::codegen_llvm_serialize_module_with_llvm_err,
|
|
|
|
WriteIr { .. } => fluent::codegen_llvm_write_ir_with_llvm_err,
|
|
|
|
PrepareThinLtoContext => fluent::codegen_llvm_prepare_thin_lto_context_with_llvm_err,
|
|
|
|
LoadBitcode { .. } => fluent::codegen_llvm_load_bitcode_with_llvm_err,
|
|
|
|
WriteThinLtoKey { .. } => fluent::codegen_llvm_write_thinlto_key_with_llvm_err,
|
|
|
|
MultipleSourceDiCompileUnit => {
|
|
|
|
fluent::codegen_llvm_multiple_source_dicompileunit_with_llvm_err
|
|
|
|
}
|
|
|
|
PrepareThinLtoModule => fluent::codegen_llvm_prepare_thin_lto_module_with_llvm_err,
|
|
|
|
ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err,
|
|
|
|
};
|
2024-01-03 16:00:29 +11:00
|
|
|
self.0
|
|
|
|
.into_diagnostic(dcx, level)
|
2024-01-09 09:08:49 +11:00
|
|
|
.with_primary_message(msg_with_llvm_err)
|
|
|
|
.with_arg("llvm_err", self.1)
|
2022-08-19 14:48:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_from_llvm_optimization_diag)]
|
|
|
|
pub(crate) struct FromLlvmOptimizationDiag<'a> {
|
|
|
|
pub filename: &'a str,
|
|
|
|
pub line: std::ffi::c_uint,
|
|
|
|
pub column: std::ffi::c_uint,
|
|
|
|
pub pass_name: &'a str,
|
2023-05-04 15:39:21 +02:00
|
|
|
pub kind: &'a str,
|
2022-08-19 14:48:15 +01:00
|
|
|
pub message: &'a str,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_from_llvm_diag)]
|
|
|
|
pub(crate) struct FromLlvmDiag {
|
|
|
|
pub message: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_write_bytecode)]
|
|
|
|
pub(crate) struct WriteBytecode<'a> {
|
|
|
|
pub path: &'a Path,
|
|
|
|
pub err: std::io::Error,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_copy_bitcode)]
|
|
|
|
pub(crate) struct CopyBitcode {
|
|
|
|
pub err: std::io::Error,
|
|
|
|
}
|
2023-07-12 17:07:34 -04:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_llvm_unknown_debuginfo_compression)]
|
|
|
|
pub struct UnknownCompression {
|
|
|
|
pub algorithm: &'static str,
|
|
|
|
}
|