File tree 1 file changed +19
-8
lines changed
compiler/rustc_codegen_llvm/src
1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -228,14 +228,25 @@ pub fn handle_native_features(sess: &Session) -> Vec<String> {
228
228
return vec ! [ ] ;
229
229
}
230
230
231
- let ptr = unsafe { llvm:: LLVMGetHostCPUFeatures ( ) } ;
232
- let str = unsafe { CStr :: from_ptr ( ptr) . to_string_lossy ( ) } ;
233
-
234
- let features = str. split ( "," ) . map ( |s| s. to_owned ( ) ) . collect ( ) ;
235
-
236
- unsafe { llvm:: LLVMDisposeMessage ( ptr) } ;
237
-
238
- features
231
+ let features_string = unsafe {
232
+ let ptr = llvm:: LLVMGetHostCPUFeatures ( ) ;
233
+ let features_string = if !ptr. is_null ( ) {
234
+ CStr :: from_ptr ( ptr)
235
+ . to_str ( )
236
+ . unwrap_or_else ( |e| {
237
+ bug ! ( "LLVM returned a non-utf8 features string: {}" , e) ;
238
+ } )
239
+ . to_owned ( )
240
+ } else {
241
+ bug ! ( "could not allocate host CPU features, LLVM returned a `null` string" ) ;
242
+ } ;
243
+
244
+ llvm:: LLVMDisposeMessage ( ptr) ;
245
+
246
+ features_string
247
+ } ;
248
+
249
+ features_string. split ( "," ) . map ( |s| s. to_owned ( ) ) . collect ( )
239
250
}
240
251
None => vec ! [ ] ,
241
252
}
You can’t perform that action at this time.
0 commit comments