rustc_codegen_llvm/
errors.rs1use std::ffi::CString;
2use std::path::Path;
3
4use rustc_data_structures::small_c_str::SmallCStr;
5use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level};
6use rustc_macros::Diagnostic;
7use rustc_span::Span;
8
9use crate::fluent_generated as fluent;
10
11#[derive(Diagnostic)]
12#[diag(codegen_llvm_symbol_already_defined)]
13pub(crate) struct SymbolAlreadyDefined<'a> {
14 #[primary_span]
15 pub span: Span,
16 pub symbol_name: &'a str,
17}
18
19#[derive(Diagnostic)]
20#[diag(codegen_llvm_sanitizer_memtag_requires_mte)]
21pub(crate) struct SanitizerMemtagRequiresMte;
22
23pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
24
25impl<G: EmissionGuarantee> Diagnostic<'_, G> for ParseTargetMachineConfig<'_> {
26 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
27 let diag: Diag<'_, G> = self.0.into_diag(dcx, level);
28 let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
29 let message = dcx.eagerly_translate_to_string(message.clone(), diag.args.iter());
30 Diag::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
31 .with_arg("error", message)
32 }
33}
34
35#[derive(Diagnostic)]
36#[diag(codegen_llvm_autodiff_without_lto)]
37pub(crate) struct AutoDiffWithoutLto;
38
39#[derive(Diagnostic)]
40#[diag(codegen_llvm_autodiff_without_enable)]
41pub(crate) struct AutoDiffWithoutEnable;
42
43#[derive(Diagnostic)]
44#[diag(codegen_llvm_lto_bitcode_from_rlib)]
45pub(crate) struct LtoBitcodeFromRlib {
46 pub err: String,
47}
48
49#[derive(Diagnostic)]
50pub enum LlvmError<'a> {
51 #[diag(codegen_llvm_write_output)]
52 WriteOutput { path: &'a Path },
53 #[diag(codegen_llvm_target_machine)]
54 CreateTargetMachine { triple: SmallCStr },
55 #[diag(codegen_llvm_run_passes)]
56 RunLlvmPasses,
57 #[diag(codegen_llvm_serialize_module)]
58 SerializeModule { name: &'a str },
59 #[diag(codegen_llvm_write_ir)]
60 WriteIr { path: &'a Path },
61 #[diag(codegen_llvm_prepare_thin_lto_context)]
62 PrepareThinLtoContext,
63 #[diag(codegen_llvm_load_bitcode)]
64 LoadBitcode { name: CString },
65 #[diag(codegen_llvm_write_thinlto_key)]
66 WriteThinLtoKey { err: std::io::Error },
67 #[diag(codegen_llvm_prepare_thin_lto_module)]
68 PrepareThinLtoModule,
69 #[diag(codegen_llvm_parse_bitcode)]
70 ParseBitcode,
71 #[diag(codegen_llvm_prepare_autodiff)]
72 PrepareAutoDiff { src: String, target: String, error: String },
73}
74
75pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String);
76
77impl<G: EmissionGuarantee> Diagnostic<'_, G> for WithLlvmError<'_> {
78 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
79 use LlvmError::*;
80 let msg_with_llvm_err = match &self.0 {
81 WriteOutput { .. } => fluent::codegen_llvm_write_output_with_llvm_err,
82 CreateTargetMachine { .. } => fluent::codegen_llvm_target_machine_with_llvm_err,
83 RunLlvmPasses => fluent::codegen_llvm_run_passes_with_llvm_err,
84 SerializeModule { .. } => fluent::codegen_llvm_serialize_module_with_llvm_err,
85 WriteIr { .. } => fluent::codegen_llvm_write_ir_with_llvm_err,
86 PrepareThinLtoContext => fluent::codegen_llvm_prepare_thin_lto_context_with_llvm_err,
87 LoadBitcode { .. } => fluent::codegen_llvm_load_bitcode_with_llvm_err,
88 WriteThinLtoKey { .. } => fluent::codegen_llvm_write_thinlto_key_with_llvm_err,
89 PrepareThinLtoModule => fluent::codegen_llvm_prepare_thin_lto_module_with_llvm_err,
90 ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err,
91 PrepareAutoDiff { .. } => fluent::codegen_llvm_prepare_autodiff_with_llvm_err,
92 };
93 self.0
94 .into_diag(dcx, level)
95 .with_primary_message(msg_with_llvm_err)
96 .with_arg("llvm_err", self.1)
97 }
98}
99
100#[derive(Diagnostic)]
101#[diag(codegen_llvm_from_llvm_optimization_diag)]
102pub(crate) struct FromLlvmOptimizationDiag<'a> {
103 pub filename: &'a str,
104 pub line: std::ffi::c_uint,
105 pub column: std::ffi::c_uint,
106 pub pass_name: &'a str,
107 pub kind: &'a str,
108 pub message: &'a str,
109}
110
111#[derive(Diagnostic)]
112#[diag(codegen_llvm_from_llvm_diag)]
113pub(crate) struct FromLlvmDiag {
114 pub message: String,
115}
116
117#[derive(Diagnostic)]
118#[diag(codegen_llvm_write_bytecode)]
119pub(crate) struct WriteBytecode<'a> {
120 pub path: &'a Path,
121 pub err: std::io::Error,
122}
123
124#[derive(Diagnostic)]
125#[diag(codegen_llvm_copy_bitcode)]
126pub(crate) struct CopyBitcode {
127 pub err: std::io::Error,
128}
129
130#[derive(Diagnostic)]
131#[diag(codegen_llvm_unknown_debuginfo_compression)]
132pub(crate) struct UnknownCompression {
133 pub algorithm: &'static str,
134}
135
136#[derive(Diagnostic)]
137#[diag(codegen_llvm_mismatch_data_layout)]
138pub(crate) struct MismatchedDataLayout<'a> {
139 pub rustc_target: &'a str,
140 pub rustc_layout: &'a str,
141 pub llvm_target: &'a str,
142 pub llvm_layout: &'a str,
143}
144
145#[derive(Diagnostic)]
146#[diag(codegen_llvm_fixed_x18_invalid_arch)]
147pub(crate) struct FixedX18InvalidArch<'a> {
148 pub arch: &'a str,
149}
150
151#[derive(Diagnostic)]
152#[diag(codegen_llvm_sanitizer_kcfi_arity_requires_llvm_21_0_0)]
153pub(crate) struct SanitizerKcfiArityRequiresLLVM2100;