mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
codegen_llvm_back: use Cow<'static, str> where applicable
This commit is contained in:
parent
1d1dc48407
commit
c4c39e9395
@ -282,10 +282,9 @@ impl<'a> ArchiveBuilder<'a> {
|
||||
let ret = if r.into_result().is_err() {
|
||||
let err = llvm::LLVMRustGetLastError();
|
||||
let msg = if err.is_null() {
|
||||
"failed to write archive".to_string()
|
||||
"failed to write archive".into()
|
||||
} else {
|
||||
String::from_utf8_lossy(CStr::from_ptr(err).to_bytes())
|
||||
.into_owned()
|
||||
};
|
||||
Err(io::Error::new(io::ErrorKind::Other, msg))
|
||||
} else {
|
||||
|
@ -106,39 +106,39 @@ pub struct DecodedBytecode<'a> {
|
||||
}
|
||||
|
||||
impl<'a> DecodedBytecode<'a> {
|
||||
pub fn new(data: &'a [u8]) -> Result<DecodedBytecode<'a>, String> {
|
||||
pub fn new(data: &'a [u8]) -> Result<DecodedBytecode<'a>, &'static str> {
|
||||
if !data.starts_with(RLIB_BYTECODE_OBJECT_MAGIC) {
|
||||
return Err("magic bytecode prefix not found".to_string())
|
||||
return Err("magic bytecode prefix not found")
|
||||
}
|
||||
let data = &data[RLIB_BYTECODE_OBJECT_MAGIC.len()..];
|
||||
if !data.starts_with(&[RLIB_BYTECODE_OBJECT_VERSION, 0, 0, 0]) {
|
||||
return Err("wrong version prefix found in bytecode".to_string())
|
||||
return Err("wrong version prefix found in bytecode")
|
||||
}
|
||||
let data = &data[4..];
|
||||
if data.len() < 4 {
|
||||
return Err("bytecode corrupted".to_string())
|
||||
return Err("bytecode corrupted")
|
||||
}
|
||||
let identifier_len = unsafe {
|
||||
u32::from_le(ptr::read_unaligned(data.as_ptr() as *const u32)) as usize
|
||||
};
|
||||
let data = &data[4..];
|
||||
if data.len() < identifier_len {
|
||||
return Err("bytecode corrupted".to_string())
|
||||
return Err("bytecode corrupted")
|
||||
}
|
||||
let identifier = match str::from_utf8(&data[..identifier_len]) {
|
||||
Ok(s) => s,
|
||||
Err(_) => return Err("bytecode corrupted".to_string())
|
||||
Err(_) => return Err("bytecode corrupted")
|
||||
};
|
||||
let data = &data[identifier_len..];
|
||||
if data.len() < 8 {
|
||||
return Err("bytecode corrupted".to_string())
|
||||
return Err("bytecode corrupted")
|
||||
}
|
||||
let bytecode_len = unsafe {
|
||||
u64::from_le(ptr::read_unaligned(data.as_ptr() as *const u64)) as usize
|
||||
};
|
||||
let data = &data[8..];
|
||||
if data.len() < bytecode_len {
|
||||
return Err("bytecode corrupted".to_string())
|
||||
return Err("bytecode corrupted")
|
||||
}
|
||||
let encoded_bytecode = &data[..bytecode_len];
|
||||
|
||||
|
@ -296,7 +296,7 @@ fn fat_lto(cgcx: &CodegenContext,
|
||||
let data = bc_decoded.data();
|
||||
linker.add(&data).map_err(|()| {
|
||||
let msg = format!("failed to load bc of {:?}", name);
|
||||
write::llvm_err(&diag_handler, msg)
|
||||
write::llvm_err(&diag_handler, &msg)
|
||||
})
|
||||
})?;
|
||||
timeline.record(&format!("link {:?}", name));
|
||||
@ -490,7 +490,7 @@ fn thin_lto(cgcx: &CodegenContext,
|
||||
symbol_white_list.as_ptr(),
|
||||
symbol_white_list.len() as u32,
|
||||
).ok_or_else(|| {
|
||||
write::llvm_err(&diag_handler, "failed to prepare thin LTO context".to_string())
|
||||
write::llvm_err(&diag_handler, "failed to prepare thin LTO context")
|
||||
})?;
|
||||
|
||||
info!("thin LTO data created");
|
||||
@ -746,7 +746,7 @@ impl ThinModule {
|
||||
{
|
||||
let diag_handler = cgcx.create_diag_handler();
|
||||
let tm = (cgcx.tm_factory)().map_err(|e| {
|
||||
write::llvm_err(&diag_handler, e)
|
||||
write::llvm_err(&diag_handler, &e)
|
||||
})?;
|
||||
|
||||
// Right now the implementation we've got only works over serialized
|
||||
@ -761,7 +761,7 @@ impl ThinModule {
|
||||
self.data().len(),
|
||||
self.shared.module_names[self.idx].as_ptr(),
|
||||
).ok_or_else(|| {
|
||||
let msg = "failed to parse bitcode for thin LTO module".to_string();
|
||||
let msg = "failed to parse bitcode for thin LTO module";
|
||||
write::llvm_err(&diag_handler, msg)
|
||||
})? as *const _;
|
||||
let module = ModuleCodegen {
|
||||
@ -785,7 +785,7 @@ impl ThinModule {
|
||||
let mut cu2 = ptr::null_mut();
|
||||
llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
|
||||
if !cu2.is_null() {
|
||||
let msg = "multiple source DICompileUnits found".to_string();
|
||||
let msg = "multiple source DICompileUnits found";
|
||||
return Err(write::llvm_err(&diag_handler, msg))
|
||||
}
|
||||
|
||||
@ -806,25 +806,25 @@ impl ThinModule {
|
||||
// You can find some more comments about these functions in the LLVM
|
||||
// bindings we've got (currently `PassWrapper.cpp`)
|
||||
if !llvm::LLVMRustPrepareThinLTORename(self.shared.data.0, llmod) {
|
||||
let msg = "failed to prepare thin LTO module".to_string();
|
||||
let msg = "failed to prepare thin LTO module";
|
||||
return Err(write::llvm_err(&diag_handler, msg))
|
||||
}
|
||||
cgcx.save_temp_bitcode(&module, "thin-lto-after-rename");
|
||||
timeline.record("rename");
|
||||
if !llvm::LLVMRustPrepareThinLTOResolveWeak(self.shared.data.0, llmod) {
|
||||
let msg = "failed to prepare thin LTO module".to_string();
|
||||
let msg = "failed to prepare thin LTO module";
|
||||
return Err(write::llvm_err(&diag_handler, msg))
|
||||
}
|
||||
cgcx.save_temp_bitcode(&module, "thin-lto-after-resolve");
|
||||
timeline.record("resolve");
|
||||
if !llvm::LLVMRustPrepareThinLTOInternalize(self.shared.data.0, llmod) {
|
||||
let msg = "failed to prepare thin LTO module".to_string();
|
||||
let msg = "failed to prepare thin LTO module";
|
||||
return Err(write::llvm_err(&diag_handler, msg))
|
||||
}
|
||||
cgcx.save_temp_bitcode(&module, "thin-lto-after-internalize");
|
||||
timeline.record("internalize");
|
||||
if !llvm::LLVMRustPrepareThinLTOImport(self.shared.data.0, llmod) {
|
||||
let msg = "failed to prepare thin LTO module".to_string();
|
||||
let msg = "failed to prepare thin LTO module";
|
||||
return Err(write::llvm_err(&diag_handler, msg))
|
||||
}
|
||||
cgcx.save_temp_bitcode(&module, "thin-lto-after-import");
|
||||
|
@ -90,7 +90,7 @@ pub const TLS_MODEL_ARGS : [(&'static str, llvm::ThreadLocalMode); 4] = [
|
||||
|
||||
const PRE_THIN_LTO_BC_EXT: &str = "pre-thin-lto.bc";
|
||||
|
||||
pub fn llvm_err(handler: &errors::Handler, msg: String) -> FatalError {
|
||||
pub fn llvm_err(handler: &errors::Handler, msg: &str) -> FatalError {
|
||||
match llvm::last_error() {
|
||||
Some(err) => handler.fatal(&format!("{}: {}", msg, err)),
|
||||
None => handler.fatal(&msg),
|
||||
@ -109,7 +109,7 @@ pub fn write_output_file(
|
||||
let result = llvm::LLVMRustWriteOutputFile(target, pm, m, output_c.as_ptr(), file_type);
|
||||
if result.into_result().is_err() {
|
||||
let msg = format!("could not write output to {}", output.display());
|
||||
Err(llvm_err(handler, msg))
|
||||
Err(llvm_err(handler, &msg))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
@ -139,7 +139,7 @@ pub fn create_target_machine(
|
||||
find_features: bool,
|
||||
) -> &'static mut llvm::TargetMachine {
|
||||
target_machine_factory(sess, find_features)().unwrap_or_else(|err| {
|
||||
llvm_err(sess.diagnostic(), err).raise()
|
||||
llvm_err(sess.diagnostic(), &err).raise()
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user