]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_llvm/src/errors.rs
New upstream version 1.69.0+dfsg1
[rustc.git] / compiler / rustc_codegen_llvm / src / errors.rs
CommitLineData
487cf647 1use std::borrow::Cow;
9ffffee4
FG
2use std::ffi::CString;
3use std::path::Path;
4
5use crate::fluent_generated as fluent;
6use rustc_data_structures::small_c_str::SmallCStr;
7use rustc_errors::{
8 DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed, Handler, IntoDiagnostic,
9};
487cf647
FG
10use rustc_macros::{Diagnostic, Subdiagnostic};
11use rustc_span::Span;
12
13#[derive(Diagnostic)]
14#[diag(codegen_llvm_unknown_ctarget_feature_prefix)]
15#[note]
16pub(crate) struct UnknownCTargetFeaturePrefix<'a> {
17 pub feature: &'a str,
18}
19
20#[derive(Diagnostic)]
21#[diag(codegen_llvm_unknown_ctarget_feature)]
22#[note]
23pub(crate) struct UnknownCTargetFeature<'a> {
24 pub feature: &'a str,
25 #[subdiagnostic]
26 pub rust_feature: PossibleFeature<'a>,
27}
28
29#[derive(Subdiagnostic)]
30pub(crate) enum PossibleFeature<'a> {
9ffffee4 31 #[help(codegen_llvm_possible_feature)]
487cf647 32 Some { rust_feature: &'a str },
9ffffee4 33 #[help(codegen_llvm_consider_filing_feature_request)]
487cf647
FG
34 None,
35}
36
37#[derive(Diagnostic)]
38#[diag(codegen_llvm_error_creating_import_library)]
39pub(crate) struct ErrorCreatingImportLibrary<'a> {
40 pub lib_name: &'a str,
41 pub error: String,
42}
43
487cf647
FG
44#[derive(Diagnostic)]
45#[diag(codegen_llvm_symbol_already_defined)]
46pub(crate) struct SymbolAlreadyDefined<'a> {
47 #[primary_span]
48 pub span: Span,
49 pub symbol_name: &'a str,
50}
51
487cf647
FG
52#[derive(Diagnostic)]
53#[diag(codegen_llvm_invalid_minimum_alignment)]
54pub(crate) struct InvalidMinimumAlignment {
55 pub err: String,
56}
57
58#[derive(Diagnostic)]
59#[diag(codegen_llvm_sanitizer_memtag_requires_mte)]
60pub(crate) struct SanitizerMemtagRequiresMte;
61
62#[derive(Diagnostic)]
63#[diag(codegen_llvm_error_writing_def_file)]
64pub(crate) struct ErrorWritingDEFFile {
65 pub error: std::io::Error,
66}
67
68#[derive(Diagnostic)]
69#[diag(codegen_llvm_error_calling_dlltool)]
70pub(crate) struct ErrorCallingDllTool {
71 pub error: std::io::Error,
72}
73
74#[derive(Diagnostic)]
75#[diag(codegen_llvm_dlltool_fail_import_library)]
76pub(crate) struct DlltoolFailImportLibrary<'a> {
77 pub stdout: Cow<'a, str>,
78 pub stderr: Cow<'a, str>,
79}
80
81#[derive(Diagnostic)]
82#[diag(codegen_llvm_dynamic_linking_with_lto)]
83#[note]
84pub(crate) struct DynamicLinkingWithLTO;
85
9ffffee4
FG
86pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
87
88impl<EM: EmissionGuarantee> IntoDiagnostic<'_, EM> for ParseTargetMachineConfig<'_> {
89 fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, EM> {
90 let diag: DiagnosticBuilder<'_, EM> = self.0.into_diagnostic(sess);
91 let (message, _) = diag.styled_message().first().expect("`LlvmError` with no message");
92 let message = sess.eagerly_translate_to_string(message.clone(), diag.args());
93
94 let mut diag = sess.struct_diagnostic(fluent::codegen_llvm_parse_target_machine_config);
95 diag.set_arg("error", message);
96 diag
97 }
487cf647
FG
98}
99
100pub(crate) struct TargetFeatureDisableOrEnable<'a> {
101 pub features: &'a [&'a str],
102 pub span: Option<Span>,
103 pub missing_features: Option<MissingFeatures>,
104}
105
106#[derive(Subdiagnostic)]
107#[help(codegen_llvm_missing_features)]
108pub(crate) struct MissingFeatures;
109
110impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
111 fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
112 let mut diag = sess.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable);
113 if let Some(span) = self.span {
114 diag.set_span(span);
115 };
116 if let Some(missing_features) = self.missing_features {
117 diag.subdiagnostic(missing_features);
118 }
119 diag.set_arg("features", self.features.join(", "));
120 diag
121 }
122}
9ffffee4
FG
123
124#[derive(Diagnostic)]
125#[diag(codegen_llvm_lto_disallowed)]
126pub(crate) struct LtoDisallowed;
127
128#[derive(Diagnostic)]
129#[diag(codegen_llvm_lto_dylib)]
130pub(crate) struct LtoDylib;
131
132#[derive(Diagnostic)]
133#[diag(codegen_llvm_lto_bitcode_from_rlib)]
134pub(crate) struct LtoBitcodeFromRlib {
135 pub llvm_err: String,
136}
137
138#[derive(Diagnostic)]
139pub enum LlvmError<'a> {
140 #[diag(codegen_llvm_write_output)]
141 WriteOutput { path: &'a Path },
142 #[diag(codegen_llvm_target_machine)]
143 CreateTargetMachine { triple: SmallCStr },
144 #[diag(codegen_llvm_run_passes)]
145 RunLlvmPasses,
146 #[diag(codegen_llvm_serialize_module)]
147 SerializeModule { name: &'a str },
148 #[diag(codegen_llvm_write_ir)]
149 WriteIr { path: &'a Path },
150 #[diag(codegen_llvm_prepare_thin_lto_context)]
151 PrepareThinLtoContext,
152 #[diag(codegen_llvm_load_bitcode)]
153 LoadBitcode { name: CString },
154 #[diag(codegen_llvm_write_thinlto_key)]
155 WriteThinLtoKey { err: std::io::Error },
156 #[diag(codegen_llvm_multiple_source_dicompileunit)]
157 MultipleSourceDiCompileUnit,
158 #[diag(codegen_llvm_prepare_thin_lto_module)]
159 PrepareThinLtoModule,
160 #[diag(codegen_llvm_parse_bitcode)]
161 ParseBitcode,
162}
163
164pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String);
165
166impl<EM: EmissionGuarantee> IntoDiagnostic<'_, EM> for WithLlvmError<'_> {
167 fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, EM> {
168 use LlvmError::*;
169 let msg_with_llvm_err = match &self.0 {
170 WriteOutput { .. } => fluent::codegen_llvm_write_output_with_llvm_err,
171 CreateTargetMachine { .. } => fluent::codegen_llvm_target_machine_with_llvm_err,
172 RunLlvmPasses => fluent::codegen_llvm_run_passes_with_llvm_err,
173 SerializeModule { .. } => fluent::codegen_llvm_serialize_module_with_llvm_err,
174 WriteIr { .. } => fluent::codegen_llvm_write_ir_with_llvm_err,
175 PrepareThinLtoContext => fluent::codegen_llvm_prepare_thin_lto_context_with_llvm_err,
176 LoadBitcode { .. } => fluent::codegen_llvm_load_bitcode_with_llvm_err,
177 WriteThinLtoKey { .. } => fluent::codegen_llvm_write_thinlto_key_with_llvm_err,
178 MultipleSourceDiCompileUnit => {
179 fluent::codegen_llvm_multiple_source_dicompileunit_with_llvm_err
180 }
181 PrepareThinLtoModule => fluent::codegen_llvm_prepare_thin_lto_module_with_llvm_err,
182 ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err,
183 };
184 let mut diag = self.0.into_diagnostic(sess);
185 diag.set_primary_message(msg_with_llvm_err);
186 diag.set_arg("llvm_err", self.1);
187 diag
188 }
189}
190
191#[derive(Diagnostic)]
192#[diag(codegen_llvm_from_llvm_optimization_diag)]
193pub(crate) struct FromLlvmOptimizationDiag<'a> {
194 pub filename: &'a str,
195 pub line: std::ffi::c_uint,
196 pub column: std::ffi::c_uint,
197 pub pass_name: &'a str,
198 pub message: &'a str,
199}
200
201#[derive(Diagnostic)]
202#[diag(codegen_llvm_from_llvm_diag)]
203pub(crate) struct FromLlvmDiag {
204 pub message: String,
205}
206
207#[derive(Diagnostic)]
208#[diag(codegen_llvm_write_bytecode)]
209pub(crate) struct WriteBytecode<'a> {
210 pub path: &'a Path,
211 pub err: std::io::Error,
212}
213
214#[derive(Diagnostic)]
215#[diag(codegen_llvm_copy_bitcode)]
216pub(crate) struct CopyBitcode {
217 pub err: std::io::Error,
218}