about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/lib.rs
diff options
context:
space:
mode:
authorkhei4 <kk.asano.luxy@gmail.com>2023-07-19 17:00:06 +0900
committerkhei4 <kk.asano.luxy@gmail.com>2023-07-20 16:53:06 +0900
commitc7bf20dfdcbedbba05445035bcabd4f706ba9e42 (patch)
treef0fe6b48db91816d00cd54bd0428d1cfcc671eae /compiler/rustc_codegen_llvm/src/lib.rs
parent4d307c482271ea3575a13b6c04222911e7706189 (diff)
downloadrust-c7bf20dfdcbedbba05445035bcabd4f706ba9e42.tar.gz
rust-c7bf20dfdcbedbba05445035bcabd4f706ba9e42.zip
address feedback from nikic and oli-obk https://github.com/rust-lang/rust/pull/113723/files
use slice memcpy rather than strcpy and write it on stdout

use println on failure

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/lib.rs')
-rw-r--r--compiler/rustc_codegen_llvm/src/lib.rs31
1 files changed, 15 insertions, 16 deletions
diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs
index c03b2188824..b0354376210 100644
--- a/compiler/rustc_codegen_llvm/src/lib.rs
+++ b/compiler/rustc_codegen_llvm/src/lib.rs
@@ -46,6 +46,7 @@ use rustc_span::symbol::Symbol;
 
 use std::any::Any;
 use std::ffi::CStr;
+use std::io::Write;
 
 mod back {
     pub mod archive;
@@ -177,32 +178,30 @@ impl WriteBackendMethods for LlvmCodegenBackend {
     type ThinData = back::lto::ThinData;
     type ThinBuffer = back::lto::ThinBuffer;
     fn print_pass_timings(&self) {
-        let msg = unsafe {
-            let cstr = llvm::LLVMRustPrintPassTimings();
+        unsafe {
+            let mut size = 0;
+            let cstr = llvm::LLVMRustPrintPassTimings(&mut size as *mut usize);
             if cstr.is_null() {
-                "failed to get pass timings".into()
+                println!("failed to get pass timings");
             } else {
-                let timings = CStr::from_ptr(cstr).to_bytes();
-                let timings = String::from_utf8_lossy(timings).to_string();
+                let timings = std::slice::from_raw_parts(cstr as *const u8, size);
+                std::io::stdout().write_all(timings).unwrap();
                 libc::free(cstr as *mut _);
-                timings
             }
-        };
-        println!("{}", msg);
+        }
     }
     fn print_statistics(&self) {
-        let msg = unsafe {
-            let cstr = llvm::LLVMRustPrintStatistics();
+        unsafe {
+            let mut size = 0;
+            let cstr = llvm::LLVMRustPrintStatistics(&mut size as *mut usize);
             if cstr.is_null() {
-                "failed to get stats".into()
+                println!("failed to get pass stats");
             } else {
-                let stats = CStr::from_ptr(cstr).to_bytes();
-                let stats = String::from_utf8_lossy(stats).to_string();
+                let stats = std::slice::from_raw_parts(cstr as *const u8, size);
+                std::io::stdout().write_all(stats).unwrap();
                 libc::free(cstr as *mut _);
-                stats
             }
-        };
-        println!("{}", msg);
+        }
     }
     fn run_link(
         cgcx: &CodegenContext<Self>,