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