Skip to content

Commit 55af020

Browse files
committed
rustc_codegen_llvm: use safe references for Pass.
1 parent e954660 commit 55af020

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/librustc_codegen_llvm/back/lto.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ fn run_pass_manager(cgcx: &CodegenContext,
468468

469469
if config.verify_llvm_ir {
470470
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
471-
assert!(!pass.is_null());
472-
llvm::LLVMRustAddPass(pm, pass);
471+
llvm::LLVMRustAddPass(pm, pass.unwrap());
473472
}
474473

475474
// When optimizing for LTO we don't actually pass in `-O0`, but we force
@@ -503,8 +502,7 @@ fn run_pass_manager(cgcx: &CodegenContext,
503502

504503
if config.verify_llvm_ir {
505504
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
506-
assert!(!pass.is_null());
507-
llvm::LLVMRustAddPass(pm, pass);
505+
llvm::LLVMRustAddPass(pm, pass.unwrap());
508506
}
509507

510508
time_ext(cgcx.time_passes, None, "LTO passes", ||

src/librustc_codegen_llvm/back/write.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ unsafe fn optimize(cgcx: &CodegenContext,
522522
// manager.
523523
let addpass = |pass_name: &str| {
524524
let pass_name = CString::new(pass_name).unwrap();
525-
let pass = llvm::LLVMRustFindAndCreatePass(pass_name.as_ptr());
526-
if pass.is_null() {
527-
return false;
528-
}
525+
let pass = match llvm::LLVMRustFindAndCreatePass(pass_name.as_ptr()) {
526+
Some(pass) => pass,
527+
None => return false,
528+
};
529529
let pass_manager = match llvm::LLVMRustPassKind(pass) {
530530
llvm::PassKind::Function => fpm,
531531
llvm::PassKind::Module => mpm,

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ extern { pub type ObjectFile; }
397397
extern { pub type SectionIterator; }
398398
pub type SectionIteratorRef = *mut SectionIterator;
399399
extern { pub type Pass; }
400-
pub type PassRef = *mut Pass;
401400
extern { pub type TargetMachine; }
402401
pub type TargetMachineRef = *const TargetMachine;
403402
extern { pub type Archive; }
@@ -1414,9 +1413,9 @@ extern "C" {
14141413
pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&Value>;
14151414
pub fn LLVMIsAConstantFP(value_ref: &Value) -> Option<&Value>;
14161415

1417-
pub fn LLVMRustPassKind(Pass: PassRef) -> PassKind;
1418-
pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> PassRef;
1419-
pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: PassRef);
1416+
pub fn LLVMRustPassKind(Pass: &Pass) -> PassKind;
1417+
pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> Option<&'static mut Pass>;
1418+
pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: &'static mut Pass);
14201419

14211420
pub fn LLVMRustHasFeature(T: TargetMachineRef, s: *const c_char) -> bool;
14221421

0 commit comments

Comments
 (0)