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