Skip to content

Commit

Permalink
Check if the pointer is null/string is not utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
as-com committed Jan 8, 2021
1 parent bc4c5ba commit 80ca198
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,25 @@ pub fn handle_native_features(sess: &Session) -> Vec<String> {
return vec![];
}

let ptr = unsafe { llvm::LLVMGetHostCPUFeatures() };
let str = unsafe { CStr::from_ptr(ptr).to_string_lossy() };

let features = str.split(",").map(|s| s.to_owned()).collect();

unsafe { llvm::LLVMDisposeMessage(ptr) };

features
let features_string = unsafe {
let ptr = llvm::LLVMGetHostCPUFeatures();
let features_string = if !ptr.is_null() {
CStr::from_ptr(ptr)
.to_str()
.unwrap_or_else(|e| {
bug!("LLVM returned a non-utf8 features string: {}", e);
})
.to_owned()
} else {
bug!("could not allocate host CPU features, LLVM returned a `null` string");
};

llvm::LLVMDisposeMessage(ptr);

features_string
};

features_string.split(",").map(|s| s.to_owned()).collect()
}
None => vec![],
}
Expand Down

0 comments on commit 80ca198

Please sign in to comment.