about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRicho Healey <richo@psych0tik.net>2014-10-28 18:58:46 -0700
committerRicho Healey <richo@psych0tik.net>2014-10-29 13:49:32 -0700
commit89e8caadae53fb0429ee95a5f1e2c07b2adc2728 (patch)
tree75562bffcff8f8106ebbf10f2a133de17eb662d8
parente05c3b7799b45b78baf49f05763865be838f5b43 (diff)
downloadrust-89e8caadae53fb0429ee95a5f1e2c07b2adc2728.tar.gz
rust-89e8caadae53fb0429ee95a5f1e2c07b2adc2728.zip
rustc: fail if LLVM is passed an invalid triple
This changes create_target_machine to correctly return a Result (Since
the underlying LLVM function can fail and return NULL)
-rw-r--r--src/librustc/back/write.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/librustc/back/write.rs b/src/librustc/back/write.rs
index f1cd8b52e5e..825e1a328bd 100644
--- a/src/librustc/back/write.rs
+++ b/src/librustc/back/write.rs
@@ -226,12 +226,10 @@ fn create_target_machine(sess: &Session) -> TargetMachineRef {
         }
     };
 
-    unsafe {
-        sess.targ_cfg
-             .target_strs
-             .target_triple
-             .as_slice()
-             .with_c_str(|t| {
+    let triple = sess.targ_cfg.target_strs.target_triple.as_slice();
+
+    let tm = unsafe {
+            triple.with_c_str(|t| {
             sess.opts.cg.target_cpu.as_slice().with_c_str(|cpu| {
                 target_feature(sess).with_c_str(|features| {
                     llvm::LLVMRustCreateTargetMachine(
@@ -249,7 +247,15 @@ fn create_target_machine(sess: &Session) -> TargetMachineRef {
                 })
             })
         })
-    }
+    };
+
+    if tm.is_null() {
+        llvm_err(sess.diagnostic().handler(),
+                 format!("Could not create LLVM TargetMachine for triple: {}",
+                         triple).to_string());
+    } else {
+        return tm;
+    };
 }